millis() doesn't work in interrupt handler?

i have the following code in an interrupt handler and it appears to be working.

void increment_counter()
  thetime = millis();
  if (thetime - lastpulse >= 12) //this is my debounce check
    timediff = (thetime - lastpulse);
    lastpulse = thetime;

however i just read some info in the online reference for interrupts that said that millis() won’t work in an interrupt.

is this going to be a problem that blows up in my face some day or should i not worry about it if it appears to be working?

i also read that using an interrupt to get time between pulses is a bad idea. anybody have any comments on this one way or another?


Hi Jeff, millis() will not increment in an interrupt handler but I would think your code should be ok if the absolute accuracy of millis is not required elsewhere in your sketch… I think the reference to millis() and interrupts is based on the fact that the timer interrupt used for triggering the millis counter will be disabled while in another interrupt, but if the handler is quick (like yours) it should only slow down the millis timing by a tiny amount.

I would think that code in your handler shouldn’t be a problem as long a the interrupt that calls increment_counter does not occur too frequently.