Hacker News new | ask | show | jobs
by jdelman 886 days ago
Is Arduino real-time? I.e. is a 6 millisecond delay guaranteed to actually be 6 milliseconds?
3 comments

The Arduino is a single-threaded microcontroller running a single code loop, plus interrupts.

delayMicroseconds is a busy-wait loop, so is relatively precise (to within a few instruction's execution time.

However, interrupts can happen during that sleep, and the time spent handling interrupts won't be accounted for properly.

It isn't a real real-time system, but for a project like this, it'll be good enough.

Yes, it is real time, but due to interrupts you have to manage critical sections with cli() and sei() and your time base is a 16.000 MHz crystal.

Most instructions for ATmega and ATtiny execute in 1 clock cycle so writing deterministic, time-critical code is straightforward.

Thanks for the tip to turn off interrupts when working with precise timing!
Largely, yes. Arduino code runs on bare metal, and delays simply block execution so they should be accurate with some constant overhead.