Using PWM from a Linux Shell
- 23 Apr 2024
- 1 Minute to read
- Print
- DarkLight
- PDF
Using PWM from a Linux Shell
- Updated on 23 Apr 2024
- 1 Minute to read
- Print
- DarkLight
- PDF
Article summary
Did you find this summary helpful?
Thank you for your feedback
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)
- Maneuver to the
/sys/class/pwm
folder
In this folder the pwm controllers should be visible as folderspwmchip0
,pwmchip1
, ... - Enter the chosen pwmchip folder.
$ cd pwmchip0
- Export the first pwm (the iMX pwm controllers have one pwm each) by
$ echo 0 > export
This exposes the actual PWM in folder pwm0.
Note:
If the PWM has been allocated for use by another driver such as a display backlight driver (for control of the backlight brightness), then it might throw an error. If so, check your device tree
- 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 100 kHz and set the duty cycle to 60 kHz.
Was this article helpful?