Hardware PWM

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

ODROID-N2

J2 - 2x20 PINS

WE SHOULD CHECK THE PIN MAP!!!

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) 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) 33 34 GND - -
I(P/D) GPIOX.6 (#482) 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

J2 - 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) 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) 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 PWM_F GPIOH.5 (#432) -
ADC.AIN2 37 38 REF 1.8V
- - GND 39 40 ADC.AIN0

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

PWM Hardware Pin-map

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

ODROID-N2
Hardware connection Linux kernel sysfs control
PWM gpio 40-pin num. pwmchip pwm_pins export command
/sys/class/pwm/
PWM_C GPIOX.5 33 pwmchip4 0 echo 0 > pwmchip4/export
PWM_D GPIOX.6 35 pwmchip4 1 echo 1 > pwmchip4/export
PWM_E GPIOX.16 12 pwmchip8 0 echo 0 > pwmchip8/export
PWM_F GPIOX.7 15 pwmchip8 1 echo 1 > pwmchip8/export

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

root@odroid:~$ cd /sys/class/pwm/
root@odroid:/sys/class/pwm# ls
pwmchip0  pwmchip12  pwmchip16  pwmchip4  pwmchip8
root@odroid:/sys/class/pwm#
ODROID-C4
Hardware connection Linux kernel sysfs control
PWM gpio 40-pin num. pwmchip pwm_pins export command
/sys/class/pwm/
PWM_A GPIOX.6 33 pwmchip0 1 echo 1 > pwmchip0/export
PWM_B GPIOX.19 35 pwmchip0 0 echo 0 > pwmchip0/export
PWM_E GPIOX.16 12 pwmchip4 0 echo 0 > pwmchip4/export
PWM_F GPIOX.7 15 pwmchip4 1 echo 1 > pwmchip4/export

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

root@odroid:~$ cd /sys/class/pwm/
root@odroid:/sys/class/pwm# ls
pwmchip0  pwmchip4  pwmchip8
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
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
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

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
root@odroid:/sys/class/pwm/pwmchip4/pwm0# echo 1 > enable
  • Disable the PWM
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.

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
root@odroid:/sys/class/pwm/pwmchip4/pwm0# echo "normal" > polarity 
  • To set polarity to inversed
root@odroid:/sys/class/pwm/pwmchip4/pwm0# echo "inversed" > polarity 
2020/03/18 16:49 · luke.go