目前正在使用STM32F205VCT6,开了TIM8定时100ms中断,程序配置如下:
#define TIM8_10Hz_Period 12000//0X1C1F//0X2ee0
#define TIM8_10Hz_Prescaler 999//99//0X03E7
void TIM8_Init(FunctionalState en)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM8, en); //¶¨Ê±Æ÷8ÌṩʱÖÓ
NVIC_InitStructure.NVIC_IRQChannel = TIM8_UP_TIM13_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 6;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
TIM_TimeBaseStructure.TIM_Period = TIM8_10Hz_Period;//TIM8_1KHz_Period;
TIM_TimeBaseStructure.TIM_Prescaler = TIM8_10Hz_Prescaler;//TIM8_1KHz_Prescaler;
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; //¼ÆÊýģʽ
TIM_TimeBaseInit(TIM8, &TIM_TimeBaseStructure);
TIM_ITConfig(TIM8, TIM_IT_Update, ENABLE); //ÔÊÐíÖжÏ
TIM_Cmd(TIM8, en);
Tick_1S_flag=0;
}
void TIM8_UP_TIM13_IRQHandler (void)
{
static UINT16 t21ms;
if(TIM_GetITStatus(TIM8,TIM_IT_Update)!=RESET) //ÅжÏÊÇ·ñΪ¶¨Ê±Æ÷2Òç³öÖжÏ
{
t21ms++;
Tick_100MS_flag=1;
if(t21ms>=10)//1000
{
t21ms=0;
Tick_1S_flag=1;
}
TIM_ClearFlag(TIM8, TIM_FLAG_Update); //ÇåÖжϱê¼Ç
TIM_ClearITPendingBit(TIM8, TIM_IT_Update);
}
}
系统时钟配置在120MHz,按上面配置,在不开优化的时候定时是正常的。开到3级优化的时候TIM8_10Hz_Period 要设到4000才差不多满足。请问各位大神这是为什么呢?一直想不通,也没找到相关参考。 |