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:
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.


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/ 

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

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 -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
Traceback (most recent call last):
  File "", 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 -f 50 -d 4 1

If something like this happens:

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:

python -f 50 -d 4 1
python -f 50 -d 13 1
python -f 50 -d 5 1
python -f 50 -d 12 1
python -f 50 -d 6 1
python -f 50 -d 11 1

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

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:



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: Logo

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.