Thesis Final

52
CONTENTS 1. INTRODUCTION 1.1 Aim of the project 2 1.2 Background of the project 3 2. BUILDING BLOCKS OF PROJECT 2.1 IR module 4 2.2 Buzzer Alarm 5 2.3 ULN stepper motor driver 6 2.4 Stepper motor 6 3. BLOCK DIAGRAM AND CIRCUIT DIAGRAM DESCRIPTION 3.1 Block Diagram description 7 3.1.1 Power Supply 7 3.1.2 Microcontroller 10 3.1.3 IR Module 16 3.1.4 Buzzer alarm 18 3.1.5 ULN2003 current driver 19 3.1.6 Stepper motor 22 3.2. Circuit Diagram 31 4. FIRMWARE IMPLEMENTATION OF THE PROJECT DESIGN 4.1 Software tools 32 4.1.1 Keil compiler 32 4.1.2 Proload 34 5. RESULTS AND DISCUSSIONS 5.1 Results 36 1

Transcript of Thesis Final

Page 1: Thesis Final

CONTENTS1. INTRODUCTION

1.1 Aim of the project 21.2 Background of the project 3

2. BUILDING BLOCKS OF PROJECT2.1 IR module 42.2 Buzzer Alarm 52.3 ULN stepper motor driver 62.4 Stepper motor 6

3. BLOCK DIAGRAM AND CIRCUIT DIAGRAM DESCRIPTION

3.1 Block Diagram description 73.1.1 Power Supply 73.1.2 Microcontroller 103.1.3 IR Module 163.1.4 Buzzer alarm 183.1.5 ULN2003 current driver 193.1.6 Stepper motor 22

3.2. Circuit Diagram 31

4. FIRMWARE IMPLEMENTATION OF THE PROJECT DESIGN4.1 Software tools 32

4.1.1 Keil compiler 324.1.2 Proload 34

5. RESULTS AND DISCUSSIONS5.1 Results 365.2 Conclusion and future scope 365.3 Advantages 365.4 Applications 36

6. APPENDIXA) Bibliography 37B) List of figures 37

1

Page 2: Thesis Final

Chapter 1

Introduction

This project is a standalone Automation of unmanned railway gate control system using AT89S52 microcontroller. Use of embedded technology makes this closed loop feedback control system efficient and reliable. Microcontroller allows dynamic and faster control. AT89S52 micro controller is the heart of the circuit as it controls all the functions.

The main aim of this project is to automatize the unmanned railway gate i.e. the gate is closed automatically whenever the train comes and is opened after the train leaves the railway-road crossing. Using this project, the arrival of the train can be identified in either direction. For this purpose, two IR transmitter and receiver pairs are used in this project.

One IR TX-RX pair is placed at one end of the railway gate. The second pair is placed at another end of the gate. In each pair, the TX and RX are arranged face to face across the railway track i.e., TX is situated at one side of the track and RX is placed at another side of the track since the RX should continuously get the signal from the transmitter.

Whenever any train is coming on the track, the IR signal will be disturbed due to the interruption of the train. Thus the microcontroller identifies the arrival of the train. Before closing the gate, the microcontroller activates the siren to alert the people who are on the track. After a small delay, the controller closes the gate by rotating the stepper motor.

The microcontroller should know whether the train left the crossing or not to open the gate. For this purpose, the second IR pair is used. This IR pair identifies the train since the IR signal is interrupted when the train comes in between the TX and RX. The microcontroller will wait for the last compartment to leave the IR pair and after leaving, the receiver again gets IR signal. Till this time the gate is closed. Now, after the train had left the crossing, the microcontroller will open the gate by rotating the stepper motor.

This project is more useful and there is no chance for accidents since time delays or length of the train is not calculated. Just the IR pairs will detect the arrival and departure of the train. The system also detects the fire occurrence in the train and the breakage of the railway track line.

1.1 Aim of the projectThe project intends to control the gate when the train is approaching the gate in order to avoid

accidents. The project also has the task of continuously monitoring the status of the fire sensor and the railway breakage line. If either the fire sensor is triggered or the breakage of the track line is occurred, the system immediately alerts the buzzer.

2

Page 3: Thesis Final

This project is a device that collects data from the fire sensor and the IR sensors, codes the data into a format that can be understood by the controlling section. This system controls the gate by closing or opening it when the train is approaching the railway- road crossing and also activates the buzzer if the fire sensor is triggered or the breakage of the track line occurs.

The objective of the project is to develop a microcontroller based control and alert system. It consists of a sensor module, microcontroller, buzzer, ULN driver and the stepper motor.

1.2 Background of the ProjectThe software application and the hardware implementation help the microcontroller read the

output values from the IR sensors and control the gate at the time of the arrival and departure of the train from the railway- road crossing. The system is totally designed using IR and embedded systems technology.

The Controlling unit has an application program to allow the microcontroller read the sensor output and perform the specified task. The performance of the design is maintained by controlling unit.

3

Page 4: Thesis Final

CHAPTER 2

2.1 IR Module:

TSAL6200 is a high efficiency infrared emitting diode in GaAlAs on GaAs technology, molded in clear, blue grey tinted plastic packages. In comparison with the standard GaAs on GaAs technology these emitters achieve more than 100 % radiant power improvement at a similar wavelength. The forward voltages at low current and at high pulse current roughly correspond to the low values of the standard technology. Therefore these emitters are ideally suitable as high performance replacements of standard emitters.

Features

Extra high radiant power and radiant intensity. High reliability. Low forward voltage. Suitable for high pulse current operation. Standard T-1¾ (∅ 5 mm) package. Angle of half intensity ϕ = ± 17°. Peak wavelength λp = 940 nm. Good spectral matching to Silicon photo detectors.

Applications

Infrared remote control units with high power requirements Free air transmission systems Infrared source for optical counters and card readers IR source for smoke detectors.

