TI中文支持网
TI专业的中文技术问题搜集分享网站

cc1310 定时器 边沿检没配置问题

您好:
我现在在用timerA的边沿计数模式。使用没法得到计数值,不知道是因为配置不正确,还是其它哪地方没配置对???麻烦帮我分析一下。配置代码流程如下:

注意:用代码默认的边沿检测引脚IO23检测,定时器中断没开启,开启后也是读不到计数值。。。。。
1.第1步
GPIO_setConfig(Board_GPIO_NST1001_DEC_IO23, GPIO_CFG_IN_NOPULL ); //timerA 边沿检测引脚
GPIO_setConfig(Board_GPIO_NST1001_P, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW);//mod lhj
2.第2步 定时器边沿配置******
//add lhj timer edge
GPTimerCC26XX_Params timeParams;
GPTimerCC26XX_Params_init(&timeParams);
timeParams.width = GPT_CONFIG_16BIT;//GPT_CONFIG_32BIT;
timeParams.mode = GPT_MODE_EDGE_COUNT_UP;//GPT_MODE_PERIODIC_UP;
timeParams.matchTiming = GPTimerCC26XX_SET_MATCH_NEXT_CLOCK;
timeParams.direction = GPTimerCC26XX_DIRECTION_UP;
timeParams.debugStallMode = GPTimerCC26XX_DEBUG_STALL_OFF;
gptime = GPTimerCC26XX_open(CC1310_LAUNCHXL_GPTIMER0A,&timeParams);

//边沿配置
//GPTimerCC26XX_setMatchValue(gptime,2);
GPTimerCC26XX_setCaptureEdge(gptime,GPTimerCC26XX_POS_EDGE );// 正边沿计数

// ClockP_FreqHz freq;
// ClockP_getCpuFreq(&freq);
// GPTimerCC26XX_Value loadVal = freq.lo *50 – 1; //5s mod lhj
// GPTimerCC26XX_setLoadValue(gptime, loadVal);
// GPTimerCC26XX_registerInterrupt(gptime,interruptTimer_5s,GPT_INT_TIMEOUT);
//GPTimerCC26XX_start(gptime);

//add lhj timer
C_FLAG = 0; //
CPUdelay(1000*48/4); //
GPIO_write(Board_GPIO_NST1001_P, 1);//给NST001供电

/* Enable interrupts */
//GPIO_enableInt(Board_GPIO_NST1001_DQ);//mod lhj
GPTimerCC26XX_start(gptime);

//add lhj

while(1)
{
CPUdelay(35000*48/4);//大约10000us
nst1001Int_Conut = GPTimerCC26XX_getValue(gptime);//读出的计数值一直是0*******???????
GPIO_toggle(Board_GPIO_LED0);
CPUdelay(5000*48/4);//大约10000us
//GPTimerCC26XX_start(gptime);

Viki Shi:

/***** Includes *****/
/* Standard C Libraries */
#include <stdlib.h>/* RTOS header files */
#include <ti/sysbios/BIOS.h>
#include <ti/sysbios/knl/Task.h>/* TI Drivers */
#include <ti/drivers/rf/RF.h>
#include <ti/drivers/PIN.h>
#include <ti/drivers/pin/PINCC26XX.h>
#include <ti/drivers/timer/GPTimerCC26XX.h>/* Driverlib Header files */
#include DeviceFamily_constructPath(driverlib/rf_prop_mailbox.h)/* Board Header files */
#include "Board.h"/***** Variable declarations *****/
/* Pin driver handle */
static PIN_Handle ledPinHandle;
static PIN_State ledPinState;PIN_Config pinTable[] =
{Board_PIN_LED1 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,Board_PIN_LED2 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,Board_PIN_BUTTON0 | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_NEGEDGE,PIN_TERMINATE
};GPTimerCC26XX_Handle hTimer0A;
static uint8_t counter = 0;void timerCallback0A(GPTimerCC26XX_Handle handle, GPTimerCC26XX_IntMask interruptMask)
{counter += 5;
}/***** Function definitions *****/void *mainThread(void *arg0)
{/* Open LED pins */ledPinHandle = PIN_open(&ledPinState, pinTable);if (ledPinHandle == NULL){while(1);}GPTimerCC26XX_Params params0A;GPTimerCC26XX_Params_init(&params0A);params0A.width= GPT_CONFIG_16BIT;params0A.mode= GPT_MODE_EDGE_COUNT_UP;params0A.debugStallMode = GPTimerCC26XX_DEBUG_STALL_OFF;hTimer0A = GPTimerCC26XX_open(CC1310_LAUNCHXL_GPTIMER0A, &params0A);if(hTimer0A == NULL){while(1);}GPTimerCC26XX_registerInterrupt(hTimer0A, timerCallback0A, GPT_INT_CAPTURE_MATCH);GPTimerCC26XX_PinMux pinMux = GPTimerCC26XX_getPinMux(hTimer0A);PINCC26XX_setMux(ledPinHandle, Board_PIN_BUTTON0, pinMux);GPTimerCC26XX_setCaptureEdge(hTimer0A, GPTimerCC26XX_NEG_EDGE);GPTimerCC26XX_setLoadValue(hTimer0A, 0xFFFFFF);GPTimerCC26XX_setMatchValue(hTimer0A, 5);GPTimerCC26XX_start(hTimer0A);while(1){Task_sleep(BIOS_WAIT_FOREVER);}
}

例程如上,按五次 BTN-1会产生中断【硬件是launchpad】

fghj dfghjk:

回复 Viki Shi:

好的太感谢了,我调试一下。

fghj dfghjk:

回复 Viki Shi:

GPTimerCC26XX_stop(hTimer0A);后,想让边沿计数重新开始检测边沿。是不是每次都GPTimerCC26XX_setLoadValue(hTimer0A, 0xFFFFFF);装载值,定时器停止后,内部的计数器会自动清零?????

Viki Shi:

回复 fghj dfghjk:

定时器时间重置直接用GPTimerCC26XX_setLoadValue(hTimer0A, 0)

赞(0)
未经允许不得转载:TI中文支持网 » cc1310 定时器 边沿检没配置问题
分享到: 更多 (0)