2 ms·
There’s a semi-wellknown trick on the raspberry pi for performing high-bandwidth and high-precision (in time) operations on GPIO pins from userland, using the D
by wallacoloo 7y ago
There’s a semi-wellknown trick on the raspberry pi for performing high-bandwidth and high-precision (in time) operations on GPIO pins from userland, using the DMA engine. You keep an in-memory buffer of the next few milliseconds of bit patterns you want to write to the memory-mapped GPIOs and then just leave the DMA engine endlessly copying data from this (circular) buffer into the GPIOs. But crucially, you “pace” the DMA transfer by configuring it to alternate between copying a word to the GPIOs and copying a word to some other peripheral that you’ve clocked at a specific rate (e.g. the audio DAC, which won’t acknowledge each write until it’s converted the previous one). This lets you define the state of the GPIOs as an arbitrary waveform sampled at some frequency of your choosing, which is a crazy powerful tool for e.g. motor control (that’s what the Printipi 3D printer does) or bitbanging communication protocols, etc.
You can also flip it around and sample GPIOs at close to 1 MHz. Piscope is an example of that. Once you start pushing 1 MHz, jitter starts to become nontrivial as you’re saturating the bus or competing with other memory transfers.
So yes: a capable DMA controller can do some pretty mind-blowing things!
- makapuf 7y agoFyi, a simple microcontroller like stm32 which is like 3$ can push gpio at 25mhz reliably.
- wallacoloo 7y agoIt’s true. And with the newer multicore Pi’s, you could probably get similar results just by pinning a thread to one core and dedicating that core to managing your IO. There are a million ways to solve any problem. Perhaps the single biggest advantage of the DMA solution for something like pi-scope is that it means people who want to use the pi as a scope need only download a piece of software: no soldering or flashing of MCUs required. The initial setup is more beginner-friendly, with the drawback that contributing might be more intimidating because the software is doing more complex work.
- jacquesm 7y agoThat sounds like an excellent start for a wavetable based synthesizer.
- sitkack 7y agoReminds me of the ASICs in the Amiga.