- 使能pwm模块的某个通道(假设某个pwm模块支持4个通道,以下示例是使能此pwm模块的通道1,通道从0开始数)
echo 1 > /sys/class/pwm/pwmchip0/export
- 配置pwm的周期、占空比以及极性
echo 90000000000 > /sys/class/pwm/pwmchip0/pwm1/period (单位为纳秒,1000000000 ns = 1s)
echo 500000000 > /sys/class/pwm/pwmchip0/pwm1/duty_cycle (占空比为50%, 0.5 s)
echo 'normal' > /sys/class/pwm/pwmchip0/pwm1/polarity (pwm信号中以低电平为开启状态,还是以高电平为开启状态,这里设置为普通极性,也就是高电平为开启状态)
- 使能pwm信号的输出
echo 1 > /sys/class/pwm/pwmchip0/pwm0/enable
- 关掉 pwm信号的输出