Extent of Interrupt functions

Does anyone know how long an interrupt function can be before it is considered too long?

Example:

int pin = 13;
volatile int state = LOW;

void setup()
{
  pinMode(pin, OUTPUT);
  attachInterrupt(0, blink, CHANGE);
}

void loop()
{
  digitalWrite(pin, state);
}

void blink()
{
  state = !state;
}

What if I want to record a time in milliseconds and set a few other flags for different functions. How long could the blink function be before it is too long to be considered an interrupt function?

Has anyone tested this? (I'm at work and I don't have a board with me)

How long could the blink function be before it is too long to be considered an interrupt function?

The simple answer is that it needs to complete before another interrupt happens. Since there is no way of knowing what other interrupts might happen, such as serial data arriving or needing to be sent, the clock ticking, etc., there is no single "that's too long" answer. It also depends on how much you can afford to have the other interrupts wait to be processed.

Ok, that's understandable. Short and simple.

Thank you.

interrupts are used for recording events that can be (partial) missed when polling is used.

imho an interrupt function has 4 main purposes: 1) capture an event (e.g. pin high ) 2) put the data belonging to the event in a processing queue (minimal size is single byte) 3) optionally do some math or administration to make processing easier (e.g. collect single bits in a byte) 4) optionally prepare for next interrupt

You need to lookup interrupt handling in the datasheet for a lot more detail. The setup of the Arduinos turns off all other interrupt when an ISR is entered. However interrupts that occur while in the ISR are not lost!. One of each is "saved".

The effect of turning off all other interrupts is the worst, serial way stop working if you stay in the ISR to long and can even kill your program if you attempt a Serial.print() etc from within the ISR, delay() of course will not work and mills and micros can be thrown out.

So try and keep your ISR as short as possible. the max is 1 tick of the micros clock.

Mark