tanshihaj
Posts: 9
Joined: Mon Jan 14, 2019 11:23 am

Issue with DMA + PWM signal generator

Wed Jul 21, 2021 8:33 pm

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 ~1MHz.

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

Image

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

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/1odpzloW (I'm just modified example from https://iosoft.blog/2020/05/25/raspberr ... ogramming/)

Where is the problem?

aBUGSworstnightmare
Posts: 3207
Joined: Tue Jun 30, 2015 1:35 pm

Re: Issue with DMA + PWM signal generator

Thu Jul 22, 2021 6:32 am

Trying to do a SW PWM on a system which has no real-time capability?

butchergg
Posts: 22
Joined: Sun Oct 28, 2012 6:14 pm

Re: Issue with DMA + PWM signal generator

Thu Jul 22, 2021 2:56 pm

aBUGSworstnightmare wrote:
Thu Jul 22, 2021 6:32 am
Trying to do a SW PWM on a system which has no real-time capability?
Well, the BCM2835 DMA-gated PWM capability does support close to microsecond-resolution in producing waveforms, it's just not well-socialized. The pigpio GPIO library for the RPi encapsulates it in it's waveform functions, and I'm using that successfully to modulate the NMRA DCC signal for model train control.

Link to the pigpio library: http://abyz.me.uk/rpi/pigpio/

Link to what appears to be a decent StackOverflow thread on how it works: https://stackoverflow.com/questions/504 ... a-dma-work

Return to “Interfacing (DSI, CSI, I2C, etc.)”