IntervalTimer usage

Status
Not open for further replies.

rbrockman

Active member
I see that with Teensyduino 1.14, IntervalTimer is now integrated and supports the use of up to 4 timers. Thank you Paul!

A question on the proper usage of instantiating and using these IntervalTimer objects. I'd like to use 8-10 differently named IntervalTimer objects, but only 4 in use at a time. These timers provide very different functions, and giving them names associated with these functions would be very useful.

Option 1:
- instantiate all 10 objects. Manage these objects such that only 4 are in use at a time using TimerX.begin(), TimerX.end();


Option 2:
- instantiate and destroy IntervalTimer objects as needed. Not sure how to do this.


Any input would be very appreciated

Thanks!
 
Last edited:
Either way should work.

Only 4 can be active at a time. If you call mytimer.begin() while 4 are already running, it will return false and the function will not be called.

Someday I plan to also implement IntervalTimer using the 1ms system timer. So timers that are a multiple of 1000 us may eventually not consume any of the 4 PIT timers, allowing more than 4 total timers.

You might consider if elapsedMillis or elaspedMicros variables might work better for some or all of your timer needs? It does require checking the number (usually if greater than some threshold) and manually setting it back to zero or subtracting threshold, but the huge advantage is you can very easily share data without worrying about "volatile" and disabling interrupts when you want to access variables that are also used by the timer functions.
 
Status
Not open for further replies.
Back
Top