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:如何配置计时器

Guru**** 1812430 points
Other Parts Discussed in Thread: ENERGYTRACE
请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/wireless-connectivity/bluetooth-group/bluetooth/f/bluetooth-forum/1273226/cc2340r5-how-to-configure-timer

器件型号:CC2340R5
主题中讨论的其他器件:ENERGYTRACE

如何在 TI 配置计时器。 请为我提供相同的示例代码。 我曾尝试使用此代码、但不起作用。

此外 、我还在 CCS 中使用了 Energytrace 选项。 它显示4 - 5天电池寿命,我不知道它是否显示正确或错误。 请确认。

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    大家好、 Ankit Jaiswal、

    在查看您的代码片段时、您似乎没有包含"LGPTimerLPF3_start"、它不会启动计时器、这将解释计时器为何不工作。 由于该器件从不进入低功耗模式、因此功耗相对较高(对于以下代码、I 测量结果为~1.5天、因为 CPU 始终处于运行状态+ GPIO、如果我卸下 GPIO 护盖以将其断开、则为6天)。  

    下面是我根据 TI 驱动程序库改编的示例:

    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);
        }
    }
    

    谢谢。
    A·F

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    请告诉我如何将器件置于低功耗模式。 因为我们的应用取决于电池寿命。   

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    大家好、 Ankit Jaiswal、

    为了帮助减少功耗、我先后使用了 LGPTimerLPF3_STOP 和 LGPTimerLPF3_Close 来停止/关闭定时器;有关如何正确停止定时器的详细信息包含在 LGPTimerLPFE.h 文件中。 计时器关闭后、功耗会 大幅降低、而我测得的数据是4年(使用 CCS EnergyTrace 工具并关闭 GPIO)、而不是6天的电池寿命。  为了实现 这一点、我使用了以下代码片段(empty.c 项目的修改版本):  

     

    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);
        }
    }

    谢谢。
    A·F