STM32定时器周期计算
公式是:
((1+TIM_Prescaler )/时钟)*(1+TIM_Period )
F103配置生成1ms的时钟((1+35 )/36M)*(1+999 ) = 1MS
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
NVIC_InitTypeDef NVIC_InitStructure;
TIM_DeInit(TIM5);
TIM_TimeBaseStructInit(&TIM_TimeBaseStructure);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM5, ENABLE);
TIM_TimeBaseStructure.TIM_Period = 999;
//APB1最大时钟36MHz, 36M/(35+1) = 1M hz
TIM_TimeBaseStructure.TIM_Prescaler = 35;//最小1us
TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM5, &TIM_TimeBaseStructure);
TIM_Cmd(TIM5, ENABLE);