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.

用timer不能capture到上升沿。

Other Parts Discussed in Thread: TM4C123GH6PM

大家好。

我用的是TM4C123GH6PM来测量码盘发出的方波信号的上升沿和下降沿。

timer设置如下:

void TimerInit() {

SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER2);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);

// configure the pins to capture.
GPIOPinConfigure(GPIO_PB0_T2CCP0);
GPIOPinConfigure(GPIO_PB1_T2CCP1);
GPIOPinTypeTimer(GPIO_PORTB_BASE, GPIO_PIN_0);
GPIOPinTypeTimer(GPIO_PORTB_BASE, GPIO_PIN_1);

GPIOPadConfigSet(GPIO_PORTB_BASE, GPIO_PIN_0,
GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU);
GPIOPadConfigSet(GPIO_PORTB_BASE, GPIO_PIN_1,
GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU);
//GPIODirModeSet(GPIO_PORTB_BASE, GPIO_PIN_0, GPIO_DIR_MODE_IN);
//GPIODirModeSet(GPIO_PORTB_BASE, GPIO_PIN_1, GPIO_DIR_MODE_IN);
// Configure the 32-bit periodic timers.
TimerConfigure(TIMER2_BASE, (TIMER_CFG_SPLIT_PAIR | TIMER_CFG_A_CAP_COUNT_UP |
TIMER_CFG_B_CAP_COUNT_UP));

// Configure the counters to count positive edges.
TimerControlEvent(TIMER2_BASE, TIMER_A, TIMER_EVENT_NEG_EDGE);
TimerControlEvent(TIMER2_BASE, TIMER_B, TIMER_EVENT_NEG_EDGE);
TimerLoadSet(TIMER2_BASE, TIMER_A, 0);
TimerLoadSet(TIMER2_BASE, TIMER_B, 0);
TimerMatchSet(TIMER2_BASE, TIMER_A, encodingDiskCon);
TimerMatchSet(TIMER2_BASE, TIMER_B, 65535);

// INT
IntEnable(INT_TIMER2A);
IntEnable(INT_TIMER2B);
TimerIntEnable(TIMER2_BASE, TIMER_CAPA_MATCH);
TimerIntEnable(TIMER2_BASE, TIMER_CAPB_MATCH);

// Need this ???
// TimerIntRegister(TIMER2_BASE, TIMER_A, Timer2AIntHandler);
// enable timer
TimerEnable(TIMER2_BASE, TIMER_BOTH);
}

然后主函数用

while (1) {
UARTprintf("%d ", TimerLoadGet(TIMER2_BASE, TIMER_A));
SysCtlDelay(SysCtlClockGet() / 3);
}

发送TimerLoadGet(TIMER2_BASE, TIMER_A),不管码盘怎么转都输出0,而且用示波器检查了码盘输出信号也很正常。

求助!