Search code examples
timerstm32pwmnucleomcu

stm32: PWM generator with 1/20 pulses


I'm struggeling on setting up a STM32-F429ZI MCU (Nucleo 144 board) to generate following PWM pattern: First channel with a variable frequency and 50% duty cycle - at least I've got this working - Second channel giving a pulse with each 20th pulse of channel 1. This is not primary a coding problem but a understanding problem of timer settings i guess (working with STM32CubeIDE). I would bet there is real simple solution... I Think there is no way to do this with only 1 timer? I'm pleased for any suggestion...

I already tried with TIM2 as clock source for TIM3 and 4 but couldn't manage to make them synchonize. For better illustration of what I want to do: enter image description here


Solution

  • I't not sure, if it could be done with two timer synchronization (the pitfall is variable frequency of the first timer). But you can use single timer+DMA to rewrite configuration of the second channel:

    1. Create in-memory array of 20 values, where one value enables the second channel and other 19 disables it
    2. Setup DMA to trigger on the timer update and to move data from the array to CCMRx (or CCRx) register. Of cource, DMA should be in circular mode