Using PWM from a linux shell

Difficulty Levels: Intermediate
Date added: June 27, 2018
Affected Products: EDM1-CF-IMX6 , EDM1-CF-IMX6SX , EDM1-IMX6PLUS , EDM1-IMX6UL , EDM1-IMX7D , EDM2-IMX6PLUS , PICO-IMX6 , PICO-IMX6UL-EMMC , PICO-IMX6UL-NAND , PICO-IMX6UL-NOR , PICO-IMX7 , PICO-IMX8M , TAM-3517 , TAO-3530 , TC-0700 , TC-0710 , TC-1010 , TDM-3730 , TEK3-IMX6 , TEK3-IMX6UL , TEP-0500-IMX6UL , TEP-0500-IMX7 , TEP-0700-IMX6UL , TEP-0700-IMX7 , TEP-1010-IMX6 , TEP-1560-IMX6 , THB-3517 , TWP-1010-IMX6 , TWP-1560-IMX6 , WBDUAL , WBQUAD , WBSOLO

Summary

This mini guide explains how to enable and test a pwm signal using linux command line.

Instructions

To enable a PWM the steps are as follows (some details might differ depending on the product)

1. Manouver to the /sys/class/pwm folder

In this folder the pwm controllers should be visible as folders pwmchip0, pwmchip1, …

The number on the pwmchip does not relate to the number of the pwm output.

2. Enter the chosen pwmchip folder.

% cd pwmchip0

3. Export the first pwm (the iMX pwm controllers have one pwm each) by

# echo 0 > export

this exposes the actual pwm in folder pwm0.

4. Enter the pwm folder

% cd pwm0

and configure the pwm

# echo 10000 > period
# echo 6000 > duty_cycle
# echo 1 > enable

This should set the PWM frequency to 10 kHz and set the duty cycle to 6 kHz.

Stay up to date with all the latest TechNexion news...

Sign-up for our Newsletter