Data Storage Tool Display Human Input Protocol Math Motor Control Sensor Signal Generation & Processing Speech & Sound Fun View all Objects


Quick Links
Contact Us
Forums
Support

Register
Login

This object is provided under license. By downloading this object, you are agreeing to the terms of the MIT License.

RC_Servo_Control

These are five programs that demonstrate various techniques for controlling RC servomotors with the Propeller chip. These are meant to be used as samples/demos, and I’ve included thorough comments that explain exactly how to use them in your own code. They are designed to be very easy to understand and adapt to fit into your own code and applications. They all dedicate a separate cog to the creation of a continuous stream of servo pulses. Once the code is running on a separate cog, a servo’s position can be changed by simply changing the value of its “position” variable in the main Hub RAM (using Spin or assembly code such as “position:=110_000”). In your own applications, you could replace the 1 second waitcnt pauses that I have in my “Demo” method with any other operations you need to perform. Single_Servo_Spin shows you how to control a motor using a few simple lines of Spin. Although this is easy to understand, it is has very poor position resolution (around 175 possible positions). Single_Servo_Assembly demonstrates how to control one RC servomotor by running a simple assembly program on a separate cog. The output pulse resolution for this technique is between 12.5-50ns when using an 80MHz system clock, which in theory corresponds to up to around 140,000 possible positions for a Parallax/Futaba Standard Servo. Two_Servo_Assembly and Three_Servo_Assembly demonstrate how to control multiple servos by running an assembly program on a separate cog. Once you understand how these two programs work, you could easily modify/expand them to control up to around ten RC servomotors. (Just reduce the “LowTime” value so that, in total, there is about 20ms between the pulses for each motor.) Because the servo pulses are sent out one after another (back to back), the current drawn by each servo will also be staggered. (If you need to control more than ten servos and don’t need as high of a position resolution, try using the Servo32v3 object in the Propeller Library.) Finally, I’ve included a program called Single_Servo_Counter that demonstrates how to use a cog’s counter to create a servo pulse. If you actually find that you are maxing out all of your Propeller chip’s processing capabilities in a particular application, you could apply this technique and try to squeeze a few more lines of code in while the cog is not busy setting up its counter. In general, I think that the servo control technique based on assembly code is probably the most logical and robust choice. I hope that these help people out!

Version:
  1.0

Type:
  Object

Attributes:


Author:
  Gavin Garner
  gavingarner@gmail.com

Categories:
  Motor Control

Downloads:
  2,236

Last Updated:
  2008-11-20



User Reviews:

  • Seairth commented:
    Thank you. This got me quickly started on my little servo project. Note to others: If you are using the Spektrum DS821 (very inexpensive digital servo), I found the timing to be somewhat different than the Parallax/Futaba servo. Here are the values that worked for me: [MAX CCW 0.872ms, position:= 62_560], [CENTER 1.500ms, position:= 120_000], [MAX CW 2.182ms, position:= 174_560]
    February 23, 2010 11:41 a.m.


  • Ralph Jansen commented:
    Great code with good comments. Got my servos running in a weekend with no previous Propeller programming experience.
    February 11, 2009 1:02 p.m.


  • evans commented:
    A well commented code that helped me understand how to work with servos! This is the BEST place to start when you are ready to learn about controlling servos with the propeller. Thank you Gavin for documenting your hard work in a manner that makes learning a little less painful for the rest of us.
    December 10, 2008 1:08 p.m.




  • Comments on this Object:


    Post a comment:




    Please contact obex.support@parallax.com with comments or questions.

    Copyright 2011 by Parallax, Inc.