Posts: 59
Joined: Tue Jan 17, 2012 3:48 pm

Jitter on pigpio's wave tables

Thu Mar 26, 2020 7:38 pm

I'm trying to generate DMX512 output via the Raspberry Pi's (currently a Raspberry Pi 4 Model B Rev 1.1 but I do have others) GPIOs using pigpiod and it's wave table functions (docs beginning at http://abyz.me.uk/rpi/pigpio/pdif2.html#wave_clear). The code that generates the wave table is here: https://github.com/kripton/ola_to_rpi_m ... t.cpp#L142

The idea came from this page: https://web.archive.org/web/20190307175 ... dmx512.cgi

In principle, everything is working. However, from time to time the fixtures (LED lights connected as receivers to the DMX512 signal generated by the Pi, there's a optocoupler and an RS-485 driver in between) are blinking/flickering from time to time. When the Pi is idle, there is no or very few flickering. When I SSH into the Pi via Wifi, open a text file in nano and scroll around, the flickering gets extreme.

Hooking up an oscilloscope and measuring the waveforms (screenshot attached), one can see that the timing is glitchy and the single bits (which should be exactly 4µs long each) are sometime shorter and sometimes longer.
Since the wavetables are (as far as I understand) generated by some piece of hardware (reading directly from memory and clocking the bits out), this should be independant of CPU usage. Thus, I assume that the glitches are either caused by something else using the same clock source and/or DMA channel and/or clock speed changes by either the CPU and/or the GPU.
However, I know that pigpio talks about clock sources (PWM and PCM) and DMA channels (0-~14). I've tried several solutions and none of them works reliably.

I am very fluent in configuring and compiling Linux kernels and I've tried several different configurations using both 4.19.108 and 5.4.something. The soundcard is completely disabled in the kernel and via config.txt but still I am unable to achieve a solid, jitter-free wave output.

I've tried looking into DeviceTrees (no experience so far) and tried to get some information about the Pi's hardware capabilities. However, I am unable to find suitable public documentation about the DMA and related hardware of the Pi.

On the Pi 1 B and the Pi 3 B+ it helped a lot to have NO HDMI connected when booting. However, even then the result was not 100% stable. On the Pi 4, HDMI/screen presence doesn't seem to make much of a difference

What I would like to know:
- Is it theoretically possible to have a jitter-free wavetable output at 250kBit/s on the GPIOs? Preparing them can take CPU time, that's fine but once it has started generating it, I need it jitter-free
- Is there any way (sysfs preferred) to know which DMA channels are available? Documentation about the DMA channels in general and their usage would also be nice
- Which DMA channel is currently used by which piece of hardware + driver?
- Basically the last two questions for clock sources (PWM/PCM)?
- Does removing drivers from the linux kernel's config even help me when the device tree is not altered?

Thank you for your help and looking forward to your comments!
DS1Z_QuickPrint_Combined.png (37.2 KiB) Viewed 119 times

Posts: 59
Joined: Tue Jan 17, 2012 3:48 pm

Re: Jitter on pigpio's wave tables

Thu Mar 26, 2020 8:00 pm

Oh, what I forgot since I also suspect clocks chaning their speeds: What is the best set of configuration options to make sure that all hardware parts (CPU, GPU, everything else) always runs at the same speed?
Currently I have in config.txt:

Code: Select all

and CPU frequency scaling disabled in my kernel config

User avatar
Posts: 14765
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Jitter on pigpio's wave tables

Thu Mar 26, 2020 9:19 pm

The most likely culprits are another sustained DMA transfer or anything else hitting the memory bus hard.

Are you running headless?

Posts: 59
Joined: Tue Jan 17, 2012 3:48 pm

Re: Jitter on pigpio's wave tables

Thu Mar 26, 2020 9:23 pm

The final plan is to NOT run headless, but for now it wouldn't be a problem.
I observed that on the Pi 1 and 3, having a screen attached at boot time makes a huge difference, on the 4 not so much.

I am running headless in the sense that no X server or wayland compositor is running, yes.

Would I be able to force "other DMA transfers" to use other methods to reduce the load on the memory bus?

Return to “Advanced users”