How to get PWM working with latest Debian image?

So, I’m trying to get PWM up and running on my BBB.

I’ve spent a good deal of time trying to track down instructions on the web, and found a whole bunch of stuff… but none of it seems to be applicable to my particular system… nor do they appear to agree with each other?

I am running the latest Debian image.

Is there a simple straight forward guide for how to enable and use PWM?

My project is in C++ and I am able to get all of the UART and GPIO functions working just fine following online instructions… but for some reason PWM is a different story.

Thanks,

Bill

Update #1

Using this tutorial…

http://www.linux.com/learn/tutorials/776799-servo-control-from-the-beaglebone-black/

I have found the device tree overlays in /lib/firmware, and I think that I have successfully loaded bone_pwm_P9_14 and bone_pwm_P9_16. I think that this is successful because the /sys/devices/ocp.3/pwm_test_P9_14.* and /sys/devices/ocp.3/pwm_test_P9_16.* directories have appeared!

That said, I was expecting to find files named “run”, “freq”, “period”, “duty”, etc. there, and I do not find these files?

Instead I have found to files named “modalias” and “uevent”, a directory named “power” and a link named “subsystem”?

Clearly I am missing something.

Suggestions?

Thanks,

Bill

Hey Bill,

I am running a Ubuntu 14.04 image, and /lib/firmware looks like it comes from the Bizarro universe. no ‘bone’ or ‘pwm’ files at all.
The only thing remotely familiar is am335x-pm-firmware.bin. The sample code I tried to run referred to ocp.2. I got some of the digital GPIO pins talking,
but I couldn’t get analog input working on 14.04.

Code where working:

int main()
{
FILE *io,*iodir,*ioval;

io = fopen("/sys/class/gpio/export", “w”);
fseek(io,0,SEEK_SET);
fprintf(io,"%d",45);
fflush(io);

iodir = fopen("/sys/class/gpio/gpio45/direction", “w”);
fseek(iodir,0,SEEK_SET);
fprintf(iodir,“out”);
fflush(iodir);

Code not Working:

FILE *pwm,*duty,*period,*run;

pwm = fopen("/sys/devices/bone_capemgr.9/slots", “w”);
fseek(pwm,0,SEEK_SET);
fprintf(pwm,“am33xx_pwm”);
fflush(pwm);

fprintf(pwm,“bone_pwm_P8_13”);
fflush(pwm);

period = fopen("/sys/devices/ocp.2/pwm_test_P8_13.14/period", “w”);
fseek(period,0,SEEK_SET);
fprintf(period,"%d",200000000);
fflush(period);

Easy to figure out why it fails - no ocp.2 files, and nothing in ocp.3 similar.

Here’s[1] the instructions I gave my students.

–Mark

[1] http://elinux.org/EBC_Pulse_Width_Modulation

Mark, thank you for the info, this is very useful.

Mark,

Thanks so much! That tutorial did the trick.

I was not submitting am33xx_pwm to the cape manager.

I’m still not sure what it is, but no matter… it works now!

Thanks again.

Bill