void TIM2_INIT()
{
RCC->APB1ENR |= (1<<0); //TIM2EN 定时器2时钟使能
TIM2->PSC |= 63999;
TIM2->ARR |=1000; //1S产生一次中断
TIM2->DIER |= TIM_DIER_UIE; //允许timer2更新中断
NVIC->ISER[0] |= (1 << (TIM2_IRQChannel & 0x1F)); //enable interrupt
TIM2->CR1 |= TIM_CR1_CEN; //使能计数器,启动TIM2;
TIM2->EGR |= TIM_EGR_UG;
}
上面是我的TIM2初始化,我现在的TIMXCLK 是64M,我现在设定分频后后的值为1000HZ,即TIM2->PSC |= 63999;;这样当ARR=1000,就是1s进入一次中断,可实际进入是断时间要远远超1s,当TIM2->PSC |= 1000;左右时,感觉才能1s进入中断一次,不知哪地方出问题,望香主不吝赐教,感觉就是时钟变慢几千倍。谢谢 |