Building a Rover project day 2 – PWM on BeagleBone

When I bought the BeagleBone it didn’t have PWM support. It was disabled for some reason by default. Luckily in the latest kernel they put it back.

The minimal kernel for PWM is: Angstrom v2012.03-core – Kernel 3.2.5+ .

The one I downloaded:
http://www.angstrom-distribution.org/demo/beaglebone/Angstrom-Cloud9-IDE-GNOME-eglibc-ipk-v2012.05-beaglebone-2012.06.18.img.xz
Which has a 3.2.18 version kernel.

This is optional, but you can update to the newest version.
The first step is to update the BeagleBone. You will need the BeagleBone to be online. Then here are the necessary commands:

opkg update
opkg upgrade


Note: In my case the update wasn’t fully successful, but the necessary update, the kernel update went good.

reboot

If everything went good, then after logging in you can see the updated kernel or:

root@beaglebone:~# uname -r

Also you can check if it’s the PWM is persist by

cd /sys/class/pwm/ 
ls

here you can see something like this:

PWM Python script
It is not a diagnostic tool yet it is very useful. It helped me a lot to understand the PWM on BeagleBone. There is a limit what you can do with it, but it is perfect for trying your wings in the world of PWM.
PWM tool

Update
To make the pwms work you have to enable the clocks. To do this, just run the PWM tool with the parameter pwm which you want to enable. (eg.:

python bbpwm.py -f 50 -d 4 1

this will enable the 1st pwm, ehrpwm.1:0)

Now to see an example, we will use the P9.14 port for the pwm. This will be the /sys/class/pwm/ehrpwm.1:0 or EHRPWM1A as you can see in the documentation of BeagleBone.

port name directory
P9.14 EHRPWM1A /sys/class/pwm/ehrpwm.1:0
root@beaglebone:~# python bbpwm.py
Traceback (most recent call last):
  File "bbpwm.py", line 6, in 
    from mmap import mmap
ImportError: No module named mmap
root@beaglebone:~# opkg install python-mmap

Note: if you get this, then you have to install python-mmap, as mentioned above.

Now use this command:

python bbpwm.py -f 50 -d 4 1

If something like this happens:

http://www.youtube.com/watch?v=oQ9kMhznbKM

Then you did well! I set up the servo wires as follows:

red (5V) to VDD5V (red in video)

brown (ground) to GND (blue in video)

yellow (signal) to P9.14 (green in video)
In my case, the servo works at 50 freq, and the duty means the positon. Number 1 at the end is the P9.14(EHRPWM1A), see more in the script.
Here is a quick script for testing:

 
#!/bin/bash
python bbpwm.py -f 50 -d 4 1
python bbpwm.py -f 50 -d 13 1
python bbpwm.py -f 50 -d 5 1
python bbpwm.py -f 50 -d 12 1
python bbpwm.py -f 50 -d 6 1
python bbpwm.py -f 50 -d 11 1

for (( j = 1; j <= 9; j++ )) ### Outer for loop ###
do
        for (( i = 4; i <= 13; i++ )) ### inner for loop ###
        do
                python bbpwm.py -f 50 -d $i 1
        done
done

PWM for evil engineers
This is just a little piece of what BeagleBone PWM is capable. My evil engineer friend told me that it is very good and customazible. You can set all the parameters of a PWM system manually.

Here are some examples:

cd /sys/class/pwm/ehrpwm.1:0
echo 1 > request
cat request
#ehrpwm.1:0 requested by sysfs
echo 20000000 > period_ns
echo 2300000 > duty_ns
echo 1 > run

different PWM signals on oscilloscope:



References
http://beaglebone.cameon.net/home/using-pwm-outputs

https://github.com/aquaticus/BeagleBone-tools/blob/master/bbpwm

http://www.angstrom-distribution.org/demo/beaglebone/

Advertisements

2 thoughts on “Building a Rover project day 2 – PWM on BeagleBone

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s