Timer Library to work with Arduino DUE
To call a function handler every 1000 microseconds:
Timer3.attachInterrupt(handler).start(1000); // or: Timer3.attachInterrupt(handler).setPeriod(1000).start(); // or, to select witchever avaliable timer: Timer.getAvailable().attachInterrupt(handler).start(1000);
To call a function handler 10 times a second:
Timer3.attachInterrupt(handler).setFrequency(10).start();
In case you need to stop a timer, just do like this:
Timer3.stop();
And to continue running:
Timer3.start();
There are 9 Timer objects already instantied for you:
Timer0, Timer1, Timer2, Timer3, Timer4, Timer5, Timer6, Timer7 and Timer8.
- Prefer to use
Timer3,Timer4andTimer5since they have no connection to hardware pins.
Timer4.attatchInterrupt(handler).setFrequency(10).start(); // Is the same as: Timer4.attatchInterrupt(handler); Timer4.setFrequency(10); Timer4.start();
// To create a custom timer, refer to: DueTimer myTimer = DueTimer(0); // Creates a Timer 0 object. DueTimer myTimer = DueTimer(3); // Creates a Timer 3 object. DueTimer myTimer = DueTimer(t); // Creates a Timer t object. // Note: Maximum t allowed is 8, as there is only 9 timers [0..8];
Timer1.setHandler(handler1).start(10); Timer1.setHandler(handler2).start(10); DueTimer myTimer = DueTimer(1); myTimer.setHandler(handler3).start(20); // Will run only handle3, on Timer 1 (You are just overriding the callback)
Timer.getAvailable().attachInterrupt(callback1).start(10); // Start timer on first avaliable timer DueTimer::getAvailable().attachInterrupt(callback2).start(10); // Start timer on seccond avaliable timer // And so on...
getAvailable()- Get the first avaliable Timer.
attachInterrupt(void (*isr)())- Attach a interrupt (callback function) for the timer of the object.
detachInterrupt()- Detach current callback of timer.
start(long microseconds = -1)- Start the timer with an optional period parameter.
stop()- Stop the timer
setFrequency(long frequency)- Set the timer frequency
long getFrequency()- Get the timer frequency
setPeriod(long microseconds)- Set the timer period (in microseconds)
long getPeriod()- Get the timer period (in microseconds)
int timer- Stores the object timer id (to acces Timers struct array).
DueTimer(int _timer)- Instantiate a new DueTimer object for Timer _timer (NOTE: All objects are already instantied!).
static const Timer Timers[]- Stores all timers information
static void (*callbacks[])()- Stores all callbacks for all timers
1.2 (2013-30-03): Clock selection. Getters. getAvailable(). "AvaliableTimer" Example.1.1 (2013-30-03): Added Timer6, Timer7, Timer8 (TC2).1.0 (2013-30-03): Original release.
