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.

CC1312R: Timer Start&Stop

Part Number: CC1312R

Hi, 

I am working on LAUNCHXL-CC1312R1 board and rfEasyLinkRx example.

Setup of the timer and the interrupt is;

 GPTimerCC26XX_Params params;

    params.width          = GPT_CONFIG_32BIT;
    params.mode           = GPT_MODE_ONESHOT_UP;
    params.debugStallMode = GPTimerCC26XX_DEBUG_STALL_OFF;
    hTimer = GPTimerCC26XX_open(Board_GPTIMER0A, &params);
    if(hTimer == NULL)
    {
        while(1);
    }

    /* Set Timeout value to 300ms */
    rxTimeoutVal = (SysCtrlClockGet()*3UL)/10UL - 1UL;
    GPTimerCC26XX_setLoadValue(hTimer, rxTimeoutVal);


    /* Register the GPTimer interrupt */
    GPTimerCC26XX_registerInterrupt(hTimer, rxTimeoutCb, GPT_INT_TIMEOUT);

Here is the code;

    PIN_setOutputValue(pinHandle, Board_PIN_LED2,1);
    PIN_setOutputValue(pinHandle, Board_PIN_LED2,0);

    GPTimerCC26XX_setLoadValue(hTimer, rxTimeoutVal);
    GPTimerCC26XX_start(hTimer);

    delay(250000); //delay 250 ms

    GPTimerCC26XX_stop(hTimer);
    PIN_setOutputValue(pinHandle, Board_PIN_LED1,1);
    PIN_setOutputValue(pinHandle, Board_PIN_LED1,0);

    GPTimerCC26XX_setLoadValue(hTimer, rxTimeoutVal);
    GPTimerCC26XX_start(hTimer);


while(1);

And here is the interrupt function;

void rxTimeoutCb(GPTimerCC26XX_Handle handle,
                 GPTimerCC26XX_IntMask interruptMask)
{
    /* Set the Timeout Flag */
    rxTimeoutFlag = true;

        PIN_setOutputValue(pinHandle, Board_PIN_LED2,1);
        PIN_setOutputValue(pinHandle, Board_PIN_LED2,0);

}

There is the led pins behaviour. Despite stopping the timer and reloading the value, timer goes 50 ms more and interrupt comes. After stopping and reloading value, what should I have to do for it to go 300ms and give interrupt? Thanks..




  • Hi Onur,

    It seems to me that the current time value is not reset when you call stop / start, or when you set a load value. The end result is that you just pause the timer for a short while, and set the timeout value to the same as before.

    It would have set load value and started counting from there if it were counting down.

    My only suggestion right now is to either

    a) Set the timer mode to count down instead of up.

    #include <ti/devices/DeviceFamily.h>
    #include DeviceFamily_constructPath(inc/hw_memmap.h)
    #include DeviceFamily_constructPath(inc/hw_gpt.h)
    
    HWREGBITW(GPT0_BASE + GPT_O_TAMR, GPT_TAMR_TACDIR_BITN) = (GPT_TAMR_TACDIR_DOWN >> GPT_TAMR_TACDIR_S);

    b) Reset the timer value manually and don't bother calling a new setLoadValue.

    HWREG(GPT0_BASE + GPT_O_TAV) = 0; // GPTimer 0A.

    I'm informing a colleague about this thread in case there are better ways :)

    Best regards,
    Aslak

  • Hi Onur,

    Another way to do this could be to update the load value by taking the current timer value in to account:

    uint32_t currentValue = GPTimerCC26XX_getValue(handle);
    GPTimerCC26XX_setLoadValue(handle, currentValue + newValue);

    I would suggest trying this approach before setting the timer in count down mode as this is not supported by the GPTimer as of today. While it is likely to work there is no testing done on this and it is possible that there could be some undefined behavior.