使用TIVAWARE库进行开发的时候,通过这个帖子,我们已经了解了TM4定时器的基本情况,但是我在自己配置4路pwm信号检测时,仍然遇到了问题。
关键要注意TimerConfigure这个函数不能对同一个定时器的不同模块(timerA/B)做重复的配置。详情见我在英文E2E论坛的帖子。
应该写成:
ROM_TimerConfigure(WTIMER0_BASE, TIMER_CFG_SPLIT_PAIR | TIMER_CFG_A_CAP_TIME_UP |TIMER_CFG_B_CAP_TIME_UP );
而非:
ROM_TimerConfigure(WTIMER0_BASE, TIMER_CFG_SPLIT_PAIR | TIMER_CFG_A_CAP_TIME_UP );
ROM_TimerConfigure(WTIMER0_BASE, TIMER_CFG_SPLIT_PAIR | TIMER_CFG_B_CAP_TIME_UP );
这样会导致上一句的设置被覆盖。
同样的,TimerEnable也应该写成
TimerEnable(WTIMER0_BASE, TIMER_BOTH);
而非
TimerEnable(WTIMER0_BASE, TIMER_A);
TimerEnable(WTIMER0_BASE, TIMER_B);
我写的四轴遥控器接收机4路PWM输入的RC初始化代码如下:
void initRC()
{
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_WTIMER0); //enable Wtimer0
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_WTIMER1); //enable Wtimer1
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC); //enable gpioC for PC4567
ROM_GPIOPinConfigure(GPIO_PC4_WT0CCP0);
ROM_GPIOPinConfigure(GPIO_PC5_WT0CCP1);
ROM_GPIOPinConfigure(GPIO_PC6_WT1CCP0);
ROM_GPIOPinConfigure(GPIO_PC7_WT1CCP1);
ROM_GPIOPinTypeTimer(GPIO_PORTC_BASE, GPIO_PIN_4);
ROM_GPIOPinTypeTimer(GPIO_PORTC_BASE, GPIO_PIN_5);
ROM_GPIOPinTypeTimer(GPIO_PORTC_BASE, GPIO_PIN_6);
ROM_GPIOPinTypeTimer(GPIO_PORTC_BASE, GPIO_PIN_7);
// ROM_GPIOPadConfigSet(GPIO_PORTC_BASE,GPIO_PIN_4,GPIO_STRENGTH_2MA,GPIO_PIN_TYPE_STD_WPD);
// ROM_GPIOPadConfigSet(GPIO_PORTC_BASE,GPIO_PIN_5,GPIO_STRENGTH_2MA,GPIO_PIN_TYPE_STD_WPD);
//ROM_GPIOPadConfigSet(GPIO_PORTC_BASE,GPIO_PIN_6,GPIO_STRENGTH_2MA,GPIO_PIN_TYPE_STD_WPD);
// ROM_GPIOPadConfigSet(GPIO_PORTC_BASE,GPIO_PIN_7,GPIO_STRENGTH_2MA,GPIO_PIN_TYPE_STD_WPD);
ROM_TimerConfigure(WTIMER0_BASE, TIMER_CFG_SPLIT_PAIR | TIMER_CFG_A_CAP_TIME_UP | TIMER_CFG_B_CAP_TIME_UP );
ROM_TimerConfigure(WTIMER1_BASE, TIMER_CFG_SPLIT_PAIR | TIMER_CFG_A_CAP_TIME_UP | TIMER_CFG_B_CAP_TIME_UP );
ROM_TimerControlEvent(WTIMER0_BASE, TIMER_BOTH, TIMER_EVENT_BOTH_EDGES );
// ROM_TimerControlEvent(WTIMER0_BASE, TIMER_B, TIMER_EVENT_NEG_EDGE );
ROM_TimerControlEvent(WTIMER1_BASE, TIMER_BOTH, TIMER_EVENT_BOTH_EDGES );
ROM_TimerLoadSet(WTIMER0_BASE, TIMER_A, 1600000-1);
ROM_TimerLoadSet(WTIMER0_BASE, TIMER_B, 1600000-1);
ROM_TimerLoadSet(WTIMER1_BASE, TIMER_A, 1600000-1);
ROM_TimerLoadSet(WTIMER1_BASE, TIMER_B, 1600000-1);
ROM_IntEnable(INT_WTIMER0A);
ROM_IntEnable(INT_WTIMER0B);
ROM_IntEnable(INT_WTIMER1A);
ROM_IntEnable(INT_WTIMER1B);
TimerIntRegister(WTIMER0_BASE, TIMER_A, WTimer0AIntHandler);
TimerIntRegister(WTIMER0_BASE, TIMER_B, WTimer0BIntHandler);
TimerIntRegister(WTIMER1_BASE, TIMER_A, WTimer1AIntHandler);
TimerIntRegister(WTIMER1_BASE, TIMER_B, WTimer1BIntHandler);
ROM_TimerIntEnable(WTIMER0_BASE, TIMER_CAPA_EVENT);
ROM_TimerIntEnable(WTIMER0_BASE, TIMER_CAPB_EVENT);
ROM_TimerIntEnable(WTIMER1_BASE, TIMER_CAPA_EVENT);
ROM_TimerIntEnable(WTIMER1_BASE, TIMER_CAPB_EVENT);
ROM_TimerEnable(WTIMER0_BASE, TIMER_BOTH);
ROM_TimerEnable(WTIMER1_BASE, TIMER_BOTH);
}
具体在中断函数里的数据处理 请等待更新。