fbpx

Interface servo motor with 8051

Some special types of application of electrical motor where rotation of the motor is required for just at certain angle not continuously for long period of time.

Motor are required with some special arrangement which makes the motor to rotate at certain angle for a given electrical input (signal).

  • Servo motor use servo mechanism.
  • It is a closed loop mechanism that uses position feedback to control the precise angular position of the shaft.
  • Servo motors have three wires.
  • Two of them are red and black which is used to give power to the motor.
  • The third wire is used to provide control signal for angular position.
  • It uses Pulse Width Modulated (PWM) waves as control signals.
  • The angle of rotation is determined by the width of the pulse at the control pin.

Hardware Required

  • Servo Motor.
  • 8051 MicroController.

Circuit

Virtual Circuit

Code

 #include <REGx51.h>
 #include <stio.h> 
 #include <intrins.h>
 sbit motor_pin = P0^0;
 void Delay(unsigned int);
 void Delay_servo(unsigned int);
 void main()
 {
  motor_pin = 0;
  do
  {
   //Turn to 0 degree
   motor_pin = 1;
   Delay_servo(50);
   motor_pin = 0;
   Delay(1000);
   //Turn to 90 degree
   motor_pin=1;
   Delay_servo(82);
   motor_pin=0;
   Delay(1000);
   //Turn to 180 degree
   motor_pin=1;
   Delay_servo(110);
   motor_pin=0;
   Delay(1000);
  }
  while(1);
 }
 void Delay(unsigned int ms)
 {
   unsigned long int us = ms*1000;
   while(us--)
   {
    nop();
   }
 }
 void Delay_servo(unsigned int us)
 {
   while(us--)
   {
    nop();
   }
 }

Leave a Reply

Your email address will not be published. Required fields are marked *