void TIM2_INIT(void)
{
GPIO_InitTypeDef GPIO_InitStruct;
NVIC_InitTypeDef NVIC_InitStructure;
TIM_ICInitTypeDef TIM2_ICInitStructure;
TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStruct;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA ,ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2,ENABLE);
GPIO_InitStruct.GPIO_Mode=GPIO_Mode_IPD;
GPIO_InitStruct.GPIO_Pin=GPIO_Pin_0|GPIO_Pin_1;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA,&GPIO_InitStruct);
GPIO_ResetBits(GPIOA,GPIO_Pin_0|GPIO_Pin_1);
TIM_TimeBaseInitStruct.TIM_Period = 0xFFFF; //é趨¼ÆêyÆ÷×Ô¶ˉÖØ×°Öé趨¼ÆêyÆ÷×Ô¶ˉÖØ×°Ö
TIM_TimeBaseInitStruct.TIM_Prescaler =72-1; //Ô¤·ÖÆμÆ÷
TIM_TimeBaseInitStruct.TIM_ClockDivision = TIM_CKD_DIV1; //éèÖÃê±Öó·Ö¸î:TDTS = Tck_tim
TIM_TimeBaseInitStruct.TIM_CounterMode = TIM_CounterMode_Up; //TIMÏòéϼÆêyÄ£ê½
TIM_TimeBaseInit(TIM2, &TIM_TimeBaseInitStruct); //¸ù¾YTIM_TimeBaseInitStructÖDÖ¸¶¨μÄ2Îêy3õê¼»ˉTIMxμÄê±¼ä»ùêyμ¥λ
TIM_EncoderInterfaceConfig(TIM2, TIM_EncoderMode_TI1, TIM_ICPolarity_BothEdge ,TIM_ICPolarity_BothEdge);
TIM2_ICInitStructure.TIM_Channel = TIM_Channel_1; //CC1S=01 Ñ¡Ôñêäèë¶Ë IC1ó3éäμ½TI1éÏ
TIM2_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising; //éÏéyÑØ2¶»ñ
TIM2_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI; //ó3éäμ½TI1éÏ
TIM2_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1; //ÅäÖÃêäèë·ÖÆμ,2»·ÖÆμ
TIM2_ICInitStructure.TIM_ICFilter = 6;//IC1F=0000 ÅäÖÃêäèëÂË2¨Æ÷ 2»ÂË2¨
TIM_ICInit(TIM2, &TIM2_ICInitStructure);
TIM2->CCMR1 |= 1<<8;
TIM2->CCER &= ~(1<<1); //CC1P='0' IC1FP1???,IC1FP1=TI1
TIM2->CCER &= ~(1<<5); //CC2P='0' IC2FP2???,IC2FP2=TI2
NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn; //TIM2ÖD¶Ï
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2; //ÏèÕ¼óÅÏ輶2¼¶
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; //′óóÅÏ輶0¼¶
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQí¨μà±»ê1Äü
NVIC_Init(&NVIC_InitStructure); //¸ù¾YNVIC_InitStructÖDÖ¸¶¨μÄ2Îêy3õê¼»ˉíaéèNVIC¼Ä′æÆ÷
TIM_ITConfig (TIM2, TIM_IT_Update|TIM_IT_CC1|TIM_IT_CC2, ENABLE);//ÔêDí¸üDÂÖD¶Ï ,ÔêDíCC1IE2¶»ñÖD¶Ï
TIM_Cmd(TIM2,ENABLE); //ê1Äü¶¨ê±Æ÷2
TIM2->CNT=0;
}
u8 BMQ_A;
u8 BMQ_B;
void TIM2_IRQHandler(void)
{
if(TIM_GetITStatus(TIM2,TIM_IT_CC1)!=RESET )
{
BMQ_A++;
LED1=0;
}
if(TIM_GetITStatus(TIM2,TIM_IT_CC2)!=RESET )
{
BMQ_B++;
}
TIM_ClearITPendingBit(TIM2,TIM_IT_Update|TIM_IT_CC1);
}
这个是我本人配置的编码器程序 但是在调试过程中发现 BMQ_A 根本就没有自增 也就是 没有进入捕获中断里面 请问各位大神 这是怎么回事 是不是我配置的问题
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>