Thursday, October 7, 2010

Servo Motor Controller

 The servo motor is widely used in model hobbyist such as airplane R/C model for moving the rudder, ailerons, elevators and acceleration control or in the car R/C model for steering and acceleration control. In this tutorial we will learn how to control the servo motor as well as the simple close loop control algorithm for this servo motor.
Since the internal control electronics of each servo motor expects to have position data updates at intervals of approximately 60 times per-second (60Hz), the timeout/label helps establish this timing without using additional pause commands or other methods. Notice from the scope trace below that we have 15mS delays between the servo pulses. This corresponds to our 15mS delay time waiting for incoming serial data in the serial-input code line.
 
Pulse Position Modulation
The most important thing to remember from this servo tutorial is that all standard servos use the Pulse Position Modulation (PPM) language. A pulse is simply whether or not the control voltage is on or off. The amount of time that a pulse is on during a 2ms time frame dictates the servos position. This time frame, or sequence, repeats around 50 times per second. During the first half of this 2ms time frame, the pulse is always on. This starts a counter, so to speak, to tell the servo to start listening for the command. The second portion of this 2ms time frame is the command that dictates the position of the servo.
Take a look at the chart below to help you better understand this servo tutorial. The amount of time during the designated 2ms time frame that the pulse will be on for the three most extreme positions(far left, far right, neutral). There are an infinite amount of positions in between these values and amount of time the pulse is ON changes in proportion. This is what makes Pulse Position Modulation analogue.
Servo #1:
Far Left Command: Time ON = 1 + 0.0 ms = 1.0 ms
Servo #2:
Neutral Command: Time ON = 1 + 0.5 ms = 1.5 ms
Servo #3:
Far Right Command: Time ON = 1 + 1.0 ms= 2.0 ms

The pulsout command uses the positional data received/stored in the byte-variable pos to generate the servo control pulses. The PIC12C671 is limited to a maximum oscillator speed of 4MHz, hence, the period of the generated pulses will be in 10uS increments.Now that we have the servo-pod ready to use, we need to figure out how to send positional data to the servo-pod that will let us position the servo motor. As stated previously -- we know that the pulsout command is dependent on the oscillator frequency, and the pulse duration will be in 10uS increments when used in conjunction with an oscillator frequency of 4MHz. Since the PIC12C671 maximum operating frequency is 4MHz, we'll have to make due with this resolution. The circuit diagram is given below:

The Test Program:
Now that you're ready to start using the servo-pods, some test code to cycle the servo motors will be necessary. Here's a quick & simple Basic Stamp routine that will cycle a servo motor attached to a servo-pod hard-coded with the unique ID #5.

No comments:

Post a Comment