TA的每日心情 | 奋斗 2013-10-28 09:28 |
---|
签到天数: 34 天 连续签到: 1 天 [LV.5]常住居民I
|
今天调试四轴遥控,需要用到定时器的输入捕获功能,于是配置TIM5如下:
/* Connect TIM pin to AF2 */
GPIO_PinAFConfig(GPIOA, GPIO_PinSource0, GPIO_AF_TIM5);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource1, GPIO_AF_TIM5);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource2, GPIO_AF_TIM5);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource3, GPIO_AF_TIM5);
TIM5_ICInitStructure.TIM_Channel = TIM_Channel_1;
TIM5_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising;
TIM5_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;
TIM5_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;
TIM5_ICInitStructure.TIM_ICFilter = 0x01;
TIM_ICInit(TIM5, &TIM5_ICInitStructure);
TIM5_ICInitStructure.TIM_Channel = TIM_Channel_2;
TIM5_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising;
TIM5_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;
TIM5_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;
TIM5_ICInitStructure.TIM_ICFilter = 0x01;
TIM_ICInit(TIM5, &TIM5_ICInitStructure);
TIM5_ICInitStructure.TIM_Channel = TIM_Channel_3;
TIM5_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising;
TIM5_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;
TIM5_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;
TIM5_ICInitStructure.TIM_ICFilter = 0x01;
TIM_ICInit(TIM5, &TIM5_ICInitStructure);
TIM5_ICInitStructure.TIM_Channel = TIM_Channel_4;
TIM5_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising;
TIM5_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;
TIM5_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;
TIM5_ICInitStructure.TIM_ICFilter = 0x01;
TIM_ICInit(TIM5, &TIM5_ICInitStructure);
TIM_ITConfig(TIM5,TIM_IT_CC1,ENABLE);
TIM_ITConfig(TIM5,TIM_IT_CC2,ENABLE);
TIM_ITConfig(TIM5,TIM_IT_CC3,ENABLE);
TIM_ITConfig(TIM5,TIM_IT_CC4,ENABLE);
TIM_Cmd(TIM5,ENABLE );
按照这样配置完成后,CH1,CH3,CH4都是可以的,正常,但是就CH2不能正常工作,找了半天,未果,后来只有使用另外一种方法来解决捕获的功能,就是再使用一个TIM6来计数,使能PA1的EXIT功能,代码如下:
TIM_Cmd(TIM6, ENABLE);
/* Connect EXTI Line0 to PA0 pin */
SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOA, EXTI_PinSource1);
EXTI_InitStructure.EXTI_Line = EXTI_Line1;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
这样终于解决了问题,四个 通道的PPM信号就可以能够捕获到了!!!
再次重申一下PA1不能用于TIM5的捕获功能。。。{:soso_e100:}{:soso_e100:}{:soso_e100:},希望我们好运!!!
|
|