Skip to main content
Arduino

Return to Revisions

2 of 2
replaced http://arduino.stackexchange.com/ with https://arduino.stackexchange.com/

Using millis() and micros() inside an interrupt routine

The documentation for attachInterrupt() says:

... millis() relies on interrupts to count, so it will never increment inside an ISR. Since delay() requires interrupts to work, it will not work if called inside an ISR. micros() works initially, but will start behaving erratically after 1-2 ms. ...

How does micros() differ from millis() (except of course for their precision)? Does the above warning mean that using micros() inside an interrupt routine is always a bad idea?

Context - I want to measure low pulse occupancy, so I need to trigger my routine when my input signal changes and record the current time.

Petr
  • 253
  • 1
  • 2
  • 12

AltStyle によって変換されたページ (->オリジナル) /