Skip to main content

Analog Output - PWM

BoardChannelsExample PWMpwmchipX
iMX6 SoloX COM8pwm1pwmchip0
iMX6 Quad COM4pwm1pwmchip0
iMX6 DualLite COM4pwm1pwmchip0
iMX6 UltraLite COM8pwm1pwmchip0
iMX7 Dual (u)COM4pwm3pwmchip1
iMX7ULP uCOMN/AN/AN/A
iMX8M Quad COM4pwm1pwmchip0
iMX8M Mini uCOM4pwm1pwmchip0
iMX8M Nano uCOM4pwm1pwmchip0

To use the PWM channels they must first be configured and enabled in the device tree. The scope of how to do that is beyond this document.

The table above list one example PWM that is enabled on all boards (backlight for LVDS). All COM boards have this on pin P138/284 of the MXM3 connector and the signal can be observed on resistor R120.

R120 on COM Carrier board V1

U-Boot

Not currently available.

Linux

To see which PWM channels have been enabled in the device tree.

ls /sys/class/pwm/
pwmchip0  pwmchip1

In this case (iMX6 DualLite) two channels are enabled. On an iMX6 SoloX board with all channels enabled it would look like this.

ls /sys/class/pwm/
pwmchip0  pwmchip1  pwmchip2  pwmchip3
pwmchip4 pwmchip5 pwmchip6 pwmchip7

Each PWM channel has its own pwmchipX folder with a couple of interesting files.

ls /sys/class/pwm/pwmchip0/
device     export  npwm      power
subsystem uevent unexport

The export/unexport files work in the same way as for gpio. To use a pwm channel it must first be exported.

echo 0 > /sys/class/pwm/pwmchip1/export

It will then appear as a pwm0 node.

ls /sys/class/pwm/pwmchip1/pwm0
capture   duty_cycle   enable   period
polarity power uevent

To set the PWM frequency to 100 kHz (100kHz equals 10000 ns period time) and set the duty cycle to 70% (0.7 * period time equals 7000).

cd /sys/class/pwm/pwmchip1/pwm0
echo 10000 > period
echo 7000 > duty_cycle
echo 1 > enable

This signal can then be observed either with an oscilloscope or by measuring with a multimeter that will typically measure an average voltage. In this case the average should be ca 2.3V which is 70% of 3.3V.