void Timer0IntHandler(void)
{
TimerIntClear(TIMER0_BASE,TIMER_CAPA_EVENT);
TimeLater=TimerValueGet(TIMER0_BASE,TIMER_A) ;
}
void InitTimer()
{
SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); // Timer0
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);//PORTB for timer0
GPIOPinConfigure(GPIO_PB6_T0CCP0 ); // configure PB6 for Timer0A
GPIOPinTypeGPIOInput(GPIO_PORTB_BASE, GPIO_PIN_6);
GPIOPinTypeTimer(GPIO_PORTB_BASE, GPIO_PIN_6);//PB6 for timer0
TimerConfigure(TIMER0_BASE,TIMER_CFG_A_CAP_TIME_UP|TIMER_CFG_SPLIT_PAIR);
TimerControlEvent(TIMER0_BASE,TIMER_A,TIMER_EVENT_BOTH_EDGES);
if(GPIOPinRead(GPIO_PORTB_BASE, GPIO_PIN_6)==24)
{
TimeBeginning=TimerValueGet(TIMER0_BASE,TIMER_A) ;
}
TimerLoadSet(TIMER0_BASE, TIMER_A, 1000);
TimerIntRegister(TIMER0_BASE,TIMER_A,Timer0IntHandler);
IntMasterEnable();
TimerIntEnable(TIMER0_BASE, TIMER_CAPA_EVENT);
TimerControlEvent(TIMER0_BASE,TIMER_A,TIMER_EVENT_NEG_EDGE);
IntEnable(INT_TIMER0A);
TimerEnable(TIMER0_BASE , TIMER_A);
}
这样配置定时器:
使用Timer0 的PB6引脚作为方波输入引脚。
配置定时器向上计数。设置初值1000
定时器设置为上升沿触发,检测到上升沿时,获取定时器的值(使用TimeValueGet()),作为方波高电平起点值。
中断注册为下降沿触发。中断函数里获取定时器的值,作为方波高电平终点值。两者作差得到高电平持续时间。
但是,我在运行程序时view expressions,发现只有高电平起点的定时器值一直为零。附图如下,这是为什么