Servo Motor Speed and Direction Control
Servo Motor Speed and Direction Control
Servo Motor Speed and Direction Control
A Stepper Motor or a step motor is a brushless, synchronous motor, which divides a full rotation
into a number of steps. Unlike a brushless DC motor, which rotates continuously when a fixed
DC voltage is applied to it, a step motor rotates in discrete step angles.
The Stepper Motors therefore are manufactured with steps per revolution of 12, 24, 72, 144, 180,
and 200, resulting in stepping angles of 30, 15, 5, 2.5, 2, and 1.8 degrees per step. The stepper
motor can be controlled with or without feedback.
Imagine a motor on an RC airplane. The motor spins very fast in one direction or another. You
can vary the speed with the amount of power given to the motor, but you cannot tell the propeller
to stop at a specific position.
Now imagine a printer. There are lots of moving parts inside a printer, including motors. One
such motor acts as the paper feed, spinning rollers that move the piece of paper as ink is being
printed on it. This motor needs to be able to move the paper an exact distance to be able to print
the next line of text or the next line of an image.
There is another motor attached to a threaded rod that moves the print head back and forth.
Again, that threaded rod needs to be moved an exact amount to print one letter after another.
This is where the stepper motors come in handy.
A Servo motor is one of the most commonly used motor for precise angular movement. The
advantage of using a servo motor is that the angular position of the motor can be controlled
without any feedback mechanism. The servo motors are usually used in commercial and
industrial applications. They are also widely used as in drive systems such as robots, aeroplanes
etc.
Hobby servo motor working principle and operation is very simple, it consisted three wires
where two of them (Black and red) used to provide power and the third wire is used to provide
control signal. Pulse Width Modulated (PWM) waves are used as control signals and the angular
position is definite by the width of the pulse at the control input. In this article, we are using a
servo motor having angle of rotation from 0-180° and angular position can be controlled by
varying the duty cycles among 1ms to 2ms.
Here the servo motor interfacing with 8051 microcontroller, the black wire connected to the
ground pin and the motor get the power from the red wire. The control of servo motor connected
port0 of 8051 microcontroller. The 11.0592MHz crystal oscillator is used to provide the clock
pulsed to the microcontroller and 22pf ceramic capacitors used to stabilize the operation of
crystal. 10KΩ and 10uf capacitor is used to provide the power on reset to the microcontroller.
Servo motor working principle mainly depends upon duty cycles. It uses Pulse Width Modulated
(PWM) waves as control signals. The angle of rotation is resolute by the pulse width of the
control pin. Here the servo motor used for angle of rotation from 0 to 180 degrees. We can
control the precise angular position by varying the pulse among 1ms to 2ms.
Servo Motor Programming With angular rotations
The servo motor working principle mainly depends upon the ‘Fleming left hand rule’. Basically
servo motors are adapted with DC motors, a position sensor, a Gear reduction, and an electronic
circuit. The DC motors achieve powered from a battery and run at high speed and low torque.
We assembled shaft and gear connected to DC motors then we can increase and decrease the
motor speed gradually.
The position sensor senses the location of the shaft from its fixed position and sends the
information to the control circuit. The control circuit decodes the signals accordingly from the
position sensor and compares the actual location of the motors with the preferred position and
accordingly controls the direction of rotation of the DC motor to get the necessary position.
Generally the servo motor requires 4.8V to 6 V DC supply.
Servo Motor Applications
If a motor gets heavy load the driver will increase the current to the motor coil as its efforts to
rotate the motor. Mainly, there is no out-of-step condition.
High-speed operation is possible by the servo motors.
First we need to understand the working principle of servo motors. Servo motor works on
PWM (Pulse width modulation) principal, means its angle of rotation is controlled by the
duration of applied pulse to its Control PIN. Basically servo motor is made up of DC motor
which is controlled by a variable resistor (potentiometer) and some gears. High speed force
of DC motor is converted into torque by Gears. We know that WORK= FORCE X DISTANCE,
in DC motor Force is less and distance (speed) is high and in Servo, force is High and distance is
less. Potentiometer is connected to the output shaft of the Servo, to calculate the angle and stop
the DC motor on required angle.
Servo motor can be rotated from 0 to 180 degree, but it can go up to 210 degree, depending on
the manufacturering. This degree of rotation can be controlled by applying a LOGIC level 1
pulse for a duration between 1ms to 2ms. A 1 ms can rotate servo to 0 degree, 1.5ms can rotate
to 90 degree and 2 ms pulse can rotate it to 180 degree. Duration between 1 to 2 ms can rotate
Servo motor to any angle between 0 to 180 degree.
Servo motor has three wires Red for Vcc (power supply), Brown for Ground, and Orange is
control wire. Control wire can be connected to 8051, we have connected it to Pin 2.1 of 8051.
Now we have to keep this pin to Logic 1 for 1ms to rotate it 0 degree, 1.5ms for 90 degree, 2 ms
for 180 degree. We have used on chip Timers of 8051 to create delay. We have created delay of
50us through the function “servo_delay”, and used “for” loop to create delay in multiple of 50us.
We are using Timer 0 and in Mode 1, so we have put 01H in TMOD register. Mode 1 is 16 bit
timer mode and TH0 contain High byte and TL0 contain Low byte of 16 bit timer. We have put
FFD2 in 16 bit timer register, FF in TH0 and D2 in TL0. Putting FFD2 will create the delay of
approx. 50 us with the crystal of 11.0592MHz. TR0 and TF0 are the bits of TCON register, TR
pin used to start timer when set and stop when reset(0). TF is overflow flag, set by hardware
when overflow and need to reset it by software. Basically TF tells the completion of Timer, and
set by hardware when 16 timer transit from FFFFH to 0000H. You can read about the “8051
Timers” to understand the calculation of value in timers registers, to create the 50 us delay.
Now when measured from CRO, 13 loops of servo_delay function will give the delay of 1ms, so
we have started from 1ms (13 loops) and gone to 2 ms (26 loops) to rotate the servo from 0 to
180 degree. But we have slowly incremented the delay from 1ms, we have divided 1ms to 2 ms
window into 7 parts like 1.14ms, 1.28 ms, 1.42ms and so on, so the servo will rotate in multiple
of approx. 26 degrees(180/7). After 180 it will automatically return to 0 degree.
#include<reg51.h>
sbit output=P2^0;
void servo_delay(int times) // Creating Delay in multilple of 50us using 8051 Timers
{
int m;
for(m=0;m<times;m++)
{
TH0=0xFF;
TL0=0xD2;
TR0=1;
while(TF0==0);
TF0=0;
TR0=0;
}
}
void main()
{
int n;
TMOD=0x01; // Selecting Timer 0, Mode 1
output=0;
while(1)
{
for(n=13;n<28;n=n+2)
{
output=1;
servo_delay(n);
output=0;
servo_delay(260);
msdelay(200);
}
}
}