IR Sensors Connection:

IR (Infra-Red) is the typical light source used as a sensor in robot to sense opaque object. The basic principle of IR sensor is based on an IR emitter and an IR receiver. IR emitter will emit infrared continuously when the power supply is provided to it. Since there is no source of power for IR receiver, it

4

Page 5: Thesis Final

would not emit any light. It will only receive infrared if there is any. Usually we will attach the IR emitter and IR receiver side by side, and point them to a reflective surface.

When the IR receiver receives infrared, it will generate voltage at its pin. The generated voltage is in the range from 0V to 5V depends on the intensity of infrared it received. This generated output will be given to the microcontroller.

2.2 Buzzer Alarm:

Digital systems and microcontroller pins lack sufficient current to drive the circuits like relays, buzzer circuits etc. While these circuits require around 10milli amps to be operated, the microcontroller’s pin can provide a maximum of 1-2milli amps current. For this reason, a driver such as a power transistor is placed in between the microcontroller and the buzzer circuit.

The operation of this circuit is as follows:

5

Page 6: Thesis Final

The input to the base of the transistor is applied from the microcontroller port pin P1.0. The transistor will be switched on when the base to emitter voltage is greater than 0.7V (cut-in voltage). Thus when the voltage applied to the pin P1.0 is high i.e., P1.0=1 (>0.7V), the transistor will be switched on and thus the buzzer will be ON.

When the voltage at the pin P1.0 is low i.e., P1.0=0 (<0.7V) the transistor will be in off state and the buzzer will be OFF. Thus the transistor acts like a current driver to operate the buzzer accordingly.

2.3 ULN STEPPER MOTOR DRIVER:

ULN is mainly suited for interfacing between low-level circuits and multiple peripheral power loads,. The series ULN20XX high voltage, high current darlington arrays feature continuous load current ratings. The driving circuitry in- turn decodes the coding and conveys the necessary data to the stepper motor, this module aids in the movement of the arm through steppers.

The driver makes use of the ULN2003 driver IC, which contains an array of 7 power Darlington arrays, each capable of driving 500mA of current. At an approximate duty cycle, depending on ambient temperature and number of drivers turned on, simultaneously typical power loads totaling over 230w can be controlled.

The device has base resistors, allowing direct connection to any common logic family. All the emitters are tied together and brought out to a separate terminal. Output protection diodes are included; hence the device can drive inductive loads with minimum extra components. Typical loads include relays, solenoids, stepper motors, magnetic print hammers, multiplexed LED, incandescent displays and heaters.

2.4 Stepper motor:

A stepper motor is an electromechanical device which converts electrical pulses into discrete mechanical movements. The stepper motor is used for position control in applications like disk drives and robotics.

The name stepper is used because this motor rotates through a fixed angular step in response to each input current pulse received by its controller. In recent years, there has been wide-spread demand of stepping motors because of the explosive growth of computer industry. Their popularity is due to the effect that they can be controlled directly by computers, microprocessors and programmable controllers. Stepper motors are ideally suited for situations where precise position and precise speed control are required without the use of closed-loop feedback. When a definite number of pulses are supplied, the shaft turns through a definite known angle. This fact

6

Page 7: Thesis Final

makes the emptor well suited for open-loop position control because no feedback need be taken from the output shaft.

CHAPTER 3

3.1 BLOCK DIAGRAM DESCRIPTION:

Fig: BLOCK DIAGRAM

The block diagram of the embedded security system consists of the following modules:

Power supply Microcontrollers IR Section Buzzer ULN2003 Current Driver Stepper Motor

3.1.1 Power Supply:Supply of 230V, 50Hz ac signal from main supply board is given to a step down

transformer. The transformer is selected such that its output ranges from 10V to 12V, which is supplied to the power supply block for making the output compatible with the TTL logic supply. This TTL logic supply acts as the power supply for the microcontroller, IR sensor, auto dialer,

7

Page 8: Thesis Final

timer circuit and buzzer. Thus the main function of the power supply is to give the voltage supply required for the logic families, which is an output of +5V.

For example a 5V regulated supply can be shown as below:

Similarly, 12v regulated supply can also be produced by suitable selection of the individual elements. Each of the blocks is described in detail below and the power supplies made from these blocks are described below with a circuit diagram and a graph of their output:

TRANSFORMER:

A transformer steps down high voltage AC mains to low voltage AC. Here we are using a center-tap transformer whose output will be sinusoidal with 12 volts peak to peak value.

The low voltage AC output is suitable for lamps, heaters and special AC motors. It is not suitable for electronic circuits unless they include a rectifier and a smoothing capacitor. The transformer output is given to the rectifier circuit.

RECTIFIER:A rectifier converts AC to DC, but the DC output is varying. There are several types of

rectifiers; here we use a bridge rectifier.

8

Page 9: Thesis Final

The Bridge rectifier is a circuit, which converts an A.C voltage to dc voltage using both half cycles of the input A.C voltage. The Bridge rectifier circuit is shown in the figure. The circuit has four diodes connected to form a bridge. The ac input voltage is applied to the diagonally opposite ends of the bridge. The load resistance is connected between the other two ends of the bridge. For the positive half cycle of the input ac voltage, diodes D1 and D3 conduct, whereas diodes D2 and D4 remain in the OFF state. The conducting diodes will be in series with the load resistance RL and hence the load current flows through RL. For the negative half cycle of the input ac voltage, diodes D2 and D4 conduct whereas, D1 and D3 remain OFF. The conducting diodes D2 and D4 will be in series with the load resistance RL and hence the current flows through RL in the same direction as in the previous half cycle. Thus a bi-directional wave is converted into unidirectional.

The output waveform of the rectifier is shown as below:

