Has anyone gotten .setNextPeriod() or .setPeriod() working for the TeensyTimerTool?
I'm trying to change the period of a TCK64 (software) timer from within the timer callback function. My code compiles just fine when I use either of these functions but they don't do anything.
I can get the code to work if I use .begin(), but I am assuming that it is not a good idea to use .begin() within a callback function.
Here is my working code example with .begin() within a callback function.
Is the above code 'safe' to run since it seems to work?
The above code is just a simple example to demonstrate the issue I am having. The program I am using it in will be making use of the general technique to perform pre-calculated acceleration profiles for a motor. I don't want to use a motor library if I can help it because I am trying to 'roll my own' and hopefully learn something along the way.
I'm trying to change the period of a TCK64 (software) timer from within the timer callback function. My code compiles just fine when I use either of these functions but they don't do anything.
I can get the code to work if I use .begin(), but I am assuming that it is not a good idea to use .begin() within a callback function.
Here is my working code example with .begin() within a callback function.
Code:
#include "TeensyTimerTool.h"
using namespace TeensyTimerTool;
PeriodicTimer tmr(TCK64);
// ==============================================
void setup()
{
// put your setup code here, to run once:
pinMode(LED_BUILTIN, OUTPUT);
tmr.begin(callback, 500); // 50us timer (period is unimportant here, just starting it up)
}
// ==============================================
void callback() // two 1/4 second LED blinks alternating with two 1/2 second blinks
{
static uint32_t period[] = {250000, 250000, 250000, 250000, 500000, 500000, 500000, 500000};
static int x = 0;
digitalToggleFast(LED_BUILTIN);
tmr.begin(callback,period[x]);
++x;
if (x > 7)
x = 0;
}
// ==============================================
void loop()
{
}
// end of code
Is the above code 'safe' to run since it seems to work?
The above code is just a simple example to demonstrate the issue I am having. The program I am using it in will be making use of the general technique to perform pre-calculated acceleration profiles for a motor. I don't want to use a motor library if I can help it because I am trying to 'roll my own' and hopefully learn something along the way.