SlideShare a Scribd company logo
Servo Control using Atmel 89S52

                 Submitted by

               Mayank Awasthi
                B.Tech(ECE)
             PDPM IIITDM, Jabalpur

               M. Tech, IIT Roorkee
            (Communication Systems)

             Contact no. 9410321979




       Under the supervision of
           Mr. Susmit Sen
        Senior Research Engineer
           Centre for Robotics
               IIT Kanpur




                                      i
ACKNOWLEDGEMENT



First of all, we would like to express our sincere thanks to our guide Mr. Susmit
Sen for his intellectual guidance, continuous interest, generous support, infinite
patience, and constant encouragement throughout this work. He has devoted his
valuable time to discuss this project, his expertise and broad knowledge in
Mechatronics & Robotics played a major role in the realization of this work. We
appreciate Mr. Susmit Sen for his confidence boosting start up to our project
work and encouragement in creative endeavors.
We especially appreciate the company of our classmates, seniors, workshop &
lab assistants and who have made useful to this work by way of discussions and
suggestions from time to time.




                                             Group Member
                                             Mayank Awasthi
                                             B.Tech(ECE)
                                             PDPM IIITDM, Jabalpur
                                             Contact no. 9336441681




                                                                                ii
CONTENTS



 I.     Servo Motors ………………...................
 II.    Atmel 89S52 Microcontrollers ………..
 III.   Keil code ………………………………..
 IV.    References ……………………………




                                                 iii
SERVO MOTORS



      A Servo is a small device that incorporates a three wire DC motor, a
      gear train, a potentiometer, an integrated circuit, and an output shaft
bearing. Of the three wires that stick out from the motor casing, one is for
power, one is for ground, and one is a control input line. The shaft of the
servo can be positioned to specific angular positions by sending a coded
signal. As long as the coded signal exists on the input line, the servo will
maintain the angular position of the shaft. If the coded signal changes, then
the angular position of the shaft changes.

    A very common use of servos is in Radio Controlled models like cars,
airplanes, robots, and puppets. They are also used in powerful heavy-duty
sail boats. Servos are rated for Speed and Torque. Normally there are two
servos of the same kind, one geared towards speed (sacrificing torque), and
the other towards torque (sacrificing speed). A good example of this is the
HS-625MG servo and the HS-645MG servo.

    Servos come in different sizes but use similar control schemes and are
extremely useful in robotics. The motors are small and are extremely powerful
for their size. It also draws power proportional to the mechanical load. A
lightly loaded servo, therefore, doesn’t consume much energy.

A typical Servo looks like a rectangular box with a motor shaft coming out of
one end and a connector with three wires out of the other end. The three
wires are the power, Control, and Ground. Servos work with voltages
between 4 and 6 volts. The control line is used to position the servo. The
servo motor comes in different sizes, which affect the overall size of the
servo. The gears of a servo vary from servo to servo. Inexpensive servos
have plastic gears, and more expensive servos have metal gears which are
much more rugged but wear faster. The potentiometer of a servo is the
feedback device. The electronics of a servo are pretty much the same in all
servos, but the output shaft bearing of a servo has either a plastic on plastic
bearing that will not take much side load or a metal on metal bearings that
stand up better under extended use, or ball bearings which work best. We
highly recommend ball bearing servos if your application demands heavy side
loads.


                                                                                iv
Servos are constructed from three basic pieces; a motor, a potentiometer
(variable resister) that is connected to the output shaft, and a control board.
The potentiometer allows the control circuitry to monitor the current angle of
the servo motor. The motor, through a series of gears, turns the output shaft
and the potentiometer simultaneously. The potentiometer is fed into the servo
control circuit and when the control circuit detects that the position is correct,
it stops the motor. If the control circuit detects that the angle is not correct, it
will turn the motor the correct direction until the angle is correct. Normally a
servo is used to control an angular motion of between 0 and 180 degrees. It is
not mechanically capable (unless modified) of turning any farther due to the
mechanical stop build on to the main output gear.

The amount of power applied to the motor is proportional to the distance it
needs to travel. So, if the shaft needs to turn a large distance, the motor will
run at full speed. If it needs to turn only a small amount, the motor will run at a
slower speed. This is called proportional control.




How Do Servos Work ?




                                                                                  v
Servos are controlled by sending them a pulse of variable width. The control
wire is used to send this pulse. The parameters for this pulse are that it has a
minimum pulse, a maximum pulse, and a repetition rate. Given the rotation
constraints of the servo, neutral is defined to be the position where the servo
has exactly the same amount of potential rotation in the clockwise direction as
it does in the counter clockwise direction. It is important to note that different
servos will have different constraints on their rotation but they all have a
neutral position, and that position is always around 1.5 milliseconds (ms).




The angle is determined by the duration of a pulse that is applied to the
control wire. This is called Pulse width Modulation. The servo expects to see
a pulse every 20 ms. The length of the pulse will determine how far the motor
turns. For example, a 1.5 ms pulse will make the motor turn to the 90 degree
position(neutral position).

    When these servos are commanded to move they will move to the position
and hold that position. If an external force pushes against the servo while the
servo is holding a position, the servo will resist from moving out of that
position. The maximum amount of force the servo can exert is the torque
rating of the servo. Servos will not hold their position forever though; the
position pulse must be repeated to instruct the servo to stay in position.

    When a pulse is sent to a servo that is less than 1.5 ms the servo rotates
