|
程序代码如下:
/* Time2 base configuration 系统频率为72M*/
TIM_TimeBaseStructure.TIM_Prescaler = 1; //定时器2的时钟频率为:72M/(1+1) = 36M
TIM_TimeBaseStructure.TIM_Period = 89; //定时器的溢出频率为400k
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);
TIM_ITConfig(TIM2, TIM_IT_Update, ENABLE);
TIM_Cmd(TIM2, ENABLE);
中断函数为:
void TIM2_IRQHandler(void)
{
if(TIM_GetITStatus(TIM2, TIM_IT_Update) == SET)
{
/* Clear TIM3 Capture compare interrupt pending bit */
TIM_ClearITPendingBit(TIM2, TIM_IT_Update);
GPIO_WriteBit(GPIOB, GPIO_Pin_8, (BitAction)(1 - GPIO_ReadOutputDataBit(GPIOB, GPIO_Pin_8)));
}
}
现在的程序现象为:
1。当设定 TIM_TimeBaseStructure.TIM_Period = 89; 时定时器的溢出频率为400K,用示波器测试PB8口为200K,这时完全正确。
2。当设定 TIM_TimeBaseStructure.TIM_Period = 39; 时定时器的溢出频率为900K,用示波器测试PB8口为225.2K,这时输出频率就不正确了。
烦请各位帮忙分析原因,主程序不做任何事情的. |
|