# Duration of an interrupt

Hi.

I have this "silly" question.

What will be the duration of an interrupt ?

For example: i have a sketch that as an interrupt that trigers to FALLING edge, inside the interrupt i have micros() function that measures the duration of the interrupt.

Should this duration will last till the next falling edge, or just while the interrupt is at low state?

Thanks.

serbar10: What will be the duration of an interrupt ?

For example: I have a sketch that has an interrupt that triggers on a FALLING edge. Inside the interrupt I call the micros() function that measures the duration of the interrupt.

Calling micros() does not measure any duration, it just gives you the current time. If you remember the time and do a subtraction you can get the time between interrupts which will be the time between FALLING edges.

``````volatile unsigned long Duration = 0;
void ISR() {
static unsigned long previousMicros = 0;
unsigned long currentMicros = micros();
Duration = currentMicros - previousMicros;
previousMicros = currentMicros;
}
``````

serbar10: What will be the duration of an interrupt ?

I think that the duration of an interrupt with 16 MHz Arduino boards can roughly be calculated as:

4 microseconds + execution time of the code within the interrupt handler

Should this duration will last till the next falling edge, or just while the interrupt is at low state?

Neither. The interrupt flag is cleared ready for the next time when the ISR is triggered. So, for a FALLING trigger the interrupt pin has to go LOW again to trigger the interrupt again once the ISR is finished. If, however, you were to use LOW as the interrupt trigger it would respond immediately on return from the ISR if the interrupt pin were still LOW at that time.

The ISR itself should be written so that it takes as short a time as possible to execute and must not include any code that depends on interrupts as they are disabled when the interrupt is triggered.