学前班
最后登录1970-1-1
在线时间 小时
注册时间2015-1-24
|
使用TIM5和TIM8做两个正交解码的计数程序,可是TIM5可以进中断,而TIM8进不了,求解乱码的都是注释
/*----------------------------------------------------------------*/
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM5, ENABLE);
TIM_DeInit(TIM5);
TIM_TimeBaseInit(TIM5, &TIM_TimeBaseStructure);
/*----------------------------------------------------------------*/
RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM8, ENABLE);
TIM_DeInit(TIM8);
TIM_TimeBaseInit(TIM8, &TIM_TimeBaseStructure);
/*----------------------------------------------------------------*/
TIM_TimeBaseStructure.TIM_Period =0xffff; //
TIM_TimeBaseStructure.TIM_Prescaler =0;
TIM_TimeBaseStructure.TIM_ClockDivision =TIM_CKD_DIV1 ;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
//TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_CenterAligned1;
TIM_TimeBaseInit(TIM5, &TIM_TimeBaseStructure);
TIM_TimeBaseInit(TIM8, &TIM_TimeBaseStructure);
/*-----------------------------------------------------------------*/
//±àÂëÅäÖà ±àÂëÄ£ê½
TIM_EncoderInterfaceConfig(TIM5, TIM_EncoderMode_TI12,
TIM_ICPolarity_Rising, TIM_ICPolarity_Rising); //TIM_ICPolarity_RisingéÏéyÑØ2¶»ñ
/*-----------------------------------------------------------------*/
//±àÂëÅäÖà ±àÂëÄ£ê½
TIM_EncoderInterfaceConfig(TIM8, TIM_EncoderMode_TI12,
TIM_ICPolarity_Rising, TIM_ICPolarity_Rising); //TIM_ICPolarity_RisingéÏéyÑØ2¶»ñ
/*-----------------------------------------------------------------*/
TIM_ICStructInit(&TIM_ICInitStructure);
TIM_ICInitStructure.TIM_ICFilter = 6; //±è½ÏÂË2¨Æ÷
TIM_ICInit(TIM5, &TIM_ICInitStructure);
TIM_ICStructInit(&TIM_ICInitStructure);
TIM_ICInitStructure.TIM_ICFilter = 6; //±è½ÏÂË2¨Æ÷
TIM_ICInit(TIM8, &TIM_ICInitStructure);
/*-----------------------------------------------------------------*/
// Clear all pending interrupts
TIM_ClearFlag(TIM5, TIM_FLAG_Update);
TIM_ITConfig(TIM5, TIM_IT_Update, ENABLE); //ê1ÄüÖD¶Ï
//Reset counter
TIM5->CNT =0;
TIM_Cmd(TIM5, ENABLE); //ê1Äü¶¨ê±Æ÷3
/*-----------------------------------------------------------------*/
// Clear all pending interrupts
TIM_ClearFlag(TIM8, TIM_FLAG_Update);
TIM_ITConfig(TIM8, TIM_IT_Update, ENABLE); //ê1ÄüÖD¶Ï
//Reset counter
TIM8->CNT =0;
TIM_Cmd(TIM8, ENABLE); //ê1Äü¶¨ê±Æ÷3
/*-----------------------------------------------------------------*/
/* Configure one bit for preemption priority */
/* Timer5ÖD¶Ï*/
NVIC_InitStructure.NVIC_IRQChannel = TIM5_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
/* Timer8ÖD¶Ï*/
NVIC_InitStructure.NVIC_IRQChannel = TIM8_UP_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
|
|