我采用的是tm4c1294ncpdt芯片,想用ti-rtos中的timer模块来定时1s实现led的闪烁,period我设置的是1000000,单位是微妙,但是结果虽然LED闪烁,但我调用timer_getperiod得到的是120000000,下面是我的源码和结果,请帮忙分析一下。
#include <xdc/std.h>
#include <xdc/runtime/System.h>
//#include <ti/sysbios/family/arm/m3/Hwi.h>
/* BIOS Header files */
#include <ti/sysbios/BIOS.h>
#include <ti/sysbios/knl/Task.h>
#include <ti/sysbios/hal/Timer.h>
#include <xdc/runtime/Error.h>
/* TI-RTOS Header files */
#include <ti/drivers/GPIO.h>
/* Example/Board Header files */
#include "Board.h"
UInt FLAG=0;
Timer_Params timerParams;
Timer_Handle timer0;
Void myIsr(UArg arg0)
{
FLAG=!FLAG;if(FLAG==0)
{GPIO_write(Board_LED0, Board_LED_ON);}else{GPIO_write(Board_LED0, Board_LED_OFF);}System_printf("Current period = %d\n", Timer_getPeriod(timer0));System_printf("%d\n",FLAG);System_flush();
}
int main(void)
{Board_initGeneral();Board_initGPIO();Error_Block eb;Error_init(&eb);Timer_Params_init(&timerParams);timerParams.period = 1000000;timerParams.periodType = Timer_PeriodType_MICROSECS;timerParams.arg = 1;timer0 = Timer_create(Timer_ANY, myIsr, &timerParams, &eb);if (timer0 == NULL){System_abort("Timer create failed");}System_flush();/* Start BIOS */BIOS_start();return (0);
}
下面是运行结果

xyz549040622:
会不会是中断中的函数太长了。你可以在中断中反转一个IO,用示波器测测,看看你的定时器设置是否OK?
TI中文支持网
