Software PWM generation using gpio in Beaglebone

Hi!

We are trying to run a servo using software PWM (No kernel modules /
hardware used, Beaglebone-Minimal Angstrom image Kernel ver. 3.1.0+).
The development is being done on the target itself(No cross compilers
being used). The code is as follows:

Yehh , even i'm facing exactly the same problem, ...please let me know
if you find any solution...:slight_smile:

#0 0x400f0114 in fwrite () from /lib/libc.so.6
#1 0x000086d0 in gpio_init ()
#2 0x00008820 in main ()

Most probably one of your fprintf() fails. The reason for it could be
wrong arguments you are passing to it. Most probably the FILE* pointer
is null. Why it could be? Because file is not opened properly. How it
could happens? For example because the path you are passing to fopen()
is wrong. How that could happen? Either file does not exists or you do
not have enough permissions or your constructed path string is wrong.
How it could be wrong? Look for example how you are using
*uninitialized* temp1 variable with strcat(). Here you are calling for
problems.

So what I would suggest to do are:

- clean up your code so that you are not manipulating uninitialized strings

- it is absolutely necessary to add error checking and handling for
fopen() function. It will tell you what is wrong.

- there is absolutely no need to open/close the file every time you
want to write to it. It is *very* inefficient. Consider adding FILE*
parameter to your gpio_control function, open the file at the
beginning of your program and close it at the end.

when you call an fopen("/sys/class/gpio/export",“w”); check alway return value : if null an error occured and
each operation after will fail
In your case perhaps wrong rights permission

This is pretty interesting. I just got a servo working using the built-
in hardware PWM and it works pretty well, but after reading some more
discussions and the SRM it sounds like the BeagleBone can only support
up to 6 servos via this method (I'm looking to control more).

I'm hoping that there's a way to make use of software PWM by default
and then offload some of that to hardware PWM if the CPU load becomes
to intense.

- Mike

I'm hoping that there's a way to make use of software PWM by default
and then offload some of that to hardware PWM if the CPU load becomes
to intense.

Speaking about software PWM generation - you might be interested to
take a look at the following article:
http://veter-project.blogspot.com/2011/09/real-time-enough-about-pwms-and-shaky.html

In addition, the following article provides great overview about what
is possible on BeagleBoard:
https://www.osadl.org/fileadmin/dam/rtlws/12/Brown.pdf

Hi Mike,

Could you point me at any docs you used to get the hardware pwm
working? (I only need to control 4 servos.)

Thanks,

Chris.

cmsdew at gmail.com

Chris, sure. You can follow this thread: http://groups.google.com/group/beagleboard/browse_thread/thread/6a529febb7703072/70dbad13db19f8be?lnk=gst&q=pwm#70dbad13db19f8be

The last couple pages are the most relevant.

  • Mike

Thanks,

Chris.

You might want to look at my project http://github.com/tallakt/servodrive

tallakt, your servodrive project would be the ideal solution. Would
you have any idea how to adapt it to the beaglebone? The pinmuxing
would be the main difference, I think.

Hi. Sorry, I only have an Beagleboard, no XM or 'bone, so I don't want
to comment on compatibility. I would also like to mention that one
user got problems with the beagleboard running servis directly off the
1.8V, but the root cause was never found (ie could be something else).

you have any idea how to adapt it to the beaglebone? The pinmuxing
would be the main difference, I think.

Actually, I never did any pin muxing. All the IO pins I used worked as
gpio right out of the box. You might want to select other pins on the
beaglebone that are preconfigured to work as gpio, and you might test
this with the generic gpio stuff (echo 1 > /dev/...)

Tallak