2025-12-11 9:02 AM
Hello,
I am using an STM32H723ZG6U and want to output a limited number of phase-shifted pulses on two pins. To do so I currently use TIM1 and TIM8 with PWM generation.
TIM1 acts as the master timer having channel 1 in 'PWM Generation CH1' as the first output and channel 2 in 'Output Compare No Output' for the phase-shift. TRGO is configured as 'Output Compare (OC2REF)'. 'One Pulse Mode' is checked for this timer.
TIM8 is the slave timer in 'Trigger Mode' with Trigger Source 'ITR0' which connects to TIM1. Channel 1 is configured as 'PWM Generation CH1' for the system's second output. This timer is also in 'One Pulse Mode'.
Apart from that both Counter Settings and PWM Generation channels are configured identically to fit my needs. When starting both PWMs for the first time after controller startup everything works as expected (i.e. PWM on TIM1 sends a number of pulses and then stays quiet, same with a phase-shift to TIM1 with PWM on TIM8). Pictures of the configurations are attached.
My problem is, that I cannot figure out, how to restart the timers properly. Whatever I did so far either leads to PWM from TIM8 not beeing started again or both timers losing synchronity which is crucial for my application.
What I tried so far is starting both timers with HAL_TIM_PWM_Start() again, setting some bits with
__HAL_TIM_CLEAR_FLAG(&htim8, TIM_FLAG_UPDATE);
__HAL_TIM_ENABLE(&htim8);
__HAL_TIM_CLEAR_FLAG(&htim1, TIM_FLAG_UPDATE);
__HAL_TIM_ENABLE(&htim1);
and setting all the timer related registers to the exact values as they were before starting the timers initially. None of the mentioned approaches solved my problem so please enlighten me, how to restart the timers by software on demand.
Solved! Go to Solution.
2025-12-12 4:07 AM
I have solved the problem now. Switching the mode from 'Active level on match' to 'Toggle on match' in the 'Output compare No Output channel 2' of TIM1 did the trick.
2025-12-11 11:12 PM
Cube/HAL is designed to provide some "typical functionality" to be easily clickable in Cube/MX; if you want anything outside that "typical functionality", it will get into way more than help, so you may be better off getting rid of it entirely and write your own code.
Generally, read out and check/compare-to-working/post content of both timers' registers, just before setting the master's TIMx_CR1.CEN.
JW
2025-12-12 2:51 AM
Hello,
could you please check that when you restart the timers to below recommendation is fulfilled (extracted from reference manual, section TIMX, One-pulse mode):
A pulse can be correctly generated only if the compare value is different from the counter initial value. Before starting (when the timer is waiting for the trigger), the configuration must
be:
• In upcounting: CNT < CCRx ≤ ARR (in particular, 0 < CCRx)
• In downcounting: CNT > CCRx
2025-12-12 4:07 AM
2025-12-12 8:17 AM
Thanks for coming back with the solution.
This is not something I would expect, indeed.
JW