cancel
Showing results for 
Search instead for 
Did you mean: 

Synchronizing Timer Output to an External Sync Input

spflanze
Associate II
Posted on December 08, 2014 at 19:59

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?

#pwm #timer-synchronization
4 REPLIES 4
Posted on December 08, 2014 at 20:15

And which STM32 part are we talking about here?

There's no direct access to the prescaler. You could however use a 32-bit TIM, with no prescaler, the same one to output your PWM as to Input Capture the reference.

The Input Capture would then allow you to latch the PHASE (TIMx->CCRx = TIMx->CNT) of the PWM being output, either of both edges thereof, and then you could adjust the PHASE via TIMx->CNT

1Hz would easily fit in a 32-bit counter clocking at 84/90 MHz (STM32F4)
Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
spflanze
Associate II
Posted on December 08, 2014 at 20:25

The processor is a STM32F373VCT6. This has the LQFP100 package.

Posted on December 08, 2014 at 20:28

I personally would connect the sync input to TIM5_CH1 and use slave reset mode to achieve the sync.

JW
Posted on December 08, 2014 at 21:14

TIM5 would be 32-bit, 72 MHz

Yes, you could reset it if you wanted to pull the phase in with a single hit. Measuring the phase, and pulling it in less abruptly might be less disruptive to attached hardware, you presumably want to measure and adjust the period so your hold-over and duty come from a more disciplined source.
Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..