I want to generate some signal on GPIO pin on Raspberry PI Zero W using DMA control blocks and PWM to pace data. However I faced with some problems while trying to generate signal at ~10-50kHz.

When I configure timings to generate 10us high state followed by 10us low state in loop (basically looping DMA control blocks) I see following picture on GPIO pin output:

oscilloscope output

In general it generates 10us pulses but sometimes something goes wrong and DMA changes GPIO state with wrong timings. It looks like this "interrupts" happens periodically each ~115us (about 8.5kHz).

Here is minimal reproducible code that generates signal on GPIO pin 23 and compiles fine on Raspberry PI Zero W: https://www.codepile.net/pile/v2JJ8L2q (I'm just modified example from https://iosoft.blog/2020/05/25/raspberry-pi-dma-programming/)

What I'm doing wrong?

  • Do you get the same behaviour with pigpio? sudo pigpiod then G=23; pigs m $G w; BG=$((1<<G));pigs wvag $BG 0 10 0 $BG 10; pigs wvcre; pigs wvtxr 0
    – joan
    Commented Jul 4, 2021 at 15:12
  • No, it seems that pigpiod generates clean 10us pulses. Commented Jul 4, 2021 at 15:19
  • UPD: It seems that sometimes pigpiod also generates distorted waves, but I can't figure out what should I do to make correct waves again. Commented Jul 4, 2021 at 17:11
  • UPD2: This issues can cоme and go while pigpiod running. I've tried several power adapters and cables so I think that's not an power issue. Commented Jul 4, 2021 at 18:33

2 Answers 2


From my experience PWM (both soft and hard) on RPI is seriously affected - at least in Python. For simple LED dimmer, where I really want no flickering when LEDs are very low light, I had to go for pigpiod. Then the problem is much less visible - at least on LEDs. The only disadvantage of pigpiod is: it consumes the CPU (deamon). However, while doing the same dimmer on Pico (in micropython) I did not notice such behaviour.


The problem with using DMA to write to I/O pins is that they don't have a FIFO.

In theory DMA should produce a steady steam of transfers with precise timing, but in reality that isn't true; there are gaps, then a few back-to-back transfers to catch up. That is why the peripherals such as UART, SPI and SMI have FIFOs; they bridge the gaps so that the peripheral sees a steady stream of data.

If you want to generate precise timing, SMI is the best option, see this post

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.