Sterling
Sterling
DIIDevHeads IoT Integration Server
Created by Sterling on 8/12/2024 in #firmware-and-baremetal
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.
6 replies