Khadas Docs

Amazing Khadas, always amazes you!

User Tools

Site Tools


products:sbc:common:applications:gpio:pwm

Differences

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

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Next revision Both sides next revision
products:sbc:common:applications:gpio:pwm [2022/11/04 10:00]
nick
products:sbc:common:applications:gpio:pwm [2023/11/07 03:29]
nick
Line 5: Line 5:
 This page introduces the usage of hardware PWM, and leads you to control the hardware PWM on the [[products:sbc:common:applications:gpio:40pin-header|40-Pin Header]]. This page introduces the usage of hardware PWM, and leads you to control the hardware PWM on the [[products:sbc:common:applications:gpio:40pin-header|40-Pin Header]].
  
-===== PWM Information =====+===== PWM Reference Table ===== 
 + 
 +|          PWM            PIN  ^  GPIO name      ^  GPIO num  ^  DT overlay node  ^  Device node              ^ 
 +^  VIM1    ''PWM_AO_A''  |  35    ''GPIOAO_3''    504        ''pwm_ao_a''      /sys/class/pwm/pwmchip4 
 +^  VIM2    ''PWM_D''      35    ''GPIODV_28''  |  478        ''pwm_d''        |  /sys/class/pwm/pwmchip1 
 +^  VIM3    ''PWM_F''      35    ''GPIOH_5''    |  432        ''pwm_f''        |  /sys/class/pwm/pwmchip4 
 +^  VIM3L  |  ''PWM_F''      35    ''GPIOH_5''    |  432        ''pwm_f''        | /sys/class/pwm/pwmchip0   | 
 +^  VIM4    ''PWM_F''      35    ''GPIOY_8''    |  482        ''pwm_f''        |  /sys/class/pwm/pwmchip4 
 +^  VIM1S  |  ''PWM_F''      35    ''GPIOZ_6''    |  503        ''pwm_f''        |  /sys/class/pwm/pwmchip0 
  
-|            PWM        PIN  ^  GPIO Name  ^  GPIO Number  ^  DT Overlays Node  ^  Device Node              ^ 
-^  VIM1      PWM_AO_A  |  35    GPIOAO_3    504          |  pwm_ao_a          |  /sys/class/pwm/pwmchip4  | 
-^  VIM2      PWM_D      35    GPIODV_28  |  478          |  pwm_d              /sys/class/pwm/pwmchip1  | 
-^  VIM3/3L  |  PWM_F      35    GPIOX_7    |  432          |  pwm_f              /sys/class/pwm/pwmchip4  | 
-^  VIM4      PWM_F      35    GPIOY_8    |  482          |  pwm_f              /sys/class/pwm/pwmchip4  | 
-^  VIM1S    |  PWM_F      35    GPIOZ_6    |  503          |  pwm_f              /sys/class/pwm/pwmchip0  | 
-^  Edge2    |  PWM14      13    GPIO3_C2    114          |  pwm14              /sys/class/pwm/pwmchip2  | 
 ===== 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]]. In order to use the PWM, you need to enable the PWM function via [[products:sbc:common:configurations:device-tree-overlay|Device Tree Overlay]].
  
-<tabbox VIM1/2/3/3L/Edge1>+<tabbox VIM1/2/3/Edge1>
  
 Edit ''/boot/env.txt'' to add the pwm node to ''overlays'' node if it doesn't exist. Edit ''/boot/env.txt'' to add the pwm node to ''overlays'' node if it doesn't exist.
Line 25: Line 27:
  
 ```shell ```shell
-overlays=uart4 pwm_ao_a pwm_f+overlays=uart3 pwm_f i2c3 i2s os08a10 watchdog
 ``` ```
  
Line 35: Line 37:
 ``` ```
  
-<tabbox VIM4>+<tabbox VIM3L>
  
-Edit ''/boot/dtb/amlogic/kvim4.dtb.overlay.env'' to add pwm node to ''fdt_overlays'' node if it doesn't exist.+Edit ''/boot/env.txt'' to add the pwm node to ''overlays'' node if it doesn't exist.
  
- +Take VIM3L as an example to enable ''PWM_F'', you need to add ''pwm_f'' node to ''overlays'' node if it doesn't exist.
-You need to add ''pwm_f'' to node ''fdt_overlays'' if it doesn't exist to enable ''PWM_F''.+
  
 ```shell ```shell
-fdt_overlays=pwm_f +overlays=uart3 pwm_f i2c3 i2s watchdog
 ``` ```
  
Line 50: Line 50:
  
 ```shell ```shell
