Interrupts vs delay

I have a general question regarding interrupts. I guess I could check it myself creating a small project.
I know that it is not allowed to use delay command within ISR.
But what about the delay in main loop. Lets say I have a sketch in which I have e.g delay(5000); command.
What will happen if the interrupt triggering factor happens while there is that 5 s delay.
Will the interrupt kick in or will it be ignored?

You guessed right.

Interrupts will be serviced while you are wasting cycles in a delay,
and continue wasting cycles after the interrupt.

I do my best to avoid delay, but morbid curiosity makes me ask: if an ISR is triggered during a delay, will that extend the delay by the number of cycles used by the interrupt?

I am avoiding delays as well. But I want to undertsnd what happens in case you have program paused by delay

A proper ISR will have no effect on millis,
however, a bad ISR could do that or halt the whole system,
as there is only one level of interrupts available.

wouldn't say "wasting", there's just nothing to do. even large mainframes have an "idle" task for that purpose

since delay() is using micros(), it doesn't matter how long an interruption there is, delay will attempt to return when the specified period of time (ms) has expired

from wiring.c

void delay(unsigned long ms)
{
        uint32_t start = micros();

        while (ms > 0) {
                yield();
                while ( ms > 0 && (micros() - start) >= 1000) {
                        ms--;
                        start += 1000;
                }
        }
}

Besides handling the results of the ISR?

Sure there are places for delay, like primitive examples.

this sounds like the argument that there's not place for "gotos"

of course there's no place for delay() in a multitasking system that many of us are familiar, if not started with. but there's certainly a place for delay() in uni-task systems

What does the interrupt do? As you have discovered, there are limitations on what you can run inside an ISR, and if your main loop is not polling the ISR, you will wait the same 5 seconds for any response.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.