This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

RTOS/LAUNCHXL-CC1310: Adjusting Phase of Periodic Clock Timer

Part Number: LAUNCHXL-CC1310

Tool/software: TI-RTOS

Dear TI Timer Support,

I have a periodic clock timer helping me synchronize a task to an outside periodic event and I'm looking for a good way to give the timer a nudge 1 tick up or down to change its phase and account for the drift between clocks - essentially I want to just modify the period of the timer occasionally for just one period to adjust it's phase with the outside event.  Any ideas on how I can do that?  I sort of need to increment or decrement the clock object's internal counter, but I don't think I can access it can I?

Thanks,

Brett

  • Hi Brett,

    I've notified the team to get you an answer.

    Thanks,
    Mitchell
  • Hello Brett,

    If what you are trying to achieve is to change the period of the clock timer object at runtime, then what you need to do is

           1)stop the timer

           2)reconfigure timer

           3)start it again.

    Please see the bellow example:

    void time_ISR(xdc_UArg arg0)
    {
        //Something
    }
    
    static void time_task(uint32_t arg0, uint32_t arg1){
        Clock_Params clockParams;
        Clock_Handle clock;
        Error_Block  eb;
    
        Error_init(&eb);
    
        Clock_Params_init(&clockParams);
        clockParams.period = 1000;
        clockParams.startFlag = TRUE;
        clock = Clock_create(time_ISR, 1, &clockParams, &eb);
      
        /*
         * 
         * 
         * 
         * Calculate new Period
         * 
         * 
         * 
         * 
         */
    
        Clock_stop(clock);
        Clock_setPeriod(clock, 5000);
        Clock_start(clock);
    }  

    I hope this helps,
    Andres Blanco

  • Hi Andres,

    Thank you very much for addressing my question.  It's actually the PHASE of the clock I want to change, not the period.  I just want to nudge the phase +/- 1 tick depending on the relative clock drift.  So for example, I will be waking up periodically every 2 seconds to synch with an external event which is also periodic.    Both events are timed using a 32khz crystal, but these crystals will not run at exactly the same frequency.  For us, a drift of 100 ppm is possible which equates to a drift of 200 uS between events.  I would like to nudge the clock forward or backward occasionally to make up for this drift.  I'd rather not create a whole new clock for this every time I need to adjust the phase since that can happen quite often.  When I create a clock with Clock_construct () I am able to specify the time to the first wakeup (the phase) as well as the periodic time.  I notice it always uses this value for every subsequent stop and starting of the clock.  Is it possible for me to change this value?  That would be pretty simple.  I could change that value and just do a stop and start on the clock.  Do you follow me?

    Thanks,

    Brett

  • Hi Brett,

    I am not sure if this would help but TIRTOS supports the following APIs for the clock:

    // Set periodic interval
    Clock_setPeriod(Clock_Handle handle, UInt32 period);
    //Set the initial Timeout
    Clock_setTimeout(Clock_Handle handle, UInt32 timeout);

    Both of these APIs can be called once you stop the clock, and will go under effect when you restart it.

    The other option I see would be using one of the hardware timers in the device in order to sync with your external event.

    Regards,
    Andres Blanco
  • Thanks Andres. I think I can make that work. I'll let you know.
  • Brett,

    If you are looking at synchronizing this for a radio protocol, you should instead use the RF driver radio time (for when future radio operations happen) and find the delta based on the delta time between an expected received time a packet from a master is received and the actual time. This error can simply be added on top of the normal scheduling you would do of radio operations with the radio triggers.

    When using the RF driver, the 4MHz radio timer will be synchronized with the RTC so that it seems like the radio timer was never off while in sleep. See the following link for documentation on the radio driver:
    dev.ti.com/.../