to a position and holds its output shaft some number of degrees
counterclockwise from the neutral point. When the pulse is wider than 1.5 ms
the opposite occurs. The minimal width and the maximum width of pulse that
will command the servo to turn to a valid position are functions of each servo.
Different brands, and even different servos of the same brand, will have
different maximum and minimums. Generally the minimum pulse will be about
1 ms wide and the maximum pulse will be 2 ms wide.




                                                                                vi
Another parameter that varies from servo to servo is the turn rate. This is the
   time it takes from the servo to change from one position to another. The worst
   case turning time is when the servo is holding at the minimum rotation and it
   is commanded to go to maximum rotation. This can take several seconds on
   very high torque servos.

HS-322HD Servo Motors Specifications:

This servo comes with mounting hardware, mounting grommets, and 4 servo
horns. The HS-322HD servo has heavy duty gears for smoother operation and
longer life when compared to normal servos. This servo has a Hitech/JR
connector which mates directly with a 0.1" 3-pin header. The servo spline has 24
teeth and mates with Hitec compatible accessories.

                                  Specifications
   Voltage
                    Operating Speed             Output Torque            Weight
   Range
                 0.19sec/60 degrees at       3kg.cm (41.6oz.in) at       43.0g
4.8V - 6V
                         4.8V                       4.8V                (1.51oz)

Wire Color Meaning

On all Hitec servos the Black wire is 'ground', the Red wire (center wire) is
'power', and the yellow (third) wire is 'signal'.




                                                                                   vii
ATMEL 89S52 MICROCONTROLLER

The AT89S52 is a low-power, high-performance CMOS 8-bit microcontroller with
8K bytes of in-system programmable Flash memory. The on-chip Flash allows
the program memory to be reprogrammed in-system or by a conventional
nonvolatile memory programmer.

By combining a versatile 8-bit CPU with in-system programmable Flash on
a monolithic chip, the Atmel AT89S52 is a powerful microcontroller which
provides a highly-flexible and cost-effective solution to many embedded control
applications.

The AT89S52 provides the following standard features: 8K bytes of Flash, 256
bytes of RAM, 32 I/O lines, Watchdog timer, two data pointers, three 16-bit
timer/counters, a six-vector two-level interrupt architecture, a full duplex serial
port, on-chip oscillator, and clock circuitry.

PIN Configuration




                       Pin configuration of ATMEL 89S52




                                                                                viii
Clock and Instruction Cycle :

In 8051, one instruction cycle consists of twelve (12) clock cycles. Instruction
cycle is sometimes called as Machine cycle by some authors.




                          Fig 5.2 : Instruction cycle of 8051

In 8051, each instruction cycle has six states (S 1 - S 6 ). Each state has two
pulses (P1 and P2)

I/O Port Configuration

Each port of 8051 has bidirectional capability. Port 0 is called 'true
bidirectional port' as it floats (tristated) when configured as input.

Port-1, 2, 3 are called 'quasi bidirectional port'.

Timers / Counters

8051 has two 16-bit programmable UP timers/counters. They can be configured
to operate either as timers or as event counters. The names of the two counters
are T0 and T1 respectively. The timer content is available in four 8-bit special
function registers, viz, TL0,TH0,TL1 and TH1 respectively.

In the "timer" function mode, the counter is incremented in every machine cycle.
Thus, one can think of it as counting machine cycles. Hence the clock rate is
1/12 th of the oscillator frequency.

In the "counter" function mode, the register is incremented in response to a 1 to 0
transition at its corresponding external input pin (T0 or T1). It requires 2 machine
cycles to detect a high to low transition. Hence maximum count rate is 1/24 th of
oscillator frequency.

The operation of the timers/counters is controlled by two special function
registers, TMOD and TCON respectively.




                                                                                   ix
Timer Mode control (TMOD) Special Function Register:

TMOD register is not bit addressable.

TMOD
Address: 89 H




Various bits of TMOD are described as follows -

Gate: This is an OR Gate enabled bit which controls the effect of         on
START/STOP of Timer. It is set to one ('1') by the program to enable the interrupt
to start/stop the timer. If TR1/0 in TCON is set and signal on      pin is high then
the timer starts counting using either internal clock (timer mode) or external
pulses (counter mode).

    It is used for the selection of Counter/Timer mode.
Mode Select Bits:




M1 and M0 are mode select bits.




                                                                                   x
Timer/ Counter control logic:




                        Fig 8.1 Timer/Counter Control Logic

Timer control (TCON) Special function register:

TCON is bit addressable. The address of TCON is 88H. It is partly related to
Timer and partly to interrupt.




                               Fig 8.2 TCON Register

The various bits of TCON are as follows.

TF1: Timer1 overflow flag. It is set when timer rolls from all 1s to 0s. It is cleared
when processor vectors to execute ISR located at address 001BH.
TR1: Timer1 run control bit. Set to 1 to start the timer / counter.
TF0: Timer0 overflow flag. (Similar to TF1)
TR0: Timer0 run control bit.
IE1: Interrupt1 edge flag. Set by hardware when an external interrupt edge is
detected. It is cleared when interrupt is processed.
IE0: Interrupt0 edge flag. (Similar to IE1)
IT1: Interrupt1 type control bit. Set/ cleared by software to specify falling edge /
low level triggered external interrupt.
IT0: Interrupt0 type control bit. (Similar to IT1)


                                                                                     xi
Timers can operate in four different modes as follows:

Timer Mode-0:

In this mode, the timer is used as a 13-bit UP counter as follows.




                      Fig. 8.3 Operation of Timer on Mode-0

The lower 5 bits of TLX and 8 bits of THX are used for the 13 bit count.Upper 3
bits of TLX are ignored. When the counter rolls over from all 0's to all 1's, TFX
flag is set and an interrupt is generated.

