//Fill in each parameter in the TIM_ICInitStruct with the default value
//把TIM_ICInitStruct 中的每一个参数按缺省值填入
TIM_ICStructInit(&TIM_ICInitStructure);
//Set the filter length //设置滤波器长度
TIM_ICInitStructure.TIM_ICFilter = 10;
//Initialize the peripheral TIMX based on the parameter TIM_ICINITSTRUCT //根据 TIM_ICInitStruct 的参数初始化外设 TIMx
TIM_ICInit(TIM5, &TIM_ICInitStructure);
//Clear the update bit for Tim //清除TIM的更新标志位
TIM_ClearFlag(TIM5, TIM_FLAG_Update);
//Enable the timer to interrupt //使能定时器中断
TIM_ITConfig(TIM5, TIM_IT_Update, ENABLE);
//Reset the timer count //重置定时器计数
TIM_SetCounter(TIM5,0);
//Enable timer 5 //使能定时器5
TIM_Cmd(TIM5, ENABLE);
}
//定时器5中断服务程序
void TIM5_IRQHandler(void)
{
if(TIM5->SR&0X0001) //Overflow interrupt //溢出中断
{
}
TIM5->SR&=~(1<<0); //Clear the interrupt flag bit //清除中断标志位
}
int Read_Encoder(void)
{
int Encoder_TIM;
//Fill in each parameter in the TIM_ICInitStruct with the default value
//把TIM_ICInitStruct 中的每一个参数按缺省值填入
TIM_ICStructInit(&TIM_ICInitStructure);
//Set the filter length //设置滤波器长度
TIM_ICInitStructure.TIM_ICFilter = 10;
//Initialize the peripheral TIMX based on the parameter TIM_ICINITSTRUCT //根据 TIM_ICInitStruct 的参数初始化外设 TIMx
TIM_ICInit(TIM5, &TIM_ICInitStructure);
//Clear the update bit for Tim //清除TIM的更新标志位
TIM_ClearFlag(TIM5, TIM_FLAG_Update);
//Enable the timer to interrupt //使能定时器中断
TIM_ITConfig(TIM5, TIM_IT_Update, ENABLE);
//Reset the timer count //重置定时器计数
TIM_SetCounter(TIM5,0);
//Enable timer 5 //使能定时器5
TIM_Cmd(TIM5, ENABLE);
}
//定时器5中断服务程序
void TIM5_IRQHandler(void)
{
if(TIM5->SR&0X0001) //Overflow interrupt //溢出中断
{
}
TIM5->SR&=~(1<<0); //Clear the interrupt flag bit //清除中断标志位
}
int Read_Encoder(void)
{
int Encoder_TIM;