AnsweredAssumed Answered

Synchronizing Timer Output to an External Sync Input

Question asked by Stephen on Dec 8, 2014
Latest reply on Dec 8, 2014 by Clive One

TIM5_CH2 will output a 1Hz continuous square wave at 50% duty cycle. The output is to synchronize is phase with a 1Hz externally input square wave also at 50% duty cycle. When the 1Hz input is lost TIM5_CH2 is to continue to output is 1Hz square wave without change in phase, such that as accurately as possible, it continues the same output as if the 1Hz synchronizing input were still there. Once the synchronizing input is regained TIM5_CH2 is to return to synchronizing with it.

The current plan is to setup TIM5_CH2 to output the 1Hz square wave, connect the 1Hz sync input to a GPIO port set to issue an interrupt on the rising edge of the sync input, and then have its service routine set and reset the UDIS bit TIM5_CR1. The UDIS set and reset would make TIM5 restart its counter from zero thus achieving the synchronization.

That plan will consume some processing cycles with each rising edge of the sync input. The firmware execution will also cause some propagation delay. Is there a way for the sync pulse to directly reset the TIM5 counter and prescaler to zero without firmware having to set and reset the UDIS bit?