The input pulse is obtained from the previous stage. If TR1/0 bit is 1 and Gate bit
is 0, the counter continues counting up. If TR1/0 bit is 1 and Gate bit is 1, then
the operation of the counter is controlled by    input. This mode is useful to
measure the width of a given pulse fed to       input.

Timer Mode-1:

This mode is similar to mode-0 except for the fact that the Timer operates in 16-
bit mode.




                      Fig 8.4 Operation of Timer in Mode 1

Timer Mode-2: (Auto-Reload Mode)

This is a 8 bit counter/timer operation. Counting is performed in TLX while THX
stores a constant value. In this mode when the timer overflows i.e. TLX becomes
FFH, it is fed with the value stored in THX. For example if we load THX with 50H
then the timer in mode 2 will count from 50H to FFH. After that 50H is again
reloaded. This mode is useful in applications like fixed time sampling.




                                                                                    xii
Fig 8.5 Operation of Timer in Mode 2

Timer Mode-3:

Timer 1 in mode-3 simply holds its count. The effect is same as setting TR1=0.
Timer0 in mode-3 establishes TL0 and TH0 as two separate counters.




                      Fig 8.6 Operation of Timer in Mode 3

Control bits TR1 and TF1 are used by Timer-0 (higher 8 bits) (TH0) in Mode-3
while TR0 and TF0 are available to Timer-0 lower 8 bits(TL0).

Interrupts:

8051 provides 5 vectored interrupts. They are -

   1.
   2. TF0
   3.
   4. TF1
   5. RI/TI

Out of these,     and      are external interrupts whereas Timer and Serial port
interrupts are generated internally. The external interrupts could be negative
edge triggered or low level triggered. All these interrupt, when activated, set the
corresponding interrupt flags. Except for serial interrupt, the interrupt flags are
cleared when the processor branches to the Interrupt Service Routine (ISR). The

                                                                                 xiii
external interrupt flags are cleared on branching to Interrupt Service Routine
(ISR), provided the interrupt is negative edge triggered. For low level triggered
external interrupt as well as for serial interrupt, the corresponding flags have to
be cleared by software by the programmer.

Each of these interrupts can be individually enabled or disabled by 'setting' or
'clearing' the corresponding bit in the IE (Interrupt Enable Register) SFR. IE
contains a global enable bit EA which enables/disables all interrupts at once.

Interrupt Enable register (IE): Address: A8H




EX0                    interrupt (External) enable bit

ET0             Timer-0 interrupt enable bit

EX1                   interrupt (External) enable bit

ET1             Timer-1 interrupt enable bit

ES             Serial port interrupt enable bit

ET2             Timer-2 interrupt enable bit

EA             Enable/Disable all

Setting '1'           Enable the corresponding interrupt

Setting '0'           Disable the corresponding interrupt

Priority level structure:

Each interrupt source can be programmed to have one of the two priority levels
by setting (high priority) or clearing (low priority) a bit in the IP (Interrupt Priority)
Register. A low priority interrupt can itself be interrupted by a high priority
interrupt, but not by another low priority interrupt. If two interrupts of different
priority levels are received simultaneously, the request of higher priority level is
served. If the requests of the same priority level are received simultaneously, an
internal polling sequence determines which request is to be serviced. Thus,
within each priority level, there is a second priority level determined by the polling
sequence, as follows.




                                                                                       xiv
Interrupt Priority register (IP)




  '0'                low priority

  '1'              high priority




                                    xv
KEIL CODE
*********************************************************************
For 11.0592 MHz crystal 1 machine cycle
For microcontroller is 1.085usec
thus for 20 msec we require count of 18433
thus count for timer
65535-18433 = 47102 = B7FE h
for 1ms = FC65 h …. 0 degree
for 2ms = F8CB h …. 180 degree */

//Here Servo is connected to P0.6
//Switches are connected at P1.5 and P1.6


#include<atmel89x52.h>

sbit servo=P0^6;
void timer1_ovf(void) interrupt 3 // timer 1 for 20ms
{
TH1=0xB7;
TL1=0xFE;
servo=1;
TR0=1;
}
void timer0_ovf(void) interrupt 1 // timer 0 for various shaft position
{
if(P1^5==1)
{
TH0=0xFC; //0 degree shaft position

TL0=0x65;
}
else if(P1^6==1)
{
TH0=0xFA; // 90 degree shaft position
TL0=0x99;
}
else if(P1^5==1&&P1^6==1)
{
TH0=0xF8; //180 degree shaft position


                                                                          xvi
TL0=0xCB;
}
servo=0;
TR0=0;
}


void main(void)
{TMOD=0x11;
ET1=1;
ET0=1;
TH1=0xB7;
TL1=0xFE;
TR1=1;
EA=1;


while(1){}
}




                  xvii
REFERENCES
http://www.robokits.com

http://www.thinkindialab.com

http://www.asel.udel.edu/robotics

http://www.asel.udel.edu/robotics

http://www.google.com

http://www.asel.udel.edu/robotics

http://www.asel.udel.edu/resna-sig13

http://www.esnips.com




                                       xviii

More Related Content

What's hot

Unit 3 steppermotors
Unit 3 steppermotorsUnit 3 steppermotors
Unit 3 steppermotors
Er.Meraj Akhtar
 
Microstepping of stepper Motor
Microstepping of stepper MotorMicrostepping of stepper Motor
Microstepping of stepper MotorANUP PALARAPWAR
 
