TeensyTimerTool

Hello Luni,

Thank you for this quick fix. I just downloaded the last release (v0.1.10) and it compile without error. Unfortunately my last project which use Teensy 4.x is at it very beginning and, while I know I'll use TeensyTimerTool, I haven't any current code which use it.
Anyway, I tested the new release with a teensy 3.2 project and it operate very well.

Thank you,
Manu
 
@luni:
What is correct way if I want to stop timer for time being?

Code:
  myTimer.begin(TimerFunction,10'000); // 10ms
This used to init timer.

I tried this to stop this timer but not working out. what is correct way to stop this timer?
Code:
myTimer.end(); //Timer Ends here.
 
I have not played with this for awhile, but my guess would be to do: myTimer.stop();

Which is defined in baseTimer... But again just a guess.
 
Which is defined in baseTimer... But again just a guess.

Valid guess, but actually this currently is only implemented for the TCK timers. The others silently ignore it. I'm currently working on filling in some missing functionality... As a workaround you can meanwhile simply call begin with a nullpointer as callback. This will effectively stop the timer.
 
Valid guess, but actually this currently is only implemented for the TCK timers. The others silently ignore it. I'm currently working on filling in some missing functionality... As a workaround you can meanwhile simply call begin with a nullpointer as callback. This will effectively stop the timer.

Thanks luni,
Code:
myTimer.begin([]{int (*pfun) (void) = NULL;},10'000); // 10ms
worked out.
 
Yes that works, but your code is a bit complicated. You probably noticed that passing a nullptr as function argument compiles but doesn't work since the library catches this as error. So, instead of passing a nullptr you need to pass an empty function:

Code:
#include "TeensyTimerTool.h"
using namespace TeensyTimerTool;

void empty() {}  // empty function

PeriodicTimer t1;

void setup()
{
    pinMode(13, OUTPUT);

    t1.begin([] { digitalWriteFast(13, !digitalReadFast(13)); }, 75'000); //Blink
    delay(3000);
    t1.begin(empty, 50'000); //stop timer
}

void loop()
{
}

Or if you prefer lambdas you can define the empty function inline:

Code:
#include "TeensyTimerTool.h"
using namespace TeensyTimerTool;

PeriodicTimer t1;

void setup()
{
    pinMode(13, OUTPUT);

    t1.begin([] { digitalWriteFast(13, !digitalReadFast(13)); }, 75'000); //Blink
    delay(3000);
    t1.begin([]{}, 50'000); //stop timer
}

void loop(){}
 
Yes,
I tried with empty function as well. That code I shared also worked. Got it I think the one you suggested looks better.
 
@luni:
What is correct way if I want to stop timer for time being?
...

I just added the missing start/stop functionality for the TCK, TMR(QUAD), GPT and PIT timers to the TeensyTimerTool v0.1.11. See here for details and download https://github.com/luni64/TeensyTimerTool/releases

Quick usage example:
Code:
#include "TeensyTimerTool.h"
using namespace TeensyTimerTool;

PeriodicTimer t1;

void setup()
{
    while (!Serial) {}
    TeensyTimerTool::attachErrFunc(ErrorHandler(Serial)); // optional, print errors on Serial
    pinMode(13, OUTPUT);

    t1.begin([] { digitalToggleFast(13); }, 50'000); //Blink

    delay(2000);  // stop timer after 2s
    t1.stop();

    delay(2000);  // restart after 2s
    t1.start();
}

void loop()
{
}

Now working on a possibility to chain the TMR timers to get 16 / 32 / 48 and 64 bit wide timers.
 
IIRC you are using the FTM timers. Forgot to add them in v0.1.11, just pushed v0.1.12 which should work for the FTMs as well
 
Imcompatibility with ILI9341_T3

Hello Luni

I found an incompatibility between TeensyTimerTool and Paul's ILI9341_t3.

When one want to use both libraries in the same sketch, compiler can't complete and throw errors.

Here is a sample of code that illustrate this :

Code:
#include "SPI.h"
#include "ILI9341_t3.h"
#include "XPT2046_Touchscreen.h"
// #include "CAN_T3.h"
#include "TeensyTimerTool.h"
using namespace TeensyTimerTool;
#define RefreshScreenPeriod 100   // 100 millisecondes

PeriodicTimer AfficherInfo(TCK);


void timerRefreshScreen() {
  Serial.println("timer Tick");
}


void setup() {
  Serial.begin (115200);
  while ((!Serial) && (millis() < 750));
  AfficherInfo.begin(timerRefreshScreen, RefreshScreenPeriod * 1000);

}

void loop() {
  // put your main code here, to run repeatedly:

}

If you comment the "#include "ILI9341_t3.h" it compile. If not, it don't compile.

Thank you.
Manu
 
It looks like ILI9341_t3 defines a macro "swap" which clashes with standard c++ headers (<functional> in this case). You can work around by including the ILI9341_t3.h after TeensyTimerTool.h. I can not test if it really works but at least it compiles then.
 
I confirm that including TeensyTimerTool before other libraries work.

However, I think there is a bug with FTM timers and Teensy 3.2 (72Mhz - compile as Faster).
When I use this as a periodic timer for 100ms, the result is a timer around 57 to 60ms.

Using the exact same code, but with TCK timer give a robust 100ms without a miss or deviation.

I tested this with a simple

Code:
#include "TeensyTimerTool.h"
using namespace TeensyTimerTool;
#define RefreshScreenPeriod 100   // 100 millisecondes

PeriodicTimer AfficherInfo(FTM0);


void timerRefreshScreen() {
  Serial.println(millis());
}


void setup() {
  Serial.begin (115200);
  while ((!Serial) && (millis() < 750));
  AfficherInfo.begin(timerRefreshScreen, RefreshScreenPeriod * 1000);

}

void loop() {
  // put your main code here, to run repeatedly:

}
 
I confirm that including TeensyTimerTool before other libraries work.

Good, maybe the maintainers of the ILI lib are willing to fix the issue. On the other hand, the workaround is quite simple...

However, I think there is a bug with FTM timers and Teensy 3.2 (72Mhz - compile as Faster).
When I use this as a periodic timer for 100ms, the result is a timer around 57 to 60ms.

No, this is to be expected. The FTMs are 16bit timers and, at standard settings will overflow at about 56ms. TeensyTimerTool detects this, issues a warning and sets the period to the max possible value. You can either check the return value of "begin" or, more easy, activate the built in error handler by adding this line to your setup()

Code:
TeensyTimerTool::attachErrFunc(ErrorHandler(Serial));

The library will then print any error to Serial (or whichever stream object you pass to the ErrorHandler constructor). This is quite useful during development. Here the output of your sketch with activated error handler:

Code:
W-100: Period overflow, set to maximum
421
465
509
552
596
640
683
727
771
814
858

See here https://github.com/luni64/TeensyTimerTool/wiki/Error-Handling for a documentation of the error handling capabilities of the library.


If you need longer periods than the standard ~50ms you can change the prescaler of the FTM timer in the config file. See here https://github.com/luni64/TeensyTimerTool/wiki/Configuration for a documentation of this feature.
 
Back
Top