请教一下,为什么
TIM_ICStructInit(&TIM_ICInitStructure);
TIM_ICInitStructure.TIM_ICFilter = 10;
TIM_ICInit(TIM4, &TIM_ICInitStructure);
这里没有设置通道呢,TIM_ICStructInit里面只设置了通道一,通道二不需要设置吗????
程序如下:
void Encoder_Init_TIM2(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_ICInitTypeDef TIM_ICInitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);//ê1Äü¶¨ê±Æ÷4μÄê±Öó
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);//ê1ÄüPB¶Ë¿úê±Öó
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1; //¶Ë¿úÅäÖÃ
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; //¸¡¿Õêäèë
GPIO_Init(GPIOA, &GPIO_InitStructure); //¸ù¾Yé趨2Îêy3õê¼»ˉGPIOB
TIM_TimeBaseStructInit(&TIM_TimeBaseStructure);
TIM_TimeBaseStructure.TIM_Prescaler = 0x0; // Ô¤·ÖÆμÆ÷
TIM_TimeBaseStructure.TIM_Period = ENCODER_TIM_PERIOD; //é趨¼ÆêyÆ÷×Ô¶ˉÖØ×°Öμ
TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;//Ñ¡Ôñê±Öó·ÖÆμ£o2»·ÖÆμ
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;//TIMÏòéϼÆêy
TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);
TIM_EncoderInterfaceConfig(TIM2, TIM_EncoderMode_TI12, TIM_ICPolarity_Rising, TIM_ICPolarity_Rising);//ê1óñàÂëÆ÷Ä£ê½3
TIM_ICStructInit(&TIM_ICInitStructure);
TIM_ICInitStructure.TIM_ICFilter = 10;
TIM_ICInit(TIM2, &TIM_ICInitStructure);
TIM_ClearFlag(TIM2, TIM_FLAG_Update);//Çå3yTIMμĸüD±ê־λ
TIM_ITConfig(TIM2, TIM_IT_Update, ENABLE);
//Reset counter
TIM_SetCounter(TIM2,0);
TIM_Cmd(TIM2, ENABLE);
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>