I’m brainstorming an application where there could be several interrupts per second from two different sources (separate interrupts), each running a function that simply adds a number to a count. I need my void loop() to perform simple analysis with that data. I was wondering if the interrupts ran asynchronously while the main loop is running or if they stopped the main loop in the middle of its processing?
My main loop does require the millis() function to be working properly, which I know isn’t possible in an interrupt per the Arduino reference, and if the interrupts run synchronously I will have to look at other solutions.
I’m not sure what you mean that interrupts run synchronously or asynchronously.
When an interrupt occurs, the main program is stopped and the interrupt service routine (ISR) is executed in a mode where no new interrupts are recognized. Upon leaving the ISR the main program will be continued where it has been interrupted.
Real parallel execution is not possible on the Arduino, because the ATMega is a single-core CPU and can do only one thing at a time. But it can switch fast 🙂 Therefore:
As long as you don’t call
millis()inside the ISR this is OK because your ISR isand therefore very fast. This will not disturb
millis()enough to be noticed by anybody.