Timing external interrupts

Hi,

I am very new to microprocessor programming and I need to take some timing information from a signal that switches between high and low. I am trying to use an interrupt and collect the time between the change but it saya in the reference that millis() will not work in the function for the ISR. Is there any other way I could get the timing info?

Thank you.

There's a patch available that addresses the problem (be sure to read through the messages and use the latest patch)...
http://code.google.com/p/arduino/issues/detail?id=187&can=1&q=millis

Alternatively, you can enable interrupts in your ISR then call millis. However, this could lead to bugs that are very difficult to fix.

I don't believe there's a problem with calling millis() in an interrupt routine.

I assume you're only calling it once - right?

There is a problem. Well, it depends on the accuracy needed. The hardware counter could overflow after interrupts are disabled but before millis is called. The returned value will be off by up to the rollover amount (I believe it's 1 millisecond). The proposed fix is to check for the overflow in millis (as well as handling the overflow in the ISR).

At least that's my understanding. :slight_smile:

There is a problem. Well, it depends on the accuracy needed. The hardware counter could overflow after interrupts are disabled but before millis is called. The returned value will be off by up to the rollover amount (I believe it's 1 millisecond)

Agreed that millis() won't update in an ISR but if you're only calling it once per pass through it's not a real issue in my mind.

but if you're only calling it once per pass through it's not a real issue in my mind

Ah! I get it! Apparently, I needed a quiet walk crazy run with the puppy to get my brain working.

So, when I wrote, "there is a problem", what I meant to write was, "there is NOT a problem so long as millis is called only once in the ISR". ;D