金牌会员
- 积分
- 1419
- 金钱
- 1419
- 注册时间
- 2011-11-27
- 在线时间
- 122 小时
|
发表于 2014-5-11 21:57:48
|
显示全部楼层
回复【2楼】小刺猬:
---------------------------------
void Timer3_Config(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_ICInitTypeDef TIM_ICInitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE); //启动Tim3时钟
TIM_DeInit(TIM3); //重设为缺省值
TIM_TimeBaseStructure.TIM_Prescaler = 0; //预分频
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; //向上计数
TIM_TimeBaseStructure.TIM_Period = 0xFFFF; //装载值
TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1; //设置了时钟分割
TIM_TimeBaseStructure.TIM_RepetitionCounter = 0x0; //周期计数器值
TIM_TimeBaseInit(TIM3,&TIM_TimeBaseStructure); //初始化TIMx的时间基数单位
TIM_EncoderInterfaceConfig(TIM3, TIM_EncoderMode_TI12, TIM_ICPolarity_Rising, TIM_ICPolarity_Rising); //TIM_ICPolarity_Rising上升沿捕获
TIM_ICStructInit(&TIM_ICInitStructure);
TIM_ICInitStructure.TIM_ICFilter = ENCODE_FILTER; //比较滤波器
TIM_ICInit(TIM3, &TIM_ICInitStructure);
TIM_Cmd(TIM3, ENABLE);
TIM3->CNT = 0;
TIM_GenerateEvent(TIM3,TIM_EventSource_Update);
}
void Timer4_Config(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_ICInitTypeDef TIM_ICInitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE); //启动Tim3时钟
TIM_DeInit(TIM4); //重设为缺省值
TIM_TimeBaseStructure.TIM_Prescaler = 0; //预分频
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; //向上计数
TIM_TimeBaseStructure.TIM_Period = 0xFFFF; //装载值
TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1; //设置了时钟分割
TIM_TimeBaseStructure.TIM_RepetitionCounter = 0x0; //周期计数器值
TIM_TimeBaseInit(TIM4,&TIM_TimeBaseStructure); //初始化TIMx的时间基数单位
TIM_EncoderInterfaceConfig(TIM4, TIM_EncoderMode_TI12, TIM_ICPolarity_Rising, TIM_ICPolarity_Rising); //TIM_ICPolarity_Rising上升沿捕获
TIM_ICStructInit(&TIM_ICInitStructure);
TIM_ICInitStructure.TIM_ICFilter = ENCODE_FILTER; //比较滤波器
TIM_ICInit(TIM4, &TIM_ICInitStructure);
TIM_Cmd(TIM4, ENABLE);
TIM4->CNT = 0;
TIM_GenerateEvent(TIM4,TIM_EventSource_Update);
} |
|