0

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?

4
  • 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
    Jul 4 at 15:12
  • No, it seems that pigpiod generates clean 10us pulses. Jul 4 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. Jul 4 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. Jul 4 at 18:33
0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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