Hacker News new | ask | show | jobs
by jws 2275 days ago
You can't really bang bits like you can with carefully cycle counted code on something like an Arduino, but you can put all your bits into a good sized buffer and use DMA to push them out a stable, hardware clocked rate. You still have to be able ping pong your buffers fast enough and that isn't really guaranteed, but for large enough buffers can be made to work, mostly, probably, well… except when…

This technique doesn't work when you need to respond to inputs rapidly, but is fine for driving steppers. I see he appears to have gone with servos and encoders, so that would be a bit of a problem since there are inputs to be read.

2 comments

> put all your bits into a good sized buffer and use DMA to push them out

Sure, time-honored technique for audio. Very on the mark.

But it doesn't really fix the "latency is forever" problem. Buffer too much and your control will lag. Too little and buffers can bottom-out. Best is to over-spec the metal and then be the only code on it so you don't need to buffer at all.

(Worst is, you didn't get to spec the metal, and there's a whole OS full of someone else's Bright Ideas between you and that 200us-or-the-reactor-goes-blooie control loop. Good luck, you're gonna need it).

> you can put all your bits into a good sized buffer and use DMA to push them out a stable, hardware clocked rate.

Obviously; without buffering, glitch-free audio playback would be impossible. I made the assumption that when we're talking about timing on Linux, it's not about throwing buffers at a hardware clocked device.

Does libgpio or some other interface on Linux give you access to clocked DMA out of the box? Do the drivers on RPi support it?

All the gpio drivers I've worked with are just directly writing state to registers.

Yes, there are DMA driven gpio libraries.