TIM_DeInit(TIM4);
TIM_TIxExternalClockConfig(TIM4, TIM_TIxExternalCLK1Source_TI2, TIM_ICPolarity_Rising, 0);
TIM_TimeBaseStructure.TIM_Period = 0; //计数值. 即自动加载值ARR
TIM_TimeBaseStructure.TIM_Prescaler = 0; //预分频,此值+1为分频的除数
TIM_TimeBaseStructure.TIM_ClockDivision = 0x0; //
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; //向上计数
TIM_TimeBaseInit(TIM4, &TIM_TimeBaseStructure);
TIM_ClearFlag(TIM4, TIM_FLAG_Update); //清除溢出中断标志
TIM_ARRPreloadConfig(TIM4, DISABLE); //禁止ARR预装载缓冲器
TIM_ITConfig(TIM4,TIM_IT_Update,ENABLE); //开启中断
//开启定时器4
TIM_Cmd(TIM4,ENABLE);
|