Skip to main content
JWelk.1
Associate
Apr 14, 2020 1:09 PM UTC
Question

Hi, I need to stop a PWM sometimes and in these cases both the low and the high side Pin should be pulled to low. Is it possible to do that?

I am working with a STM32G474 and I want to use a PWM with 390kHz for a boost converter. I generate a PWM with the HRTIM WaveformOutputStart. Using WaveformOutputStop pulls the LPWM to low, but the HPWM remains on high.

This topic has been closed for replies.

6 replies

waclawek.jan
Super User
Apr 14, 2020 6:58 PM UTC

This is a recurring question with TIM, I don't have experience with HRTIM but one of the most straightforward solutions is to change the respective pins' mode in GPIO_MODER to Out.

JW

JWelk.1
JWelk.1Author
Associate
Apr 23, 2020 1:11 PM UTC

Thanks for your answer.

If I start the PWM in the main, it is working fine,. But if after a short delay I change the Pins mode to GPIO Output, the PWM isn't working anymore, although in that part nothing is changed. Any clues what I might be doing wrong?

int main(void)
{
 HAL_Init();
 SystemClock_Config();
 
 /* Initialize all configured peripherals */
 MX_GPIO_Init();
 MX_HRTIM1_Init();
 MX_DMA_Init();
 MX_ADC1_Init();
 
 //PWM Start
 HAL_HRTIM_WaveformOutputStart(&hhrtim1, HRTIM_OUTPUT_TB1 | HRTIM_OUTPUT_TB2 | HRTIM_OUTPUT_TC1 | HRTIM_OUTPUT_TC2 | HRTIM_OUTPUT_TE1 | HRTIM_OUTPUT_TE2);
 HAL_HRTIM_WaveformCounterStart(&hhrtim1, HRTIM_TIMERID_TIMER_B | HRTIM_TIMERID_TIMER_C | HRTIM_TIMERID_TIMER_E);
 
 tein_A1 = (uint32_t)(0.1*14000);
 HRTIM1->sTimerxRegs[HRTIM_TIMERINDEX_TIMER_B].CMP1xR=tein_A1;
 
HAL_Delay(5000);
tein_A1 = (uint32_t)(0.2*14000);
HRTIM1->sTimerxRegs[HRTIM_TIMERINDEX_TIMER_B].CMP1xR=tein_A1;
 
HAL_Delay(5000);
tein_Akku1=0;
if(tein_Akku1==0){
	GPIOA->MODER |= GPIO_MODER_MODER10_0;
	HAL_GPIO_WritePin(GPIOA, GPIO_PIN_10, GPIO_PIN_RESET);
 }
}

JWelk.1
JWelk.1Author
Associate
Apr 23, 2020 11:21 AM UTC

I found the Null Duty cycle exception in the reference Manual, but that isn't working either. Does anyone have an example Code where that is working?

waclawek.jan
Super User
Apr 23, 2020 1:51 PM UTC

> GPIOA->MODER |= GPIO_MODER_MODER10_0;

If that pin was previously AF (0b01) this puts it into Analog (0b11) instead of Out (0b01).

Also, if you don't have an infinite loop at the end of your program, it will go to .... well that exactly depends on your startup code.

JW

JWelk.1
JWelk.1Author
Associate
Apr 24, 2020 1:29 PM UTC

Thanks a lot! It works now and both outputs end up being Low.

If I want to Restart the PWM later, can I just use GPIO_MODER again or do I have to make some additional changes?

waclawek.jan
Super User
Apr 25, 2020 11:36 AM UTC

> can I just use GPIO_MODER again

Yes.

The timer keeps running so you might make the change somewhere in the middle of the cycle, be aware of that.

JW