cancel
Showing results for 
Search instead for 
Did you mean: 

How do I generate 'N' PWM pulses on TIM2 CH4.

CStas
Associate

I have inherited a PCBA that needs to generate a fixed number of PWM pulses on TIM2 CH4.

I have successfully setup TIM1 as the Master (with repetition count = 0) and TIM4 as a Gated Slave.

TIM1 CH1 is generating 2kHz PWM indefinitely.

TIM2 CH4 is generating 1kHz PWM indefinitely.

If repetition count is non zero, the TIM2 CH4 PWM freq decreases.

Can I configure TIM1 such that it stops after '2N' cycles and therefore TIM2 stops after 'N' cycles?

3 REPLIES 3
S.Ma
Principal

Which STM32? On STM32F437, one timer would probably be good enough if one of the channel is fed by cyclic DMA to provide 2 pulses at 1kHz.

STM32F415. Is there an example of the above?

> Can I configure TIM1 such that it stops after '2N' cycles

Try to set TIM1_RCR to 2N, and use one-pulse mode, ie set TIM1_CR.OPM=1.

Note, that the RCR register is 8-bit, so that maximum N is 127.

JW