Issues with the timer Teensy 4.1

Hi,

I am try to run a 5mS Timer with the IntervalTimer.h in Teensy4.1
I am listening to serial port characters for begin/end timer.

#define testTimerInterval 5000 // Timer Interval for PID loop in microsceconds 100-100uS 1000 - 1mS 10000 - 10 mS 100000 - 100mS
void processSerial() {
if (Serial.available() > 0) {
char commandCharacter = Serial.read(); //we use characters (letters) for controlling the switch-case
switch (commandCharacter) //based on the command character, we decide what to do
{
case 's':
testTimer.end();
break;
case 'S
testTimer.begin(TimerLoop, testTimerInterval); // Timer interval in microseconds 100000 = 100 mS; 1000 = 1mS
break;
}

And my timerloop is given below:
void TimerLoop() {
Serial.println("Test");
}
The issue I am facing is that when I press the 'S' and 's' characters alternatively to start and stop the timers , the code gets hanged and Teensy gets restarted after a few tries.
I can I solve this issue?
 
Ideally a complete sketch when posted allows others to copy and run the sketch.
Are there other Serial.prints anywhere - that could be conflicting with the _ISR() TimerLoop() printing.

Also, when posting code use the " </> " icon on the toolbar to place the CODE for better readability where the indenting is preserved.

Not sure if others might see an obvious problem - also note that each USB 'send' includes a terminating character - and the processSerial() only reads a single character. If anything in the unshown code delays calls to that - the characters may be backing up.
 
Hi,
I was using a USB host communication in the timer which caused some delays resulting in the code hang. Increasing the timer interval seemed to resolve the issue. Thank you
 
Back
Top