stm32 TIMER

SMT32 TM1 做定时器用

  • 初始化定时器

初始化定时器

TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3,ENABLE);

TIM_TimeBaseInitStructure.TIM_ClockDivision=TIM_CKD_DIV1;		//时钟源分频设置
TIM_TimeBaseInitStructure.TIM_CounterMode=TIM_CounterMode_Up;		//计数模式
TIM_TimeBaseInitStructure.TIM_Period=pre;							//计数上限
TIM_TimeBaseInitStructure.TIM_Prescaler=psc;						//计时器分频
TIM_TimeBaseInit(TIM3,&TIM_TimeBaseInitStructure);

TIM_SetCounter(TIM1,0);			//设置数值
TIM_Cmd(TIM1, ENABLE);			//开始计时

1.TIM_ARRPreloadConfig //ENABLE–允许立即写入ARR缓冲区
2.TIM_SetAutoreload //自动重装载值归零
3.TIM_SetCounter //设置CNT计数器的值
4. u6 TIM_GetCounter(TIM_TypeDef* TIMx); // 获得 TIMx 计数器的值

你可能感兴趣的:(stm32 TIMER)