Khadas Docs

Amazing Khadas, always amazes you!

User Tools

Site Tools


Sidebar

products:sbc:edge-2l:applications:gpio:pwm

Edge-2L PWM

Introduction

This page explains how to use the hardware PWM (Pulse Width Modulation) and guides you through controlling it on the 16-Pin Header.

To use the PWM functionality on the Edge-2L, you must attach the Edge-2L IO board.

PWM information

PWM PIN GPIO Name GPIO Number DT Overlays Node Device Node
Edge-2L PWM1 14 GPIO1_B4 44 edge-2l-io-pwm /sys/class/pwm/pwmchip0

Enable PWM

To use the hardware PWM, you must first enable it by applying a Device Tree Overlay.

Edit the file /boot/dtb/rockchip/rk3576-khadas-edge-2l.dtb.overlay.env and add the overlay edge-2l-io-pwm to the fdt_overlays parameter if it is not already present:

fdt_overlays=edge-2l-io-pwm

Reboot the system for the change to take effect. After rebooting, verify that the PWM device node exists:

$ ls /sys/class/pwm/pwmchip0
device  export  npwm  power  subsystem  uevent  unexport

Disable PWM to use as GPIO

If you wish to use the pin as a standard GPIO instead of PWM, remove the edge-2l-io-pwm entry from the fdt_overlays parameter in the Device Tree Overlay configuration file and reboot.

Control PWM via sysfs

Enable and Configure PWM:

The following sequence enables PWM channel 0, sets a period of 1,000,000 nanoseconds (1 kHz), a duty cycle of 500,000 nanoseconds (50% duty), and starts the output:

# Export PWM channel 0
$ echo 0 | sudo tee /sys/class/pwm/pwmchip0/export
 
# Set period to 1,000,000 ns (1 kHz)
$ echo 1000000 | sudo tee /sys/class/pwm/pwmchip0/pwm0/period
 
# Set duty cycle to 500,000 ns (50%)
$ echo 500000 | sudo tee /sys/class/pwm/pwmchip0/pwm0/duty_cycle
 
# Enable PWM output
$ echo 1 | sudo tee /sys/class/pwm/pwmchip0/pwm0/enable

Use an oscilloscope to verify the PWM signal on the corresponding pin.

pwm-oscilloscope

When using an oscilloscope to measure the PWM waveform, ensure that the Edge-2L's GND is connected to the oscilloscope's ground reference.

Disable PWM:

To stop the PWM signal:

echo 0 | sudo tee /sys/class/pwm/pwmchip0/pwm0/enable
Last modified: 2026/05/11 02:08 by nick