Khadas Docs

Amazing Khadas, always amazes you!

User Tools

Site Tools


products:sbc:common:applications:gpio:pwm

This is an old revision of the document!


PWM

Introduction

This document mainly describes the usage of hardware PWM. You will learn how to control the hardware PWM on the 40-Pin Header.

PWM Information

PWM PIN & GPIO Number DT Overlays Node Device Node
PWM_AO_A PIN35 - GPIOAO_3 (#504) pwm_ao_a /sys/class/pwm/pwmchip4

Enable PWM

PWM_AO_A:

$ echo 1 | sudo tee /sys/class/pwm/pwmchip4/export
$ echo 1000000 | sudo tee /sys/class/pwm/pwmchip4/pwm1/period
$ echo 500000 | sudo tee /sys/class/pwm/pwmchip4/pwm1/duty_cycle
$ echo 1 | sudo tee /sys/class/pwm/pwmchip4/pwm1/enable

Use an oscilloscope to check if the pins have been successfully enabled.

pwm-oscilloscope

If you use an oscilloscope to view the PWM waveform, remember that the SBC and the oscilloscope need to share the same GND (ground).

Disable PWM

$ echo 0 | sudo tee /sys/class/pwm/pwmchip4/pwm1/enable
Last modified: 2022/07/12 06:01 by nick