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.

CCS/TMS570LS1224: Using rtiSetPeriod() to Dynamically Change rti Timer

Part Number: TMS570LS1224

Tool/software: Code Composer Studio

Hi Hercules team,

I am currently looking to use the rti module as a "sleep()" function.

I noticed that the rtiSetPeriod() function updates only after an additional "tick" of the previous period length has passed (expected behavior).

This unfortunately means that when setting the period to a large value (like 1000ms) then trying to change to a small value (100us), we must wait up to an additional 1000ms before the timer can change.

Is there a way to force the "tick" to happen faster so that we can immediately switch the period to something smaller?

Here's the code I am currently trying to use as a "sleep" or "delay" function, to help clarify what I am trying to do:

//**************
//delay function, input = number of microseconds
//**************
void delayus(uint16 us) {
    if (us == 0)
       return;
    else
    {
        rtiSetPeriod(rtiCOMPARE0, 10*us);
        rtiEnableNotification(rtiNOTIFICATION_COMPARE0);
        rtiStartCounter(rtiCOUNTER_BLOCK0);
        while(RTI_TIMEOUT==0); //this is set to 1 in notificaiton.c rtiNotification
        RTI_TIMEOUT = 0;
        rtiDisableNotification(rtiNOTIFICATION_COMPARE0);
        rtiStopCounter(rtiCOUNTER_BLOCK0);
        rtiResetCounter(rtiCOUNTER_BLOCK0);
    }
}

//***************
//notificaiton.c:
//***************
void rtiNotification(uint32 notification)
{
/*  enter user code between the USER CODE BEGIN and USER CODE END. */
/* USER CODE BEGIN (9) */
    RTI_TIMEOUT = 1;
/* USER CODE END */
}

To get the above code to work, I need to add another "while()" loop to wait for a tick to occur before the "rtiSetPeriod" takes effect.

Thanks!

Vince Toledo

  • Vince,

    As you have identified the rtiSetPeriod only configures the "Update Compare Value" for the selected counter. This value only takes effect on a compare match, so that the next counter value to be compared matches the new period that you have chosen.

    To get around this limitation you should write your own function to set up the actual compare value to be checked to generate the first compare match event once the counter has been stopped and reset. You do stop the counter and reset it as part of the delay function. Please use the rtiInit function as reference for configuring the compare value registers as per your desired duration.

    Regards,

    Sunil

  • Thanks Sunil!

    I was definitely mixing up the COMPx and UDCPx values, so I really appreciate your clarification. I was able to get this working properly!

    Thanks for your patience and time,

    Vince Toledo