STM8S003定时器2产生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);