写了个可调频率的PWM,但是输出的PWM波形不规整,在变换的时候出现尖角。定时器初始化函数:
TIM_TimeBaseInitStructure.TIM_Prescaler = 35999;
TIM_TimeBaseInitStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInitStructure.TIM_Period = Prescaler_Val[0];
TIM_TimeBaseInitStructure.TIM_ClockDivision = 0;
TIM_TimeBaseInit(TIM3, &TIM_TimeBaseInitStructure);
/*PWM1 configuration :channel 1*/
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_Pulse = Prescaler_Val[0]/2;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
TIM_OC1Init(TIM3, &TIM_OCInitStructure);
TIM_ITConfig(TIM3, TIM_IT_Update , ENABLE);
/* TIM1 counter enable */TIM_Cmd(TIM3,ENABLE);
中断函数:
void TIM3_IRQHandler(void)
{
if(TIM_GetFlagStatus(TIM3, TIM_IT_Update) != RESET)
{
TIM_SetAutoreload(TIM3,Prescaler_Value[i]);
TIM_SetCompare1(TIM3,Prescaler_Value[i]/2);
TIM_ClearFlag(TIM3, TIM_IT_Update);
}
}
在仿真中可以很好的实现,但是在实际的开发板上就不能实现了,请大家指点一二,小弟再次感激不尽!!! |