Servo motor drive
Servo motor driveServo motor drive
Servo motor drive
Tanmay Popat
 
Understanding Common Servo Motors
Understanding Common Servo MotorsUnderstanding Common Servo Motors
Understanding Common Servo Motors
Greenkeith
 
Electric Servo Motor
Electric Servo MotorElectric Servo Motor
Electric Servo MotorGello Hembz
 
Stepping Motor Driver IC Using PWM Chopper Type: TB62209FG
Stepping Motor Driver IC Using PWM Chopper Type: TB62209FGStepping Motor Driver IC Using PWM Chopper Type: TB62209FG
Stepping Motor Driver IC Using PWM Chopper Type: TB62209FG
Premier Farnell
 
SERVO MOTOR CONTROLLER
SERVO MOTOR CONTROLLERSERVO MOTOR CONTROLLER
SERVO MOTOR CONTROLLER
JITENDRA SUWASIYA
 
Cnc feed drives
Cnc feed drivesCnc feed drives
Cnc feed drives
Akhil Krishnan G
 
Excessive vibration issues in two pole electric motors
Excessive vibration issues in two pole electric motorsExcessive vibration issues in two pole electric motors
Excessive vibration issues in two pole electric motors
Adam Bron
 
Interfacing stepper motor
Interfacing stepper motorInterfacing stepper motor
Interfacing stepper motorPRADEEP
 
Servo Motors Adjust
Servo Motors Adjust Servo Motors Adjust
Servo Motors Adjust
Marc Vendrell
 
Servo systems, servomotors
Servo systems, servomotorsServo systems, servomotors
Servo systems, servomotors
abhishek srivastava
 
Control system
Control systemControl system
Control system
Prabhu R
 
Micro stepping mode for stepper motor
Micro stepping mode for stepper motorMicro stepping mode for stepper motor
Micro stepping mode for stepper motor
Swathi Venugopal
 
Stepper speed control
Stepper speed controlStepper speed control
Stepper speed control
Saumya Ranjan Behura
 
Stepper motor control
Stepper motor controlStepper motor control
Stepper motor control
Jatin Arora
 
PROJECT REPORT anti theft and auto braking car
PROJECT REPORT anti theft and auto braking carPROJECT REPORT anti theft and auto braking car
PROJECT REPORT anti theft and auto braking carMehul kumar
 
Stepper motor interfacing
Stepper motor interfacingStepper motor interfacing
Stepper motor interfacing
BIRLA VISHVAKARMA MAHAVIDYALAY
 
Stepper motor
Stepper motorStepper motor
Stepper motor
sethuvalmiki
 
1. servo basic
1. servo basic1. servo basic
1. servo basic
benson215
 

What's hot (20)

Unit 3 steppermotors
Unit 3 steppermotorsUnit 3 steppermotors
Unit 3 steppermotors
 
Microstepping of stepper Motor
Microstepping of stepper MotorMicrostepping of stepper Motor
Microstepping of stepper Motor
 
Servo motor drive
Servo motor driveServo motor drive
Servo motor drive
 
Understanding Common Servo Motors
Understanding Common Servo MotorsUnderstanding Common Servo Motors
Understanding Common Servo Motors
 
Electric Servo Motor
Electric Servo MotorElectric Servo Motor
Electric Servo Motor
 
Stepping Motor Driver IC Using PWM Chopper Type: TB62209FG
Stepping Motor Driver IC Using PWM Chopper Type: TB62209FGStepping Motor Driver IC Using PWM Chopper Type: TB62209FG
Stepping Motor Driver IC Using PWM Chopper Type: TB62209FG
 
SERVO MOTOR CONTROLLER
SERVO MOTOR CONTROLLERSERVO MOTOR CONTROLLER
SERVO MOTOR CONTROLLER
 
Cnc feed drives
Cnc feed drivesCnc feed drives
Cnc feed drives
 
Excessive vibration issues in two pole electric motors
Excessive vibration issues in two pole electric motorsExcessive vibration issues in two pole electric motors
Excessive vibration issues in two pole electric motors
 
Interfacing stepper motor
Interfacing stepper motorInterfacing stepper motor
Interfacing stepper motor
 
Servo Motors Adjust
Servo Motors Adjust Servo Motors Adjust
Servo Motors Adjust
 
Servo systems, servomotors
Servo systems, servomotorsServo systems, servomotors
Servo systems, servomotors
 
Control system
Control systemControl system
Control system
 
Micro stepping mode for stepper motor
Micro stepping mode for stepper motorMicro stepping mode for stepper motor
Micro stepping mode for stepper motor
 
Stepper speed control
Stepper speed controlStepper speed control
Stepper speed control
 
Stepper motor control
Stepper motor controlStepper motor control
Stepper motor control
 
PROJECT REPORT anti theft and auto braking car
PROJECT REPORT anti theft and auto braking carPROJECT REPORT anti theft and auto braking car
PROJECT REPORT anti theft and auto braking car
 
Stepper motor interfacing
Stepper motor interfacingStepper motor interfacing
Stepper motor interfacing
 
Stepper motor
Stepper motorStepper motor
Stepper motor
 
1. servo basic
1. servo basic1. servo basic
1. servo basic
 

Similar to Pdpm,mayank awasthi,jabalpur,i it kanpur, servo motor,keil code

Asts file
Asts file Asts file
Asts file
ssmb45
 
Gesture control wheel chair cum stretcher
Gesture control wheel chair cum stretcherGesture control wheel chair cum stretcher
Gesture control wheel chair cum stretcher
IRJET Journal
 
