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