2022-07-29 05:26 AM
I am trying to use the HRTIM peripheral on the STM32Hh753VI as a PWM generator with variable duty cycle. I want to use Timer B1 on pin PC8.
Firstly, I tried using Simple HAL functions:
HAL_HRTIM_SimplePWMStart(&hhrtim, HRTIM_TIMERINDEX_TIMER_B, HRTIM_OUTPUT_TB1);
Indeed a PWM signal is seen on pin PC8. However, I am unable to change the duty cycle. The macro __HAL_HRTIM_SETCOMPARE has no effect.
__HAL_HRTIM_SETCOMPARE(&hhrtim, HRTIM_TIMERINDEX_TIMER_B, HRTIM_COMPAREUNIT_1, x);
The signal on the output does not change, regardless of the value I give. Looking at the compare register via the SRF view, I see that the compare value does change, but it does not have any effect on the output.
Secondly, I tried to use the Advanced/Waveform methods. However, in this case I get no output at all. I am following the BuckBoost example project for the STM32F3348 from STM32CubeF3. This is how I am attempting to start the output. However, the voltage stays at 0.
HAL_StatusTypeDef res1, res2, res3;
HRTIM_CompareCfgTypeDef compare_config;
compare_config.AutoDelayedMode = HRTIM_AUTODELAYEDMODE_REGULAR;
compare_config.AutoDelayedTimeout = 0;
compare_config.CompareValue = 0x1FFD;
res1 = HAL_HRTIM_WaveformCompareConfig(&hhrtim, HRTIM_TIMERINDEX_TIMER_B, HRTIM_COMPAREUNIT_1, &compare_config);
res2 = HAL_HRTIM_WaveformOutputStart(&hhrtim, HRTIM_OUTPUT_TB1);
res3 = HAL_HRTIM_WaveformCounterStart(&hhrtim, HRTIM_TIMERID_TIMER_B);
How can I:
OR
Kind regards,
Jim
2022-07-29 05:32 AM
Found it. In the .ioc file you have to add a Set Source and a Reset Source under the output configuration. As a source I selected "Timer period event forces the output to its active state". As a reset source I selected "Timer compare 1 event forces the output to its inactive state".
2023-01-30 04:04 AM
For anyone else who stumbles across this in future:
If you are using the Simple HAL functions, you need to call `HAL_HRTIM_SoftwareUpdate()` after you call `__HAL_HRTIM_SETCOMPARE()`.
For example:
// start the HRTIM PWM output
HAL_HRTIM_SimplePWMStart(&hhrtim1, HRTIM_TIMERINDEX_TIMER_A, HRTIM_OUTPUT_TA1);
uint32_t i = 0;
while(1)
{
// set the PWM duty cycle value (into a 'shadow register')
__HAL_HRTIM_SETCOMPARE(&hhrtim1, HRTIM_TIMERINDEX_TIMER_A, HRTIM_COMPAREUNIT_1, i++);
// copy the PWM duty cycle value from the 'shadow register' to the 'active register'
HAL_HRTIM_SoftwareUpdate(&hhrtim1, HRTIM_TIMERUPDATE_A);
}
2023-12-14 03:49 AM - edited 2023-12-14 03:55 AM
Exists a way to make the copy of the 'shadow register' to the 'active register' automatic at thye begin of the PWM cycle?, to update it by software generates large glitches because done in the middle of the pwm cycle
NOTE:
HRTIM_CompareCfgTypeDef compare_config;
compare_config.AutoDelayedMode = HRTIM_AUTODELAYEDMODE_REGULAR;
compare_config.AutoDelayedTimeout = 0;
compare_config.CompareValue = 0x1FFD;
Is the same than:
HRTIM_CompareCfgTypeDef compare_config={0};
compare_config.CompareValue = 0x1FFD;
Because HRTIM_AUTODELAYEDMODE_REGULAR is 0
2024-03-27 06:44 AM
Hi, I have the same problem to change duty while running.
More complex method using HAL_HRTIM_WaveformOutputStart and HAL_HRTIM_WaveformCounterStart was OK.
And HAL_HRTIM_SimplePWMStart was OK.
In your case, following is the solution this was also other member told before. Please consider cubeide setting parameters for Set Source/Reset Source.
pOutputCfg.SetSource = HRTIM_OUTPUTSET_TIMPER;
pOutputCfg.ResetSource = HRTIM_OUTPUTRESET_TIMCMP1;
Following can be change the duty.
__HAL_HRTIM_SETCOMPARE(&hhrtim1, HRTIM_TIMERINDEX_TIMER_B, HRTIM_COMPAREUNIT_1, duty);
HAL_HRTIM_SoftwareUpdate(&hhrtim1, HRTIM_TIMERUPDATE_B);
In Simple and waveform, both method, __HAL_HRTIM_SETCOMPARE can help to change duty but there is problem. Changed duty is stable (pwm output) but sometimes pwm is fluctuating(flash).
If you clear your problem to change duty then you got the same situation as I had.
Have you find solution? Good day.