AUTOMATIC COIL WINDING MACHINE
AUTOMATIC COIL WINDING MACHINEAUTOMATIC COIL WINDING MACHINE
AUTOMATIC COIL WINDING MACHINE
IRJET Journal
 
Actuators.pptx
Actuators.pptxActuators.pptx
Actuators.pptx
bhaveshagrawal35
 
Improving Accuracy With Servomotors And High Speed Network
Improving Accuracy With Servomotors And High Speed NetworkImproving Accuracy With Servomotors And High Speed Network
Improving Accuracy With Servomotors And High Speed NetworkYuki Honda
 
(04052013) presentation on TSI.pptx
(04052013)  presentation on TSI.pptx(04052013)  presentation on TSI.pptx
(04052013) presentation on TSI.pptx
MukeshKumarVaishnav1
 
Automatic sun tracking system asts
Automatic sun tracking system   astsAutomatic sun tracking system   asts
Automatic sun tracking system astssanket68
 
Servo 2.0
Servo 2.0Servo 2.0
IRJET-3 Fabrication of Pedal Assist Bicycle
IRJET-3 	  Fabrication of Pedal Assist BicycleIRJET-3 	  Fabrication of Pedal Assist Bicycle
IRJET-3 Fabrication of Pedal Assist Bicycle
IRJET Journal
 
Self Obstacle Avoiding Rover
Self Obstacle Avoiding RoverSelf Obstacle Avoiding Rover
Self Obstacle Avoiding Rover
Emam Hasan
 
AUTOMATIC WHITEBOARD CLEANER
AUTOMATIC WHITEBOARD CLEANERAUTOMATIC WHITEBOARD CLEANER
AUTOMATIC WHITEBOARD CLEANER
Fahim Mahmud
 
Report no.4(microprocessor)
Report no.4(microprocessor)Report no.4(microprocessor)
Report no.4(microprocessor)Ronza Sameer
 
Newppt major
Newppt majorNewppt major
Newppt major
Shivangi Jain
 
Arduino Based Project.pptx
Arduino Based Project.pptxArduino Based Project.pptx
Arduino Based Project.pptx
Abhishek Sharma
 
Speed Control of PMBLDC Motor using LPC 2148 – A Practical Approach
Speed Control of PMBLDC Motor using  LPC 2148 – A Practical Approach  Speed Control of PMBLDC Motor using  LPC 2148 – A Practical Approach
Speed Control of PMBLDC Motor using LPC 2148 – A Practical Approach IJEEE
 
speed sensor.pptx
speed sensor.pptxspeed sensor.pptx
speed sensor.pptx
tdxku
 
Servomotor
ServomotorServomotor
Servomotor
SatheeshCS2
 
ME 6702 Mechatronic unit V
ME 6702 Mechatronic unit VME 6702 Mechatronic unit V
ME 6702 Mechatronic unit V
NAVEEN UTHANDI
 
Vector Speed Control of Induction Motor
Vector Speed Control of Induction MotorVector Speed Control of Induction Motor
Vector Speed Control of Induction Motor
Ranjith Samala
 

Similar to Pdpm,mayank awasthi,jabalpur,i it kanpur, servo motor,keil code (20)

Asts file
Asts file Asts file
Asts file
 
Gesture control wheel chair cum stretcher
Gesture control wheel chair cum stretcherGesture control wheel chair cum stretcher
Gesture control wheel chair cum stretcher
 
AUTOMATIC COIL WINDING MACHINE
AUTOMATIC COIL WINDING MACHINEAUTOMATIC COIL WINDING MACHINE
AUTOMATIC COIL WINDING MACHINE
 
Actuators.pptx
Actuators.pptxActuators.pptx
Actuators.pptx
 
Improving Accuracy With Servomotors And High Speed Network
Improving Accuracy With Servomotors And High Speed NetworkImproving Accuracy With Servomotors And High Speed Network
Improving Accuracy With Servomotors And High Speed Network
 
(04052013) presentation on TSI.pptx
(04052013)  presentation on TSI.pptx(04052013)  presentation on TSI.pptx
(04052013) presentation on TSI.pptx
 
Project paper
Project paperProject paper
Project paper
 
Automatic sun tracking system asts
Automatic sun tracking system   astsAutomatic sun tracking system   asts
Automatic sun tracking system asts
 
Servo 2.0
Servo 2.0Servo 2.0
Servo 2.0
 
IRJET-3 Fabrication of Pedal Assist Bicycle
IRJET-3 	  Fabrication of Pedal Assist BicycleIRJET-3 	  Fabrication of Pedal Assist Bicycle
IRJET-3 Fabrication of Pedal Assist Bicycle
 
Self Obstacle Avoiding Rover
Self Obstacle Avoiding RoverSelf Obstacle Avoiding Rover
Self Obstacle Avoiding Rover
 
AUTOMATIC WHITEBOARD CLEANER
AUTOMATIC WHITEBOARD CLEANERAUTOMATIC WHITEBOARD CLEANER
AUTOMATIC WHITEBOARD CLEANER
 
Report no.4(microprocessor)
Report no.4(microprocessor)Report no.4(microprocessor)
Report no.4(microprocessor)
 
Newppt major
Newppt majorNewppt major
Newppt major
 
Arduino Based Project.pptx
Arduino Based Project.pptxArduino Based Project.pptx
Arduino Based Project.pptx
 
Speed Control of PMBLDC Motor using LPC 2148 – A Practical Approach
Speed Control of PMBLDC Motor using  LPC 2148 – A Practical Approach  Speed Control of PMBLDC Motor using  LPC 2148 – A Practical Approach
Speed Control of PMBLDC Motor using LPC 2148 – A Practical Approach
 
