8 years, 1 month ago.

Timer interrupt? Ticker? with variable period

Hello. I would like to ask: Is there something similar to compare functions of other microprocessors? (You put a value in a register, activate a timer and when the timer reaches that value something happen)

In other words I need to repeatedly call a function at a specific rate.

Use a ticker! you could say, yes- I thought so too. But there is no function to change the interval of the ticker dynamically right? I would have to attach and detach repeatedly and actually- can you even detach a ticker from inside the function it called??

Or use a Timeout... but then again can you reattach the timeout from inside the function it called??

Can someone please help me telling me how to implement what I am trying to do???

Thanks

Question relating to:

2 Answers

8 years, 1 month ago.

Yes, you can. If you change the period all the time, use a Timeout. If you use almost always the same interval, use a Ticker. You are allowed to change it from the function that is being called by the Timeout/Ticker. (Internally a Ticker is simply a Timeout which does exactly that, call itself again in its own function, before the user function is being called).

Accepted Answer

Thank you for your reply. So I am allowed to change it. How? By detaching and attaching it again?

Also I am reading something about "TimerEvent". Where can I find documentation about this? I searched the site but couldnt find anything...

posted by Cristian Fuentes 10 Mar 2016

Just attach it (again), then the new one is used iirc. Timerevents are only used internally in the mbed lib.

posted by Erik - 10 Mar 2016
8 years, 1 month ago.

Timeout is best approach for scheduling events in future as Erik said. For example;

Schedule event_1 for 30 seconds later. When event_1 occured immediately schedule event_2 25 seconds later. When event_2 occured, immediately schedule event_3 15 seconds later..... etc

I experienced that, attach the ticker again with different time parameter immediately after first event occur can cause some problems. Because, you always know and sure that timeout will end and won't be triggered again, but ticker isn't.