The varying DC output is suitable for lamps, heaters and standard motors. It is not suitable for electronic circuits unless they include a smoothing capacitor.

SMOOTHING:

9

Page 10: Thesis Final

The smoothing block, smoothes the DC from varying greatly to a small ripple. The ripple voltage is defined as the deviation of the load voltage from its DC value. Smoothing is also named as filtering.

Filtering is frequently effected by shunting the load with a capacitor. The action of this system depends on the fact that the capacitor stores energy during the conduction period and delivers this energy to the loads during the no conducting period. In this way, the time during which the current passes through the load is prolonged, and the ripple is considerably decreased. The action of the capacitor is shown with the help of waveform. The waveform of the rectified output after smoothing is given below:

REGULATOR:

A regulator eliminates ripple by setting DC output to a fixed voltageVoltage regulator ICs are available with fixed (typically 5, 12 and 15V)

10

Page 11: Thesis Final

3.1.2 Microcontrollers:Microprocessors and microcontrollers are widely used in embedded systems products. Microcontroller is a programmable device. A microcontroller has a CPU in addition to a fixed amount of RAM, ROM, I/O ports and a timer embedded all on a single chip. The fixed amount of on-chip ROM, RAM and number of I/O ports in microcontrollers makes them ideal for many applications in which cost and space are critical.

The Intel 8051 is Harvard architecture, single chip microcontroller (µC) which was developed by Intel in 1980 for use in embedded systems. It was popular in the 1980s and early 1990s, but today it has largely been superseded by a vast range of enhanced devices with 8051-compatible processor cores that are manufactured by more than 20 independent manufacturers including Atmel, Infineon Technologies and Maxim Integrated Products.

11

Page 12: Thesis Final

Features of AT89S52: 8K Bytes of Re-programmable Flash Memory. RAM is 256 bytes. 4.0V to 5.5V Operating Range. Fully Static Operation: 0 Hz to 33 MHz’s Three-level Program Memory Lock. 256 x 8-bit Internal RAM. 32 Programmable I/O Lines. Three 16-bit Timer/Counters. Eight Interrupt Sources. Full Duplex UART Serial Channel. Low-power Idle and Power-down Modes. Interrupt recovery from power down mode. Watchdog timer. Dual data pointer. Power-off flag. Fast programming time. Flexible ISP programming (byte and page mode).

Description:The AT89s52 is a low-voltage, high-performance CMOS 8-bit microcomputer with 8K bytes of Flash programmable memory. The device is manufactured using Atmel’s high density nonvolatile memory technology and is compatible with the industry-standard MCS-51 instruction set. The on chip flash allows the program memory to be reprogrammed in system or by a conventional non volatile memory programmer. By combining a versatile 8-bit CPU with Flash on a monolithic chip, the Atmel AT89s52 is a powerful microcomputer, which provides a highly flexible and cost-effective solution to many embedded control applications.In addition, the AT89s52 is designed with static logic for operation down to zero frequency and supports two software selectable power saving modes. The Idle Mode stops the CPU while allowing the RAM, timer/counters, serial port and interrupt system to continue functioning. The power-down mode saves the RAM contents but freezes the oscillator disabling all other chip functions until the next hardware reset.

12

Page 13: Thesis Final

13

Page 14: Thesis Final

Pin description:Vcc Pin 40 provides supply voltage to the chip. The voltage source is +5V.GND Pin 20 is the ground.Ports:Port 0Port 0 is an 8-bit open drain bidirectional I/O port. As an output port, each pin can sink eight TTL inputs. When 1s are written to port 0 pins, the pins can be used as high impedance inputs. Port 0 can also be configured to be the multiplexed low-order address/data bus during accesses to external program and data memory. In this mode, P0 has internal pull-ups.

Port 0 also receives the code bytes during Flash programming and outputs the code bytes during Program verification. External pull-ups are required during program verification.

Port 1Port 1 is an 8-bit bidirectional I/O port with internal pull-ups. The Port 1 output buffers can sink/source four TTL inputs. When 1s are written to Port 1 pins, they are pulled high by the internal pull-ups and can be used as inputs. As inputs, Port 1 pins that are externally being pulled low will source current (IIL) because of the internal pull-ups. In addition, P1.0 and P1.1 can be configured to be the timer/counter 2 external count input (P1.0/T2) and the timer/counter 2 trigger input (P1.1/T2EX), respectively, as shown in the following table.

Port 1 also receives the low-order address bytes during Flash programming and verification.

Port 2Port 2 is an 8-bit bidirectional I/O port with internal pull-ups. The Port 2 output buffers

can sink/source four TTL inputs. When 1s are written to Port 2 pins, they are pulled high by the internal pull-ups and can be used as inputs. As inputs, Port 2 pins that are externally being pulled low will source current (IIL) because of the internal pull-ups.

14

Page 15: Thesis Final

Port 2 emits the high-order address byte during fetches from external program memory and during accesses to external data memory that uses 16-bit addresses (MOVX @ DPTR). In this application, Port 2 uses strong internal pull-ups when emitting 1s. During accesses to external data memory that uses 8-bit addresses (MOVX @ RI), Port 2 emits the contents of the P2 Special Function Register. The port also receives the high-order address bits and some control signals during Flash programming and verification.

Port 3Port 3 is an 8-bit bidirectional I/O port with internal pull-ups. The Port 3 output buffers can sink/source four TTL inputs. When 1s are written to Port 3 pins, they are pulled high by the internal pull-ups and can be used as inputs. As inputs, Port 3 pins that are externally being pulled low will source current (IIL) because of the pull-ups. Port 3 receives some control signals for Flash programming and verification.

Port 3 also serves the functions of various special features of the AT89S52, as shown in the following table.

InterruptsThe AT89S52 has a total of six interrupt vectors: two external interrupts (INT0 and INT1), three timer interrupts (Timers 0, 1, and 2) and the serial port interrupt. These interrupts are all shown in the below figure.

