3 ms·
Is Arduino real-time? I.e. is a 6 millisecond delay guaranteed to actually be 6 milliseconds?
by jdelman 3y ago
Is Arduino real-time? I.e. is a 6 millisecond delay guaranteed to actually be 6 milliseconds?
- AYoung010 3y agoLargely, yes. Arduino code runs on bare metal, and delays simply block execution so they should be accurate with some constant overhead.
- mcpherrinm 3y agoThe 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.
- vvoid 3y agoYes, 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.
- chybby 3y agoThanks for the tip to turn off interrupts when working with precise timing!