Jump to content

PWM on H3 (and H2+) with mainline kernel


Recommended Posts

Requirements

  • Fresh enough nighly or manually built image
  • Latest kernel and dtb packages (26.03.2017 or newer)

 

Limitations

As stated in other PWM related threads, hardware PWM output is supported only on pin PA5 which is also UART0 ("debug" serial console) RX pin, so enabling PWM will disable this console.

 

Activation

Add "pwm" to "overlays" line in /boot/armbianEnv.txt

Example:

overlays=pwm

Reboot is required to apply the changes

Armbian overlays documentation: https://docs.armbian.com/User-Guide_Allwinner_overlays/

 

PWM sysfs interface

Official documentation: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git/tree/Documentation/ABI/testing/sysfs-class-pwm?h=v4.10

Please note that this ABI is considered "testing" so it may change in the future.

 

Sysfs interface example

# activate the PWM. On H3 only 1 PWM is supported, so exporting PWM 0
echo 0 > /sys/class/pwm/pwmchip0/export
# set period to 10ms
echo 10000000 > /sys/class/pwm/pwmchip0/pwm0/period
# set normal polarity. needs to be reset explicitly. Bug?
echo "inversed" > /sys/class/pwm/pwmchip0/pwm0/polarity
echo "normal" > /sys/class/pwm/pwmchip0/pwm0/polarity
# enable the PWM
echo 1 > /sys/class/pwm/pwmchip0/pwm0/enable
# set duty cycle to 1ms
echo 1000000 > /sys/class/pwm/pwmchip0/pwm0/duty_cycle

Result:

 

 


20170130_275659.png.8dcd6c0448989dba6e1c1d52cd5d28b2.png
 

 

# set duty cycle to 2ms
echo 2000000 > /sys/class/pwm/pwmchip0/pwm0/duty_cycle

Result:

 

 


20170130_275735.png.252ef389ef0a6d067fa2ce05bf4482cc.png
 

 

 

# set duty cycle to 1us, period to 2us
echo 1000 > /sys/class/pwm/pwmchip0/pwm0/duty_cycle
echo 2000 > /sys/class/pwm/pwmchip0/pwm0/period

Result:

 

 


20170130_280026.png.f5dc9cb48435da58136752e0413c98f3.png
 

 

 

Please note that some settings needs to be changed in a correct sequence, i.e. you can't set duty cycle higher than period

root@orangepiplus2e:~# echo 1000 > /sys/class/pwm/pwmchip0/pwm0/duty_cycle
root@orangepiplus2e:~# echo 500 > /sys/class/pwm/pwmchip0/pwm0/period
-bash: echo: write error: Invalid argument
root@orangepiplus2e:~#

 

Link to comment
Share on other sites

  • Igor unpinned this topic
Guest
This topic is now closed to further replies.
×
×
  • Create New...

Important Information

Terms of Use - Privacy Policy - Guidelines