Consider the following code. In a nut shell, one function launches the other on a timer, and the other then delays for some time and then cancels the timer. This is running on a Teensy 4.0
To make things easy to follow, each function toggles PinA, and PinB is set when the timer is started and then cleared by the other function soon after it is called by the timer (before the delay).
Below are two oscilloscope images.
When the timer is longer than the delay, everything is fine. In this example, the first time it is run the pulses are 10 usecs apart.
Now, if the delay is longer than the clock, the first time it is okay, but the second time the pulses are 4 usecs apart.
After that, no matter how the times are set., the pulses are always 4 usecs apart. In other words, the timer appears to be corrupted, and, it never recovers until the device is powered off or rebooted.
To make things easy to follow, each function toggles PinA, and PinB is set when the timer is started and then cleared by the other function soon after it is called by the timer (before the delay).
Below are two oscilloscope images.
When the timer is longer than the delay, everything is fine. In this example, the first time it is run the pulses are 10 usecs apart.
Now, if the delay is longer than the clock, the first time it is okay, but the second time the pulses are 4 usecs apart.
After that, no matter how the times are set., the pulses are always 4 usecs apart. In other words, the timer appears to be corrupted, and, it never recovers until the device is powered off or rebooted.
Code:
unsigned int u1 = 10;
unsigned int u2 = 1;
void testinner( ) {
digitalWriteFast(PinA, HIGH);
delayMicroseconds(1);
digitalWriteFast(PinA, LOW);
digitalWriteFast( PinB, LOW );
delayMicroseconds( u2);
shutterTimer.end( );
}
void testclock( ) {
digitalWriteFast(PinA, HIGH);
delayMicroseconds(1);
digitalWriteFast(PinA, LOW);
digitalWriteFast( PinB, HIGH );
shutterTimer.begin( testinner, u1 );
}