Skip to main content
CStas
Associate
Feb 19, 2019 3:53 AM UTC
Question

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

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?

    This topic has been closed for replies.

    3 replies

    S.Ma
    Principal
    Feb 19, 2019 6:14 AM UTC

    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.

    CStas
    CStasAuthor
    Associate
    Feb 19, 2019 8:44 AM UTC

    STM32F415. Is there an example of the above?

    waclawek.jan
    Super User
    Feb 19, 2019 10:33 PM UTC

    > 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