cancel
Showing results for 
Search instead for 
Did you mean: 

To synchronize timers

mfcprog
Associate II
Posted on April 22, 2012 at 20:52

Hi,

working with the STM32F103 processor, I`m searching for a solution to sychronize a STM32 timer to an external input signal. This signal has a constant frequency of e.g. 24Hz or 30Hz.

Using a input capture timer I`m able with the help of ''clive1'' to receive every piece of this input signal.

Now I want to transmit this received signal again. Unfortunately not with the same frequency as the input signal frequency. The frequency of the output signal is 8x the input frequency, which means I need another timer to generate this frequency. This timer must be synchronized to the input capture timer.

At the moment I start a second timer for the output frequency with the 8x frequency of the input signal. I know the input frequency from the input capture timer (delay between two received pkts).

If I receive the first pkt after the initialization the second timer,  I reset the second timer TIM2->CNT register to acchieve a synchronization. But this dosen`t work, because after a short time (about 5mins) the input signal is no longer synchronize to the output signal.

In my main routine:

while(1)

{

    /*syncFlag is at startup = 1 to sync the second timer to the input capture timer. If I recvd

    a new pkt the flag ''captureFlag'' will be set to one in the ISR */

    if((syncFlag) && (captureFlag))

    {

       /* received a new input pkt -> get this pkt */

       GetRcvdInputSignal();            

        /* reset timer2 */

        TIM2->CNT = 0; 

        /* clear all flags */ 

        captureFlag = syncFlag= 0;  

    }

    else if(captureFlag )

    {

        GetRcvdInputSignal(); 

        captureFlag = 0;

    }

    

    /* timer2Flag is the flag from the second timer which will be set in the ISR */

    if(timer2Flag)

    {

        TxdSignal();

        if(SignalOutofSync())

        {   /* input signal no longer in sync with the output signal */

            //error

        }

        timer2Flag = 0;

    }

}

I hope you can give me some hints to acchieve a proper synchronization between the input & output signal. Because I think I didn`t use the right way at the moment.

best regards

Hans

10 REPLIES 10
harry_rostovtsev
Associate II
Posted on August 27, 2012 at 21:59

Sorry to highjack your thread, OP.  To avoid any further highjacking this thread, I started a new one here:

https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Stop%20PWM%20output%20after%20N%20steps&currentviews=9