STM8S003K3用Tim1的通道4输出20KHz的PWM波

void Init_pwm()
{
TIM1_DeInit();
TIM1_TimeBaseInit(0, TIM1_COUNTERMODE_UP, 800, 0x00);//250
TIM1_OC4Init(TIM1_OCMODE_PWM1, TIM1_OUTPUTSTATE_ENABLE, 400, TIM1_OCPOLARITY_LOW, TIM1_OCIDLESTATE_RESET);//50%占空比
TIM1_CCxCmd(TIM1_CHANNEL_4, ENABLE);
TIM1_OC4PreloadConfig(ENABLE);
TIM1_CtrlPWMOutputs(ENABLE);
TIM1_Cmd(ENABLE);
}

posted @ 2016-02-21 23:58  《云中漫步》  阅读(4745)  评论(0编辑  收藏  举报