Each of these interrupt sources can be individually enabled or disabled by setting or clearing a bit in Special Function Register IE. IE also contains a global disable bit, EA, which disables all interrupts at once. The below table shows that bit position IE.6 is unimplemented. User software should not write a 1 to this bit position, since it may be used in future AT89 products.

15

Page 16: Thesis Final

Timer 2 interrupt is generated by the logical OR of bits TF2 and EXF2 in register T2CON. Neither of these flags is cleared by hardware when the service routine is vectored to. In fact, the service routine may have to determine whether it was TF2 or EXF2 that generated the interrupt, and that bit will have to be cleared in software.The Timer 0 and Timer 1 flags, TF0 and TF1, are set at S5P2 of the cycle in which the timers overflow. The values are then polled by the circuitry in the next cycle. However, the Timer 2 flag, TF2, is set at S2P2 and is polled in the same cycle in which the timer overflows.

16

Page 17: Thesis Final

3.1.3 IR Module:WHAT IS INFRARED?Infrared is an energy radiation with a frequency below our eyes sensitivity, so we cannot see it. Even that we cannot "see" sound frequencies, we know that it exist, we can listen them.

Even that we cannot see or hear infrared, we can feel it at our skin temperature sensors. When you approach your hand to fire or warm element, you will "feel" the heat, but you can't see it. You can see the fire because it emits other types of radiation, visible to your eyes, but it also emits lots of infrared that you can only feel in your skin.

IR GENERATIONTo generate a 36 kHz pulsating infrared is quite easy, more difficult is to receive and

identify this frequency.  This is why some companies produce infrared receivers, that contains the filters, decoding circuits and the output shaper, that delivers a square wave, meaning the existence or not of the 36kHz incoming pulsating infrared.

It means that those 3 dollars small units, have an output pin that goes high (+5V) when there is a pulsating 36kHz infrared in front of it, and zero volts when there is not this radiation.

A square wave of approximately 27uS (microseconds) injected at the base of a transistor, can drive an infrared LED to transmit this pulsating light wave.  Upon its presence, the commercial receiver will switch its output to high level (+5V).If you can turn on and off this frequency at the transmitter; your receiver's output will indicate when the transmitter is on or off.

17

Page 18: Thesis Final

Those IR demodulators have inverted logic at its output, when a burst of IR is sensed it drives its output to low level, meaning logic level = 1.

IR Transmitter:

TSAL6200 is a high efficiency infrared emitting diode in GaAlAs on GaAs technology, molded in clear, blue grey tinted plastic packages. In comparison with the standard GaAs on GaAs technology these emitters achieve more than 100 % radiant power improvement at a similar wavelength. The forward voltages at low current and at high pulse current roughly correspond to the low values of the standard technology. Therefore these emitters are ideally suitable as high performance replacements of standard emitters.

Features

Extra high radiant power and radiant intensity. High reliability. Low forward voltage. Suitable for high pulse current operation. Standard T-1¾ (∅ 5 mm) package. Angle of half intensity ϕ = ± 17°. Peak wavelength λp = 940 nm. Good spectral matching to Silicon photodetectors.

Applications

Infrared remote control units with high power requirements Free air transmission systems Infrared source for optical counters and card readers IR source for smoke detectors.

IR Sensors Connection:

IR (Infra-Red) is the typical light source used as a sensor in robot to sense opaque object. The basic principle of IR sensor is based on an IR emitter and an IR receiver. IR emitter will emit infrared continuously when the power supply is provided to it. Since there is no source of power for IR receiver, it would not emit any light. It will only receive infrared if there is any. Usually we will attach the IR emitter and IR receiver side by side, and point them to a reflective surface.When the IR receiver receives infrared, it will generate voltage at its pin. The generated voltage is in the range from 0V to 5V depends on the intensity of infrared it received. This generated output will be given to the microcontroller.

18

Page 19: Thesis Final

3.1.4 Buzzer Alarm:

Digital systems and microcontroller pins lack sufficient current to drive the circuits like relays, buzzer circuits etc. While these circuits require around 10milli amps to be operated, the microcontroller’s pin can provide a maximum of 1-2milli amps current. For this reason, a driver such as a power transistor is placed in between the microcontroller and the buzzer circuit.

The operation of this circuit is as follows:The input to the base of the transistor is applied from the microcontroller port pin P1.0. The transistor will be switched on when the base to emitter voltage is greater than 0.7V (cut-in voltage). Thus when the voltage applied to the pin P1.0 is high i.e., P1.0=1 (>0.7V), the transistor will be switched on and thus the buzzer will be ON.

When the voltage at the pin P1.0 is low i.e., P1.0=0 (<0.7V) the transistor will be in off state and the buzzer will be OFF. Thus the transistor acts like a current driver to operate the buzzer accordingly.

Buzzer interfacing with the Microcontroller:

19

Page 20: Thesis Final

3.1.5 ULN2003 CURRENT DRIVER:

ULN STEPPER MOTOR DRIVER:

ULN is mainly suited for interfacing between low-level circuits and multiple peripheral power loads,. The series ULN20XX high voltage, high current darlington arrays feature continuous load current ratings. The driving circuitry in- turn decodes the coding and conveys the necessary data to the stepper motor, this module aids in the movement of the arm through steppers.

20

Page 21: Thesis Final

The driver makes use of the ULN2003 driver IC, which contains an array of 7 power Darlington arrays, each capable of driving 500mA of current. At an approximate duty cycle, depending on ambient temperature and number of drivers turned on, simultaneously typical power loads totaling over 230w can be controlled.

The device has base resistors, allowing direct connection to any common logic family. All the emitters are tied together and brought out to a separate terminal. Output protection diodes are included; hence the device can drive inductive loads with minimum extra components. Typical loads include relays, solenoids, stepper motors, magnetic print hammers, multiplexed LED, incandescent displays and heaters.

