PA3 STM8S003F3
timer2_init(); //初始化 #define PUL_COUNT 4000 void timer2_init(void) { TIM2_DeInit(); TIM2_TimeBaseInit(TIM2_PRESCALER_8, PUL_COUNT-1); //62.5HZ 2M/8 /4000=62.5HZ 1个数4us TIM2_OC3Init(TIM2_OCMODE_PWM1, TIM2_OUTPUTSTATE_ENABLE, PUL_COUNT/2, TIM2_OCPOLARITY_HIGH); /* TIM1 counter enable */ TIM2_Cmd(ENABLE); }timer2_init
#define ADD_LOAD 2000000/8 void set_pwm1(unsigned int arr) //arr 设置的频率,单位HZ 占空比固定50% { double T_ARR; unsigned int PWM_Per=0; T_ARR=(double)ADD_LOAD/arr; T_ARR=T_ARR+0.5; PWM_Per = (unsigned int)T_ARR; TIM2_SetAutoreload(PWM_Per-1); TIM2_SetCompare3(PWM_Per/2); }set_pwm1
标签:TIM2,stm8,arr,--,ARR,Per,int,PWM From: https://www.cnblogs.com/zhouyuqing1024/p/18220209