-$ ls /sys/class/pwm/pwmchip4+$ ls /sys/class/pwm/pwmchip0
 device  export  npwm  power  subsystem  uevent  unexport device  export  npwm  power  subsystem  uevent  unexport
 ``` ```
  
-<tabbox VIM1S>+<tabbox VIM4>
  
-Edit ''/boot/dtb/amlogic/kvim1s.dtb.overlay.env'' to add pwm node to ''fdt_overlays'' node if it doesn't exist.+Edit ''/boot/dtb/amlogic/kvim4.dtb.overlay.env'' to add pwm node to ''fdt_overlays'' node if it doesn't exist.
  
  
Line 69: Line 69:
  
 ```shell ```shell
-$ ls /sys/class/pwm/pwmchip0+$ ls /sys/class/pwm/pwmchip4
 device  export  npwm  power  subsystem  uevent  unexport device  export  npwm  power  subsystem  uevent  unexport
 ``` ```
  
-<tabbox Edge2>+<tabbox VIM1S>
  
-Edit ''/boot/dtb/rockchip/rk3588s-khadas-edge2.dtb.overlay.env'' to add pwm node to ''fdt_overlays'' node if it doesn't exist.+Edit ''/boot/dtb/amlogic/kvim1s.dtb.overlay.env'' to add pwm node to ''fdt_overlays'' node if it doesn't exist.
  
  
-You need to add ''pwm14'' to node ''fdt_overlays'' if it doesn't exist to enable ''PWM14''.+You need to add ''pwm_f'' to node ''fdt_overlays'' if it doesn't exist to enable ''PWM_F''.
  
 ```shell ```shell
-fdt_overlays=pwm14+fdt_overlays=pwm_f
  
 ``` ```
Line 88: Line 88:
  
 ```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
 ``` ```
- 
 </tabbox> </tabbox>
  
-===== Disable PWM to Use 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]]. 
  
 ===== Control PWM ===== ===== Control PWM =====
Line 102: Line 98:
 **Enable PWM:** **Enable PWM:**
  
-<tabbox VIM1/3/3L/4> +<tabbox VIM1/3/4> 
  
 ```shell ```shell
Line 110: Line 106:
 echo 1 | sudo tee /sys/class/pwm/pwmchip4/pwm1/enable echo 1 | sudo tee /sys/class/pwm/pwmchip4/pwm1/enable
 ``` ```
 +
 <tabbox VIM2>  <tabbox VIM2> 
  
Line 119: Line 116:
 ``` ```
  
-<tabbox VIM1S+<tabbox VIM3L/1S
  
 ```shell ```shell
Line 127: Line 124:
 echo 1 | sudo tee /sys/class/pwm/pwmchip0/pwm1/enable echo 1 | sudo tee /sys/class/pwm/pwmchip0/pwm1/enable
 ``` ```
-<tabbox Edge2>  
- 
-```shell 
-echo 0 | sudo tee /sys/class/pwm/pwmchip2/export 
-echo 1000000 | sudo tee /sys/class/pwm/pwmchip2/pwm0/period 
-echo 500000 | sudo tee /sys/class/pwm/pwmchip2/pwm0/duty_cycle 
-echo 1 | sudo tee /sys/class/pwm/pwmchip2/pwm0/enable 
-``` 
- 
 </tabbox> </tabbox>
  
Line 148: Line 136:
 **Disable PWM:** **Disable PWM:**
  
-<tabbox VIM1/3/3L/4> +<tabbox VIM1/3/4> 
 ```shell ```shell
 echo 0 | sudo tee /sys/class/pwm/pwmchip4/pwm1/enable echo 0 | sudo tee /sys/class/pwm/pwmchip4/pwm1/enable
Line 156: Line 144:
 echo 0 | sudo tee /sys/class/pwm/pwmchip1/pwm1/enable echo 0 | sudo tee /sys/class/pwm/pwmchip1/pwm1/enable
 ``` ```
-<tabbox VIM1S+<tabbox VIM3L/1S
 ```shell ```shell
 echo 0 | sudo tee /sys/class/pwm/pwmchip0/pwm1/enable echo 0 | sudo tee /sys/class/pwm/pwmchip0/pwm1/enable
-``` 
-<tabbox Edge2>  
-```shell 
-echo 0 | sudo tee /sys/class/pwm/pwmchip2/pwm0/enable 
 ``` ```
 </tabbox> </tabbox>
 +
 +===== Disable PWM to Use 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]].
 +
  
  
Last modified: 2023/12/25 22:01 by jacobe