Driving a Stepper Motor using uln2003:

Note that the first pin (identified in the procedure shown above) is connected to D0 of the parallel port (through the ULN2003, of course). Each successive pin of the stepper motor is connected to successive data lines on the parallel port. If this order is not correct, the motor will not rotate, but will wiggle around from side to side. The clamp circuit shown does not connect the clamp directly to the supply voltage. Instead, it uses a zener diode. This ensures that the decaying current in the coils are not abruptly cut off, which produces a lot of heat.

It is simple, it involves setting the bits on the port on and off in a specific sequence. The step sequence is given below for full step and half steps. At any time only one pin is active in the full step.

21

Page 22: Thesis Final

Full Step

Step No.

D0 D1 D2 D3

1 1 0 0 0

2 0 1 0 0

3 0 0 1 0

4 0 0 0 1

Half Step

Step No.

D0 D1 D2 D3

1 1 0 0 0

2 1 1 0 0

3 0 1 0 0

4 0 1 1 0

5 0 0 1 0

6 0 0 1 1

7 0 0 0 1

8 1 0 0 1

The difference between half step and full step is that for the same step rate, half-step gives you half the speed, twice the resolution, and roughly twice the power consumption. It also gives you twice the torque. To reverse the direction of the motor, send the sequence in reverse order.  

The main features of ULN2003 are as follows:

Seven darlington per package Output current 500ma per driver (600ma peak) Output voltage 50v Integrated suppression diodes for inductive loads

22

Page 23: Thesis Final

Outputs can be paralleled for high current TTL/CMOS/DTL compatible inputs Inputs pinned opposite outputs to simplify layout. Transient protected outputs

3.1.6 Stepper motor:

A stepper motor is an electromechanical device which converts electrical pulses into discrete mechanical movements. The stepper motor is used for position control in applications like disk drives and robotics.

23

Page 24: Thesis Final

The name stepper is used because this motor rotates through a fixed angular step in response to each input current pulse received by its controller. In recent years, there has been wide-spread demand of stepping motors because of the explosive growth of computer industry. Their popularity is due to the effect that they can be controlled directly by computers, microprocessors and programmable controllers. Stepper motors are ideally suited for situations where precise position and precise speed control are required without the use of closed-loop feedback. When a definite number of pulses are supplied, the shaft turns through a definite known angle. This fact makes the emptor well suited for open-loop position control because no feedback need be taken

from the output shaft.

Every stepper motor has a permanent magnet rotor also known as shaft surrounded by a stator poles. The most common stepper motor s have four stator windings that are paired with a center-tapped. This type of stepper motor is commonly referred to as a four-phase stepper motor. The center tap allows a change of current direction in each of two coils when a winding is grounded, there by resulting in a polarity change of the stator.

The shaft or spindle of a stepper motor rotates in discrete step increments when electrical command pulses are applied to it in the proper sequence. The direction of the rotation is determined by the stator poles. the stator poles are determined by the current sent through the wire coils. As the polarity of the current is changed, the polarity is also changed causing the reverse motion of the motor The sequence of the applied pulses is directly related to the direction of motor shafts rotation.. The speed of the motor shafts rotation is directly related to the frequency of the input pulses and the length of rotation is directly related to the number of input pulses applied. While a conventional motor shaft moves freely, stepper motor shaft moves ina fixed repeatable increment which allows one to move it to a precise position. This repeatable fixed movement is possible as a result of basic magnetic theory where poles of he same polarity repel and opposite poles attract.

24

Page 25: Thesis Final

The stepper motor converts digital signals into fixed mechanical increment of motion. It thereby provides a natural interface with the digital computer. It is a synchronous motor such that the rotor rotates a specific incremental number of degrees for each pulse input given to the motor system. These motors can provide accurate positioning without the need of position feedback sensors when compared to other motors. The position is known simply by keeping track of the input step pulses. Usually, position information can be obtained simply by keeping count of the pulses sent to the motor thereby eliminating the need of expensive position sensors and feedback control

Stepper motors are rated by the torque they produce, step angle, steps per second and the number of teeth on rotor. The minimum degree of rotation with which the stepper motor turns for a single pulse if supply to one wire or a pair is called step angle. The minimum step angle is always a function of the number of teeth on rotor .i.e., the smaller the step angle the more teeth the rotor possess.

Smaller the step angle, greater the number of steps per revolution and higher the resolution or the accuracy of positioning obtained. The step angles can be as small as 0.72˚ or as large as 90˚.

The motor speed is measured in steps per second.

Steps per second = (Revolution per minute x steps per Revolution)/ 60

Stepping motors has the extraordinary ability to operate at very high speeds (upto 20,000 steps per second) and yet to remain fully in synchronism with the command pulses, when the pulse rate is high, the shaft rotation seems continuous. If the stepping rate is increased too quickly, the motor loses synchronism and stops. Stepper motors are designed to operate for long periods with the rotor held in a fixed position and with rated current flowing in the stator windings whereas for most of the other motors, this results in collapse of back E.M.F and a very high current which can lead to a quick burn out.

A stepper motor is a special kind of motor that moves in individual steps which are usually .9 degrees each. Each step is controlled by energizing coils inside the motor causing the shaft to move to the next position. Turning these coils on and off in sequence will cause the motor to rotate forward or reverse. The time delay between each step determines the motor's speed. Steppers can be moved to any desired position reliably by sending them the proper number of step pulses.

25

Steps per complete revolution= Number of phases (coils) x Number of teeth on rotor

Page 26: Thesis Final

A stepper motor's shaft has permanent magnets attached to it. Around the body of the motor is a series of coils that create a magnetic field that interacts with the permanent magnets. When these coils are turned on and off the magnetic field cause the rotor to move. As the coils are turned on and off in sequence the motor will rotate forward or reverse.

