Using interupts

I need to use an interrupt to catch a timed event. Now i'm timing this event which is the idea of using an interrupt but according to the reference the value of millis() does not increment when the interrupt goes into it's function. Does this mean that the counter actually stops or that the value returned by it is frozen when the interrupt goes off but the counter is still going in the background ? what about micros() ?

It also says that nothing can be returned by the interrupt function, so err what is the point of the interrupt ? I need to take the values of time on the first interrupt and then on the second and calculate the difference and i need that value to go on a display. How do i do anything useful with the interrupts function ?

millis() will not increment. micros() will, however sooner or later (if you hang around in the interrupt) it will become incorrect as it cannot process timer overflow interrupts.

The counter (hardware counter) does not stop.

... so err what is the point of the interrupt?

Either do something directly (eg. change an output pin), remember something (eg. the time from micros() or millis() ) in a volatile global variable, or set a global flag.

I need to take the values of time on the first interrupt and then on the second and calculate the difference and i need that value to go on a display. How do i do anything useful with the interrupts function ?

That's perfectly valid. (Except for the display part, normally you let the main loop do that).

You can do this two ways. The first, easy way is to attach your event to an external interrupt or pin change interrupt. Then when the interrupt fires, you simply record millis() and/or micros(), and flag that it happened. Your main program can then deal with differences between times and such.

There are accuracy issues with this method. Your times may be a little bit off depending on whether other interrupts or critical sections were happening, and what state the millis() and micros() code is in. Is it going to be a big issue if you are a few microseconds off?

The other, more accurate way is to use the analog compare input capture function. When your event fires, the time is captured for you. Your accuracy can be within one clock cycle. Then your ISR can more leisurely store off the time stamp for your main program to handle. Do you need accuracy close to a 16 millionth of a second?

Maybe the pulseIn() function will do?

Works on pulses from 10 microseconds to 3 minutes in length.

http://arduino.cc/en/Reference/PulseIn

TanHadron:
You can do this two ways. The first, easy way is to attach your event to an external interrupt or pin change interrupt. Then when the interrupt fires, you simply record millis() and/or micros(), and flag that it happened. Your main program can then deal with differences between times and such.

There are accuracy issues with this method. Your times may be a little bit off depending on whether other interrupts or critical sections were happening, and what state the millis() and micros() code is in. Is it going to be a big issue if you are a few microseconds off?

The other, more accurate way is to use the analog compare input capture function. When your event fires, the time is captured for you. Your accuracy can be within one clock cycle. Then your ISR can more leisurely store off the time stamp for your main program to handle. Do you need accuracy close to a 16 millionth of a second?

I only need millisecond accuracy so not a problem, so can I store a value in a variable from the interupt routine to use in my main program ?

so can I store a value in a variable from the interupt routine to use in my main program ?

That depends on what you mean by "from the interrupt routine". Other functions can not access variables that are local to the ISR. However, the ISR can access global variables, as can the rest of the functions. Just be sure that any variables that are used by the ISR and other functions are declared volatile.

And read my link above about critical sections.

Yep i'm going through it but wikll take me time to understand it all.

So from what I understand I can setup a volatile variable that the main program and functions/interrupt routines access and store data in. that would work, my interrupt fires, I check the time and store it in the voltatile variable, and somehow set some sort of flag (another variable ?) to tell the main program that the interrupt occurred so that when it gets to a determined point in the main program it does it's thing with the data and reset the "flag" variable, there will be a substantial amount of time between interrupts so no problem with any timings.

Yes, basically.

If the stored value from the interrupt will always be different than the initial or last value then you can use that fact to check on in your regular code.