新人,STM8L051F3的PWM生成问题,希望各位不吝赐教
PWM波一直出不来
程序如下:
void Tim3_Init(void)
{
CLK_PeripheralClockConfig(CLK_Peripheral_TIM3,ENABLE);
TIM3_DeInit();
//打开串口时钟源
TIM3_TimeBaseInit(TIM3_Prescaler_16 , TIM3_CounterMode_Up, 999);
TIM3_PrescalerConfig(TIM3_Prescaler_16,TIM3_PSCReloadMode_Update);
TIM3_ARRPreloadConfig(ENABLE);
TIM3_ITConfig(TIM3_IT_Update,ENABLE);
TIM3_Cmd(ENABLE);
}
/*使用定时器3的通道2输出PWM*/
void TIM3_PWM_Initial(void)
{
GPIO_Init(GPIOD, GPIO_Pin_0, GPIO_Mode_Out_PP_High_Fast);
CLK_PeripheralClockConfig(CLK_Peripheral_TIM3, ENABLE);
TIM3_OC2Init(TIM3_OCMode_PWM2,
TIM3_OutputState_Enable ,
200,//占空比
TIM3_OCPolarity_High ,
TIM3_OCIdleState_Set);
TIM3_OC2PreloadConfig(ENABLE);
TIM3_Cmd(ENABLE);
}
|