You can busyloop on the monotonically increasing microsecond counter. The micros() can do microsecond-accurate sleeps that way on some Arduinos that are performant enough.TooManyPixels wrote: ↑20 Oct 2023, 23:42I just quickly checked my Arduino program (which I haven't touched in over a month) and I think I see the problem...
It's accurate to 1 microsecond on Teensy 4.0. It's delightfully accurate when nothing is running in background.
Keep in mind that USB HID has processing overhead that can jitter that slightly, so remember to finish (and maybe flush USB packet-sending; something Teensy 4.0 supports an API call for) right after a busywait, so the next busywait isn't jittered by your Teensy's USB software stack, or slows down the USB, etc. Also, incoming packets may cause issues, so your busyloop needs to have interrupts enabled (to keep USB stack working), but they will generally jitter the busyloop exit by less than 10 microseconds.
Teensy 4.0 is an Arduino clone running a 600 Mhz ARM Cortex M7, and is easily capable of realtiming events to 1 microsecond in many situations if your code is written decent enough.
Many Arduino clones exist, but Teensy 4.0 is the most delightful realtime-accurate inexpensive "prefab out of box" one I've used recently.
It even supports 8000Hz USB.