luni64 / TeensyTimerTool

Generic Interface to Teensy Timers
MIT License
82 stars 18 forks source link

Timer is not Accurate in 0.3.2 release #9

Closed iharshadec closed 3 years ago

iharshadec commented 3 years ago

@luni64 @lunOptics HW:- Teensy 4.0 I was using 0.1.10 Release till date and today I updated to 0.3.2 release. I see that my code is not working anymore. Here is the example that I was using earlier. I have this code working with correct timing on 0.1.10 Release + 600/528/150 Mhz

Instead of 10mSec I am gettting this function called at every 1.5uSec Approx. image

/********************************************************
 * Basic usage of the timer
 * 
 * Generates a timer from the timer pool and
 * starts it with a period of 250ms. 
 * The timer callback simply toggles the built in LED
 * 
 ********************************************************/

#include "TeensyTimerTool.h"

using namespace TeensyTimerTool;
PeriodicTimer t1(PIT);

void vStartTimer()
{
  t1.begin(callback, 10'000); //10mSec
}

void vStopTimer()
{
  t1.begin([] {}, 10'000); //10mSec  
}

void callback()
{
    digitalWriteFast(LED_BUILTIN, !digitalReadFast(LED_BUILTIN));    
}

void setup()
{
    pinMode(LED_BUILTIN,OUTPUT);   
    vStartTimer();
}

void loop()
{   
}
luni64 commented 3 years ago

Sorry for the delayed answer. I tested your code and it works nicely. image

Do you still have this issue?