speed sensor.pptx
speed sensor.pptxspeed sensor.pptx
speed sensor.pptx
 
Servomotor
ServomotorServomotor
Servomotor
 
ME 6702 Mechatronic unit V
ME 6702 Mechatronic unit VME 6702 Mechatronic unit V
ME 6702 Mechatronic unit V
 
Vector Speed Control of Induction Motor
Vector Speed Control of Induction MotorVector Speed Control of Induction Motor
Vector Speed Control of Induction Motor
 

More from Department of Telecommunications, Ministry of Communication & IT (INDIA) (9)

Workshop proposal
Workshop proposalWorkshop proposal
Workshop proposal
 
Feeding system for disabled report
Feeding system for disabled reportFeeding system for disabled report
Feeding system for disabled report
 
Numerical methods generating polynomial
Numerical methods generating polynomialNumerical methods generating polynomial
Numerical methods generating polynomial
 
Design ideas mayank
Design ideas mayankDesign ideas mayank
Design ideas mayank
 
Adaptive signal processing simon haykins
Adaptive signal processing simon haykinsAdaptive signal processing simon haykins
Adaptive signal processing simon haykins
 
Analogic
AnalogicAnalogic
Analogic
 
jacobi method, gauss siedel for solving linear equations
jacobi method, gauss siedel for solving linear equationsjacobi method, gauss siedel for solving linear equations
jacobi method, gauss siedel for solving linear equations
 
An Introduction To Speech Recognition
An Introduction To Speech RecognitionAn Introduction To Speech Recognition
An Introduction To Speech Recognition
 
Numerical Methods Solving Linear Equations
Numerical Methods Solving Linear EquationsNumerical Methods Solving Linear Equations
Numerical Methods Solving Linear Equations
 

