Is the incrementing of the timer register(s) used by millis() and micros() paused during the execution of an ISR?
To check this I wrote a simple sketch to run on a Teensy 4.1
Output:
More outputs:
The behaviour is inconsistent on every reset.
What is causing this weird behaviour?
And, this did not answer my original question about whether or not the timers are paused during an ISR. Any answers would be very helpful.
To check this I wrote a simple sketch to run on a Teensy 4.1
Code:
IntervalTimer timer;
int interruptTimeTaken = 0;
void interrupt() {
int startTime = millis();
// useless calculations, takes ~500 ms to run
for (int i = 0; i < 1000; i++) {
for (int j = 0; j < 1000; j++) {
pow(i, j);
}
}
interruptTimeTaken = millis() - startTime;
}
void setup() {
// put your setup code here, to run once:
Serial.begin(250000);
Serial.println("starting");
timer.begin(interrupt, 1000000); // time period = 1 second
// measure time taken outside of the interrupt
int delayStartTime = millis();
delay(2000);
Serial.print("delay time taken: "); Serial.println(millis() - delayStartTime);
}
void loop() {
// put your main code here, to run repeatedly:
if (interruptTimeTaken != 0) {
Serial.print("interrupt time taken: "); Serial.println(interruptTimeTaken);
timer.end();
while (true) {}
}
}
Output:
More outputs:
The behaviour is inconsistent on every reset.
What is causing this weird behaviour?
And, this did not answer my original question about whether or not the timers are paused during an ISR. Any answers would be very helpful.