following Instuction only works for Linux kernel 3.11 or greater

PWM devices are listed under /sys/class/pwm

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 

example

 
root@MBaXXX:~ echo <value in nanoseconds> > /sys/class/pwm/pwmchip<pwmchipnr>/pwm<pwmnr>period

example

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

example

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

example

root@MBaXXX: echo 1 > /sys/class/pwm/pwmchip<pwmchipnr>/pwm<pwmnr>/enable

example

root@MBaXXX: echo 0 > /sys/class/pwm/pwmchip<pwmchipnr>/pwm<pwmnr>/enable

example

  • Last modified: 2022/08/04 15:02