How To Use Hardware PWM

Check HardwarePWM Pin

Hardware PWM had open at default dtb configuration.So you need to check which Physical pin is connect to it .

  1. PWM_F on VIM1 GPIO-Out
  2. PWM_D on VIM2 GPIO-Out
  3. PWM_F on VIM3 GPIO-Out

Switch to root user

Ordinary users cannot control GPIO, so they need to switch to the root user.

khadas@Khadas:~$ sudo -i
[sudo] password for khadas:

Set Hardware PWM

Setup and enable PWM

root@Khadas:~# echo 1 > /sys/class/pwm/pwmchip4/export
root@Khadas:~# echo 1000000 > /sys/class/pwm/pwmchip4/pwm1/period
root@Khadas:~# echo 500000 > /sys/class/pwm/pwmchip4/pwm1/duty_cycle
root@Khadas:~# echo 1 > /sys/class/pwm/pwmchip4/pwm1/enable

If you sueccess to enable it , you can see it with oscilloscope.


Disable PWM

root@Khadas:~# echo 0 > /sys/class/pwm/pwmchip4/pwm1/enable