我试了一下,好像是3ms小弟这没有示波器,只能看电脑秒变化用多次计数累加再除次数得到的好像是3ms
RCC_HCLKConfig(RCC_SYSCLK_Div1); // AHB时钟等于SYSCLK RCC_PCLK2Config(RCC_HCLK_Div1); //APB2时钟等于SYSCLK RCC_PCLK1Config(RCC_HCLK_Div2);//低速APB1时钟等于SYSCLK/2 RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9); // PLLCLK = 8MHz * 9 = 72 MHz [配置PLL时钟源和乘法因子][PLL时钟输入等于HSE时钟][PLL乘法因子取值9]
void TIM_Configuration(void) { TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; // TIM_OCInitTypeDef TIM_OCInitStructure ; TIM_DeInit( TIM2);//复位TIM2定时器
/* TIM2 configuration */ TIM_TimeBaseStructure.TIM_Period = 0x0fa0; //4000 TIM_TimeBaseStructure.TIM_Prescaler = 0x36; //分频0x36 TIM_TimeBaseStructure.TIM_ClockDivision = 0x0; // 时钟分割 TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; //计数方向向上计数 TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure); TIM_ClearFlag(TIM2, TIM_FLAG_Update); //清除TIM2溢出中断标志 TIM_ITConfig(TIM2, TIM_IT_Update, ENABLE); //TIM2溢出中断允许 TIM_Cmd(TIM2, ENABLE); //允许tim2计数 } |