[vc_row][vc_column][vc_column_text]For some applications, a sysfs support is desired. In this post, we show how to add PWM sysfs support for pcDuino.
Below are the support files for pwm driver sysfs,
https://github.com/pcduino/modules/tree/master/pcduino-pwm-sysf[/vc_column_text][vc_tour][vc_tab title=”Ubuntu” tab_id=”1395129254-1-55″][vc_column_text]For Ubuntu, we just need to replace pwm.ko.
Replace /lib/modules/3.4.29+/kernel/drivers/hardwarelib/pwm.ko and reboot
[/vc_column_text][/vc_tab][vc_tab title=”Android” tab_id=”1395129254-2-91″][vc_column_text]For Andriod, we need to replace kernel (uImage).
Replace uImage
1. copy uImage to usb disk
2. open terminal apk, run these commands
$ su # busybox mount /dev/block/nanda /mnt/extsd/ # busybox cp /mnt/usbhost1/uImage /mnt/extsd/ && sync # busybox umount /mnt/extsd # reboot -n 1
[/vc_column_text][/vc_tab][vc_tab title=”API Interface” tab_id=”1395129544466-2-9″][vc_column_text]/sys/devices/virtual/misc/pwmtimer/freq/pwmX (r/w min_freq to max_freq )
/sys/devices/virtual/misc/pwmtimer/freq_range/pwmX (read only: freq range)
/sys/devices/virtual/misc/pwmtimer/level/pwmX (r/w 0 to max_level )
/sys/devices/virtual/misc/pwmtimer/enable/pwmX (r/w 1: enable, 0:disable)
/sys/devices/virtual/misc/pwmtimer/max_level/pwmX (read only)
( X should be one of 5/6/3/9/10/11 )[/vc_column_text][/vc_tab][vc_tab title=”Examples” tab_id=”1395129570945-3-2″][vc_column_text]## following these steps to config pwm via sysfs interface
## 1) set pin mode function to pwm mode
## PWM5/6
## echo 2 > /sys/devices/virtual/misc/gpio/mode/gpio5
## echo 2 > /sys/devices/virtual/misc/gpio/mode/gpio6
## PWM3/9/10/11
## echo 1 > /sys/devices/virtual/misc/gpio/mode/gpio3
## echo 1 > /sys/devices/virtual/misc/gpio/mode/gpio9
## echo 1 > /sys/devices/virtual/misc/gpio/mode/gpio10
## echo 1 > /sys/devices/virtual/misc/gpio/mode/gpio11
## 2) disable pwm before changing freq
## echo 0 > /sys/devices/virtual/misc/pwmtimer/enable/pwmX
## 3) set freq ( min_freq <= freq <= max_freq )
## echo FREQ > /sys/devices/virtual/misc/pwmtimer/enable/pwmX
## you can get freq first: cat /sys/devices/virtual/misc/pwmtimer/freq_range/pwmX
## example:
## cat /sys/devices/virtual/misc/pwmtimer/freq_range/pwmX
## max_freq:66700
## min_freq:2
## 4) set duty cycle
## duty_cycle = level / max_level
## get max_level:
## cat /sys/devices/virtual/misc/pwmtimer/enable/pwmX
## set level ( 0 <= level <= max_level ):
## echo LEVEL > /sys/devices/virtual/misc/pwmtimer/level/pwmX
## 5) enable it
## echo 1 > /sys/devices/virtual/misc/pwmtimer/enable/pwmX
for example:
$echo 2 > /sys/devices/virtual/misc/gpio/mode/gpio5 $cd /sys/devices/virtual/misc/pwmtimer/ $echo 195 > freq/pwm5 $echo 1 > level/pwm5 $echo 1 > enable/pwm5 # update level setting only(do not change freq) $echo 100 > level/pwm5
[/vc_column_text][/vc_tab][vc_tab title=”Results” tab_id=”1395278570100-4-8″][vc_column_text]PWM with a frequency of 20Hz:
Measured results on scope:
PWM with a frequency of 50Hz:
Measured results on scope:
[/vc_column_text][/vc_tab][/vc_tour][/vc_column][/vc_row]
Leave a Reply
You must be logged in to post a comment.