Hardware PWM


ODROID-C2 Has two possible PWM ports.

Starting from Ubuntu Release (v1.1) or a kernel update performed on 2016-02-26 or later includes the PWM support.

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

To use PWM on Android,
you should insmod modules from .ko files first.

$ su
$ cd /lib/modules
$ insmod pwm-meson.ko
$ insmod pwm-ctrl.ko

Option 1: Single PWM

The code below loads the PWM module with a single PWM and the PWM controller module.

PWN PIN: 33

sudo modprobe pwm-meson
sudo modprobe pwm-ctrl

Option 2: Two PWMs

PWM PINS:

PWM0: 33

PWM1: 19

sudo modprobe pwm-meson npwm=2
sudo modprobe pwm-ctrl

If you are using TWO pwm setup, PWM1 & SPI can not be used simultaneously.
Because GPIOX_7(pin19) has two function spi_mosi & pwm.

Examples of usage

You can control this pwm via simple sysfs entries.

In Android, /sys/devices/pwm-ctrl.v3.
And you should set the frequency first to use PWM.

On /sys/devices/platform/pwm-ctrl/, you'll find the following files:

In Ubuntu Image 18.04 or later, /sys/devices/pwm-ctrl.

duty0

Duty cycle of 1023 (10bit resolution)

echo 102 > duty0

will result in 102/1023 (approx 10%) of Duty cycle.

echo 512 > duty0

will result 50:50 of Duty cycle.

enable0

Enable/Disable this PWM

echo 1 > enable0

Will enable this PWM

echo 0 > enable0

Will disable this PWM.

freq0

This is the PWM Frequency in Hertz!

echo 100000 > freq0

This will set the frequency to 100kHz

Maximum Frequency is 1Mhz.

On PWM0 you can test for higher frequencies. There are no guarantees! 1Mhz is what we support.

If you are using TWO pwm setup, You have: enable0, freq0, duty0 AND enable1, freq1, duty1

How to access the PWM port in C language