In this tutorial, we will demo how to use PWM on pcDuino 8.
pcDuino8 extra PWM interface only have one road, following I will show how to use it.
Here I will provide sysfs file system interface. The detail fle structure as following:
root@ubuntu:/sys/devices/virtual/misc/pwmtimer# tree
.
├── dev
├── enable
│ └── pwm0
├── freq
│ └── pwm0
├── freq_range
│ └── pwm0
├── level
│ └── pwm0
├── max_level
│ └── pwm0
├── power
│ ├── async
│ ├── autosuspend_delay_ms
│ ├── control
│ ├── runtime_active_kids
│ ├── runtime_active_time
│ ├── runtime_enabled
│ ├── runtime_status
│ ├── runtime_suspended_time
│ └── runtime_usage
├── subsystem -> ../../../../class/misc
└── uevent
7 directories, 16 files
We will use the oscilloscope to test the signal.
Download the PWM driver as the following:硬件
#sudo apt-get install git #git clone https://github.com/Pillar1989/a80-modules/ #cd pwm #sudo insmod hw_pwm.ko
Load the driver then we will see the pwmtimer under the /sys/devices/virtual/misc/.
Software demo as following:
root@ubuntu:/sys/devices/virtual/misc/pwmtimer/enable# echo 1 > pwm0 root@ubuntu:/sys/devices/virtual/misc/pwmtimer/enable# cd .. root@ubuntu:/sys/devices/virtual/misc/pwmtimer/freq# cat pwm0 200000
Input the following commands to modify the frequency :
root@ubuntu:/sys/devices/virtual/misc/pwmtimer/freq# echo 100000 > pwm0
Modify the duty cycle, the duty ratio maximum is 720.
root@ubuntu:/sys/devices/virtual/misc/pwmtimer/level# cat pwm0
360
root@ubuntu:/sys/devices/virtual/misc/pwmtimer/level# echo 180 > pwm0
root@ubuntu:/sys/devices/virtual/misc/pwmtimer/level# echo 540 > pwm0