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.

how to config the Prescaler of the Timer.

i want the Timer 0 work in 16BIT mode,and  prescaler  ratio = 8

but I can't find a function to config the Timer A Pre-scaler(TAPSR) in the Driver code(GPTimerCC26XX), only find the :

#define GPT_TAPR_TAPSR_W 8
#define GPT_TAPR_TAPSR_M 0X000000FF
#define GPT_TAPR_TAPSR_S 0

and find :

AUXTimerPrescalerSet(uint32_t ui32Timer,uint32_t ui32PrescalerDiv);

in the "aux_timer.h"

but i don't know how to use this, so ,how to config the Prescaler of the Timer?

Thanks a lot in advance.

  • The driver is taking care of this for you.

    Please see that function

    static void GPTimerCC26XXSetLoadMatch(GPTimerCC26XX_Handle handle, GPTimerCC26XX_Value loadMatchVal, uint32_t regPre, uint32_t regLoadMatch)

    It extracts bit[16:23] of loadMatchVal and write it into prescaler.

    /*!
     *  @brief  Shared code to be used by GPTimerCC26XX_setLoadValue / GPTimerCC26XX_setMatchValue
     *          Sets load/match values using input value and register offset for
     *          prescaler and load/match register
     *          Functions calling this should specifiy which the register offset
     *          within the module base to the corresponding timer A register.
     */
    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;
    }

  • thank you!

    it is a static type function.you can find the CC26XXSetMatch() and CC26XXSetLoad(),why not a "CC26XXSetPrescaler()"?

    people must write a "CC26XXSetPrescaler()" themself in the "GPTimerCC26XX.c". Best not to change the Official library。

    thank you very much,you are a kind man.

    LiNan
  • i call the function:
    GPTimerCC26XX_setMatchValue(Prop_handle,0x1FFFF);
    GPTimerCC26XX_start(Prop_handle);
    GPTimerCC26XX_registerInterrupt(Prop_handle,callback,GPT_INT_TIMEOUT);

    but the Maximum Time is still 2.7ms rather than 5.4ms, i can't find the reason,please help me !
  • When you set the match value to be 0x1FFFF, that means the timeout will happen when GPTimer counts 131071 ticks.
    The GPTimer is running on 48MHz clk, so 1 tick will take 1/48000000 second.
    When you write you want 0x1FFFF = 131071 ticks, then the time to interrupt happen will be 131071/48000000 = 0.0027 second = 2.7ms

    So GPTimer is doing the correct thing, if you need more time, then set the tick number to double.
  • i set the match value to be 0x3FFFE~0xFFFFFF, Maximum Time is always 2.7ms.

    i think there must be other problems. could you give me  some examples about how to config the Timer?

    hanks a lot!!

  • Dear Christin,
    i watch the GPT0 register when debug,i find the TAPR register is aways 0x00000000, even i set:GPTimerCC26XX_setMatchValue(Prop_handle,0x3FFFE);

    So the function GPTimerCC26XX_setMatchValue() is to config the TAMATCHR and TAPMR rather than TAPR,

    so how to config the rIgister TAPR? where is the function?


    Regards,
    LiNan
  • You can find the timer example on the driver file. The official support version is in TI-RTOS 2.20.

    TI-RTOS can be downloaded here :

    The GPTimer driver can be found here after downloaded :

    C:\ti\tirtos_cc13xx_cc26xx_2_20_01_08\products\tidrivers_cc13xx_cc26xx_2_20_01_10\packages\ti\drivers\timer

    in GPTimerCC26xx.h, there is code snippet of how to configure timer:

       GPTimerCC26XX_Handle hTimer;
       void timerCallback(GPTimerCC26XX_Handle handle, GPTimerCC26XX_IntMask interruptMask) {
           // interrupt callback code goes here. Minimize processing in interrupt.
       }
     
       void taskFxn(UArg a0, UArg a1) {
         GPTimerCC26XX_Params params;
         GPTimerCC26XX_Params_init(&params);
         params.width          = GPT_CONFIG_16BIT;
         params.mode           = GPT_MODE_PERIODIC_UP;
         params.debugStallMode = GPTimerCC26XX_DEBUG_STALL_OFF;
         hTimer = GPTimerCC26XX_open(CC2650_GPTIMER0A, &params);
         if(hTimer == NULL) {
           Log_error0("Failed to open GPTimer");
           Task_exit();
         }
     
         Types_FreqHz  freq;
         BIOS_getCpuFreq(&freq);
         GPTimerCC26XX_Value loadVal = freq.lo / 1000 - 1; //47999
         GPTimerCC26XX_setLoadValue(hTimer, loadVal);
         GPTimerCC26XX_registerInterrupt(hTimer, timerCallback, GPT_INT_TIMEOUT);
     
         GPTimerCC26XX_start(hTimer);
     
         while(1) {
           Task_sleep(BIOS_WAIT_FOREVER);
         }
       }
    

  • Dear Christin,

    i have done these, it works as excepted.but the Timer Max period is 2.7ms,so i want to config the TAPR =0x04
    i use the Driver: cc26xx_2_20_00_08.
    in the GPTimerCC26xx.h,i find no function to config the TAPR register, so I have been looking for a way to config the TAPR,Does the new version cc26xx_2_20_01_08 include this function to config the TAPR?

    Regards,
    LiNan

  • Hi,

    Can you post your code? I have no problem using the timer to have LED toggle once every 5.4ms.

    I am using the example code I pasted above and simply change the Load value to 0x3FFFF.

    If you want to use match function then you need to change your interrupt mask from timeout to match.

  • Dear Christin,

    I have solved this proble.i make a miske :

    i called the function :

    GPTimeCC26XX_setMatchValue() rather than GPTimeCC26XX_setLoaderValue() 

    so the Timer worked error.

    Thank u for your help and your patience!

    Regards,

    LiNan