Pdpm,mayank awasthi,jabalpur,i it kanpur, servo motor,keil code

  • 1. Servo Control using Atmel 89S52 Submitted by Mayank Awasthi B.Tech(ECE) PDPM IIITDM, Jabalpur M. Tech, IIT Roorkee (Communication Systems) Contact no. 9410321979 Under the supervision of Mr. Susmit Sen Senior Research Engineer Centre for Robotics IIT Kanpur i
  • 2. ACKNOWLEDGEMENT First of all, we would like to express our sincere thanks to our guide Mr. Susmit Sen for his intellectual guidance, continuous interest, generous support, infinite patience, and constant encouragement throughout this work. He has devoted his valuable time to discuss this project, his expertise and broad knowledge in Mechatronics & Robotics played a major role in the realization of this work. We appreciate Mr. Susmit Sen for his confidence boosting start up to our project work and encouragement in creative endeavors. We especially appreciate the company of our classmates, seniors, workshop & lab assistants and who have made useful to this work by way of discussions and suggestions from time to time. Group Member Mayank Awasthi B.Tech(ECE) PDPM IIITDM, Jabalpur Contact no. 9336441681 ii
  • 3. CONTENTS I. Servo Motors ………………................... II. Atmel 89S52 Microcontrollers ……….. III. Keil code ……………………………….. IV. References …………………………… iii
  • 4. SERVO MOTORS A Servo is a small device that incorporates a three wire DC motor, a gear train, a potentiometer, an integrated circuit, and an output shaft bearing. Of the three wires that stick out from the motor casing, one is for power, one is for ground, and one is a control input line. The shaft of the servo can be positioned to specific angular positions by sending a coded signal. As long as the coded signal exists on the input line, the servo will maintain the angular position of the shaft. If the coded signal changes, then the angular position of the shaft changes. A very common use of servos is in Radio Controlled models like cars, airplanes, robots, and puppets. They are also used in powerful heavy-duty sail boats. Servos are rated for Speed and Torque. Normally there are two servos of the same kind, one geared towards speed (sacrificing torque), and the other towards torque (sacrificing speed). A good example of this is the HS-625MG servo and the HS-645MG servo. Servos come in different sizes but use similar control schemes and are extremely useful in robotics. The motors are small and are extremely powerful for their size. It also draws power proportional to the mechanical load. A lightly loaded servo, therefore, doesn’t consume much energy. A typical Servo looks like a rectangular box with a motor shaft coming out of one end and a connector with three wires out of the other end. The three wires are the power, Control, and Ground. Servos work with voltages between 4 and 6 volts. The control line is used to position the servo. The servo motor comes in different sizes, which affect the overall size of the servo. The gears of a servo vary from servo to servo. Inexpensive servos have plastic gears, and more expensive servos have metal gears which are much more rugged but wear faster. The potentiometer of a servo is the feedback device. The electronics of a servo are pretty much the same in all servos, but the output shaft bearing of a servo has either a plastic on plastic bearing that will not take much side load or a metal on metal bearings that stand up better under extended use, or ball bearings which work best. We highly recommend ball bearing servos if your application demands heavy side loads. iv
  • 5. Servos are constructed from three basic pieces; a motor, a potentiometer (variable resister) that is connected to the output shaft, and a control board. The potentiometer allows the control circuitry to monitor the current angle of the servo motor. The motor, through a series of gears, turns the output shaft and the potentiometer simultaneously. The potentiometer is fed into the servo control circuit and when the control circuit detects that the position is correct, it stops the motor. If the control circuit detects that the angle is not correct, it will turn the motor the correct direction until the angle is correct. Normally a servo is used to control an angular motion of between 0 and 180 degrees. It is not mechanically capable (unless modified) of turning any farther due to the mechanical stop build on to the main output gear. The amount of power applied to the motor is proportional to the distance it needs to travel. So, if the shaft needs to turn a large distance, the motor will run at full speed. If it needs to turn only a small amount, the motor will run at a slower speed. This is called proportional control. How Do Servos Work ? v
  • 6. Servos are controlled by sending them a pulse of variable width. The control wire is used to send this pulse. The parameters for this pulse are that it has a minimum pulse, a maximum pulse, and a repetition rate. Given the rotation constraints of the servo, neutral is defined to be the position where the servo has exactly the same amount of potential rotation in the clockwise direction as it does in the counter clockwise direction. It is important to note that different servos will have different constraints on their rotation but they all have a neutral position, and that position is always around 1.5 milliseconds (ms). The angle is determined by the duration of a pulse that is applied to the control wire. This is called Pulse width Modulation. The servo expects to see a pulse every 20 ms. The length of the pulse will determine how far the motor turns. For example, a 1.5 ms pulse will make the motor turn to the 90 degree position(neutral position). When these servos are commanded to move they will move to the position and hold that position. If an external force pushes against the servo while the servo is holding a position, the servo will resist from moving out of that position. The maximum amount of force the servo can exert is the torque rating of the servo. Servos will not hold their position forever though; the position pulse must be repeated to instruct the servo to stay in position. When a pulse is sent to a servo that is less than 1.5 ms the servo rotates to a position and holds its output shaft some number of degrees counterclockwise from the neutral point. When the pulse is wider than 1.5 ms the opposite occurs. The minimal width and the maximum width of pulse that will command the servo to turn to a valid position are functions of each servo. Different brands, and even different servos of the same brand, will have different maximum and minimums. Generally the minimum pulse will be about 1 ms wide and the maximum pulse will be 2 ms wide. vi
  • 7. Another parameter that varies from servo to servo is the turn rate. This is the time it takes from the servo to change from one position to another. The worst case turning time is when the servo is holding at the minimum rotation and it is commanded to go to maximum rotation. This can take several seconds on very high torque servos. HS-322HD Servo Motors Specifications: This servo comes with mounting hardware, mounting grommets, and 4 servo horns. The HS-322HD servo has heavy duty gears for smoother operation and longer life when compared to normal servos. This servo has a Hitech/JR connector which mates directly with a 0.1" 3-pin header. The servo spline has 24 teeth and mates with Hitec compatible accessories. Specifications Voltage Operating Speed Output Torque Weight Range 0.19sec/60 degrees at 3kg.cm (41.6oz.in) at 43.0g 4.8V - 6V 4.8V 4.8V (1.51oz) Wire Color Meaning On all Hitec servos the Black wire is 'ground', the Red wire (center wire) is 'power', and the yellow (third) wire is 'signal'. vii
  • 8. ATMEL 89S52 MICROCONTROLLER The AT89S52 is a low-power, high-performance CMOS 8-bit microcontroller with 8K bytes of in-system programmable Flash memory. The on-chip Flash allows the program memory to be reprogrammed in-system or by a conventional nonvolatile memory programmer. By combining a versatile 8-bit CPU with in-system programmable Flash on a monolithic chip, the Atmel AT89S52 is a powerful microcontroller which provides a highly-flexible and cost-effective solution to many embedded control applications. The AT89S52 provides the following standard features: 8K bytes of Flash, 256 bytes of RAM, 32 I/O lines, Watchdog timer, two data pointers, three 16-bit timer/counters, a six-vector two-level interrupt architecture, a full duplex serial port, on-chip oscillator, and clock circuitry. PIN Configuration Pin configuration of ATMEL 89S52 viii
  • 9. Clock and Instruction Cycle : In 8051, one instruction cycle consists of twelve (12) clock cycles. Instruction cycle is sometimes called as Machine cycle by some authors. Fig 5.2 : Instruction cycle of 8051 In 8051, each instruction cycle has six states (S 1 - S 6 ). Each state has two pulses (P1 and P2) I/O Port Configuration Each port of 8051 has bidirectional capability. Port 0 is called 'true bidirectional port' as it floats (tristated) when configured as input. Port-1, 2, 3 are called 'quasi bidirectional port'. Timers / Counters 8051 has two 16-bit programmable UP timers/counters. They can be configured to operate either as timers or as event counters. The names of the two counters are T0 and T1 respectively. The timer content is available in four 8-bit special function registers, viz, TL0,TH0,TL1 and TH1 respectively. In the "timer" function mode, the counter is incremented in every machine cycle. Thus, one can think of it as counting machine cycles. Hence the clock rate is 1/12 th of the oscillator frequency. In the "counter" function mode, the register is incremented in response to a 1 to 0 transition at its corresponding external input pin (T0 or T1). It requires 2 machine cycles to detect a high to low transition. Hence maximum count rate is 1/24 th of oscillator frequency. The operation of the timers/counters is controlled by two special function registers, TMOD and TCON respectively. ix
  • 10. Timer Mode control (TMOD) Special Function Register: TMOD register is not bit addressable. TMOD Address: 89 H Various bits of TMOD are described as follows - Gate: This is an OR Gate enabled bit which controls the effect of on START/STOP of Timer. It is set to one ('1') by the program to enable the interrupt to start/stop the timer. If TR1/0 in TCON is set and signal on pin is high then the timer starts counting using either internal clock (timer mode) or external pulses (counter mode). It is used for the selection of Counter/Timer mode. Mode Select Bits: M1 and M0 are mode select bits. x
  • 11. Timer/ Counter control logic: Fig 8.1 Timer/Counter Control Logic Timer control (TCON) Special function register: TCON is bit addressable. The address of TCON is 88H. It is partly related to Timer and partly to interrupt. Fig 8.2 TCON Register The various bits of TCON are as follows. TF1: Timer1 overflow flag. It is set when timer rolls from all 1s to 0s. It is cleared when processor vectors to execute ISR located at address 001BH. TR1: Timer1 run control bit. Set to 1 to start the timer / counter. TF0: Timer0 overflow flag. (Similar to TF1) TR0: Timer0 run control bit. IE1: Interrupt1 edge flag. Set by hardware when an external interrupt edge is detected. It is cleared when interrupt is processed. IE0: Interrupt0 edge flag. (Similar to IE1) IT1: Interrupt1 type control bit. Set/ cleared by software to specify falling edge / low level triggered external interrupt. IT0: Interrupt0 type control bit. (Similar to IT1) xi
  • 12. Timers can operate in four different modes as follows: Timer Mode-0: In this mode, the timer is used as a 13-bit UP counter as follows. Fig. 8.3 Operation of Timer on Mode-0 The lower 5 bits of TLX and 8 bits of THX are used for the 13 bit count.Upper 3 bits of TLX are ignored. When the counter rolls over from all 0's to all 1's, TFX flag is set and an interrupt is generated. The input pulse is obtained from the previous stage. If TR1/0 bit is 1 and Gate bit is 0, the counter continues counting up. If TR1/0 bit is 1 and Gate bit is 1, then the operation of the counter is controlled by input. This mode is useful to measure the width of a given pulse fed to input. Timer Mode-1: This mode is similar to mode-0 except for the fact that the Timer operates in 16- bit mode. Fig 8.4 Operation of Timer in Mode 1 Timer Mode-2: (Auto-Reload Mode) This is a 8 bit counter/timer operation. Counting is performed in TLX while THX stores a constant value. In this mode when the timer overflows i.e. TLX becomes FFH, it is fed with the value stored in THX. For example if we load THX with 50H then the timer in mode 2 will count from 50H to FFH. After that 50H is again reloaded. This mode is useful in applications like fixed time sampling. xii
  • 13. Fig 8.5 Operation of Timer in Mode 2 Timer Mode-3: Timer 1 in mode-3 simply holds its count. The effect is same as setting TR1=0. Timer0 in mode-3 establishes TL0 and TH0 as two separate counters. Fig 8.6 Operation of Timer in Mode 3 Control bits TR1 and TF1 are used by Timer-0 (higher 8 bits) (TH0) in Mode-3 while TR0 and TF0 are available to Timer-0 lower 8 bits(TL0). Interrupts: 8051 provides 5 vectored interrupts. They are - 1. 2. TF0 3. 4. TF1 5. RI/TI Out of these, and are external interrupts whereas Timer and Serial port interrupts are generated internally. The external interrupts could be negative edge triggered or low level triggered. All these interrupt, when activated, set the corresponding interrupt flags. Except for serial interrupt, the interrupt flags are cleared when the processor branches to the Interrupt Service Routine (ISR). The xiii
  • 14. external interrupt flags are cleared on branching to Interrupt Service Routine (ISR), provided the interrupt is negative edge triggered. For low level triggered external interrupt as well as for serial interrupt, the corresponding flags have to be cleared by software by the programmer. Each of these interrupts can be individually enabled or disabled by 'setting' or 'clearing' the corresponding bit in the IE (Interrupt Enable Register) SFR. IE contains a global enable bit EA which enables/disables all interrupts at once. Interrupt Enable register (IE): Address: A8H EX0 interrupt (External) enable bit ET0 Timer-0 interrupt enable bit EX1 interrupt (External) enable bit ET1 Timer-1 interrupt enable bit ES Serial port interrupt enable bit ET2 Timer-2 interrupt enable bit EA Enable/Disable all Setting '1' Enable the corresponding interrupt Setting '0' Disable the corresponding interrupt Priority level structure: Each interrupt source can be programmed to have one of the two priority levels by setting (high priority) or clearing (low priority) a bit in the IP (Interrupt Priority) Register. A low priority interrupt can itself be interrupted by a high priority interrupt, but not by another low priority interrupt. If two interrupts of different priority levels are received simultaneously, the request of higher priority level is served. If the requests of the same priority level are received simultaneously, an internal polling sequence determines which request is to be serviced. Thus, within each priority level, there is a second priority level determined by the polling sequence, as follows. xiv
  • 15. Interrupt Priority register (IP) '0' low priority '1' high priority xv
  • 16. KEIL CODE ********************************************************************* For 11.0592 MHz crystal 1 machine cycle For microcontroller is 1.085usec thus for 20 msec we require count of 18433 thus count for timer 65535-18433 = 47102 = B7FE h for 1ms = FC65 h …. 0 degree for 2ms = F8CB h …. 180 degree */ //Here Servo is connected to P0.6 //Switches are connected at P1.5 and P1.6 #include<atmel89x52.h> sbit servo=P0^6; void timer1_ovf(void) interrupt 3 // timer 1 for 20ms { TH1=0xB7; TL1=0xFE; servo=1; TR0=1; } void timer0_ovf(void) interrupt 1 // timer 0 for various shaft position { if(P1^5==1) { TH0=0xFC; //0 degree shaft position TL0=0x65; } else if(P1^6==1) { TH0=0xFA; // 90 degree shaft position TL0=0x99; } else if(P1^5==1&&P1^6==1) { TH0=0xF8; //180 degree shaft position xvi