2014-12-08 10:59 AM
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-synchronization2014-12-08 11:15 AM
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)2014-12-08 11:25 AM
The processor is a STM32F373VCT6. This has the LQFP100 package.
2014-12-08 11:28 AM
I personally would connect the sync input to TIM5_CH1 and use slave reset mode to achieve the sync.
JW2014-12-08 12:14 PM
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.