//设置PWM的输出//Cycle:为周期,单位(us)//Pulse_Num:为脉冲个数(小于3200)void TIM2_TIM3_PWM(u16 Cycle, u16 Pulse_Num){ u16 TIM3per = 0; u32 Time = 0; //改变TIM3的重装值改变脉冲频率这里设置脉冲占空比为50% //改变TIM2的预分频器和重装值改变脉冲个数 Time = Cycle * Pulse_Num; Time /= 100; //预分频为7200,100us计数一次 TIM3per = Cycle/10; //预分频为720,10us计数一次 TIM_SetAutoreload(TIM2, Time+1);//设置TIM2的重装值 TIM_SetAutoreload(TIM3, TIM3per-1);//设置TIM3的重装值 TIM_SetCompare1(TIM3,TIM3per/2);//设置占空比为50% TIM_Cmd(TIM2,ENABLE);//使能TIM2} |