Using an external signal to clear TIM counter
I'm using TIM2 as a PWM. I have an (periodic) external signal that should reset the TIM2 counter to zero, so that the PWM is synchronized to the external signal. In a previous naive setup, I used the external signal to generate an interrupt (EXTI), and reset the counter in software (TIM2->CNT = 0). There is too much latency (and lack of determinism) in this approach so I would like to use the input signal to perform a hardware timer clear.
I suspect I want to use TIM2 with trigger source TI1_ED. Then bring the external signal into TIM2 CHAN1. Then I can use TIM2 CHAN2 as PWM output.
Can someone indicate if this is the right approach, or should I think about it in a different way? I can prototype it on a STM32F4 discovery board.
Thanks
#tim-counter