Re:Building a USB SNES Controller
by jdelman on Friday January 19, 2024 @03:23PM
(#39060585)
Is Arduino real-time? I.e. is a 6 millisecond delay guaranteed to actually be 6 milliseconds?
[ Parent
| on HN ]
Re:Building a USB SNES Controller
by mcpherrinm on Friday January 19, 2024 @03:49PM
(#39060936)
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.
Largely, yes. Arduino code runs on bare metal, and delays simply block execution so they should be accurate with some constant overhead.
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.