Skip to main content
Visitor II
March 17, 2025
Question

Change Period/Pulse of HRTIM based SimplePWM

  • March 17, 2025
  • 1 reply
  • 515 views

Custom board, STM32H747 device, Simple PWM

 

Using the code generated by MX, and adding a call to HAL_HRTIM_SimplePWMStart, I can generate a nice simple PWM output signal. If I change the initial values for period/pulse, rebuild, and program to the device, I can see the changed output signal. Now I want to change the period and/or the pulse after it has started. I've tried this a few ways. one is:

 

 	// Update the period/pulse stored in the structs above...

 	__HAL_HRTIM_SETPERIOD(&hhrtim, HRTIM_TIMERINDEX_TIMER_A, g_TimeBaseCfg.Period);
 	__HAL_HRTIM_SETCOMPARE(&hhrtim, HRTIM_TIMERINDEX_TIMER_A, HRTIM_COMPAREUNIT_1, g_SimplePWMChannelCfg.Pulse);
 	HAL_HRTIM_SoftwareUpdate(&hhrtim, HRTIM_TIMERINDEX_TIMER_A);

 

I've also tried doing:

 	// Update the period/pulse stored in the structs above...

 	if (HAL_HRTIM_SimplePWMStop(&hhrtim, HRTIM_TIMERINDEX_TIMER_A, HRTIM_OUTPUT_TA1) != HAL_OK)
 	{
 		Error_Handler();
 	}

 	if (HAL_HRTIM_TimeBaseConfig(&hhrtim, HRTIM_TIMERINDEX_TIMER_A, &g_TimeBaseCfg) != HAL_OK)
 	{
 	 Error_Handler();
 	}
 	if (HAL_HRTIM_SimplePWMChannelConfig(&hhrtim, HRTIM_TIMERINDEX_TIMER_A, HRTIM_OUTPUT_TA1, &g_SimplePWMChannelCfg) != HAL_OK)
 	{
 	 Error_Handler();
 	}
 	if (HAL_HRTIM_SimplePWMStart(&hhrtim, HRTIM_TIMERINDEX_TIMER_A, HRTIM_OUTPUT_TA1) != HAL_OK)
 	{
 		Error_Handler();
 	}

 

Regardless of which method I try, the resulting output signal is still using the same period and pulse. Can any one name the one or hundred simple things I'm missing?

 

Thank you,

C-Coder

    This topic has been closed for replies.

    1 reply

    ST Employee
    March 19, 2025

    Hello, 

    Please consider using the Advanced configuration (instead of HAL_Simple), even if changing period/compare does not need additional action than you described above.

     

    Best regards.