2025-03-05 12:50 PM - edited 2025-03-05 12:51 PM
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:
2025-03-05 3:27 PM
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.
2025-03-06 1:36 AM
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.
2025-03-06 6:24 AM
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.
2025-03-06 6:40 AM
I mean, why when the One Pulse Mode is on, it hardware stops the counter and the channel outputs a low level (as you can see on the screen) and does not remain at a high level. Even the HAL function works this way...
2025-03-06 7:01 AM - edited 2025-03-06 7:02 AM
When CNT=0 and the pin/channel are enabled, the output should be low, yes?
In upcounting one pulse mode, when update happens, CNT is set back to 0 and the counter stops.
2025-03-06 7:11 AM - edited 2025-03-06 7:13 AM
@TDK wrote:When CNT=0 and the pin/channel are enabled, the output should be low, yes?
yes
I need the output to remain at a high level after the timer stops, but why does it become low, because before the timer started, the output was at a high level.
2025-03-06 8:00 AM
Before the timer starts, the timer is not driving the pin. It's probably set as high impedance and is floating high due to whatever is on the board. You can examine the state of the registers at this point to determine exactly why.