You are on page 1of 7

http://www.pyroelectro.

com/tutorial
s/servo_motor/data.html
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).

Hi-Tec Servo Motors .


- Power (4.8V-6V)
()
(Signal)
& ,
.
,
PIC. ,
1 pic.
PWM
inorder servos
Pulse PWM .
:
: 50Hz
Up-time: 0.9mS-> 2.1mS
Down-time: 19.1mS-17.9mS

. , PWM 50 Hz.
, PWM 0 Volt 5
( 0 1). ? Uptime
10ms & downtime 10ms
(10ms + 10ms = 20ms).
The Single Servo Schematic
Although we'll be using the Olimex P-40 development board, you can also
breadboard 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 alot 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.
Click to Enlarge:

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.
The Multi Servo Schematic
One thing about robotics is that you are never ever doing only 1 thing at a time.
When it comes to using servos in robotics it is very common that your project will
have 2, 3 or even 4 servos that need to be operated at once. The multi servo schematic
below is not very different from the single servo schematic above, but the software
method for controlling the 3 servos simultaneously is intuitively different. We'll go
over this in detail in the next section.
Click to Enlarge:

3 Pins are used to output control PWM signals to the 3 servos. RB0, RB1 &
RB2. Don't forget these names because in the next section we'll see them again.

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 inorder 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.
Download The Entire Program Here: servo_single.c
Begin Code
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 try as you might but you
won't be able to change the angle it's at.

Motor Servo
3:
Servo Motor. : 90 -> 45 -> 0 .
:
inorder
PWM , .
' .
: servo_single.c

(count = 0? <50? + +) / / 50 * 0,020 = 1

{
PORTB = 0x01? / / PORTB Pin 0 = 5V ( 1)
Delay1KTCYx (7)? / / 1.5mS
Delay100TCYx (5)?

PORTB = 0x00? / / PORTB Pin 0 = 0V ( 0)


Delay1KTCYx (92)? / / 18.5mS
Delay100TCYx (5)?
}

45
1 .
1 , ,
.

***Warning Advanced Topics***


Continue Reading Only If You're Familiar With Timers & Interrupts
Mulitple Servo Motor Control Software
This next program is more advanced than the ones in previous tutorials. It uses
interrupts & timers to control the servos instead of delays. This is a great advantage
because we'll be able to control up to 9 servos at the same time. For the sake of
keeping the tutorial short i'll just use two servos at the same time.
Download The Entire Program Here: multi_servo.c
This program is even longer than the first one, so instead of attempting at an
explanation of the code here, I just put more comments in the code than I normally do.
If you've been programming with the PIC for a while it should make a decent amount
of sense to you. If you have any questions about the code just say something in the
forums.
*** ***
&

Motor Servo

. & servos
.
9 servos .
servos .
: multi_servo.c
,
,

, . PIC
.
.

Servo Motor Control: Conclusion


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 desireable 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, airtronics
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
amd your own creative programming 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!

Previous Page

Servo Motor:
Servo Motor
Servo Motors
. .
,
.

,
servos .

servos . Hi-Tec,
Futaba, airtronics .

PWM .

servos .

servos .
servos PIC AMD
,
.


servos
.
servos
.
DC Motors &
Servo Motors stepper
.
, stepper
.
, servo!

You might also like