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.

CC2340R5: How to configure Timer

Part Number: CC2340R5
Other Parts Discussed in Thread: ENERGYTRACE

How can I configure Timer in TI. Kindly provide me sample code for the same. I have tried with this code, but it's not working.

And also I have used the Energy Trace option in CCS. It shows 4 - 5 days Battery Life, I don't know whether it is showing right or wrong. Kindly confirm.

  • Hello Ankit Jaiswal,

    Looking at your code snippet you included it seems like you did not include the "LGPTimerLPF3_start", which would not start the timer, which would explain why the timer is not working. Since the device never enters a low power mode the power consumption is relatively high (I measured ~1.5 days on the code below since CPU is always active + the GPIO, and 6 days if I remove the GPIO cover to disconnect it). 

    Included is an example I adapted from TI Driver Library:

    int count = 0;
    int val = 0;
    LGPTimerLPF3_Handle hTimer;
    void timerCallback(LGPTimerLPF3_Handle lgptHandle, LGPTimerLPF3_IntMask interruptMask) {
        count++;
        val = count;
    }
    /*
     *  ======== mainThread ========
     */
    void *mainThread(void *arg0)
    {
        /* 1 second delay */
        uint32_t time = 1;
    
        /* Call driver init functions */
        GPIO_init();
    
        /* Configure the LED pin */
        GPIO_setConfig(CONFIG_GPIO_LED_0, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW);
        GPIO_setConfig(CONFIG_GPIO_LED_1, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW);
    
        uint32_t counterTarget;
         hTimer = NULL;
         LGPTimerLPF3_Params params;
         LGPTimerLPF3_Params_init(&params);
         params.hwiCallbackFxn = timerCallback;
         hTimer = LGPTimerLPF3_open(CONFIG_LGPTIMER_0, &params);
         if(hTimer == NULL) {
           //Log_error0("Failed to open LGPTimer");
           //Task_exit();
         }
         counterTarget = 48000;  // 1 ms with a system clock of 48 MHz
         LGPTimerLPF3_setInitialCounterTarget(hTimer, counterTarget, true);
         LGPTimerLPF3_enableInterrupt(hTimer, LGPTimerLPF3_INT_TGT);
         LGPTimerLPF3_start(hTimer, LGPTimerLPF3_CTL_MODE_UP_PER);
         sleep(time);
        while (1)
        {
            sleep(time);
            GPIO_toggle(CONFIG_GPIO_LED_0);
        }
    }
    

    Thanks,
    Alex F

  • Please let me know How to put Device into Low Power Mode. Because Our application depends upon battery life.  

  • Hello Ankit Jaiswal,

    To help reduce power consumption, I used LGPTimerLPF3_stop then LGPTimerLPF3_close to stop/close the timer; the details on how to stop the timer correctly are included in the LGPTimerLPFE.h file. Once the timer is closed the power consumption drops drastically, and instead of 6 days of battery life, I measured 4 years (using CCS EnergyTrace tool with the GPIO covers off). The following code snippet (modified version of empty.c project) is what I used to achieve this: 

     

    void *mainThread(void *arg0)
    {
        /* 1 second delay */
        uint32_t time = 1;
    
        /* Call driver init functions */
        GPIO_init();
    
        /* Configure the LED pin */
        GPIO_setConfig(CONFIG_GPIO_LED_0, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW);
        GPIO_setConfig(CONFIG_GPIO_LED_1, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW);
    
        uint32_t counterTarget;
         hTimer = NULL;
         LGPTimerLPF3_Params params;
         LGPTimerLPF3_Params_init(&params);
         params.hwiCallbackFxn = timerCallback;
         hTimer = LGPTimerLPF3_open(CONFIG_LGPTIMER_0, &params);
         if(hTimer == NULL) {
           //Log_error0("Failed to open LGPTimer");
           //Task_exit();
         }
         counterTarget = 48000;  // 1 ms with a system clock of 48 MHz
         LGPTimerLPF3_setInitialCounterTarget(hTimer, counterTarget, true);
         LGPTimerLPF3_enableInterrupt(hTimer, LGPTimerLPF3_INT_TGT);
         LGPTimerLPF3_start(hTimer, LGPTimerLPF3_CTL_MODE_UP_PER); //LGPTimerLPF3_CTL_MODE_UP_ONCE
         sleep(time);
         LGPTimerLPF3_stop(hTimer);
         LGPTimerLPF3_close(hTimer);
    
        while (1)
        {
            sleep(time);
            GPIO_toggle(CONFIG_GPIO_LED_0);
        }
    }

    Thanks,
    Alex F