Linux Core PWM User's Guide

From Texas Instruments Wiki
Jump to: navigation, search
Linux Core PWMSS Driver's Guide
Linux PSP


Linux has support for Enhanced Pulse Width Modulator (ePWM) and Auxiliary Pulse Width Modulator (APWM) modules. APWM is Enhanced Capture (eCAP) module configured in PWM mode. These devices are part of The Pulse-Width Modulation Subsystem (PWMSS)

PWMSS software architecture

AM335X PWM-SS arch.JPG

Driver Configuration

Procedure to build eHRPWM driver

         Device Drivers --->
                 <*> Pulse Width Modulation(PWM) Support --->
                    <*> eHRPWM PWM support   

Procedure to build eCAP driver

         Device Drivers --->
                 <*> Pulse Width Modulation(PWM) Support --->
                    <*> eCAP PWM support   

Driver Usage


The current release of the driver supports only PWM mode. eCAP can be controlled from the user space through SYSFS interface. SYSFS interface for eCAP is available at

target$ cat /sys/class/pwm/pwmchipN


‘N’ is the eCAP instance.

Various SYSFS Attributes

2 types of SYSFS attributes are available

  1. Request and Control attributes
  2. Configuration attributes


  • Below examples uses eCAP instance 0 (i = 0).

Type 1 attributes

  • export Attribute.

Ask the kernel to export a PWM channel. Writing 0 to the export attribute Acquires the channel and writing 0 to the unexport attribute Frees/Releases the channel. Before performing any operations, device has to be requested first.


  • Request the Device:
target$ echo 0 > /sys/class/pwm/pwmchip0/export
  • free the device:
target$ echo 0 > /sys/class/pwm/pwmchip0/unexport
  • run Attribute

Enable/disable the PWM channel


  • Enable the PWM
target$ echo 1 > /sys/class/pwm/pwmchip0/pwm0/enable
  • Disable the PWM
target$ echo 0 > /sys/class/pwm/pwmchip0/pwm0/enable

Before enabling the module, the module needs to be configured using below configuration attributes. Else proper operation is not assured.

Type 2 attributes

i.Setting the Period
Following attributes set the period of the PWM waveform.

  • period Attribute

Enter the period in nano seconds value.

if the period is 1 sec , enter

target$ echo 1000000000 > /sys /class/pwm/pwmchip0/pwm0/period

ii.Setting the Duty
Following attributes set the duty of the PWM waveform.

  • duty_cycle Attribute

Enter the Duty cycle value in nanoseconds.

target$ echo val > /sys/class/pwm/pwmchip0/pwm0/duty_cycle

iii.Setting the Polarity

  • Polarity Attribute.

Setup Signal Polarity

To set the polarity to Active High, Enter

target$ echo 1 > /sys /class/pwm/pwmchip0/pwm0/polarity

To set the polarity to Active Low, Enter

target$ echo 0 > /sys /class/pwm/pwmchip0/pwm0/polarity

Controlling backlight

Following are the 2 procedures to vary brightness of the LCD screen.

i. Setting duty percentage of pwm wave from eCAP sysfs files

target$ echo val > /sys/class/pwm/pwmchip0/pwm0/duty_cycle

'val' can range from 0 to 100.
ii. Setting brightness from backlight sysfs files

target$ echo val > /sys/class/backlight/backlight.8/brightness
'val' can range from 0 to 8.