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.

LAUNCHXL-CC1310: CC1310 定时器参考代码

Part Number: LAUNCHXL-CC1310
Other Parts Discussed in Thread: CC1310

想使用下CC1310的定时器实现1ms的定时功能,有没有相关的例程?

  • https://dev.ti.com/tirex/content/simplelink_cc13x0_sdk_4_20_02_07/docs/tidrivers/doxygen/html/index.html

    您好,这里为您提供了定时器相关api函数说明,另外我这边为您提供了demo

    您这边可以参考sdk目录下 ti drivers 里面的pwm工程参考定时器

  • /*
     * Copyright (c) 2015-2019, Texas Instruments Incorporated
     * All rights reserved.
     *
     * Redistribution and use in source and binary forms, with or without
     * modification, are permitted provided that the following conditions
     * are met:
     *
     * *  Redistributions of source code must retain the above copyright
     *    notice, this list of conditions and the following disclaimer.
     *
     * *  Redistributions in binary form must reproduce the above copyright
     *    notice, this list of conditions and the following disclaimer in the
     *    documentation and/or other materials provided with the distribution.
     *
     * *  Neither the name of Texas Instruments Incorporated nor the names of
     *    its contributors may be used to endorse or promote products derived
     *    from this software without specific prior written permission.
     *
     * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
     * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
     * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
     * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
     * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
     * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     */
    
    /*
     *  ======== pwmled2.c ========
     */
    /* For usleep() */
    #include <unistd.h>
    #include <stddef.h>
    
    /* Driver Header files */
    #include <ti/drivers/PWM.h>
    
    /* Example/Board Header files */
    #include "Board.h"
    
    /*
     *  ======== mainThread ========
     *  Task periodically increments the PWM duty for the on board LED.
     */
    void *mainThread(void *arg0)
    {
        /* Period and duty in microseconds */
        uint16_t   pwmPeriod = 3000;
        uint16_t   duty = 0;
        uint16_t   dutyInc = 100;
    
        /* Sleep time in microseconds */
        uint32_t   time = 50000;
        PWM_Handle pwm1 = NULL;
        PWM_Handle pwm2 = NULL;
        PWM_Params params;
    
        /* Call driver init functions. */
        PWM_init();
    
        PWM_Params_init(&params);
        params.dutyUnits = PWM_DUTY_US;
        params.dutyValue = 0;
        params.periodUnits = PWM_PERIOD_US;
        params.periodValue = pwmPeriod;
        pwm1 = PWM_open(Board_PWM0, &params);
        if (pwm1 == NULL) {
            /* Board_PWM0 did not open */
            while (1);
        }
    
        PWM_start(pwm1);
    
        pwm2 = PWM_open(Board_PWM1, &params);
        if (pwm2 == NULL) {
            /* Board_PWM0 did not open */
            while (1);
        }
    
        PWM_start(pwm2);
    
        /* Loop forever incrementing the PWM duty */
        while (1) {
            PWM_setDuty(pwm1, duty);
    
            PWM_setDuty(pwm2, duty);
    
            duty = (duty + dutyInc);
    
            if (duty == pwmPeriod || (!duty)) {
                dutyInc = - dutyInc;
            }
    
            usleep(time);
        }
    }
    

  • 没有看到定时器的相关操作!

  • 您好,目前没有定时器的例程

    https://dev.ti.com/tirex/explore/content/simplelink_cc13x0_sdk_4_20_01_03/docs/tidrivers/doxygen/html/_g_p_timer_c_c26_x_x_8h.html

    您可以参考以上api函数文档以及以下代码

    #include <unistd.h>
    #include <stdint.h>
    #include <stddef.h>
    
    /* Driver Header files */
    #include <ti/drivers/GPIO.h>
    #include <ti/drivers/Power.h>
    #include <ti/drivers/power/PowerCC26XX.h>
    #include <ti/drivers/timer/GPTimerCC26XX.h>
    
    #include <ti/sysbios/BIOS.h>
    #include <ti/sysbios/knl/Task.h>
    
    #include <xdc/runtime/Types.h>
    
    /* Board Header file */
    #include "Board.h"
    
    GPTimerCC26XX_Handle hTimer0A;
    
    void timerCallback0A(GPTimerCC26XX_Handle handle, GPTimerCC26XX_IntMask interruptMask)
    {
        GPIO_toggle(Board_GPIO_LED0);
    }
    
    /*
     *  ======== mainThread ========
     */
    void *mainThread(void *arg0)
    {
        GPIO_init();
    
        GPIO_setConfig(Board_GPIO_LED0, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW);
    
        GPTimerCC26XX_Params params0A;
        GPTimerCC26XX_Params_init(&params0A);
        params0A.width          = GPT_CONFIG_16BIT;
        params0A.mode           = GPT_MODE_PERIODIC;
        params0A.direction      = GPTimerCC26XX_DIRECTION_UP;
        params0A.debugStallMode = GPTimerCC26XX_DEBUG_STALL_OFF;
        hTimer0A = GPTimerCC26XX_open(CC1310_LAUNCHXL_GPTIMER0A, &params0A);
    
        if(hTimer0A == NULL)
        {
            while(1);
        }
    
        Power_setDependency(PowerCC26XX_XOSC_HF);
    
        Types_FreqHz  freq;
        BIOS_getCpuFreq(&freq);
        GPTimerCC26XX_Value loadVal = (freq.lo / 1000)*348 - 1;
        GPTimerCC26XX_setLoadValue(hTimer0A, loadVal);
        GPTimerCC26XX_registerInterrupt(hTimer0A, timerCallback0A, GPT_INT_TIMEOUT);
    
        GPTimerCC26XX_start(hTimer0A);
    
        while(1)
        {
            Task_sleep(BIOS_WAIT_FOREVER);
        }
    }

    您可以测试一下以上内容,它每 348 毫秒发出一次中断:

  • 有问题随时论坛交流,希望可以帮助到您。