Archive for March 28, 2011

Servo Motor Control Using 8051 Micrcontroller

The control signals for the rotation of the motor are provided by 8051 microcontroller.For basic concepts and know-how of a servo motor, refer to the article Servo Motor.

Source Code

Here,i have used AT89S51  microcontroller.Code is written in C using  Keil uVision4.
#include<reg51.h>
sbit output=P1^0;          //Output to motor

void timer(int msec)     // Function for timer
{
int i;

for(i=0;i<msec;i++)

{
TMOD=0x20;         // Mode2
TH1=0xFF;
TL1=0xD1;
//TH1= -23;        // 50usec timer
TR1=1;
while(TF1==0);
TF1=0;
TR1=0;
}
}

void main()
{
int i;

output=0;

while(1)
{
//anticlockwise direction
for(i=0;i<500;i++)
{
output=1;
timer(20);
output=0;
timer(360);
}
//clockwise direction
for(i=0;i<500;i++)
{
output=1;
timer(40);
output=0;
timer(360);
}
}
}

Circuit

Servo motor control