//用于数码管计数
TIM_DeInit( TIM2 ); //将TIM寄存器重置为缺省值
TIM_InternalClockConfig( TIM2 ); //SMS =000采用内部时钟给TIM2提供时钟源( TIMxCLK( 72MHz ) -> CK_INT -> CK_PSC -> CK_CNT )
TIM_TimeBaseStructure.TIM_Period=2000; //2000*1/1000=1S
TIM_TimeBaseStructure.TIM_Prescaler=35999; //35999+1/72M=1/2000;
TIM_TimeBaseStructure.TIM_ClockDivision=0;
TIM_TimeBaseStructure.TIM_CounterMode=TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM2,&TIM_TimeBaseStructure);
TIM_ClearFlag( TIM2, TIM_FLAG_Update ); //清除溢出中断标志位
TIM_ARRPreloadConfig( TIM2, DISABLE ); //禁止ARR预装载缓冲器
TIM_ITConfig( TIM2,TIM_IT_Update,ENABLE );// 打开更新事件中断
TIM_Cmd(TIM2,ENABLE); //使能TIM2
//数码管扫描
TIM_DeInit( TIM6 ); //将TIM6寄存器重置为缺省值
TIM_InternalClockConfig( TIM6 );
TIM_TimeBaseStructure.TIM_Period=10; //扫描周期5ms
TIM_TimeBaseStructure.TIM_Prescaler=35999;
TIM_TimeBaseStructure.TIM_ClockDivision=0;
TIM_TimeBaseStructure.TIM_CounterMode=TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM6,&TIM_TimeBaseStructure);
TIM_ClearFlag( TIM6, TIM_FLAG_Update ); //清除溢出中断标志位
TIM_ARRPreloadConfig( TIM6, DISABLE ); //禁止ARR预装载缓冲器
TIM_ITConfig( TIM6,TIM_IT_Update,ENABLE );// 打开更新事件中断
TIM_Cmd(TIM6,ENABLE); //使能TIM6
//温度采集
TIM_DeInit(TIM5);
TIM_TimeBaseStructure.TIM_Period=300; //150ms
TIM_TimeBaseStructure.TIM_Prescaler=35999;
TIM_TimeBaseStructure.TIM_ClockDivision=0;
TIM_TimeBaseStructure.TIM_CounterMode=TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM5,&TIM_TimeBaseStructure);
TIM_ClearFlag(TIM5, TIM_FLAG_Update );
TIM_ITConfig(TIM5,TIM_IT_Update,ENABLE );
TIM_Cmd(TIM5,ENABLE);
除此以外我PWM3用了ch2和ch4控制电机转速。
我试了下,定时器4和定时器5无论哪个使用,我用delay_ms时候,都会使原有的时间变短许多。
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>