2025-10-31 10:54 PM
Above is the configuration of my Timer.
- To generate pulse, first I used HAL_TIM_OnePulse_Start but with that pulse was not generate.
- So I did this:
while(1)
{
HAL_TIM_PWM_Stop(&htim17, TIM_CHANNEL_1);
__HAL_TIM_SET_COUNTER(&htim17, 0);
HAL_TIM_PWM_Start(&htim17, TIM_CHANNEL_1);
HAL_Delay(100);
}- Pulse is generated but also getting a glitch pulse before the actual pulse.
This is happening due to stopping and immediately starting PWM pulse. The transition is causing this glitch.
2025-11-01 12:09 PM
HAL_TIM_PWM_Stop does too much. It will eventually disable the timer, i.e. the timer looses control over the pin.
Try instead switching the channel1 mode from PWM Mode 2 (0111) to 0100: Force inactive level - OC1REF is forced low or 0101: Force active level - OC1REF is forced high. This can be done easily at the register level and maybe the is a hal function for that.
hth
KnarfB
2025-11-02 11:44 PM
> To generate pulse, first I used HAL_TIM_OnePulse_Start but with that pulse was not generate
That's because what's called in Cube/HAL as OnePulse mode is *NOT* just generating one pulse using the OnePulse mode of the timer, but a more complex functionality where the target timer is to be started via its slave-mode controller in Trigger mode.
JW
2025-11-04 8:53 PM - edited 2025-11-04 8:54 PM
I uploaded the same code on the NUCLEO-G071RB and on my custom board which has STM32G071RB the same controller as the kit. I get prefect pulses on kit without any glitch before the actual pulse, whereas I get otherwise in my custom board.
The schematic of my custom board matches with the kit. After connecting pull-down register there were not glitches but it happens if the polarity are reversed.