You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

27 lines
798 B
Markdown

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

# PWM_Servo
- 舵机通过PWM控制PWM周期固定20ms50Hz脉冲宽度在0.5ms-2.5ms2.5%-12.5%)之间,对应最小-最大角度
- 接线用3P杜邦线连接开发板和舵机舵机棕色线对应GND
- 需要打开外部晶振将SYSCLK配置到72MHzAPB timer clocks也配置到72MHz
- 给PB8配置TIM4_CH3
- 进入Timers - TIM4
- 勾选Internal Clock
- Channel3配置PWM Generation CH3
- Prescaler配置为720-1Counter Period配置为2000-1这样PWM频率就是50Hz
- PWM Generation Channel3 - Pulse配置为150即占空比7.5%
> 占空比 = 此数值 / Counter Period
- HAL_TIM_PWM_Start(&htim4, TIM_CHANNEL_3) 启动PWM输出
- __HAL_TIM_SET_COMPARE(&htim4, TIM_CHANNEL_3, 250) 可以改变占空比