odroid-c4:application_note:gpio:pwm

Hardware PWM

For pin position, numbers and names, please refer to the pinmap.

Default Pin State GPIO & Export No Net Name Pin Number Pin Number Net Name GPIO & Export No Default Pin State
- - 3.3V 1 2 5.0V - -
I(P/D) GPIOX.17 (#493) I2C0_SDA 3 4 5.0V - -
I(P/U) GPIOX.18 (#494) I2C0_SCL 5 6 GND - -
I(P/D) GPIOA.13 (#473) 7 8 TXD1 GPIOX.12 (#488) I(P/U)
- - GND 9 10 RXD1 GPIOX.13 (#489) I(P/U)
I(P/U) GPIOX.3 (#479) 11 12 PWM_E GPIOX.16 (#492) I(P/U)
I(P/U) GPIOX.4 (#480) 13 14 GND - -
I(P/U) GPIOX.7 (#483) PWM_F 15 16 GPIOX.0 (#476) I(P/U)
- - 3.3V 17 18 GPIOX.1 (#477) I(P/U)
I(P/U) GPIOX.8 (#484) SPI0_MOSI 19 20 GND - -
I(P/U) GPIOX.9 (#485) SPI0_MISO 21 22 GPIOX.2 (#478) I(P/U)
I(P/U) GPIOX.11 (#487) SPI0_CLK 23 24 SPI0_SS0 GPIOX.10 (#486) I(P/U)
- - GND 25 26 SPI0_SS1 GPIOA.4 (#464) I(P/D)
I(P/U) GPIOA.14 (#474) I2C1_SDA 27 28 I2C1_SCL GPIOA.15 (#475) I(P/U)
I(P/U) GPIOX.14 (#490) 29 30 GND - -
I(P/U) GPIOX.15 (#491) 31 32 GPIOA.12 (#472) I(P/D)
I(P/U) GPIOX.5 (#481) PWM_C 33 34 GND - -
I(P/D) GPIOX.6 (#482) PWM_D 35 36 GPIOX.19 (#495) -
ADC.AIN3 37 38 REF 1.8V
- - GND 39 40 ADC.AIN2

2018/12/17 12:20 · luke.go

ODROID-C4

Default Pin State GPIO & Export No Net Name Pin Number Pin Number Net Name GPIO & Export No Default Pin State
- - 3.3V 1 2 5.0V - -
I(P/D) GPIOX.17 (#493) I2C0_SDA 3 4 5.0V - -
I(P/U) GPIOX.18 (#494) I2C0_SCL 5 6 GND - -
I(P/D) GPIOX.5 (#481) PWM_C 7 8 TXD1 GPIOX.12 (#488) I(P/U)
- - GND 9 10 RXD1 GPIOX.13 (#489) I(P/U)
I(P/U) GPIOX.3 (#479) PWM_D 11 12 PWM_E GPIOX.16 (#492) I(P/U)
I(P/U) GPIOX.4 (#480) 13 14 GND - -
I(P/U) GPIOX.7 (#483) PWM_F 15 16 GPIOX.0 (#476) I(P/U)
- - 3.3V 17 18 GPIOX.1 (#477) I(P/U)
I(P/U) GPIOX.8 (#484) SPI0_MOSI 19 20 GND - -
I(P/U) GPIOX.9 (#485) SPI0_MISO 21 22 GPIOX.2 (#478) I(P/U)
I(P/U) GPIOX.11 (#487) SPI0_SCLK 23 24 SPI0_CS0 GPIOX.10 (#486) I(P/U)
- - GND 25 26 SPI0_CS1 GPIOH.6 (#433) I(P/D)
I(P/U) GPIOA.14 (#474) I2C1_SDA 27 28 I2C1_SCL GPIOA.15 (#475) I(P/U)
I(P/U) GPIOX.14 (#490) 29 30 GND - -
I(P/U) GPIOX.15 (#491) 31 32 GPIOH.7 (#434) I(P/D)
I(P/U) GPIOX.6 (#482) PWM_A 33 34 GND - -
I(P/D) GPIOX.19 (#495) PWM_B 35 36 GPIOH.5 (#432) -
ADC.AIN2 37 38 REF 1.8V
- - GND 39 40 ADC.AIN0

2019/10/29 16:27 · luke.go

ODROID-M1

The ODROID-M1 provides 40-pin dual row expansion header “J1”.
The location and pinout of these connectors are illustrated below. (Board Revision 1.0 : 2021/11/12)
All signals on the expansion headers are 3.3V except for the analog input signal.

J1 - 2x20 PINS

Default Pin State GPIO & Export No Net Name Pin Number Pin Number Net Name GPIO & Export No Default Pin State
- - 3.3V 1 2 5.0V - -
I(P/D) GPIO3B.6 (#110) I2C0_SDA 3 4 5.0V - -
I(P/U) GPIO3B.5 (#109) I2C0_SCL 5 6 GND - -
I(P/D) GPIO0B.6 (#14) 7 8 UART1_TX GPIO3D.6 (#126) I(P/U)
- - GND 9 10 UART1_RX GPIO3D.7 (#127) I(P/U)
I(P/U) GPIO0C.0 (#16) UART0_RX 11 12 GPIO3D.0 (#120) I(P/U)
I(P/U) GPIO0C.1 (#17) UART0_TX 13 14 GND - -
I(P/U) GPIO3B.2 (#106) 15 16 GPIO3C.6 (#118) I(P/U)
- - 3.3V 17 18 GPIO3C.7 (#119) I(P/U)
I(P/U) GPIO2D.1 (#89) SPI0_MOSI 19 20 GND - -
I(P/U) GPIO2D.0 (#88) SPI0_MISO 21 22 GPIO3D.1 (#121) I(P/U)
I(P/U) GPIO2D.3 (#91) SPI0_SCLK 23 24 SPI0_CS0 GPIO2D.2 (#90) I(P/U)
- - GND 25 26 GPIO3D.2 (#122) I(P/D)
I(P/U) GPIO0B.4 (#12) I2C1_SDA 27 28 I2C1_SCL GPIO0B.3 (#11) I(P/U)
I(P/U) GPIO4C.1 (#145) UART1_CTS 29 30 GND - -
I(P/U) GPIO4B.6 (#142) UART1_RTS 31 32 GPIO3D.3 (#123) I(P/D)
I(P/U) GPIO0B.5 (#13) 33 34 GND - -
I(P/D) GPIO3D.5 (#125) 35 36 GPIO3D.4 (#124) -
ADC.AIN1 37 38 REF 1.8V
- - GND 39 40 ADC.AIN0

GPIO WiringPi Name Mode Initial Level Header Pin Header Pin Initial Level Mode Name WiringPi GPIO
3.3V 1 2 5v
110 8 I2C.SDA0 IN 1 3 4 5v
109 9 I2C.SCL0 IN 1 5 6 GND
14 7 GPIO.14 IN 1 7 8 1 IN TxD1 15 126
GND 9 10 1 IN TxR1 16 127
16 0 GPIO.16 IN 1 11 12 1 IN GPIO.120 1 120
17 2 GPIO.17 IN 1 13 14 GND
106 3 GPIO.106 IN 1 15 16 1 IN GPIO.118 4 118
3.3v 17 18 1 IN GPIO.119 5 119
89 12 SPIO_MOSI IN 1 19 20 GND
88 13 SPIO_MISO IN 1 21 22 1 IN GPIO.121 6 121
91 14 SPI_CLK IN 1 23 24 1 IN SPI_CE0 10 90
GND 25 26 1 IN GPIO.122 11 122
12 30 I2C.SDA1 IN 1 27 28 1 IN I2C_.SCL1 31 11
145 21 GPIO.145 IN 1 29 30 GND
142 22 GPIO.142 IN 1 31 32 0 IN GPIO.123 26 123
13 23 GPIO.13 IN 0 33 34 GND
125 24 GPIO.125 IN 0 35 36 1 OUT GPIO.124 27 124
25 AIN.2 37 38 1.8V 28
GND 39 40 AIN.0 29
2022/01/06 15:10 · neal

Enable PWM

Before using the PWM, you should enable the pwm by the dtbo.
Please check the DTBO page

PWM Hardware Pin-map

You can access each PWM pin using sysfs interface.
The following table shows the pwm pins availables.

ODROID-N2
The pwm chip number is based on the below table.
The top index show your dtbo selection.
PWM_CD Only PWM_EF Only PWM_CD & PWM_EF
PWM_CD pwmchip4 X pwmchip4
PWM_EF X pwmchip4 pwmchip8
Hardware connection Linux kernel sysfs control
PWM gpio 40-pin num. pwmchip pwm_pins export command
/sys/class/pwm/
PWM_C GPIOX.5 33 pwmchip<num> 0 echo 0 > pwmchip<num>/export
PWM_D GPIOX.6 35 pwmchip<num> 1 echo 1 > pwmchip<num>/export
PWM_E GPIOX.16 12 pwmchip<num> 0 echo 0 > pwmchip<num>/export
PWM_F GPIOX.7 15 pwmchip<num> 1 echo 1 > pwmchip<num>/export

pwmchip#NUM can be found in /sys/class/pwm/

target
root@odroid:~$ cd /sys/class/pwm/
root@odroid:/sys/class/pwm# ls
pwmchip0  pwmchip12  pwmchip16  pwmchip4  pwmchip8
root@odroid:/sys/class/pwm#
ODROID-C4
The pwm chip number is based on the below table.
The top index show your dtbo selection.
PWM_AB Only PWM_CD Only PWM_EF Only PWM_AB && PWM_CD PWM_CD && PWM_EF
PWM_AB pwmchip0 X X pwmchip0 X pwmchip0
PWM_CD X pwmchip0 X pwmchip4 pwmchip0 pwmchip4
PWM_EF X X pwmchip0 X pwmchip4 pwmchip8
Hardware connection Linux kernel sysfs control
PWM gpio 40-pin num. pwmchip pwm_pins export command
/sys/class/pwm/
PWM_A GPIOX.6 33 pwmchip<num> 0 echo 0 > pwmchip<num>/export
PWM_B GPIOX.19 35 pwmchip<num> 1 echo 1 > pwmchip<num>/export
PWM_C GPIOX.5 7 pwmchip<num> 0 echo 0 > pwmchip<num>/export
PWM_D GPIOX.3 11 pwmchip<num> 1 echo 1 > pwmchip<num>/export
PWM_E GPIOX.16 12 pwmchip<num> 0 echo 0 > pwmchip<num>/export
PWM_F GPIOX.7 15 pwmchip<num> 1 echo 1 > pwmchip<num>/export

pwmchip#NUM can be found in /sys/class/pwm/

target
root@odroid:~$ cd /sys/class/pwm/
root@odroid:/sys/class/pwm# ls
pwmchip0  pwmchip4  pwmchip8
root@odroid:/sys/class/pwm#
ODROID-M1
The pwm chip number is based on the below table.
The top index show your dtbo selection.
PWM_1 Only PWM_2 Only PWM_9 Only PWM_1 & 2 PWM_1 & 9 PWM_2 & 9 PWM_1 & 2 & 9
PWM_1 pwmchip0 X X pwmchip0 pwmchip0 X pwmchip0
PWM_2 X pwmchip0 X pwmchip1 X pwmchip0 pwmchip1
PWM_9 X X pwmchip2 X pwmchip3 pwmchip3 pwmchip4
Hardware connection Linux kernel sysfs control
PWM gpio 40-pin num. pwmchip pwm_pins export command
/sys/class/pwm/
PWM_1 GPIO0B.5 33 pwmchip<num> 0 echo 0 > pwmchip<num>/export
PWM_2 GPIO0B.6 7 pwmchip<num> 0 echo 1 > pwmchip<num>/export
PWM_9 GPIO3B.2 15 pwmchip<num> 0 echo 0 > pwmchip<num>/export

pwmchip#NUM can be found in /sys/class/pwm/

target
root@odroid:~$ cd /sys/class/pwm/
root@odroid:/sys/class/pwm# ls
pwmchip0  pwmchip1  pwmchip2  pwmchip3  pwmchip4
root@odroid:/sys/class/pwm#

The Example tested on the ODROID-N2.

You can control this pwm via simple sysfs entries.
This example uses pin number 12 which is connected to the GPIO_16(GPIOX_16).
Output PWM_E to GPIOX_16 pin.

Various SYSFS Attributes

  • Request the device
target
root@odroid:~$ cd /sys/class/pwm/
root@odroid:/sys/class/pwm# echo 0 > pwmchip4/export
root@odroid:/sys/class/pwm# cd pwmchip4
root@odroid:/sys/class/pwm/pwmchip4# ls
device  export  npwm  power  pwm0  subsystem  uevent  unexport
root@odroid:/sys/class/pwm/pwmchip4#
  • Free the device
target
root@odroid:~$ cd /sys/class/pwm/
root@odroid:/sys/class/pwm# echo 0 > pwmchip4/unexport
root@odroid:/sys/class/pwm# cd pwmchip4/
root@odroid:/sys/class/pwm/pwmchip4# ls
device  export  npwm  power  subsystem  uevent  unexport


period

The total period of the PWM signal.
Value is in nanoseconds and is the sum of the active and inactive time of the PWM.
The default is zero. If the period is zero, other sysfs of pwm cannot be changed.
Must change 'period' first.
Example
If the period is 1 ms, enter

target
root@odroid:/sys/class/pwm/pwmchip4/pwm0# echo 1000000 > period

The period will set to 1 ms and PWM Frequency will be 1 kHz.

enable

Enable/Disable the PWM channel

  • Enable the PWM
target
root@odroid:/sys/class/pwm/pwmchip4/pwm0# echo 1 > enable
  • Disable the PWM
target
root@odroid:/sys/class/pwm/pwmchip4/pwm0# echo 0 > enable


duty_cycle

The active time of the PWM signal.
Value is in nanoseconds and must be less than the period.

target
root@odroid:/sys/class/pwm/pwmchip4/pwm0# echo 500000 > duty_cycle 


Polarity

The polarity of the PWM signal.
Value is the string “normal” or “inversed”.
If the polarity is “normal”, the PWM signal is high during the active time(duty_cycle) and is low during the other time(period - duty_cycle).
Example

  • To set polarity to normal
target
root@odroid:/sys/class/pwm/pwmchip4/pwm0# echo "normal" > polarity 
  • To set polarity to inversed
target
root@odroid:/sys/class/pwm/pwmchip4/pwm0# echo "inversed" > polarity 
2020/03/18 16:49 · luke.go
  • odroid-c4/application_note/gpio/pwm.txt
  • Last modified: 2020/04/23 16:09
  • by luke.go