v0.4.1
New features:
- Added a new 64bit timer (TCK_RTC) which is based on the built in real time clock instead of the cycle counter which is used for the other TCK timers. The TCK_RTC might be useful for applications where smaller drift of the RTC crystal is important. (e.g. https://forum.pjrc.com/threads/68062-Teensy-4-1-RTC-get-milliseconds-correctly)
Resolution of the timer is 1/32.678 kHz = 30,052µs
The example shows how to use this timer to print out the relative drift between the 32kHz RTC crystal the the main 24MHz crystal.
#include "TeensyTimerTool.h"
using namespace TeensyTimerTool;
PeriodicTimer t1(TCK_RTC);
constexpr uint32_t period = 500'000; //µs
void callback()
{
static uint32_t start = micros();
static uint32_t idx = 0;
uint32_t now = micros() - start;
uint32_t expected = idx++ * period;
int32_t delta = now - expected;
float drift = 1E6 * delta / expected; // ppm
Serial.printf("t: %d µs, rel. drift: %.2f ppm\n", now, drift);
}
void setup(){
t1.begin(callback, period);
}
void loop(){
}
-
Added setPeriod and setNextPeriod to the TCK, PIT, GPT and TMR timers.
- setPeriod tries to change the current period to a new value. This of course only works if the new period is longer than the old period or the
change request comes early enough in the current period. In case the change request comes 'too late' the current period will end, the
callback will be called and the next period has the correct period - setNextPeriod sets the new period after the current period. This never generates a wrong period in between (as can happen with setPeriod)
- setPeriod tries to change the current period to a new value. This of course only works if the new period is longer than the old period or the
-
Destructors should work correctly now. I.e. you can use the timers as local variables. Leaving the scope while the timer runs will gracefully stop it and release allocated hardware resources.
Misc
- Large restructuring of the code. This might have generated bugs. PLEASE report any unusual behavior in the issues section.