Skip to main content
Visitor II
March 5, 2025
Question

STM32F072 PWM One pulse

  • March 5, 2025
  • 2 replies
  • 1061 views

Hello

Need help, need to set PWM in a one pulse mode, so that at start timer there would be a low level output for a time equal to value of CCRx, after compare the output would be change to a high level and would remain so after overflow and stopping the counter.

Now I use PWM Mode 2 and active high level (tried PWM Mode 1 and active low level), as a result, after the counter stops, the output goes to low level, as shown on the screenshot:

1.png

 

    This topic has been closed for replies.

    2 replies

    Super User
    March 5, 2025

    Set up the timer so the pulse is high when CNT = 0 and low when CNT >= 1 (so CCRx = 1), then adjust ARR for the length of pulse you want. You will have 1 count of delay before the pulse starts.

    peitAuthor
    Visitor II
    March 6, 2025

    Do I still need to set the channel as PWM mode for this?

     

    In fact, I can't understand why there is a high level before the start timer, and a low level after the counter overflow, i.e. the timer tries to form the next period, but it is stopped and the stop occurs when the output is at a low level.

    Super User
    March 6, 2025

    Yes it needs to be in PWM mode.

     

    > In fact, I can't understand why there is a high level before the start timer, and a low level after the counter overflow

    Probably because the pin/channel is not fully initialized yet. It gets initialized when you start the channel.

    Graduate II
    March 7, 2025

    So ensure that you have your IO Pin configured in Output Push-Pull for your application and not in Open Drain. 

    This is present in CubeIDE on your GPIO Settings for the Timers.

    The next thing, is to ensure that you have set the Idle State of the Timer you are using as "Set". And the Channel Polarity configured as "Low".

    If these settings are correct, inspect the alternate functions of the IO Pin you are using. It is likely that there might be a conflict of different peripherals on the IO Pin. Especially if you're using RTC or another Timer trigger inputs, ect. This depends on your application and obviously you didn't share this detail here. 

    Alternatively, use the debugger but ensure that you set the Debug Timer Freeze registers correctly to ensure that the timer actually stops when you interrupt the code. Inspect the content of the registers.