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
815 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.

# 无源蜂鸣器
- 初始化外部晶振配置SYSCLK与Timer Clock均为72MHz
- 配置PB9为TIM4_CH4
- 配置TIM4
- 勾选Internal Clock
- Channel4配置为PWM Generation CH4
- Prescaler配置为72-1
- Counter Period配置为500-1此时PWM频率为2kHz
- 可选因为蜂鸣器比较吵可以配置一下KEY1PB12按下KEY1时蜂鸣器才响
- 可选再配置KEY2PB13需Pull-Up按下KEY2可以发出不同的音调
- 改变频率通过配置ARR寄存器实现htim4.Instance->ARR = 500
- 注意驱动蜂鸣器的占空比应该保持在20%左右,过高的占空比将导致声音嘶哑
> 每次改变PWM频率都配置一次占空比
>
> __HAL_TIM_SET_COMPARE(&htim4, TIM_CHANNEL_4, htim4.Instance->ARR/5);