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. 

3 REPLIES 3
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

waclawek.jan
Super User

> 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

jowakar122
Senior

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.