幸狐Luckfox Pico RV1103【PWM测试】

由于在 LuckFox Pico 和 LuckFox Pico Plus 引脚复用,会有引脚功能冲突,所以默认不能全部开启 PWM功能。


】使用 GPIO sysfs 接口控制 PWM:


1] 查看默认开启的 PWM 接口:

# ls -l /sys/class/pwm

lrwxrwxrwx    1 root     root             0 pwmchip10 -> ../../devices/platform/ff490020.pwm/pwm/pwmchip10

lrwxrwxrwx    1 root     root             0 pwmchip1 -> ../../devices/platform/ff350010.pwm/pwm/pwmchip1

lrwxrwxrwx    1 root     root             0 pwmchip11 -> ../../devices/platform/ff490030.pwm/pwm/pwmchip11

lrwxrwxrwx    1 root     root             0 pwmchip0 -> ../../devices/platform/ff350000.pwm/pwm/pwmchip0


2] 测试 PWM。将PWM1_M0(GPIO0_A4_d)导出到用户空间:

echo 0 > /sys/class/pwm/pwmchip1/export


3] 设置 PWM 周期 单位为ns,比如 1KHz 频率的周期就是 1000000ns:

echo 1000000 > /sys/class/pwm/pwmchip1/pwm0/period


4] 设置占空比:
 #表示将占空比设置为 10%(100,000 纳秒为一个周期,持续时间为 10,000 纳秒)

echo 100000 > /sys/class/pwm/pwmchip1/pwm0/duty_cycle  

echo 200000 > /sys/class/pwm/pwmchip1/pwm0/duty_cycle

echo 300000 > /sys/class/pwm/pwmchip1/pwm0/duty_cycle

echo 400000 > /sys/class/pwm/pwmchip1/pwm0/duty_cycle

echo 500000 > /sys/class/pwm/pwmchip1/pwm0/duty_cycle

echo 600000 > /sys/class/pwm/pwmchip1/pwm0/duty_cycle

echo 700000 > /sys/class/pwm/pwmchip1/pwm0/duty_cycle

echo 800000 > /sys/class/pwm/pwmchip1/pwm0/duty_cycle

echo 900000 > /sys/class/pwm/pwmchip1/pwm0/duty_cycle

 #表示将占空比设置为 100%(1000000 纳秒为一个周期,持续时间为 1000000 纳秒)

echo 1000000 > /sys/class/pwm/pwmchip1/pwm0/duty_cycle

#将占空比设为0,相当于停止占空比输出

echo 0 > /sys/class/pwm/pwmchip1/pwm0/duty_cycle


5] 设置正常 PWM 极性:

#设置正常pwm极性

echo "normal" > /sys/class/pwm/pwmchip1/pwm0/polarity

#设置翻转pwm极性:

echo "inversed" > /sys/class/pwm/pwmchip1/pwm0/polarity


6] 使能 PWM :

echo 1 > /sys/class/pwm/pwmchip1/pwm0/enable



7] 关闭 PWM :

echo 0 > /sys/class/pwm/pwmchip1/pwm0/enable



8] 取消将 PWM 导出到用户空间:

echo 0 > /sys/class/pwm/pwmchip1/unexport


9] 操作流程截图:


】测试官方SDK自带例程:
1] 下载SDK&编译测试例程或下载已编译好的例程:(提取码:jwz0)
      SDK GitHub下载


(以下操作需进入Pico开发板的终端进行操作)

3] 运行测试例程:    
chmod 777 ./luckfox_pwm_test
## 赋予文件可执行权限
./luckfox_pwm_test 3

4] 运行效果: