The servo motor has been around for quite some time.

It has gained a lot of popularity for it ease of use & application, especially in hobby & RC electronics. Almost every RC car, helicopter or plane will have at least 1 servo motor inside. This tutorial will cover:

1. Servo Motor Theory. 2. Single Servo Motor Control w/ PIC. 3. Multiple Servo Motor Control w/ PIC.

It is highly recommended that you understand how to program a PIC before continuing with this tutorial. I have a tutorial written that explains this process. Take a quick look through it if you're not familiar with the PIC Microprocessor. The Servo Motor

The Servo Connector

Purpose of this project The purpose of this project is to explain what a servo motor is, how it is used & how to control it using the PIC microcontroller. Basic servo theory will be explained and then we'll look at some sample programming methods to control servo motors. A great advantage of servo motors is that they are very easy to control in comparison with other types of motors (DC, Stepper) that require an H-Bridge or external circuitry. The servo motor has all this circuitry internally. Inside the Servo Motor

Like DC motors, servo motors have been around a long time and are used in a wide variety of applications. The basic design of the servo motor is the same no matter the size or manufacturer. The picture below illustrates a cut-away of a servo and shows you what it looks like on the inside.

The bottom has the servo controller board which interprets the signal input & turns on the motor inside which is geared up. You cannot see it clearly but there is also a potentiometer (aka a variable resistor) inside the servo as well. The servo uses the potential meter for finding the different angles that it will rotate to. These so called "pots" can go bad so, don't automatically throw away servos if they don't work properly, often times all that needs to be replaced is the pot inside. Servo Motor in Action To illustrate how to control a servo motor, first we'll look at the sample program in action. The video below shows a PIC controlling a servo. It tells the servo to move to three distinct locations over and over forever: 0°, 45° & 90° (Note standard servos can rotate a maximum of 90°).

Servo Motor Theory Hi-Tec Servo Motors have three wires coming out of them.

·Red - Power (4.8v-6v) ·Black (Ground) ·Yellow (Signal)

The power & ground wires are hooked directly up to whatever battery or power supply you are using to power the servos. The Signal wire will be hooked up to the microcontroller used to control the servo, in our case the PIC. A noticeable first impression, the servo only requires 1 pin from the pic. The PWM Signal The signal that we need to create inorder to control the servos is called a Pulse With Modulation signal or PWM for short. The general requirements are: Frequency: 50Hz Up-time: 0.9mS->2.1mS Down-time: 19.1mS-17.9mS At first glance these definitions & numbers might make little or no sense. So lets look at a simple PWM wave at 50Hz.

So a PWM wave is just a signal that changes between 0 volts & 5 volts (digital logic 0 and 1). We see that the wave is symmetrical; uptime is 10mS & downtime is 10mS which when added together give us the period (10mS + 10mS = 20mS).

The Single Servo Schematic Although we'll be using the Olimex P-40 development board, you can alsobreadboard out the

circuit as it is very simple. The schematic for our first pass at controlling a servo is shown below. Servos can start to sink a lot of current like any motors so it is wise to be sure that your batteries can handle high currents. Since we're only using 1 or 2 servos, current won't be an issue.

You may have noticed that the servos we're using are rated at 4.8v & 6v. We're hooking 5v to the servos in this tutorial just to make things easier. This will not harm the servos in any way. They can be safely operated between 4.8 and 6 volts. The increase in voltage gives the servos more torque.

Single Servo Motor Control Software Our first program is from the example video in part 3: 'Inside The Servo Motor'. It moves the motor from: 90° -> 45° -> 0°. First we take a look at how to get the necessary numbers for our program:

Now that we know the necessary delays to create in order to get a proper servo PWM input signal, let's look at the code. The code is fairly long so I'll go over the most important part.

for(count=0;count<50;count++) //50 * 0.020 Seconds = 1 Second { PORTB = 0x01; //PortB Pin 0 = 5v (logic 1) Delay1KTCYx(7); //Delay 1.5mS Delay100TCYx(5); PORTB = 0x00; //PortB Pin 0 = 0v (logic 0) Delay1KTCYx(92);//Delay 18.5mS Delay100TCYx(5); }

END CODE This little chunk of code will move the servo to a 45° angle and hold there for 1 second. The servos are very strong so for that 1 second tries as you might but you won't be able to change the angle it's at.

An Overview of Servo Motor Control

Servo Motors are definitely very useful in the world of robotics. They allow us torque & precise movements. They are great 'actuators' for imitating things like fingers, hand or leg movements. The ease of control via the PIC makes them all the more desirable to use in projects, however even servos have their limitations. What To Do Now There are many different types of servos out there. Hi-Tec, Futaba just to name a few. Some have different wiring & even use different types of PWM input signals. This may force you to change the programming style I've created to better suite your specific servos.

Please note that the methods I've used in this tutorial for controlling servos are not the only ones. You can potentially control as many servos as you want with a PIC and your own creative programmings so don’t feel that you are limited by the code I've shown you here today. Conclusion The tutorial was able to cover everything I had hoped it would and we had success in controlling servos which was our main purpose & goal. I will have more projects coming which use servos so you can see how they fit into projects which are doing many things at once. Having now gone over how to control DC Motors & Servo Motors I'll be able to move onto stepper motors in a future tutorial. So for those of you who have been waiting to see it, a stepper motor tutorial is in the works & coming. Congratulations, now you can control an electric servo motor!

Sign up to vote on this title
UsefulNot useful