9.PWM输出测试
该教程演示如何通过开发板的GPIO输出PWM波
一、准备工作
- 准备1块BearPi-Pico H2821开发板
二、编译代码
在Windows下编译操作
点击左侧的“KConfig”,打开配置界面.
选择Support PWM Sample
Application ---> [*] Enable Sample. [*] Enable the Sample of peripheral. [ ] Enable all the sample of peripheral, it's just for build. [ ] Support ADC Sample. [ ] Support BLINKY Sample. [ ] Support BUTTON Sample. [ ] Support DMA Sample. [ ] Support I2C Sample. [ ] Support I2S Sample. [ ] Support KEYSCAN Sample. [ ] Support PINCTRL Sample. [*] Support PWM Sample. PWM Sample Configuration --->
设置PWM输出的GPIO,这边以设置板载LED连接的GPIO31为例。
PWM Sample Configuration ---> (31) Choose PWM pin.
按下"Save"键保存配置。
可在代码中修改高低电平时间,已达到输出不同占空比的PWM波
编译烧录固件
参考环境搭建教程编译烧录代码
在Ubuntu下编译操作
在MobaXterm中输入:
./build.py menuconfig
选择Support PWM Sample
Application ---> [*] Enable Sample. [*] Enable the Sample of peripheral. [ ] Enable all the sample of peripheral, it's just for build. [ ] Support ADC Sample. [ ] Support BLINKY Sample. [ ] Support BUTTON Sample. [ ] Support DMA Sample. [ ] Support I2C Sample. [ ] Support I2S Sample. [ ] Support KEYSCAN Sample. [ ] Support PINCTRL Sample. [*] Support PWM Sample. PWM Sample Configuration --->
设置PWM输出的GPIO,这边以设置板载LED连接的GPIO31为例。
PWM Sample Configuration ---> (31) Choose PWM pin.
按下"ESC"键退出并保存配置。
可在代码中修改高低电平时间,已达到输出不同占空比的PWM波
编译烧录固件
参考环境搭建教程编译烧录代码
三、测试
烧录固件后按下开发的复位按键,用示波器或者逻辑分析查看PWM输出引脚的PWM波,或者通过改变不同的占空比,观察开发板上的LED灯的亮度变化。