Khadas Docs

Amazing Khadas, always amazes you!

User Tools

Site Tools


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

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
products:sbc:edge-2l:applications:gpio:pwm [2025/11/25 04:30]
gray created
products:sbc:edge-2l:applications:gpio:pwm [2026/05/11 02:08] (current)
nick ↷ Page moved from local:users:gray:products:sbc:edge-2l:applications:gpio:pwm to products:sbc:edge-2l:applications:gpio:pwm
Line 5: Line 5:
 ===== Introduction ===== ===== Introduction =====
  
-This page introduces the usage of hardware PWMand leads you to control the hardware PWM on the [[products:sbc:edge-2L:applications:gpio:40pin-header|16-pin Header]] .+This page explains how to use the hardware PWM (Pulse Width Modulation) and guides you through controlling it on the [[products:sbc:edge-2L:applications:gpio:40pin-header|16-Pin Header]].
  
 <WRAP important > <WRAP important >
-For Edge-2L, in order to use the PWM function, you need to attach the IO extension board.+To use the PWM functionality on the Edge-2L, you must attach the Edge-2L IO board.
 </WRAP> </WRAP>
-===== PWM Information =====+===== PWM information =====
  
 |            PWM        PIN  ^  GPIO Name  ^  GPIO Number  ^  DT Overlays Node  ^  Device Node              ^ |            PWM        PIN  ^  GPIO Name  ^  GPIO Number  ^  DT Overlays Node  ^  Device Node              ^
-^  Edge-2L    |  PWM14     |  13   |  GPIO3_C2   |  114            edge-2l-io-pwm      /sys/class/pwm/pwmchip2  |+^  Edge-2L    |  PWM1     |  14   |  GPIO1_B4   |  44            edge-2l-io-pwm      /sys/class/pwm/pwmchip0  |
  
  
 ===== Enable PWM ===== ===== Enable PWM =====
  
-In order to use the PWM, you need to enable the PWM function via [[products:sbc:common:configurations:device-tree-overlay|Device Tree Overlay]].+To use the hardware PWM, you must first enable it by applying a [[products:sbc:common:configurations:device-tree-overlay|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:
-Edit ''/boot/dtb/rockchip/rk3576-khadas-edge-2l.dtb.overlay.env'' to add pwm node to ''fdt_overlays'' node if it doesn't exist. +
- +
- +
-You need to add ''edge-2l-io-pwm'' to node ''fdt_overlays'' if it doesn't exist to enable ''PWM14''.+
  
 ```shell ```shell
 fdt_overlays=edge-2l-io-pwm fdt_overlays=edge-2l-io-pwm
- 
 ``` ```
  
-After rebootyou will see the pwm device node.+Reboot the system for the change to take effect. After rebootingverify that the PWM device node exists:
  
 ```shell ```shell
-$ ls /sys/class/pwm/pwmchip2+$ ls /sys/class/pwm/pwmchip0
 device  export  npwm  power  subsystem  uevent  unexport device  export  npwm  power  subsystem  uevent  unexport
 ``` ```
  
-===== Disable PWM to Use GPIO =====+===== Disable PWM to use as GPIO =====
  
-If you want to use normal GPIO instead of PWM, you can remove the PWM node in [[products:sbc:common:configurations:device-tree-overlay|Device Tree Overlay]].+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 =====+===== Control PWM via sysfs=====
  
-**Enable PWM:** +**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:
 ```shell ```shell
-echo 0 | sudo tee /sys/class/pwm/pwmchip2/export +# Export PWM channel 0 
-echo 1000000 | sudo tee /sys/class/pwm/pwmchip2/pwm0/period +echo 0 | sudo tee /sys/class/pwm/pwmchip0/export 
-echo 500000 | sudo tee /sys/class/pwm/pwmchip2/pwm0/duty_cycle + 
-echo 1 | sudo tee /sys/class/pwm/pwmchip2/pwm0/enable+# 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 check if the pins have been successfully enabled.+Use an oscilloscope to verify the PWM signal on the corresponding pin.
  
 {{products:sbc:common:applications:gpio:pwm-oscilloscope.png|pwm-oscilloscope}} {{products:sbc:common:applications:gpio:pwm-oscilloscope.png|pwm-oscilloscope}}
  
-<WRAP info > +<WRAP info >  
-If you use an oscilloscope to view the PWM waveform, remember that the SBC and the oscilloscope need to share the same GND (ground).+When using an oscilloscope to measure the PWM waveform, ensure that the Edge-2L's **GND** is connected to the oscilloscope'ground reference
 </WRAP> </WRAP>
  
 **Disable PWM:** **Disable PWM:**
  
 +To stop the PWM signal:
 ```shell ```shell
-echo 0 | sudo tee /sys/class/pwm/pwmchip2/pwm0/enable+echo 0 | sudo tee /sys/class/pwm/pwmchip0/pwm0/enable
 ``` ```
  
  
  
Last modified: 2025/11/25 04:30 by gray