PWM

This guide will show you how to use PWM (Pulse Width Modulation).

Enable PWM

PWM_F:
1
2
3
4
$ echo 1 | sudo tee /sys/class/pwm/pwmchip4/export
$ echo 1000000 | sudo tee /sys/class/pwm/pwmchip4/pwm1/period
$ echo 500000 | sudo tee /sys/class/pwm/pwmchip4/pwm1/duty_cycle
$ echo 1 | sudo tee /sys/class/pwm/pwmchip4/pwm1/enable
PWM_D:
1
2
3
4
$ echo 1 | sudo tee /sys/class/pwm/pwmchip1/export
$ echo 1000000 | sudo tee /sys/class/pwm/pwmchip1/pwm1/period
$ echo 500000 | sudo tee /sys/class/pwm/pwmchip1/pwm1/duty_cycle
$ echo 1 | sudo tee /sys/class/pwm/pwmchip1/pwm1/enable
PWM_F:
1
2
3
4
$ echo 1 | sudo tee /sys/class/pwm/pwmchip4/export
$ echo 1000000 | sudo tee /sys/class/pwm/pwmchip4/pwm1/period
$ echo 500000 | sudo tee /sys/class/pwm/pwmchip4/pwm1/duty_cycle
$ echo 1 | sudo tee /sys/class/pwm/pwmchip4/pwm1/enable
PWM_F:
1
2
3
4
$ echo 1 | sudo tee /sys/class/pwm/pwmchip4/export
$ echo 1000000 | sudo tee /sys/class/pwm/pwmchip4/pwm1/period
$ echo 500000 | sudo tee /sys/class/pwm/pwmchip4/pwm1/duty_cycle
$ echo 1 | sudo tee /sys/class/pwm/pwmchip4/pwm1/enable

Use an oscilloscope to check if the pins have been successfully enabled.

pwm-Oscilloscope

Note

If you use an oscilloscope to view the PWM waveform, remember that the SBC and the oscilloscope need to share the same GND (ground).

Disable PWM

1
$ echo 0 | sudo tee /sys/class/pwm/pwmchip4/pwm1/enable
1
$ echo 0 | sudo tee /sys/class/pwm/pwmchip1/pwm1/enable
1
$ echo 0 | sudo tee /sys/class/pwm/pwmchip4/pwm1/enable
1
$ echo 0 | sudo tee /sys/class/pwm/pwmchip4/pwm1/enable