BACK E.M.F:

A motor is a machine which converts electric energy into mechanical energy. Its action is based on the principle that when a current carrying conductor is placed in a magnetic field, it experiences a mechanical force whose direction is given by Fleming’s left hand rule.

The left hand is held with the thumb, index finger and middle finger mutually at right angles.

The First finger represents the direction of the magnetic Field. The Second finger represents the direction of the Current (in the classical direction, from

positive to negative). The Thumb represents the direction of the Thrust or resultant Motion.

Energy conversion is not possible unless there is some opposition whose overcoming provides the necessary means for such conversion. In case of generator it was the magnetic drag which provided the necessary opposition. The equivalent in the case of a motor is called as the back E.M.F.

As soon as the armature or the rotor starts rotating, dynamically (or emotionally) induced E.M.F is produced in the armature conductors. The direction of this induced E.M.F as found by the Fleming’s right hand rule, is in direct opposition to the applied voltage. That is why this is known as BACK E.M.F or counter E.M.F. The electrical work done in overcoming this opposition is converted into mechanical energy developed in the armature. Therefore, it is obvious that but for the production of this opposing E.M.F energy could not have been possible.

When the armature rotates the conductors also rotate and hence cut the flux. In accordance with the laws of electromagnetic induction, E.M.F is induced in them whose direction, is in

26

Page 27: Thesis Final

opposition to the applied voltage. This induced E.M.F is called back E.M.F. Obviously supply voltage has to drive armature current against the opposition of back E.M.F.

These motors also suffer from E.M.F, which means that once the coil is turned off it starts to generate current because the motor is still rotating. There needs to be an explicit way to handle this extra current in a circuit otherwise it can cause damage and affect performance of the motor.

The ULN2003 / MC1413 is a 7-bit 50V 500mA TTL-input NPN Darlington driver. This is more than adequate to control a four phase unipolar stepper motor such as the KP4M4-001.

