|
M4C123GH6PM如何捕获高电平脉冲宽度(50us到100ms)?
[复制链接]
TI具有Context M4内核的TM4C123GH6PM,配置捕获进入中断没问题,可以计上升沿次数,但我要捕获一个高电平脉冲宽度(50us-100ms),请问该怎么实现呢,期待广大坛友的解答。
int main(void)
{
//system config
SysCtlClockSet(SYSCTL_SYSDIV_2_5|SYSCTL_USE_PLL
|SYSCTL_OSC_MAIN|SYSCTL_XTAL_16MHZ);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
SysCtlDelay(200);//配置完系统寄存器后要延时一段时间
//GPIO config
GPIOPinConfigure(GPIO_PB7_T0CCP1);
GPIOPinTypeTimer(GPIO_PORTB_BASE, GPIO_PIN_7);
GPIOPinTypeGPIOOutput(GPIO_PORTE_BASE, GPIO_PIN_1); //PE1--Trig Output
//Timer config
TimerConfigure(TIMER0_BASE, TIMER_CFG_SPLIT_PAIR | TIMER_CFG_B_CAP_TIME_UP);
TimerControlEvent(TIMER0_BASE, TIMER_B, TIMER_EVENT_POS_EDGE);
//Int config
IntEnable(INT_TIMER0B);
TimerIntEnable(TIMER0_BASE, TIMER_CAPB_EVENT);
IntMasterEnable();
//TimerLoadSet(TIMER0_BASE, TIMER_B, 0);//设置初值为0
//TimerMatchSet(TIMER0_BASE, TIMER_B, 80);//设置匹配值
TimerEnable(TIMER0_BASE, TIMER_B);
while(1)
{
HC_SRO4_Start();
SysCtlDelay(800);
}
}
void Timer0B_Int_Handler()
{
TimerIntClear(TIMER0_BASE, TIMER_CAPB_EVENT);
t[Count]=TimerValueGet(TIMER0_BASE,TIMER_B);
Count++;
if(Count==2)
{
time=t[1]-t[0];
HC_SR04_Count_distance();
Count=0;
}
}
//通过Debug跟踪,Count可以计数,但t[1]和t[0]的值始终是0,不知道是肿么回事。。。
|
|