For some applications, a sysfs support is desired. In this post, we show how to add PWM sysfs support for pcDuino.
For Ubuntu, we just need to replace pwm.ko.
Replace /lib/modules/3.4.79+/kernel/drivers/hardwarelib/pwm.ko and reboot
$sudo modeprobe gpio $sudo modeprobe pwm
## 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/m
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
Leave a Reply
You must be logged in to post a comment.