STM32F103,TIM1定时器定时对怎么回事啊?

2019-10-15 19:25发布

用的原子个的mini板,本来定时的50us,出来确实250us。头都大了。

这是我的定时器程序:
void TIM1_Int_Init(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
NVIC_InitTypeDef NVIC_InitStructure;

RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1,ENABLE);

TIM_DeInit(TIM1); 

TIM_TimeBaseStructure.TIM_Period = 49;
TIM_TimeBaseStructure.TIM_Prescaler = 71;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
TIM_TimeBaseInit(TIM1,&TIM_TimeBaseStructure);


    NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1); //设置NVIC中断分组1: 1位抢占优先级,3位响应优先级

NVIC_InitStructure.NVIC_IRQChannel = TIM1_UP_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);

TIM_ClearFlag(TIM1, TIM_FLAG_Update); 
TIM_ITConfig(TIM1,TIM_IT_Update,ENABLE);

TIM_Cmd(TIM1,ENABLE);

}

void TIM1_UP_IRQHandler(void)
{
if(TIM_GetITStatus(TIM1,TIM_IT_Update) !=RESET )
{
LED1 = !LED1; 
TIM_ClearITPendingBit(TIM1,TIM_IT_Update);
}
}
附上我的程序,希望各位朋友能解决,我们共同学习!谢谢!
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。