cancel
Showing results for 
Search instead for 
Did you mean: 

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

ProNet36
Associate

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

1 REPLY 1
waclawek.jan
Super User

> 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