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/07/12 06:28]
nick [Table]
products:sbc:common:applications:gpio:pwm [2023/03/30 06:35]
ivan [PWM Reference Table]
Line 3: Line 3:
 ===== Introduction ===== ===== Introduction =====
  
-This document mainly describes the usage of hardware PWM. You will learn how 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 =====
  
-<tabbox VIM1>+|            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/3L  |  ''PWM_F''      35    ''GPIOH_5''    |  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  |
  
-^  PWM        PIN  ^  GPIO Number      ^  DT Overlays Node  ^  Device Node              ^ 
-|  PWM_AO_A  |  35    GPIOAO_3 (#504)  |  pwm_ao_a          |  /sys/class/pwm/pwmchip4  | 
  
-<tabbox VIM2> +===== Enable PWM =====
- +
-^  PWM    ^  PIN  ^  GPIO Number        DT Overlays Node  ^  Device Node              ^ +
-|  PWM_D  |  35    GPIODV_28 (#478)  |  pwm_d              /sys/class/pwm/pwmchip1 +
- +
-<tabbox VIM3/3L> +
- +
-^  PWM    |  PIN  ^  GPIO Number      DT Overlays Node  ^  Device Node              ^ +
-|  PWM_F  |  35    GPIOX_7 (#432)  |  pwm_f              /sys/class/pwm/pwmchip4 +
- +
-<tabbox VIM4> +
- +
-^  PWM    ^  PIN  ^ GPIO Number      ^  DT Overlays Node  ^  Device Node              ^ +
-|  PWM_F  |  35    GPIOY_8 (#482)  |  pwm_f              /sys/class/pwm/pwmchip4 +
- +
-</tabbox> +
- +
- +
-===== Enabel 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]].
Line 70: Line 55:
 ``` ```
  
 +<tabbox VIM1S>
 +
 +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 ''pwm_f'' to node ''fdt_overlays'' if it doesn't exist to enable ''PWM_F''.
 +
 +```shell
 +fdt_overlays=pwm_f
 +
 +```
 +
 +After reboot, you will see the pwm device node.
 +
 +```shell
 +$ ls /sys/class/pwm/pwmchip0
 +device  export  npwm  power  subsystem  uevent  unexport
 +```
 </tabbox> </tabbox>
  
 ===== Disable PWM to Use GPIO ===== ===== Disable PWM to Use GPIO =====
  
-If you want to use normal GPIO instead of PWM, you can remove the PWM node in device tree overlays configration file+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 83: Line 86:
  
 ```shell ```shell
-echo 1 | sudo tee /sys/class/pwm/pwmchip4/export +echo 1 | sudo tee /sys/class/pwm/pwmchip4/export 
-echo 1000000 | sudo tee /sys/class/pwm/pwmchip4/pwm1/period +echo 1000000 | sudo tee /sys/class/pwm/pwmchip4/pwm1/period 
-echo 500000 | sudo tee /sys/class/pwm/pwmchip4/pwm1/duty_cycle +echo 500000 | sudo tee /sys/class/pwm/pwmchip4/pwm1/duty_cycle 
-echo 1 | sudo tee /sys/class/pwm/pwmchip4/pwm1/enable+echo 1 | sudo tee /sys/class/pwm/pwmchip4/pwm1/enable
 ``` ```
 <tabbox VIM2>  <tabbox VIM2> 
  
 ```shell ```shell
-echo 1 | sudo tee /sys/class/pwm/pwmchip1/export +echo 1 | sudo tee /sys/class/pwm/pwmchip1/export 
-echo 1000000 | sudo tee /sys/class/pwm/pwmchip1/pwm1/period +echo 1000000 | sudo tee /sys/class/pwm/pwmchip1/pwm1/period 
-echo 500000 | sudo tee /sys/class/pwm/pwmchip1/pwm1/duty_cycle +echo 500000 | sudo tee /sys/class/pwm/pwmchip1/pwm1/duty_cycle 
-echo 1 | sudo tee /sys/class/pwm/pwmchip1/pwm1/enable+echo 1 | sudo tee /sys/class/pwm/pwmchip1/pwm1/enable
 ``` ```
  
 +<tabbox VIM1S> 
 +
 +```shell
 +echo 1 | sudo tee /sys/class/pwm/pwmchip0/export
 +echo 1000000 | sudo tee /sys/class/pwm/pwmchip0/pwm1/period
 +echo 500000 | sudo tee /sys/class/pwm/pwmchip0/pwm1/duty_cycle
 +echo 1 | sudo tee /sys/class/pwm/pwmchip0/pwm1/enable
 +```
 </tabbox> </tabbox>
  
Line 111: Line 122:
 <tabbox VIM1/3/3L/4>  <tabbox VIM1/3/3L/4> 
 ```shell ```shell
-echo 0 | sudo tee /sys/class/pwm/pwmchip4/pwm1/enable+echo 0 | sudo tee /sys/class/pwm/pwmchip4/pwm1/enable
 ``` ```
 <tabbox VIM2>  <tabbox VIM2> 
 ```shell ```shell
-echo 0 | sudo tee /sys/class/pwm/pwmchip1/pwm1/enable+echo 0 | sudo tee /sys/class/pwm/pwmchip1/pwm1/enable 
 +``` 
 +<tabbox VIM1S>  
 +```shell 
 +echo 0 | sudo tee /sys/class/pwm/pwmchip0/pwm1/enable
 ``` ```
 </tabbox> </tabbox>
  
  
Last modified: 2023/12/25 22:01 by jacobe