Skip to content

v0.4.1

Compare
Choose a tag to compare
@luni64 luni64 released this 07 Nov 10:00
· 40 commits to master since this release

New features:

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)
  • 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.