Skip to content

64 bit TCK Timer

Compare
Choose a tag to compare
@luni64 luni64 released this 02 Aug 13:19
· 90 commits to master since this release

The 32bit cycle counter (ARM_DWT_CYCCNT) which is used for the TCK timers overflows quite fast (e.g. every 7s on a T4@600MHz). I therefore added a variant of the TCK timers which extends ARM_DWT_CYCCNT to 64bit (v0.2.0). This allows for periods up to to full 2^32 microseconds (4295 seconds, 71.6 minutes). The new timer works on all T3.x and T4.x boards. I'll add the documentation to the TeensyTimerTool WIKI in the next days.

Here a small T4 sketch which prints out the overflow duration of the timers currently available with the TeensyTimerTool. The sketch was run in standard configuration, i.e., F_CPU=600MHz, GPT & PIT @24MHz, QUAD @150MHz with prescaler: PSC_AUTO.

#include "TeensyTimerTool.h"
using namespace TeensyTimerTool;

PeriodicTimer t1(TCK);
PeriodicTimer t2(TCK64);  // <-- new
PeriodicTimer t3(GPT1);
PeriodicTimer t4(TMR3);
PeriodicTimer t5(PIT);

PeriodicTimer blink(TCK);

void empty(){}

void setup()
{
    while (!Serial) {}

    t1.begin(empty, 1'000);
    t2.begin(empty, 1'000);
    t3.begin(empty, 1'000);
    t4.begin(empty, 1'000);
    t5.begin(empty, 1'000);

    Serial.printf("TCK:           %8.3f seconds\n", t1.getMaxPeriod());
    Serial.printf("TCK64:         %8.3f seconds\n", t2.getMaxPeriod());    // <-- new
    Serial.printf("GPT(@24MHz)    %8.3f seconds\n", t3.getMaxPeriod());
    Serial.printf("QUAD(PSC_AUTO) %8.3f seconds\n", t4.getMaxPeriod());
    Serial.printf("PIT(@24MHz)    %8.3f seconds\n", t5.getMaxPeriod());

    pinMode(LED_BUILTIN, OUTPUT);
    blink.begin([] { digitalToggle(LED_BUILTIN); }, 300'000); // heart beat
}

void loop()
{
}

And here the output

TCK:              6.711 seconds
TCK64:         4294.967 seconds
GPT(@24MHz)     178.957 seconds
QUAD(PSC_AUTO)    0.056 seconds
PIT(@24MHz)     178.957 seconds