Using PWM from sysfs
following Instuction only works for Linux kernel 3.11 or greater
Where to find PWM devices in sysfs
PWM devices are listed under /sys/class/pwm
export PWM device
You must export the PWM at first, otherwise the other commands in this tutorial will not work
root@MBaXXX:~ cd /sys/class/pwm // enter pwm folder in sysfs root@MBaXXX:/sys/class/pwm cd pwmchip<pwmchipnr> // enter the desired pwmchip folder root@MBaXXX:/sys/your/path/to/pwmchip/pwmchip<pwmchipnr> echo <pwmnr> > export // export device PWM<pwmnr> root@MBaXXX:/sys/your/path/to/pwmchip/pwmchip<pwmchipnr> cd pwm<pwmnr> // enter exported pwm device folder
set PWM period
root@MBaXXX:~ echo <value in nanoseconds> > /sys/class/pwm/pwmchip<pwmchipnr>/pwm<pwmnr>period
set PWM duty cycle
The value of duty cycle must be less than the value of pwm period
root@MBaXXX:~ echo <value in nanoseconds> > /sys/class/pwm/pwmchip<pwmchipnr>/pwm<pwmnr>duty_cycle
change polarity of the PWM signal
root@MBaXXX:~ echo "normal" > /sys/class/pwm/pwmchip<pwmchipnr>/pwm<pwmnr>/polarity // set polarity to normal root@MBaXXX:~ echo "inversed" > /sys/class/pwm/pwmchip<pwmchipnr>/pwm<pwmnr>/polarity // set polarity to inversed
enable PWM
root@MBaXXX: echo 1 > /sys/class/pwm/pwmchip<pwmchipnr>/pwm<pwmnr>/enable
disable PWM
root@MBaXXX: echo 0 > /sys/class/pwm/pwmchip<pwmchipnr>/pwm<pwmnr>/enable