Interrupts and delay()

I am uncertain whether interrupts can occur in other Arduino processors such as the Nano and Uno when the delay() function is controlling the chip.

According to the Arduino reference:
"Certain things do go on while the delay() function is controlling the Atmega chip however, because the delay function does not disable interrupts."

This specifically mentions the Atmega and not others such as the Nano and Uno .

Has anyone got further information on this?

On AVR based processors, delay() is like any other code. It can be interrupted, unless you specifically turn the interrupts off before calling the function.

A quirk of Arduino on AVR is that delay() is essentially ignored if the interrupts are off, because it depends on interrupts for the millis() tick. I don't know how that might work with other types of processors.

Interrupts are not disabled by delay(). Interrupts can happen during a delay() but delay() (millis()) will not increment during an interrupt as interrupts are disabled in an ISR (Interrupt Service Routine).

The chip in an Uno or a Nano is an atmega328.

Atmega is the controller chip. UNO, Nano etc. are boards using an Atmega chip.

Of course, the common mistake is in thinking you need to use interrupts. Using delay() is entirely inappropriate when you need to perform multiple tasks and there is a temptation to imagine that interrupts provide a means to do other things during the delay. This is foolish. :roll_eyes:

My project is an inside/outside temperature measurement. As I wanted to do a reading of a D18SB20 sensor for the indoors measurement, readings needed to be delayed a couple of minutes between readings to avoid sensor self heating effects. The outside temperature was conveyed using a 433MHz Tx/Rx pair with a RadioHead protocol which works well. This signal occurs non precisely approximately every 20 minutes.

However, I was initially worried that during the delay period a transmission would be missed. Further reading of the RadioHead documentation shows that it uses Timer1 to issue interrupts. Information from correspondents above have shown that interrupts can occur during the delay() statement and that was my chief concern.

So this concern has been solved thanks to all. Just a further query, when is it appropriate to use millis() as my understanding is that it can reach enormously large numbers before revering to zero and restarting?

If you read the DS18B20 asynchronous, then you don't have to wait for conversion (no delay).
It's all in the examples of the DS18B20.
Leo..

There is absolutely no need whatsoever to use interrupts whether timer1 or otherwise for such a project. That is just nonsense. :roll_eyes:

Just learn to program properly. Study the tutorials here. There is no problem with millis().

The RadioHead library (RH_ASK.h) protocol description includes the documentation below:

/// \par Timers
/// The RH_ASK driver uses a timer-driven interrupt to generate 8 interrupts per bit period. RH_ASK
/// takes over a timer on Arduino-like platforms. By default it takes over Timer 1. You can force it
/// to use Timer 2 instead by enabling the define RH_ASK_ARDUINO_USE_TIMER2 near the top of RH_ASK.cpp
/// On Arduino Zero it takes over timer TC3. On Arduino Due it takes over timer
/// TC0. On ESP8266, takes over timer0 (which conflicts with ServoTimer0).

Interrupts are integral to the operation and if you chose to use RadioHead then this "nonsense" cannot be avoided.

Yes, but that is already in the library and I presume only happens during the call your program makes to the library, so your own code has nothing to do with it.

To arrange your timing between readings and such, you just use the procedures described in the link I gave; you do not need to deal with interrupts.