本帖最后由 eddy836 于 2009-11-13 08:23 编辑
器件型号:STM32F103V8
功能:TIM1 OC1输出比较
问题:输出比较停止后更改预分频再开启,偶尔无输出,而且此时貌似程序跑飞,连接串口的小液晶有5秒定时更新,此时已无更新,按键中断能进。因为每次发生这种情况总是在初始化该函数的时候,不调用该函数没有这样的情况,所以怀疑是不是TIM初始化的问题,望大侠赐教。
上程序,输出比较中断关闭,开启时:
TIM_CtrlPWMOutputs(TIM1, ENABLE);
TIM_Cmd(TIM1, ENABLE);
关闭时:
TIM_CtrlPWMOutputs(TIM1, DISABLE);
TIM_Cmd(TIM1, DISABLE);
每次开启时调用初始化函数TIM_Configuration()。
void TIM_Configuration(u8 t)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_OCInitTypeDef TIM_OCInitStructure;
TIM_DeInit(TIM1);
/* Time base configuration */
TIM_TimeBaseStructure.TIM_Period =1799;
TIM_TimeBaseStructure.TIM_Prescaler = 2*t+3; // 20 <= t <= 60
TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Down;
TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure);
/* Output Compare Toggle Mode configuration: Channel1 */
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_Toggle;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low;
TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Reset;
TIM_OC1Init(TIM1, &TIM_OCInitStructure);
TIM_OC1PreloadConfig(TIM1, TIM_OCPreload_Disable);
TIM_ARRPreloadConfig(TIM1, DISABLE);
} |