|Targeted Hardware||phyBOARD-Zeta (i.MX7)|
|Targeted Software||BSP Yocto FSL iMX7 PD18.2.0|
Pulse-width modulation (PWM) is a modulation technique used for a variety of purposes in electronics. Typical PWM signals are repeating signals characterized by their period and duty cycle. A PWM signal period is the length of time from the start to the end of one cycle of the PWM signal. A PWM signal duty cycle is the proportion of the PWM signal period during which the signal is 'on' or active. This how-to guide will detail the steps necessary to enable and use PWM on the phyBOARD-Zeta (i.MX7) in Linux.
Enabling all available PWMs in Linux device tree
Two PWM signals are brought out to the phyBOARD-Zeta carrier board: X_PWM2 and X_PWM3. These two signals correspond to the PWM outputs on the i.MX7 processor. By default, only PWM3 is enabled in the device tree files for use with the PHYTEC PEB-AV-02 LCD adapter as a backlight signal. To use both PWM2 and PWM3 in Linux, you must enable PWM2 and disable the LCD adapter. To enable PWM2, you will need to modify the device tree file imx7s-pba-c-09.dtsi.
Find the '&iomuxc_lpsr' entry in the file and, under the imx7d-phycore node, add the following lines to pinmux GPIO1_IO02 as PWM2_OUT:
To disable the LCD adapter, you will need to modify the device tree file imx7d-phyboard-zeta-001.dts.
Comment out (or delete) the following line to disable the LCD adapter:
Enabling the PWMs in Linux
Controlling the PWM signals in Linux is handled through the sysfs interface. Run the following commands to export (request access to) PWM2 and PWM3:
To unexport (free up) PWM2 and PWM3, run the following commands:
Configuring the PWM period, duty cycle, and polarity
The period of the PWM signals in Linux is measured in nanoseconds. To set the period of the PWM2 signal to one second, run the following command after PWM2 has been exported:
The duty cycle of the PWM signals in Linux is also measured in nanoseconds. To set the duty cycle of the PWM2 to 50%, or a half-second 'on' time, run the following command:
The polarity of the PWM signals in Linux controls whether the 'on' time of the signal is active high or active low. To set the polarity of PWM2 to active high, run the following command:
To set the polarity of PWM2 to active low, run the following command:
Starting the PWM signal
You must start a PWM signal in Linux after configuring it. To start PWM2, run the following command after following the instructions above:
Finally, to disable PWM2 when it is no longer needed, run the following command:
Official Linux PWM documentation
You can find more details about the above commands and other Linux PWM interface information in the official documentation found online here or in your local Linux kernel source file Documentation/pwm.txt.