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.

TMS570LC4357: Queiry on delay using the timers(on rollover condition)

Part Number: TMS570LC4357

Tool/software:

Hi,

Inorder to generate delay, we have the following pseudo code, which is similar to an example code from TI

void delay(MicroSeconds period_value)
{
    Uint64 initial_time;
    Uint64 current_time;

    get_current_timer_value(initial_time);
    Uint64 ticks_value = convert_microsec_to_ticks_values(period_value);
   
    do
    {
        get_current_timer_value(current_time);
    }
    while ( (current_time - initial_time) < ticks_value );

     return;
}
period_value refers to the amount of delay needed(passed as an argument).

When the controller is running continuously for days, is there any chance that, current_time value will be less than initial_time value because of roll over condition of uint64 type. The question is, if roll over occurs for the above variables, how the handling is done in TI ? or should we add any rollover conditions in the code ?
 

  • Hi Bharath,

    I verified the RTI driver code for TMS570LC4357 and i don't find the function called "get_current_timer_value" and we do have "rtiGetCurrentTick"

    Are you talking about this function only? If not, can you please provide your complete project for verification.

    --
    Thanks & regards,
    Jagadish.

  • Hi Jagadish,
    Yes the function you have pointed is similar to what we have. We have modified it according to our standards. So, my quiery referring to previous comment:

    When the controller is running continuously for days, is there any chance that, current_time value will be less than initial_time value because of roll over condition of uint64 type. The question is, if roll over occurs for the above variables, how the handling is done in TI ? or should we add any rollover conditions in the code ?

  • Hi Bharath Kumar,

    uint64 will not get roll over but there is one boundary condition that need to take care in application level. I want to explain the behavior first:

    To illustrate the behavior i configured 1Sec timeout for RTI Compare 0 as shown below:

    And my RTI clock after pre-scaler is 1Mhz

    So based on this, my COMPx and UDCPx registers are assigned with 1000000:

    So, what timer will do is that it will continuously increment FRCx for every RTC clock pulse (after prescaler). If this FRCx value matches with COMPx means timeout occur and it will generate the compare0 interrupt. And now after this interrupt to generate the interrupts periodically the timer module will add the UDCPx value to the COMPx to generate next interrupt. So again, FRCx will chase the COMPx value and if matches this value again we will get the interrupt and this process will continue.

    Now if we verify rtiGetCurrentTick function definition:

    It is returning the tick value as below:

    tick = RTI_CNT_FRCx - (RTI_CMP_COMPx - RTI_CMP_UDCPx);

    So, this tick value will give us number of RTI clock pulses counted by FRCx.

    Example:

    In our case we configured 1000000 right, that means we will get ticks between 0 to 999999,

    To understand the behavior i did the below, i am continuously reading the tick value and sending it to the UART port

    As you can see it is continuously incrementing till it reaches to the 1000000 and then rollover to zero and start again.

    So, if application want to create delay using this tick value, then application should take care of this boundary condition.

    I mean there is a possibility for current value can be less than initial value at this boundary condition.

    One solution is below:

    After reading current value, compare it with the initial value and if it is less than initial value then please add UDCPx to the current value.

    void delay(MicroSeconds period_value)
    {
        Uint64 initial_time;
        Uint64 current_time;
    
        get_current_timer_value(initial_time);
        Uint64 ticks_value = convert_microsec_to_ticks_values(period_value);
       
        do
        {
            get_current_timer_value(current_time);
    		if(current_time < initial_time)
    		{
    			current_time = current_time + rtiREG->CMP[0].UDCPx;
    		}
        }
        while ( (current_time - initial_time) < ticks_value );
    
         return;
    }

    --
    Thanks & regards,
    Jagadish.