2025-07-27 11:43 PM - last edited on 2025-07-28 1:58 AM by Andrew Neil
Hi everyone,
I’m trying to chain two timers on an STM32U585 so that:
TIM1 generates a PWM on PA8 at 125 Hz (2 ms high / 6 ms low).
TIM8 acts as a 20 µs sampler: it should reset and start counting at the falling edge of the TIM1 PWM, then fire its Update IRQ after 20 µs.
So far I’ve tried:
// TIM1: 125 Hz PWM at 160 MHz / APB2
htim1.Init.Prescaler = 319; // 160 MHz/320 = 500 kHz → 2 µs tick
htim1.Init.Period = 3999; // 4000×2 µs = 8 ms → 125 Hz
// …
TIM_MasterConfigTypeDef mcfg = {0};
mcfg.MasterOutputTrigger = TIM_TRGO_OC1REF; // TRGO on CCR1-match (PWM falling edge)
HAL_TIMEx_MasterConfigSynchronization(&htim1, &mcfg);
// TIM8: 20 µs sampling, slave-reset on TIM1_TRGO
htim8.Init.Prescaler = 159; // 160 MHz/160 = 1 MHz → 1 µs tick
htim8.Init.Period = 19; // 20×1 µs = 20 µs sample interval
// …
TIM_SlaveConfigTypeDef scfg = {0};
scfg.SlaveMode = TIM_SLAVEMODE_RESET;
scfg.InputTrigger = TIM_TS_ITR0; // ITR0 = internal TIM1_TRGO
HAL_TIM_SlaveConfigSynchro(&htim8, &scfg);
HAL_TIM_Base_Start_IT(&htim8);
However, TIM8 still resets on the rising edge (timer overflow) of TIM1, not the falling CCR1 match. I’ve checked RM0456’s “Internal trigger connection” table and ITR0 really maps to TIM1_TRGO, but internal triggers apparently only detect rising edges. I also tried using ETRF (external trigger) but could not get PA8 routed to TIM8_ETR easily.
My question:
Is there a way to make TIM1’s TRGO output respond to the PWM falling edge and have TIM8’s Slave-Reset on that falling-edge signal?
If I must use an external pin or IC channel, which registers / HAL calls do I need so that TIM8 will reset precisely on the High→Low transition of TIM1_CH1?
Any example code or register-level guidance would be hugely appreciated!
Thanks in advance,
Dave
2025-07-28 12:24 AM - edited 2025-07-28 12:24 AM
> TIM8 still resets on the rising edge (timer overflow) of TIM1
How do you know?
Isn't TIM8 free running?
Read out and check/post content of TIM1 and TIM8 registers.
JW