Handling PWM Pulse Synchronization and Delays with STM32F411 Using DMA and Timers

I'm working with an STM32F411 board to generate a PWM signal using timers, PWM, and DMA. My goal is to output 16 pulses every 2 ms, with each pulse representing one bit. Each pulse has a period of approximately 3 microseconds, and the duty cycle varies. I'm using libopencm3 to manage the peripherals. To achieve this, I write to a 32-bit output capture/compare register (TIMx->CCRx) using a DMA transfer from a memory buffer containing 16 32-bit integers. The PWM signal stays HIGH as long as the timer's counter is less than the CCR register value, and then it goes LOW until the timer overflows. I actually have two questions to ask guys ; + What happens if the DMA transfer is not perfectly synchronized with the PWM output? For instance, if the first two CCR values are transferred during the first pulse period, is the second value discarded, or does the PWM peripheral store it for the second pulse? + How can I configure the PWM peripheral to output exactly 16 pulses, then set the line to LOW and wait until the next set of 16 pulses needs to be sent? Currently, I'm only able to continuously output pulses, but I'm struggling with implementing a delay between pulse trains. Any guidance on this would be most appreciated.
Solution:
Hello,if you are using DMA,you can stop all the DMA operations for the required halt time using xxxDMA_stop() and restart it later
Jump to solution
4 Replies
ZacckOsiemo
ZacckOsiemo2mo ago
Perhaps use the dma transfer complete interrupt to turn off the PWM?
ZacckOsiemo
ZacckOsiemo2mo ago
Also kinda seems like this could be solved without DMA at the cost of a bit more code complexity but better precision control. @Edison_ngunjiri thoughts?
Solution
Edison_ngunjiri
Edison_ngunjiri2mo ago
Hello,if you are using DMA,you can stop all the DMA operations for the required halt time using xxxDMA_stop() and restart it later
Sterling
Sterling2mo ago
Ohhh, okay @Edison_ngunjiri .. Will do that 🙏
Want results from more Discord servers?
Add your server