`It is recommended to connect a 12v zener diode between the power supply and VDD (Pin 9) on the chip, to absorb reverse (or "back") E.M.F from the magnetic field collapsing when motor coils are switched off. (See Douglas W. Jones' rather more sophisticated example).

Driving a stepper motor:

The four leads of the stator winding are controlled by the four bits of the 8051 port (p1.0-p1.3). However, since the 8051 lacks sufficient current to drive the stepper motor windings, we must use a driver such as uln2003a to energize the stator. Instead of the uln2003a, we could have used transistors as drivers.

However, notice that if transistors are used as drivers, we must also use diodes to take care of inductive current generated when the coil is turned off. One reason that the uln2003a is preferable to the use of transistors as drivers is that the uln2003 has as internal diode to take care of back E.M.F.

Most stepper motor circuits that are available online have a bunch of transistors, Sometimes power transistors too quite a complicated circuit that drives you away far form using it. Well i felt for most robotic use the stepper motor can be driven by a simple ULN2003 IC that costs just 12 bucks in my backyard.

While controlling the stepper motor with a embedded or distributed micromole for a specific application, the controlling signals from the controller to the stepper motor must be boosted up using a driven circuitry in order to have the compatibility between them. In the following figure, we show that the stepper motor is driven with ULN 2003 driven circuitry.

27

Page 28: Thesis Final

Identify the

wire : Common and windings

The following steps show the 8051 connection to the stepper motor Use an ohmmeter to measure the resistance of the leads. This should identify which COM

leads are connected to which winding leads. The common wire(s) are connected to positive side of the motor’s power supply.

To distinguish common wire from a coil-end wire is by measuring the resistance. Resistance between common wire and coil-end wire is always half of what it is between coil-end and coil-end wires. Just take your millimeter and check the resistance between the wires. one wire is a common and it must bear a resistance of 75 ohms with all the other wires then that is the common wire. This is due to the fact that there is actually twice the length of coil between the ends and only half from center (common wire) to the end.

A pulse is an electrical signal that repeats ON and OFF voltages as shown in the

Illustration below. Each cycle of ON and OFF (1 cycle) is called a “pulse.” Normally, 5 volts is used. ON is high and OFF is low.

Working principle of Stepper motor:

To make a stepper motor rotate, you must constantly turn on and off the coils. If you simply energize one coil the motor will just jump to that position and stay there resisting change.

28

Page 29: Thesis Final

This energized coil pulls full current even though the motor is not turning. The stepper motor will generate a lot of heat at standstill. The ability to stay put at one position rigidly is often an advantage of stepper motors. The torque at standstill is called the holding torque.

Because steppers can be controlled by turning coils on and off, they are easy to control using digital circuitry and microcontroller chips. The controller simply energizes the coils in a certain pattern and the motor will move accordingly. At any given time the computer will know the position of the motor since the number of steps given can be tracked. This is true only if some outside force of greater strength than the motor has not interfered with the motion.

When a phase winding of a stepper motor is energized with current, a magnetic flux is developed in the saturate direction of this flux is determined by the “right hand rule” which states:” if the coil is grasped in the right hand with fingers pointing in the direction of the recurrent in the winding (the thumb is extended at right angle to the fingers), then the thumb will point in the direction of the magnetic field.”

The number of times the stepper motor turns on and off depends on the number of teeth present on the rotor and this is shown with an example in which four-step sequence is considered. Four-step sequence means, after completing every four steps, the rotor moves only one tooth pitch. In this example, the rotor has only 25 teeth and so it makes 100 steps for one complete rotation.

Illustrates one complete rotation of a stepper motor.  At position 1, we can see that the rotor is beginning at the upper electromagnet, which is currently active (has voltage applied to it).  To move the rotor clockwise (CW), the upper electromagnet is deactivated and the right electromagnet is activated, causing the rotor to move 90 degrees CW, aligning itself with the active magnet.  This process is repeated in the same manner at the south and west electromagnets until we once again reach the starting position.

You may double the resolution of some motors by a process known as "half-stepping".  Instead of switching the next electromagnet in the rotation on one at a time, with half stepping you turn on both electromagnets, causing an equal attraction between, thereby doubling the resolution. 

There are basically two types of stepper motors depending on the arrangements of the electromagnetic coils. They are unipolar and bipolar

Unipolar:

29

Page 30: Thesis Final

In a unipolar stepper motor, there are four separate electromagnets. To turn the motor, first coil "1" is given current, then it's turned off and coil 2 is given current, then coil 3, then 4, and then 1 again in a repeating pattern. Current is only sent through the coils in one direction; thus the name unipolar.

A unipolar stepper motor will have 5 (or 6) wires coming out of it. Four of those wires are each connected to one end of one coil. The extra wire (or 2) is called "common" and is connected to the other ends of all four coils. To operate the motor, the "common" wire is connected to the supply voltage, and the other four wires are connected to ground through transistors, so the transistors control whether current flows or not. A microcontroller or stepper motor controller is used to activate the transistors in the right order. These are the cheapest way to get precise angular movements.

Bipolar motor:

In a bipolar motor, there are only two coils, and current must be sent through a coil first in one direction and then in the other direction; thus the name bipolar. Bipolar motors need more than 4 transistors to operate them, but they are also more powerful than a unipolar motor of the same weight. To be able to send current in both directions, engineers can use an H-bridge to control each coil or a step motor driver chip. This type of motor is not regularly used for robotics.

Bipolar controllers can switch between supply voltage, ground, and unconnected. Unipolar controllers can only connect or disconnect a cable, because the voltage is already hard wired. Unipolar controllers need center-tapped windings.

It is possible to drive unipolar stepper motors with bipolar drivers. The idea is to connect the output pins of the driver to 4 transistors. The transistor must be grounded at the emitter and the driver pin must be connected to the base. Collector is connected to the coil wire of the motor.

Stepper motor advantages and disadvantages:

Advantages:

The rotation angle of the motor is proportional to the input pulse. the motor has full torque at standstill(if the windings are energized) Precise positioning and repeatability of movement since good stepper motors have an

accuracy of 3-5% of a step and this error is non-cumulative from one step to the next. Excellent response to starting/stopping/reversing. Very reliable since they are no contact brushes in the motor. Therefore the life of the

motor is simply dependent on the life of the bearing.

30

Page 31: Thesis Final

The mottos response to the digital input pulses provides open-loop control, making the motor simpler and less costly to control.

It is possible to achieve very slow speed synchronous rotation with a load that is directly coupled to the shaft.

a wide range of rotational speeds can be realized as the speed is proportional to the frequency of the input pulses.

Disadvantages:

Resonances can occur if not properly controlled Not easy to operate at extremely high speeds. This motor can also be heated at standing because of the torque required to hold it in

position.

When to use stepper motors:

Computer-controlled stepper motors are one of the most versatile forms of positioning systems, particularly when digitally controlled as part of a servo system. Stepper motors can be used to advantage where you need to control rotation angle, position and synchronism. Stepper motors are used in floppy disk drives, flatbed scanners, and typewriters, printers-y plotters, milling machines, valve actuators, medical equipment, fax machines, automotive and many more devices.

3.2 Circuit Diagram

31

Page 32: Thesis Final

This project is useful in controlling the gate at the railway- road crossing. AT89S52 microcontroller is the heart of the circuit as it controls all the functions.

Two IR TX – RX pairs are used in this project to identify the arrival and departure of the train at the railway- road crossing. The two IR pairs are fixed to the gate. The TX and RX are arranged face to face across the door so that the RX should get IR signal continuously.

Whenever the train is arriving at the railway-road crossing, the first IR RX identifies the train since the IR signal gets disturbed. The microcontroller observes the output of the first IR RX carefully and closes the gate by rotating the stepper motor. This is done to alert the persons to stop for few minutes to indicate that the train is approaching the crossing.

The microcontroller will wait for the last compartment to leave the IR pair and after leaving, the receiver again gets IR signal. Till this time the gate is closed. Now, after the train had left the crossing, the microcontroller will open the gate by rotating the stepper motor.

The system also has the task of monitoring the fire sensor output and also the track line. Either if the fire sensor triggers or if the track line breaks, the microcontroller will alert the buzzer immediately. The output of the fire sensor and the track line are given to two different port pins of the microcontroller. Thus, the microcontroller continuously monitors the output of fire sensor, track line along with the output of the two pairs of IR sensors.

CHAPTER 4

32

Page 33: Thesis Final

Firmware Implementation of the project design

This chapter briefly explains about the firmware implementation of the project. The required software tools are discussed in section 4.2. Section 4.3 shows the flow diagram of the project design. Section 4.4 presents the firmware implementation of the project design.

4.1 Software Tools Required

Keil µv3, Proload are the two software tools used to program microcontroller. The working of each software tool is explained below in detail.

Programming Microcontroller:A compiler for a high level language helps to reduce production time. To program the

AT89S52 microcontroller the Keil µv3 is used. The programming is done strictly in the embedded C language. Keil µv3 is a suite of executable, open source software development tools for the microcontrollers hosted on the Windows platform.

The compilation of the C program converts it into machine language file (.hex). This is the only language the microcontroller will understand, because it contains the original program code converted into a hexadecimal format. During this step there are some warnings about eventual errors in the program. This is shown in Fig 4.1. If there are no errors and warnings then run the program, the system performs all the required tasks and behaves as expected the software developed. If not, the whole procedure will have to be repeated again. Fig 4.2 shows expected outputs for given inputs when run compiled program.

One of the difficulties of programming microcontrollers is the limited amount of resources the programmer has to deal with. In personal computers resources such as RAM and processing speed are basically limitless when compared to microcontrollers. In contrast, the code on microcontrollers should be as low on resources as possible.

4.1.1 Keil Compiler:

Keil compiler is software used where the machine language code is written and compiled. After compilation, the machine source code is converted into hex code which is to be dumped into the microcontroller for further processing. Keil compiler also supports C language code.

33

Page 34: Thesis Final

34

Page 35: Thesis Final

4.1.2 Proload:Proload is software which accepts only hex files. Once the machine code is converted

into hex code, that hex code has to be dumped into the microcontroller and this is done by the Proload. Proload is a programmer which itself contains a microcontroller in it other than the one which is to be programmed. This microcontroller has a program in it written in such a way that it accepts the hex file from the Keil compiler and dumps this hex file into the microcontroller which is to be programmed. As the Proload programmer kit requires power supply to be operated, this power supply is given from the power supply circuit designed above. It should be noted that this programmer kit contains a power supply section in the board itself but in order to switch on that power supply, a source is required. Thus this is accomplished from the power supply board with an output of 12volts.

Features Supports major Atmel 89 series devices Auto Identify connected hardware and devices Error checking and verification in-built Lock of programs in chip supported to prevent program copying 20 and 40 pin ZIF socket on-board Auto Erase before writing and Auto Verify after writing Informative status bar and access to latest programmed file Simple and Easy to use Works on 57600 speed

Description

It is simple to use and low cost, yet powerful flash microcontroller programmer for the Atmel 89 series. It will Program, Read and Verify Code Data, Write Lock Bits, Erase and Blank Check. All fuse and lock bits are programmable. This programmer has intelligent onboard firmware and connects to the serial port. It can be used with any type of computer and requires no special hardware. All that is needed is a serial communication ports which all computers have.

All devices have signature bytes that the programmer reads to automatically identify the chip. No need to select the device type, just plug it in and go! All devices also have a number of lock bits to provide various levels of software and programming protection. These lock bits are

35

Page 36: Thesis Final

fully programmable using this programmer. Lock bits are useful to protect the program to be read back from microcontroller only allowing erase to reprogram the microcontroller. The programmer connects to a host computer using a standard RS232 serial port. All the programming 'intelligence' is built into the programmer so you do not need any special hardware to run it. Programmer comes with window based software for easy programming of the devices.

Programming SoftwareComputer side software called 'Proload V4.1' is executed that accepts the Intel HEX format file generated from compiler to be sent to target microcontroller. It auto detects the hardware connected to the serial port. It also auto detects the chip inserted and bytes used. Software is developed in Delphi 7 and requires no overhead of any external DLL.

36

Page 37: Thesis Final

Chapter 5

Results and Discussions

5.1 ResultsAssemble the circuit on the PCB as shown in Fig 5.1. After assembling the circuit on the

PCB, check it for proper connections before switching on the power supply.

5.2 Conclusion and Future Scope

The implementation of Automatic railway gate control system using IR is done successfully. The communication is properly done without any interference between different modules in the design. Design is done to meet all the specifications and requirements. Software tools like Keil Uvision Simulator, Proload to dump the source code into the microcontroller, Orcad Lite for the schematic diagram have been used to develop the software code before realizing the hardware.

The performance of the system is more efficient. Reading the values from the IR sensors and controlling the gate with the help of stepper motor and also continuously read the fire sensor output and alert the buzzer immediately either if the fire sensor triggers or if the breakage of the railway track occurs is the main job carried out by the microcontroller. The mechanism is controlled by the microcontroller.

Circuit is implemented in Orcad and implemented on the microcontroller board. The performance has been verified both in software simulator and hardware design. The total circuit is completely verified functionally and is following the application software.

It can be concluded that the design implemented in the present work provide portability, flexibility and the data transmission is also done with low power consumption.

5.3 Advantages

Cost effective User friendly Low power consumption

5.4 Applications

This project can be used to control the gate at the railway-road crossing. This project can be used to detect the track line breakage.

37

Page 38: Thesis Final

AppendixA> Bibliography:1.  www.wikipedia.com2. www.8051projects.info 3. www.8052.com 4. http://www.ecse.rpi.edu/~schubert/Unused%20stuff/More%20reprints/2002%20Carruthers

%20%28Wiley%20Encyclopedia%29%20Wireless%20infrared%20communications.pdf5. http://en.wikipedia.org/wiki/Infrared6. http://www.windows.ucar.edu/tour/link=/physical_science/magnetism/

em_infrared.html&edu=mid7. http://www.zntu.edu.ua/base/lection/rpf/lib/zhzh03/8051_tutorial.pdf 8. http://www.atmel.com/dyn/resources/prod_documents/doc1919.pdf 9. http://microcontrollershop.com/product_info.php?products_id=1078

B> List of figures:S.No. Figure Page No.

1 IR Transmitter 42 Connection between IR transmitter and receiver 53 Block diagram of project 74 i) Block diagram of power supply for the system

ii) Transformer general notation with its outputiii) Rectifier circuit

8

5 Transformer circuit with its general output 96 i) Smoothing process in capacitor filter

ii) Regulator block diagram10

7 i) AT89S52 pin diagramii) AT89S52 architecture

12

8 i) Light spectrumii) IR general circuitiii) IR working

16

9 IR transmitter 1710 Buzzer alarm interfaced with 8051 1811 i) ULN2003 current driver DIP 16 package

ii) ULN2003 pin connection and block diagram19

12 Driving a stepper motor using ULN2003 2013 Stepper motor 2214 Stepper motor working procedure 2315 Stepper motor 2516 Project circuit diagram 3117 i) Compilation procedure of source code

ii) Running procedure of compiled program33

18 ATMEL 8051 device programmer 3419 Dumping of program procedure 35

38