cancel
Showing results for 
Search instead for 
Did you mean: 

STM32G0: PWM Pulse + One-Pulse mode

jowakar122
Senior

jowakar122_1-1761976053182.pngjowakar122_0-1761976034066.png

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.

jowakar122_2-1761976295716.png

This is happening due to stopping and immediately starting PWM pulse. The transition is causing this glitch. 

1 REPLY 1
KnarfB
Super User

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