tcottle
Well-known member
I'm in the process of converting over one of our products that use the impossible to get Teensy 3.2 to the more available Teensy 4.0. I've turned up a bug in the TimerOne library
I'm running on a Win10 laptop using Visual Studio 2022 (V 17.2.3) and the Visual Micro plugin (latest issue). Arduino 1.8.19 Teensyduino 1.56
Here is the minimum code that shows the issue:
On a Teensy 3.2 here is the output

and on a Teensy 4.0 here is the output. Note that the duty cycle is wrong and the timebase changed

and a secondary issue in the Teensy 3.2. The durations are 1/2 of what I expected. I expected a pulse train high for 0.1mS and low for 0.9mS. In my original 3.2 production code I just multiplied by 2 and moved on ...
I'm running on a Win10 laptop using Visual Studio 2022 (V 17.2.3) and the Visual Micro plugin (latest issue). Arduino 1.8.19 Teensyduino 1.56
Here is the minimum code that shows the issue:
Code:
#include <TimerOne.h>
volatile long offset = 100;
void setup()
{
pinMode(0, OUTPUT);
digitalWrite(0, LOW);
Timer1.initialize(1000); // 1mS
Timer1.attachInterrupt(Timer1_ISR);
Timer1.start();
}
void loop()
{
}
void Timer1_ISR(void) {
if (digitalRead(0) == LOW) {
digitalWrite(0, HIGH);
Timer1.initialize(offset);
}
else {
digitalWrite(0, LOW);
Timer1.initialize(1000 - offset);
}
Timer1.restart();
}
On a Teensy 3.2 here is the output

and on a Teensy 4.0 here is the output. Note that the duty cycle is wrong and the timebase changed

and a secondary issue in the Teensy 3.2. The durations are 1/2 of what I expected. I expected a pulse train high for 0.1mS and low for 0.9mS. In my original 3.2 production code I just multiplied by 2 and moved on ...

