luni
Well-known member
TeensyTimerTool - Easy to use interface to the Teensy Timers
I just published TeensyTimerTool on GitHub https://github.com/luni64/TeensyTimerTool. The library provides an easy to use interface to the Teensy timers. Currently it works on the T4.0 and uses the GPT (2x) and QUAD (16x) timer modules/channels. Additionally it provides up to 20 software based timers with exactly the same interface. Extension to the PIT modules and the other boards is planned. All timers can be used in periodic and one-shot mode. You can either specify which hard/software timer you want to use; or -if you don't care- you can get the next free timer from a pool.
Here a quick example how to use a timer from the pool and set it up in one-shot mode:
If you want to use GPT1 instead, all you need to do is to replace the line
by
The gitHub readme contains more examples demonstrating the usage.
Callbacks
In addition to the usual pointer to void functions all timers accept non static member functions, lambdas, funktors etc. as callbacks. This makes it very easy to pass state to the member function or do classes which embed timers and callbacks. Examples here. If for some reason you prefer a plain vanilla function pointer interface you can configure the library accordingly.
Performance
I tried to optimize the performance as much as possible. Any further optimization input would be very welcome. Due to the high speed of the ARM core the performance of the software timers is pretty amazing and actually beats the hardware timers if you don't generate too much instances.
Status
The code base is quite new and probably contains bugs and improvement possibilities.
As always: Any feedback, bugreports and general rants are very welcome.
I just published TeensyTimerTool on GitHub https://github.com/luni64/TeensyTimerTool. The library provides an easy to use interface to the Teensy timers. Currently it works on the T4.0 and uses the GPT (2x) and QUAD (16x) timer modules/channels. Additionally it provides up to 20 software based timers with exactly the same interface. Extension to the PIT modules and the other boards is planned. All timers can be used in periodic and one-shot mode. You can either specify which hard/software timer you want to use; or -if you don't care- you can get the next free timer from a pool.
Here a quick example how to use a timer from the pool and set it up in one-shot mode:
C++:
#include "TeensyTimerTool.h"
using namespace TeensyTimerTool;
Timer t1;
void setup()
{
pinMode(LED_BUILTIN,OUTPUT);
t1.beginOneShot(callback);
}
void loop()
{
digitalWriteFast(LED_BUILTIN, HIGH);
t1.trigger(10'000); // trigger the timer with 10ms delay
delay(500);
}
void callback() // switch off LED
{
digitalWriteFast(LED_BUILTIN, LOW);
}
If you want to use GPT1 instead, all you need to do is to replace the line
Code:
Timer t1;
Code:
Timer t1(GPT1)
The gitHub readme contains more examples demonstrating the usage.
Callbacks
In addition to the usual pointer to void functions all timers accept non static member functions, lambdas, funktors etc. as callbacks. This makes it very easy to pass state to the member function or do classes which embed timers and callbacks. Examples here. If for some reason you prefer a plain vanilla function pointer interface you can configure the library accordingly.
Performance
I tried to optimize the performance as much as possible. Any further optimization input would be very welcome. Due to the high speed of the ARM core the performance of the software timers is pretty amazing and actually beats the hardware timers if you don't generate too much instances.
Status
The code base is quite new and probably contains bugs and improvement possibilities.
As always: Any feedback, bugreports and general rants are very welcome.
Last edited: