Controlling a servo
Hi, I'm new at using my propeller and I'm trying a few basic projects to learn more about it. right now I'm trying to control a servo, but I haven't found how to do it. Could someone help me out with so me code for controlling a standard servo. I'm confused on what the best commands are for doing this with the propeller chip. (I'm starting with the propeller education kit, and a servo)
Thanks, this will be much appreciated.
Thanks, this will be much appreciated.
Comments
I generally use my own code of a few lines...
Here a link to some general PWM Tutorial
propeller.wikispaces.com/PWM
which will soon lead you back to a tutorial somewhere burried here in this forum...
I might use your questions to improve some of it..
I am using the servo32 object to control 3 servos in an insect style robot based on the book Insectronics by
Karl Williams. My ultimate goal however is to build a homebrew version of a hex crawler similar to the
Crust Crawler or Nomad. Therein lies my problem with servo32. According to my reading of it's self-documentation
it is capable of controlling up to 32 servos with a single cog and I do not see how this could be possible for the following
reason. A servo requires a 1 to 2 msec. pulse at least once every 20 msec. This gives a maximum of 10 servos per
20 msec. frame. If you try to do more than 10 servos therefore (using a single cog) you will exceed the 20 msec.
refresh requirement. There are 50 20msec frames in one second which is what gives rise to the ~50 hz refresh rate.
As nearly as I can see right now my best bet would be to use 2 cogs per 9 servos which would give me the 18 I need
(6 legs 3 DOF). This leads me to another difficulty with servo32 in that it appears that it launches itself into the next
available cog when you call its start method. then your program calls it with pin and duration parameters. I am not
sure how one would go about launching two copies of servo32 and keeping track of which was doing what. I know that
someone else has successfully written propeller code to control a Crust Crawler but I don't have access to it, and besides
the whole point of this exercise (aside from having fun) is to learn about the capabilities of the prop.
Any hints tips or help to figure out what I'm missing here would be appreciated.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
jac {^[noparse]:)[/noparse]}
Never underestimate the power of human stupidity! (It bites me all the time!)
Follow the links given above.
What you’re describing would be true if each servo was activated sequentially, but that's not the case with Servo32.· Servo32 groups the pins into 4 groups of 8 servos.· Each group of 8 servos has an allocated time frame·of 5ms.· Among·each group ALL 8 servos are initiated at the same time or in parallel, so within 3ms or so within each allocated time frame,· ALL 8 servos are done.· 2mS are reserved for program overhead.· As·time elapses for each of the 8 servos, the·pulse signal drops off in accordance to the·set pulse duration you assign to the servo. You could allow ALL 32 servos to operate this way, but the amount of startup current required to simultaneously drive 32 servos can become problematic.· 8 servos is a much friendlier number to work with.· As far as resolution limitations...· This application is geared·toward hobby servos, which simply put... aren't really that accurate.· Anything more than 1/1000 is most likely going to be overkill.· The range of Servo32 is fixed mainly to protect the servo as to not produce a signal capable of going out of bounds.· Typically this out of bounds range is 1ms·to 2ms,·however if you find that an application requires·a signal outside of this range, Servo32 can be adjusted for a pulse up to 2.75ms and down to 0.25mS.· I hope that this clears up any confusion with Servo32.
·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
Post Edited (Beau Schwabe (Parallax)) : 3/11/2008 4:14:26 PM GMT
What does your wiring to the servo look like?
What voltage are you powering the servo with?
Are you sharing the same ground connection of the servo(Black) with the Propeller (Vss)?... If not,·it should be shared.
The "Servo32_v3 Demo.spin" should pan a servo back-n-forth on P0 when connected to·the Propeller.· Make sure that
this program works first before you make any modifications.
Say for example you have a servo on pin 5 (P5) that you want to initialize·to center position.· The code might look something
like this:
You MUST initially use 'SERVO.Set' to tell the servo handler which pins that you are using for the servo(s).· This needs to be done before you actually start the servo handler with 'SERVO.Start'.
Once that is done (just two lines of code) you can use the 'SERVO.Set' to position the servo at any position between 1ms (1000) and 2ms (2000) at any time through the remainder of the program.
·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
@ deSilva: Will do. I have read some of your stuff before and have found it both interesting and informative.
@ Beau: Thanks for the enlightenment. I knew from the internal docs about the time slots, but I didn't realize
the full implications. I fully understand about the current surge problem, and I think your solution to it is really slick!
my hex crawler application, I think judicious pin allocation can solve a lot of it. It'll require some thought though.
As for the resolution thing, it does seem rather useless to waste processing bandwidth on resolution that the mechanics
just aren't able to deliver..
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
jac {^[noparse]:)[/noparse]}
Never underestimate the power of human stupidity! (It bites me all the time!)