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.

CC2640R2F: Timer to calculate the time

Part Number: CC2640R2F

I'm using library <ti/drivers/timer/GPTimerCC26XX.h>

I do not understand the loadvalue variable.

It is supposed to change the value of the register GPT_O_TAILR but when I put 0x00000001, the value I see is 10 ms but if I put 0x0000FFFF, the value es 1 ms

The frequency is 48 MHz, so I understand that 1 tick is 1/48MHz if I am in a periodic timer with count up. 

Can anyone explain me what am  i doing wrong? or What value corresponds to each tick?

My program is:

void timerCallbackFunction(GPTimerCC26XX_Handle handle, GPTimerCC26XX_IntMask interruptMask){

// // Begin read
GPIO_toggle(Board_GPIO_LED1);
}

void *mainThread(void *arg0)
{
unsigned int status;

GPTimerCC26XX_Params_init(&params);
params.width = GPT_CONFIG_32BIT;
params.mode = GPT_MODE_PERIODIC_UP;
params.debugStallMode = GPTimerCC26XX_DEBUG_STALL_OFF;
hTimer = GPTimerCC26XX_open(Board_GPTIMER1A, &params);
loadVal = 0x000000001; 

GPTimerCC26XX_setLoadValue(hTimer, loadVal);
GPTimerCC26XX_registerInterrupt(hTimer, timerCallbackFunction, GPT_INT_TIMEOUT);
GPTimerCC26XX_start(hTimer);

/* Call driver init functions */
GPIO_init();

/* Loop forever echoing */
while (1) {
// // Begin read
GPIO_toggle(Board_GPIO_LED0);
sleep(1);
}

}

/* FROM LIBRARY GPTimerCC26XX*/

static void GPTimerCC26XXSetLoadMatch(GPTimerCC26XX_Handle handle, GPTimerCC26XX_Value loadMatchVal, uint32_t regPre, uint32_t regLoadMatch)
{
/* Get the pointer to the object and hwAttrs */
GPTimerCC26XX_HWAttrs const *hwAttrs = handle->hwAttrs;
GPTimerCC26XX_Object *object = handle->object;
uint32_t offset = GPT_LUT[handle->timerPart].offset;

/* Split value into correct timer and prescaler register for 16 bit modes. */
if (object->width == GPT_CONFIG_16BIT)
{
/* Upper byte is used by prescaler */
uint8_t prescaleValue = 0xFF & (loadMatchVal >> 16);
/* Discard upper byte (24 bits max) */
loadMatchVal &= 0xFFFF;

/* Set prescale value */
HWREG(hwAttrs->baseAddr + offset + regPre) = prescaleValue;
}

/* Set load / match value */
HWREG(hwAttrs->baseAddr + offset + regLoadMatch) = loadMatchVal;
}


void GPTimerCC26XX_setLoadValue(GPTimerCC26XX_Handle handle, GPTimerCC26XX_Value loadValue)
{
GPTimerCC26XXSetLoadMatch(handle, loadValue, GPT_O_TAPR, GPT_O_TAILR);
}

  • Hello Adriana Gomez,

    I would recommend using our timer library, it is easier to use.

    inside timer.h there is an example on how to use it. see below:

    * # Usage #
    * The following example code opens a timer in continuous callback mode. The
    * period is set to 1000 Hz.
    *
    * @code
    * Timer_Handle handle;
    * Timer_Params params;
    *
    * Timer_Params_init(&params);
    * params.periodUnits = Timer_PERIOD_HZ;
    * params.period = 1000;
    * params.timerMode = Timer_CONTINUOUS_CALLBACK;
    * params.timerCallback = someTimerCallbackFunction;
    *
    * handle = Timer_open(Board_TIMER0, &params);
    *
    * if (handle == NULL) {
    * // Timer_open() failed
    * while (1);
    * }
    *
    * status = Timer_start(handle);
    *
    * if (status == Timer_STATUS_ERROR) {
    * //Timer_start() failed
    * while (1);
    * }
    *
    * sleep(10000);
    *
    * Timer_stop(handle);

    Regards,
    AB
  • I tried to use that library but I'm working on cc2640r2 launchpad but the variable Board_TIMER0 is not defined in "Board.h". I try to use Board_GPTIMER0A from "Board.h" but it didn't work. I received an error that handle was not correct.
    I'm working in sdk:simplelink_cc2640r2_sdk_1_50_00_58, could you tell me where do I find Board_TIMER0 ?
  • Hello Adrianna,

    You can use Board_GPTIMER0A

    Regards,
    AB