STM8S003定時器2產(chǎn)生PWM
可對初學者有一定借鑒作用
//開時鐘
CLK_PeripheralClockConfig(CLK_PERIPHERAL_TIMER2, ENABLE);
//賦值前先關
TIM2_DeInit();
TIM2_Cmd(DISABLE);
TIM2_TimeBaseInit(TIM2_PRESCALER_2, 1427);//1427*1us=700HZ
//PWM1 Mode configuration: Channel3,50%
TIM2_OC3Init(TIM2_OCMODE_PWM1, TIM2_OUTPUTSTATE_ENABLE,713, TIM2_OCPOLARITY_HIGH);
//捕獲比較寄存器CCR1
TIM2_OC3PreloadConfig(ENABLE);
//自動裝載寄存器ARR
TIM2_ARRPreloadConfig(ENABLE);
TIM2_Cmd(ENABLE);