News for hackers. Stuff that matters.
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?
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.

Re:Building a USB SNES Controller by AYoung010 on Friday January 19, 2024 @03:48PM (#39060918)
Largely, yes. Arduino code runs on bare metal, and delays simply block execution so they should be accurate with some constant overhead.
Re:Building a USB SNES Controller by vvoid on Friday January 19, 2024 @06:28PM (#39062836)
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.

Re:Building a USB SNES Controller by chybby on Friday January 19, 2024 @10:55PM (#39064504)
Thanks for the tip to turn off interrupts when working with precise timing!