Skip to main content
Associate
July 28, 2025
Question

TIM1 (125 Hz PWM) to trigger TIM8 only on PWM falling edge

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:

  1. 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?

  2. 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

This topic has been closed for replies.

2 replies

waclawek.jan
Super User
July 28, 2025

> 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

ST Technical Moderator
July 29, 2025

Hello @ProNet36 

Sensitivity can't be configured on internal triggers (ITRs). always sensitive to a rising edge (or high level as per selected slave mode.)

Possible workarounds:

  • Option 1: output the signal on TIM1_OC1 and connect it (physically) to TIM8_ETR input. Then at TIM8 level select the ETR input as trigger of the slave mode controller. It is also possible to connect TIM1_OC1 to TIM8_TI1 (channel 1 configured as input) and then select tim_ti1f_ed as trigger of the slave mode controller
  • Option 2: change the polarity of TIM1_OC1 output.

In order to give better visibility on the answered topics, please click on 'Best answer' on the reply which solved your issue or answered your question. Saket_Om