Sie sind auf Seite 1von 136

AUTOMATIC LOAD SHARING OF TRANSFORMERS

CONTENTS
S.No. 1. 2. 3. 5. 6. 7. 8. 9. Contents Abbreviations Abstract Introduction Block diagram Block diagram Description Schematic Schematic Description (pin to pin connectivity) Hardware components a. Microcontroller (max 50 pages) b. MAX 232 c. Power supply d. ADC e. Current sensor f. LCD g. Relay Page

10.

Circuit description

11.

Software components a. About Keil b. Embedded C Source Code Conclusion or Synopsis Bibliography

12. 12. 13.

OUT SIDE

ABBREVIATIONS
2

Symbol
ACC B PSW SP DPTR DPL DPH P0 P1 P2 P3 IP IE TMOD TCON T2CON T2MOD TH0 TL0 TH1 TL1 TH2 TL2 SCON SBUF PCON

Name
Accumulator B register Program status word Stack pointer Data pointer 2 bytes Low byte High byte Port0 Port1 Port2 Port3 Interrupt priority control Interrupt enable control Timer/counter mode control Timer/counter control Timer/counter 2 control Timer/counter mode2 control Timer/counter 0high byte Timer/counter 0 low byte Timer/counter 1 high byte Timer/counter 1 low byte Timer/counter 2 high byte Timer/counter 2 low byte Serial control Serial data buffer Power control

Figure Locations
S.No.
1 2 3 4 5 6 7 8 9 10 11

Figure Components of Typical Linear Power Supply An Electrical Transformer Bridge Rectifier Bridge Rectifier Positive Cycle Bridge Rectifier Negative Cycle Three terminal voltage Regulator Functional Diagram of Microcontroller Pin Diagram of Microcontroller Oscillator connections External clock drive connections A register 3

Page No.

12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41

B register RAM RAM Allocation Register Banks PSW DPTR SP PORT 0 TL0 and TH0 DB9 Connecting Microcontroller to PC

Types of SIM Structures


Smart Card Pin-out Smart Card Reader LCD MAX 232 Pin-out MAX 232 Operating circuit MAX 232 Logic output Relay Project New Project Select Target device Select device for Target Copy 8051 startup code Source group 1 New file Opened new file File Save Add files to the source group Adding files to the source group

42 43 44 45 46 47

Compilation After Compilation Build Selecting the Ports to be visualized Start Debugging

CHAPTER 1
1. INTRODUCTION 1.1 EMBEDDED SYSTEMS:
Embedded systems are designed to do some specific task, rather than be a generalpurpose computer for multiple tasks. Some also have real time performance constraints that must be met, for reason such as safety and usability; others may have low or no performance requirements, allowing the system hardware to be simplified to reduce costs. 5

An embedded system is not always a separate block - very often it is physically built-in to the device it is controlling. The software written for embedded systems is often called firmware, and is stored in read-only memory or flash convector chips rather than a disk drive. It often runs with limited computer hardware resources: small or no keyboard, screen, and little memory. Wireless communication has become an important feature for commercial products and a popular research topic within the last ten years. There are now more mobile phone subscriptions than wired-line subscriptions. Lately, one area of commercial interest has been low-cost, low-power, and short-distance wireless communication used for \personal wireless networks." Technology advancements are providing smaller and more cost effective devices for integrating computational processing, wireless communication, and a host of other functionalities. These embedded communications devices will be integrated into applications ranging from homeland security to industry automation and monitoring. They will also enable custom tailored engineering solutions, creating a revolutionary way of disseminating and processing information. With new technologies and devices come new business activities, and the need for employees in these technological areas. Engineers who have knowledge of embedded systems and wireless communications will be in high demand. Unfortunately, there are few adorable environments available for development and classroom use, so students often do not learn about these technologies during hands-on lab exercises. The communication mediums were twisted pair, optical fiber, infrared, and generally wireless radio. INTRODUCTION TO THE PROJECT: In this project AUTOMATIC LOAD SHARING OF TRANSFORMERS we are using two transformers, one is main transformer (TF1) and the next is backup transformer (TF2). Here the load is directly connected to the secondary of the main transformer as well as backup transformer; here two transformers are connected through the relay. The transfers switch senses when utility power is interrupted, and starts up the transformer TF2 which acts as a backup transformer. If the utility power remains absent, 6

the transfer switch disconnects the load from the utility and connects it to the Transformer TF2, restoring electricity to the load. The transfer switch continues to monitor utility power, and when it is restored, switches the load from the Transformer TF2 back to the Main transformer TF1. Once the Transformer TF2 is disconnected, it goes through a cooldown routine and is automatically shut down. The objective of the present project is to satisfy the above needs with an extent. The present system is designed around two transformers. One transformer (TF1) is used as the main supply and the other transformer (TF2) is used in the place of the generator (for demo purpose). These two transformers are connected with the relay which is controlled by the embedded controller. The loads are connected to the main line (TF1) and as well as to the TF2. Initially TF1 is connected to the load, the loads run with this power. Due to any reason this power is interrupted, then it is identified by the controller and it immediately switches ON to the TF2 through the relay. The controller continuously monitors the TF1 (main line). When it finds the power on it again switches the loads connection to the main line. All the status of the transformers will be displayed on LCD. BLOCK DIAGRAM:

POWER SUPPLY

LCD DISPLAY

Main Transformer (TF1)

AT 89C51 MICRO CONTROLLER

RELAY 7 LOAD

ADC

Sharing transformer (TF2)

CURRENT SENSOR

BLOCK DIAGRAM EXPLANATION: The above block diagram gives the overview of the project in the pictorial form with the help of the block diagram we will create pre model of the project and the analyze the function of the project the explanation of the project with block diagram over view is given as follows. Power Supply Section: This section is meant for supplying Power to all the sections mentioned above. It basically consists of a Transformer to step down the 230V ac to 18V ac followed by diodes. Here diodes are used to rectify the ac to dc. After rectification the obtained rippled dc is filtered using a capacitor Filter. A positive voltage regulator is used to regulate the obtained dc voltage. Microcontroller Section: This section forms the control unit of the whole project. This section basically consists of a Microcontroller with its associated circuitry like Crystal with capacitors, Reset circuitry, Pull up resistors (if needed) and so on. The Microcontroller forms the heart of the project because it controls the devices being interfaced and communicates with the devices according to the program being written. 8

Transformers: In general, the ac line voltage present in your house wiring is not suitable for electronic circuits. Most circuits require a considerably lower voltage, while a few require higher voltages. The transformer serves to convert the ac line voltage to a voltage level more appropriate to the needs of the circuit to be powered. At the same time, the transformer provides electrical isolation between the ac line and the circuit being powered, which is an important safety consideration. However, a line transformer is generally large and heavy, and is rather expensive. Therefore, some power supplies (notably for PCs) are deliberately designed to operate directly from the ac line without a line transformer. The output of the transformer is still an ac voltage, but now of an appropriate magnitude for the circuit to be powered. ADC: Analog to digital (A/D, ADC) converters are electrical circuit devices that convert continuous signals, such as voltages or currents, from the analog domain to the digital domain where the signals are represented by numbers. LCD Display Section: This section is basically meant to show up the status of the project. This project makes use of Liquid Crystal Display to display / prompt for necessary information.

Sensors: This part of the system consists of current sensor. These sensor sense various parameters of load- current and are then sent to the Analog to Digital Converter.

Relay:
In this project Relays are used to the Trip the transformer. A relay is an electrical switch that opens and closes under control of another electrical circuit. In the original form, the switch is operated by an electromagnet to open or close one or many sets of contacts.

SCHEMATIC:

10

SCHEMATIC EXPLANATION: Firstly, the required operating voltage for Microcontroller 89C51 is 5V. Hence the 5V D.C. power supply is needed by the same. This regulated 5V is generated by first stepping down the 230V to 18V and 12 V operating voltage for relays. Hence another supply is required to generate 12V. The step downed a.c voltage is being rectified by the Bridge Rectifier. The diodes used are 1N4007. The rectified a.c voltage is now filtered using a C filter. Now the rectified, filtered D.C. voltage is fed to the Voltage Regulator. This voltage regulator allows us to have a Regulated Voltage which is +5V. We are using two voltage regulators i.e., 7805 and 7812. These voltage regulators regulate 5v for microcontroller and 12v for relays. The rectified; filtered and regulated voltage is again filtered for ripples using an electrolytic capacitor 100F. Now the output from this section is fed to 40th pin of 89c51 microcontroller to supply operating voltage. The microcontroller 89C51 with Pull up resistors at Port0 and crystal oscillator of 11.0592 MHz crystal in conjunction with couple of capacitors of is placed at 18 th & 19th pins of 89c51 to make it work (execute) properly. The LCD is interfaced to Microcontroller. The data pins of LCD are connected to Port 0. The control pins of LCD are connected to Port 2 as shown in schematic. One of the port 3 pin is connected to the secondary side of transformer one through bridge rectifier and regulator to check the status of the transformer one i.e whether the power supply is on or off to the transformer one through relay. Relay is used to on & off the transformer occurred it is connected to P2.0 microcontroller. The data pins of ADC are connected to the port 1 of microcontroller. What ever the data in ADC from C.T (current transformer) will be converted from analog to digital and fed it to the microcontroller.

11

CHAPTER III HARDWARE Components


The Hardware components used in this project are Regulated Power Supply Microcontroller Transformers Relay ADC Current sensor LCD

12

3.1 MICROCONTROLLER 89C51


INTRODUCTION: A Micro controller consists of a powerful CPU tightly coupled with memory RAM, ROM or EPROM), various I / O features such as Serial ports, Parallel Ports, Timer/Counters, Interrupt Controller, Data Acquisition interfaces-Analog to Digital Converter (ADC), Digital to Analog Converter (ADC), everything integrated onto a single Silicon Chip.

It does not mean that any micro controller should have all the above said features on chip, Depending on the need and area of application for which it is designed, The ONCHIP features present in it may or may not include all the individual section said above. Any microcomputer system requires memory to store a sequence of instructions making up a program, parallel port or serial port for communicating with an external system, timer / counter for control purposes like generating time delays, Baud rate for the serial port, apart from the controlling unit called the Central Processing Unit.

Advantages of microcontrollers: 13

1. If a system is developed with a microprocessor, the designer has to go for external memory such as RAM, ROM or EPROM and peripherals and hence the size of the PCB will be large enough to hold all the required peripherals. But, the micro controller has got all these peripheral facilities on a single chip so development of a similar system with a micro controller reduces PCB size and cost of the design. One of the major differences between a micro controller and a microprocessor is that a controller often deals with bits , not bytes as in the real world application, for example switch contacts can only be open or close, indicators should be lit or dark and motors can be either turned on or off and so forth.

COMPARISON What is the difference between a microprocessor and microcontroller? By microprocessor is meant the general-purpose microprocessors such as Intels x86 Family(8086,80286,80386,80486,and the Pentium)or Motorolas680x0 family(68000,68010,68020,68030,68040.etc.).These microprocessors contain no RAM, no ROM, and no I/O PORTS on the chip itself. For this reason, they are commonly referred as general-purpose microprocessors.

14

Data bus

CPU
General purpose Micro Processor RAM ROM

I/O PORT

TIMER

SERIAL COM PORT

Address bus

(A)General purpose Micro processor System

CPU RAM I/O

ROM

TIMER Serial COM PORT

(b) Microcontroller A system designer using a general-purpose microprocessor such as the Pentium or the 68040 must add RAM, ROM, I/O PORTS, and TIMERS externally to make them functional. Although the addition of external RAM, ROM and I/O PORTS makes these systems bulkier and much expensive, they have the advantage of versatility such that the designer can decide on the amount of RAM, ROM and I/O PORTS needed to fit the task at hand this is not the case with microcontrollers. A microcontroller has a CPU (a microprocessor) in addition to a fixed amount of RAM, ROM, I/OPORTS, and a timer all on a single chip. In other words, the processor, RAM, ROM, I/OPORTS, and timer are all embedded together on one chip; therefore, the designer cant add any external memory, I/O, or timer to it. The fixed amount of on-chip ROM, RAM, and number of I/O PORTS in microcontrollers makes them ideal for many 15

applications in which cost and space are critical. In many applications, for example a TV remote control, there is no need for the computing power of a 486 or even an 8086 microprocessor. In many applications, the space it takes, the power it consumes, and the price per unit are much more critical considerations than the computing power. These applications most often require some I/O operation to read signal and turn on and off certain bits. For these reason some call these processors IBP (itty-bitty processors). In 1981,Intel corporation introduced an 8 bit microcontroller called the 8051.This microcontroller had 128 bytes of RAM,4K bytes of on-chip ROM, two timers, one serial port, and 4 ports(each 8-bits wide)all on single chip. At that time it was also referred to as a system on a chip. The 8051 is an 8-bit processor, meaning that the CPU can work on only 8-bits of data at a time. Data larger than 8-bits has to be broken into 8-bit pieces to be processed by the CPU. The 8051 can have a maximum of 64K bytes of ROM; many manufacturers have put only 4Kbytes on chip. A Micro controller consists of a powerful CPU tightly coupled with memory, various I/O interfaces such as serial port, parallel port timer or counter, interrupt controller, data acquisition interfaces-Analog to Digital converter, Digital to Analog converter, integrated on to a single silicon chip. If a system is developed with a microprocessor, the designer has to go for external memory such as RAM, ROM, EPROM and peripherals. But controller is provided all these facilities on a single chip. Development of a Micro controller reduces PCB size and cost of design. One of the major differences between a Microprocessor and a Micro controller is that a controller often deals with bits not bytes as in the real world application. Intel has introduced a family of Micro controllers called the MCS-51.

The Major Features:

16

Compatible with MCS-51 products 4k Bytes of in-system Reprogrammable flash memory Fully static operation: 0HZ to 24MHZ Three level programmable clock 128 * 8 bit timer/counters Six interrupt sources Programmable serial channel Low power idle power-down modes

Why AT 89C51? : The system requirements and control specifications clearly rule out the use of 16, 32 or 64 bit micro controllers or microprocessors. Systems using these may be earlier to implement due to large number of internal features. They are also faster and more reliable but, the above application is satisfactorily served by 8-bit micro controller. Using an inexpensive 8-bit Microcontroller will doom the 32-bit product failure in any competitive market place. Coming to the question of why to use AT89C51 of all the 8-bit microcontroller available in the market the main answer would be because it has 4 Kb on chip flash memory which is just sufficient for our application. The on-chip Flash ROM allows the program memory to be reprogrammed in system or by conventional non-volatile memory Programmer. Moreover ATMEL is the leader in flash technology in todays market place and hence using AT 89C51 is the optimal solution.

AT89C51 MICROCONTROLLER ARCHITECTURE 17

The 89C51 architecture consists of these specific features: Eight bit CPU with registers A (the accumulator) and B Sixteen-bit program counter (PC) and data pointer (DPTR) Eight- bit stack pointer (PSW) Eight-bit stack pointer (Sp) Internal ROM or EPROM (8751) of 0(8031) to 4K (89C51) Internal RAM of 128 bytes: 1. Four register banks, each containing eight registers 2. Sixteen bytes, which maybe addressed at the bit level 3. Eighty bytes of general- purpose data memory Thirty two input/output pins arranged as four 8-bit ports:p0-p3 Two 16-bit timer/counters: T0 and T1 Full duplex serial data receiver/transmitter: SBUF Control registers: TCON, TMOD, SCON, PCON, IP, and IE Two external and three internal interrupts sources. Oscillator and clock circuits.

18

Functional block diagram of micro controller The 89C51 oscillator and clock: The heart of the 89C51 circuitry that generates the clock pulses by which all the internal all internal operations are synchronized. Pins XTAL1 And XTAL2 is provided for connecting a resonant network to form an oscillator. Typically a quartz crystal and capacitors are employed. The crystal frequency is the basic internal clock frequency of the microcontroller. The manufacturers make 89C51 designs that run at specific minimum and maximum frequencies typically 1 to 16 MHz.

19

Oscillator and timing circuit

Types of memory: The 89C51 have three general types of memory. They are on-chip memory, external Code memory and external Ram. On-Chip memory refers to physically existing memory on the micro controller itself. External code memory is the code memory that resides off chip. This is often in the form of an external EPROM. External RAM is the Ram that resides off chip. This often is in the form of standard static RAM or flash RAM.

a) Code memory 20

Code memory is the memory that holds the actual 89C51 programs that is to be run. This memory is limited to 64K. Code memory may be found on-chip or off-chip. It is possible to have 4K of code memory on-chip and 60K off chip memory simultaneously. If only off-chip memory is available then there can be 64K of off chip ROM. This is controlled by pin provided as EA b) Internal RAM The 89C51 have a bank of 128 of internal RAM. The internal RAM is found onchip. So it is the fastest Ram available. And also it is most flexible in terms of reading and writing. Internal Ram is volatile, so when 89C51 is reset, this memory is cleared. 128 bytes of internal memory are subdivided. The first 32 bytes are divided into 4 register banks. Each bank contains 8 registers. Internal RAM also contains 128 bits, which are addressed from 20h to 2Fh. These bits are bit addressed i.e. each individual bit of a byte can be addressed by the user. They are numbered 00h to 7Fh. The user may make use of these variables with commands such as SETB and CLR. FLASH MEMORY: Flash memory (sometimes called "flash RAM") is a type of constantly-powered non volatile that can be erased and reprogrammed in units of memory called blocks. It is a variation of electrically erasable programmable read-only memory (EEPROM) which, unlike flash memory, is erased and rewritten at the byte level, which is slower than flash memory updating. Flash memory is often used to hold control code such as the basic input/output system (BIOS) in a personal computer. When BIOS needs to be changed (rewritten), the flash memory can be written to in block (rather than byte) sizes, making it easy to update. On the other hand, flash memory is not useful as random access memory (RAM) because RAM needs to be addressable at the byte (not the block) level. Flash memory gets its name because the microchip is organized so that a section of memory cells are erased in a single action or "flash." The erasure is caused by FowlerNordheim tunneling in which electrons pierce through a thin dielectric material to remove 21

an electronic charge from a floating gate associated with each memory cell. Intel offers a form of flash memory that holds two bits (rather than one) in each memory cell, thus doubling the capacity of memory without a corresponding increase in price. Flash memory is used in digital cellular phones, digital cameras, LAN switches, PC Cards for notebook computers, digital set-up boxes, embedded controllers, and other devices.

Memory Types

22

Memory Type FLASH ROM Read-Only Memory SRAM Static Random-Access Memory EPROM Memory EEPROM Electrically DRAM Dynamic Random Access Memory or Erasable E2

Features Low-cost, high-density, high-speed architecture; low power; high reliability Mature, high-density, reliable, low cost; time-consuming mask required, suitable for high production with stable code Highest speed, high-power, low-density memory; limited density drives up cost High-density memory; must be exposed

Electrically Programmable Read-Only to ultraviolet light for erasure Electrically byte-erasable; lower

Programmable reliability, higher cost, lowest density High-density, low-cost, high-speed, highpower

Read-Only Memory

Technical Overview of Flash Memory Flash memory is a nonvolatile memory using NOR technology, which allows the user to electrically program and erase information. Intel Flash memory uses memory cells similar to an EPROM, but with a much thinner, precisely grown oxide between the floating gate and the source (see Figure 2). Flash programming occurs when electrons are placed on the floating gate. The charge is stored on the floating gate, with the oxide layer allowing the cell to be electrically erased through the source. Intel Flash memory is an extremely reliable nonvolatile memory architecture.

23

Pin diagram of AT89C51

Pin Description: VCC: Supply voltage. GND: Ground.

Port 0: Port 0 is an 8-bit open-drain bi-directional 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 24

impedance inputs. Port 0 may 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 1: Port 1 is an 8-bit bi-directional 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. Port 1 also receives the low-order address bytes during Flash programming and verification. Port 2: Port 2 is an 8-bit bi-directional 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. Port 2 emits the high-order address byte during fetches from external program memory and during accesses to external data memories that use 16-bit addresses (MOVX @DPTR). In this application, it uses strong internal pull-ups when emitting 1s. During accesses to external data memories that use 8-bit addresses (MOVX @ RI), Port 2 emits the contents of the P2 Special Function Register. Port 2 also receives the high-order address bits and some control signals during Flash programming and verification.

Port 3: Port 3 is an 8-bit bi-directional 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

25

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 also serves the functions of various special features of the AT89C51 as listed below: Port 3 also receives some control signals for Flash programming and verification

Tab 6.2.1 Port pins and their alternate functions RST: Reset input. A high on this pin for two machine cycles while the oscillator is running resets the device. ALE/PROG: Address Latch Enable output pulse for latching the low byte of the address during accesses to external memory. This pin is also the program pulse input (PROG) during Flash programming. In normal operation ALE is emitted at a constant rate of 1/6the oscillator frequency, and may be used for external timing or clocking purposes. Note, however, that one ALE pulse is skipped during each access to external Data Memory. If desired, ALE operation can be disabled by setting bit 0 of SFR location 8EH. With the bit set, ALE is active only during a MOVX or MOVC instruction. Otherwise, the pin is weakly pulled high. Setting the ALE-disable bit has no effect if the microcontroller is in external execution mode. 26

PSEN: Program Store Enable is the read strobe to external program memory. When the AT89C51 is executing code from external program memory, PSEN is activated twice each machine cycle, except that two PSEN activations are skipped during each access to external data memory. EA/VPP: External Access Enable (EA) must be strapped to GND in order to enable the device to fetch code from external program memory locations starting at 0000H up to FFFFH. Note, however, that if lock bit 1 is programmed, EA will be internally latched on reset. EA should be strapped to VCC for internal program executions. This pin also receives the 12-volt programming enable voltage (VPP) during Flash programming, for parts that require 12-volt VPP. XTAL1: Input to the inverting oscillator amplifier and input to the internal clock operating circuit. XTAL2: Out put from the inverting oscillator amplifier. Oscillator Characteristics: XTAL1 and XTAL2 are the input and output, respectively, of an inverting amplifier which can be configured for use as an on-chip oscillator, as shown in Figs 6.2.3. Either a quartz crystal or ceramic resonator may be used. To drive the device from an external clock source, XTAL2 should be left unconnected while XTAL1 is driven as shown in Figure 6.2.4.There are no requirements on the duty cycle of the external clock signal, since the input to the internal clocking circuitry is through a divide-by-two flip-flop, but minimum and maximum voltage high and low time specifications must be observed.

27

Oscillator Connections Notes:

External Clock Drive Configuration

1. Under steady state (non-transient) conditions, IOL must be externally limited as follows: Maximum IOL per port pin: 10 mA Maximum IOL per 8-bit port: Port 0: 26 mA Ports 1, 2, 3: 15 mA Maximum total IOL for all output pins: 71 mA If IOL exceeds the test condition, VOL may exceed the related

specification. Pins are not guaranteed to sink current greater than the listed test conditions. 2. Minimum VCC for Power-down is 2V.

Types of memory: The 8051 have three general types of memory. They are on-chip memory, external Code memory and external Ram. On-Chip memory refers to physically existing memory on the micro controller itself. External code memory is the code memory that resides off chip. This is often in the form of an external EPROM. External RAM is the Ram that resides off chip. This often is in the form of standard static RAM or flash RAM. b) Code memory

28

Code memory is the memory that holds the actual 8051 programs that is to be run. This memory is limited to 64K. Code memory may be found on-chip or off-chip. It is possible to have 4K of code memory on-chip and 60K off chip memory simultaneously. If only off-chip memory is available then there can be 64K of off chip ROM. This is controlled by pin provided as EA b) Internal RAM The 8051 have a bank of 128 bytes of internal RAM. The internal RAM is found on-chip. So it is the fastest Ram available. And also it is most flexible in terms of reading and writing. Internal Ram is volatile, so when 8051 is reset, this memory is cleared. 128 bytes of internal memory are subdivided. The first 32 bytes are divided into 4 register banks. Each bank contains 8 registers. Internal RAM also contains 128 bits, which are addressed from 20h to 2Fh. These bits are bit addressed i.e. each individual bit of a byte can be addressed by the user. They are numbered 00h to 7Fh. The user may make use of these variables with commands such as SETB and CLR. Special Function registered memory: Special function registers are the areas of memory that control specific functionality of the 8051 micro controller. a) Accumulator (0E0h) As its name suggests, it is used to accumulate the results of large no of instructions. It can hold 8 bit values. B) B register (0F0h) The B register is very similar to accumulator. It may hold 8-bit value. The b register is only used by MUL AB and DIV AB instructions. In MUL AB the higher byte of the product gets stored in B register. In div AB the quotient gets stored in B with the remainder in A. c) Stack pointer (81h) 29

The stack pointer holds 8-bit value. This is used to indicate where the next value to be removed from the stack should be taken from. When a value is to be pushed onto the stack, the 8051 first store the value of SP and then store the value at the resulting memory location. When a value is to be popped from the stack, the 8051 returns the value from the memory location indicated by SP and then decrements the value of SP. d) Data pointer The SFRs DPL and DPH work together work together to represent a 16-bit value called the data pointer. The data pointer is used in operations regarding external RAM and some instructions code memory. It is a 16-bit SFR and also an addressable SFR. e) Program counter The program counter is a 16 bit register, which contains the 2 byte address, which tells the 8051 where the next instruction to execute to be found in memory. When the 8051 is initialized PC starts at 0000h. And is incremented each time an instruction is executes. It is not addressable SFR. f) PCON (power control, 87h) The power control SFR is used to control the 8051s power control modes. Certain operation modes of the 8051 allow the 8051 to go into a type of sleep mode which consume much lee power.

g) TCON (timer control, 88h) The timer control SFR is used to configure and modify the way in which the 8051s two timers operate. This SFR controls whether each of the two timers is running or stopped and contains a flag to indicate that each timer has overflowed. Additionally, some non-timer related bits are located in TCON SFR. These bits are used to configure the way

30

in which the external interrupt flags are activated, which are set when an external interrupt occurs.

h) TMOD (Timer Mode, 89h) The timer mode SFR is used to configure the mode of operation of each of the two timers. Using this SFR your program may configure each timer to be a 16-bit timer, or 13 bit timer, 8-bit auto reload timer, or two separate timers. Additionally you may configure the timers to only count when an external pin is activated or to count events that are indicated on an external pin.

i) TO (Timer 0 low/high, address 8A/8C h) These two SFRs taken together represent timer 0. Their exact behavior depends on how the timer is configured in the TMOD SFR; however, these timers always count up. What is configurable is how and when they increment in value. j) T1 (Timer 1 Low/High, address 8B/ 8D h) These two SFRs, taken together, represent timer 1. Their exact behavior depends on how the timer is configured in the TMOD SFR; however, these timers always count up. What is Configurable is how and when they increment in value. k) P0 (Port 0, address 90h, bit addressable)

31

This is port 0 latch. Each bit of this SFR corresponds to one of the pins on a micro controller. Any data to be outputted to port 0 is first written on P0 register. For e.g., bit 0 of port 0 is pin P0.0, bit 7 is pin p0.7. Writing a value of 1 to a bit of this SFR will send a high level on the corresponding I/O pin whereas a value of 0 will bring it to low level. l) P1 (port 1, address 90h, bit addressable) This is port latch1. Each bit of this SFR corresponds to one of the pins on a micro controller. Any data to be outputted to port 0 is first written on P0 register. For e.g., bit 0 of port 0 is pin P1.0, bit 7 is pin P1.7. Writing a value of 1 to a bit of this SFR will send a high level on the corresponding I/O pin whereas a value of 0 will bring it to low level m) P2 (port 2, address 0A0h, bit addressable) : This is a port latch2. Each bit of this SFR corresponds to one of the pins on a micro controller. Any data to be outputted to port 0 is first written on P0 register. For e.g., bit 0 of port 0 is pin P2.0, bit 7 is pin P2.7. Writing a value of 1 to a bit of this SFR will send a high level on the corresponding I/O pin whereas a value of 0 will bring it to low level. n) P3(port 3,address B0h, bit addressable) : This is a port latch3. Each bit of this SFR corresponds to one of the pins on a micro controller. Any data to be outputted to port 0 is first written on P0 register. For e.g., bit 0 of port 0 is pin P3.0, bit 7 is pin P3.7. Writing a value of 1 to a bit of this SFR will send a high level on the corresponding I/O pin whereas a value of 0 will bring it to low level o) IE (interrupt enable, 0A8h): The Interrupt Enable SFR is used to enable and disable specific interrupts. The low 7 bits of the SFR are used to enable/disable the specific interrupts, where the MSB bit is used to enable or disable all the interrupts. Thus, if the high bit of IE is 0 all interrupts are disabled regardless of whether an individual interrupt is enabled by setting a lower bit.

32

p) IP (Interrupt Priority, 0B8h) The interrupt priority SFR is used to specify the relative priority of each interrupt. On 8051, an interrupt maybe either low or high priority. An interrupt may interrupt interrupts. For e.g., if we configure all interrupts as low priority other than serial interrupt. The serial interrupt always interrupts the system, even if another interrupt is currently executing. However, if a serial interrupt is executing no other interrupt will be able to interrupt the serial interrupt routine since the serial interrupt routine has the highest priority.

q) PSW (Program Status Word, 0D0h) The program Status Word is used to store a number of important bits that are set and cleared by 8051 instructions. The PSW SFR contains the carry flag, the auxiliary carry flag, the parity flag and the overflow flag. Additionally, it also contains the register bank select flags, which are used to select, which of the R register banks currently in use.

r) SBUF (Serial Buffer, 99h) SBUF is used to hold data in serial communication. It is physically two registers. One is writing only and is used to hold data to be transmitted out of 8051 via TXD. The other is read only and holds received data from external sources via RXD. Both mutually exclusive registers use address 99h. I/O ports: 33

One major feature of a microcontroller is the versatility built into the input/output (I/O) circuits that connect the 8051 to the outside world. The main constraint that limits numerous functions is the number of pins available in the 8051 circuit. The DIP had 40 pins and the success of the design depends on the flexibility incorporated into use of these pins. For this reason, 24 of the pins may each used for one of the two entirely different functions which depend, first, on what is physically connected to it and, then, on what software programs are used to program the pins.

PORT 0 Port 0 pins may serve as inputs, outputs, or, when used together, as a bi directional low-order address and data bus for external memory. To configure a pin as input, 1 must be written into the corresponding port 0 latch by the program. When used for interfacing with the external memory, the lower byte of address is first sent via PORT0, latched using Address latch enable (ALE) pulse and then the bus is turned around to become the data bus for external memory. PORT 1 Port 1 is exclusively used for input/output operations. PORT 1 pins have no dual function. When a pin is to be configured as input, 1 is to be written into the corresponding Port 1 latch.

PORT 2 Port 2 maybe used as an input/output port. It may also be used to supply a high order address byte in conjunction with Port 0 low-order byte to address external memory. Port 2 pins are momentarily changed by the address control signals when supplying the high byte a 16-bit address. Port 2 latches remain stable when external memory is addressed, as they do not have to be turned around (set to 1) for data input as in the case for Port 0.

34

PORT 3 Port 3 may be used to input /output port. The input and output functions can be programmed under the control of the P3 latches or under the control of various special function registers. Unlike Port 0 and Port 2, which can have external addressing functions and change all eight-port b se, each pin of port 3 maybe individually programmed to be used as I/O or as one of the alternate functions. The Port 3 alternate uses are:

Pin P3.0 - RXD P3.1 - TXD P3.2 - INTO 0 P3.3 - INTO 1 P3.4 - T0 P3.5 T1 P3.6 - WR P3.7 - RD

Alternate Use Serial data input Serial data output External interrupt 0 External interrupt 1 External Timer 0 input External timer 1 input External memory write pulse External memory read pulse SBUF

SFR

SBUF TCON.1 TCON.3 TMOD TMOD -

TIMERS
On-chip timing/counting facility has proved the capabilities of the microcontroller for implementing the real time application. These includes pulse counting, frequency measurement, pulse width measurement, baud rate generation, etc,. Having sufficient number of timer/counters may be a need in a certain design application. The 8051 has two timers/counters. They can be used either as timers to generate a time delay or as counters to 35

count events happening outside the microcontroller. Let discuss how these timers are used to generate time delays and we will also discuss how they are been used as event counters. PROGRAMMING 8051 TIMERS The 8051 has timers: Timer 0 and Timer1.they can be used either as timers or as event counters. Let us first discuss about the timers registers and how to program the timers to generate time delays. BASIC RIGISTERS OF THE TIMER Both Timer 0 and Timer 1 are 16 bits wide. Since the 8051 has an 8-bit architecture, each 16-bit timer is accessed as two separate registers of low byte and high byte. TIMER 0 REGISTERS

The 16-bit register of Timer 0 is accessed as low byte and high byte. the low byte register is called TL0(Timer 0 low byte)and the high byte register is referred to as TH0(Timer 0 high byte).These register can be accessed like any other register, such as A,B,R0,R1,R2,etc.for example, the instruction MOV TL0, #4Fmoves the value 4FH into TL0,the low byte of Timer 0.These registers can also be read like any other register.

D15 D14 D13

D12

D11

D10

D9 36

D8

D7

D6

D5

D4 D3 D2

D1

D0

TH0

TL0

TIMER 1 REGISTERS Timer 1 is also 16-bit register is split into two bytes, referred to as TL1 (Timer 1 low byte) and TH1(Timer 1 high byte).these registers are accessible n the same way as the register of Timer 0. TMOD (timer mode) REGISTER Both timers 0 and 1 use the same register, called TMOD, to set the various timer operation modes. TMOD is an 8-bit register in which the lower 4 bits are set aside for Timer 0 and the upper 4 bits for Timer 1.in each case; the lower 2 bits are used to set the timer mode and the upper 2 bits to specify the operation.

MODES: 37

M1, M0: M0 and M1 are used to select the timer mode. There are three modes: 0, 1, 2.Mode 0 is a 13-bit timer, mode 1 is a 16-bit timer, and mode 2 is an 8-bit timer. We will concentrate on modes 1 and 2 since they are the ones used most widely. we will soon describe the characteristics of these modes, after describing the reset of the TMOD register.

GATE

Gate control when set. The timer/counter is enabled only while the INTx pin is high and the TRx control pin is. set. When cleared, the timer is enabled.

C/T

Timer or counter selected cleared for timer operation (Input from internal system clock).set for counter operation (input TX input pin).

M1 M0 M1 0 M0 0

Mode bit 1 Mode bit 0 MODE 0 Operating Mode 13-bit timer mode 8-bit timer/counter THx with TLx as 5-bit prescaler.

16-bit timer mode 16-bit timer/counters THx with TLx are cascaded; there is no prescaler

8-bit auto reload 8-bit auto reload timer/counter;THx 38

Holds a value that is to be reloaded into TLx each time it overflows. 1 1 3 Split timer mode.

TMOD Register C/T (clock/timer): This bit in the TMOD register is used to decide whether the timer is used as a delay generator or an event counter. If C/T=0, it is used as a timer for time delay generation. The clock source for the time delay is the crystal frequency of the 8051.this section is concerned with this choice. The timers use as an event counter is discussed in the next section. EX: Find the values of TMOD to operate as timers in the following modes. (a) Mode 1 Timer 1 (b) Mode 2 Timer 0.Mode 2 Timer 1 (c) Mode 0 Timer 1 Solution: (a)TMOD is 00010000 = 10H The gate control bit and C/T bit are made 0, and the unused timer(Timer 0 bit is also 0) (b) TMOD is 01010010=52H (c) TMOD is 00000000H = 00H Note: 8051 Timers use 1/12 of XTAL frequency, regardless of machine cycle time.

39

Clock source for timer As you know, every timer needs a clock pulse to tick. What is the source of the clock pulse for the 8051 timers? If C/T=0, the crystal frequency attached to the 8051 is the source of the clock for the timer. This means that the size of the crystal frequency attached to the 8051 also decides the speed at which the 8051 timer ticks. The frequency for the timer is always 1/12th the frequency of the crystal attached to the 8051. Although various 8051-based systems have an XTAL frequency of 10MHz,we will concentrate on the XTAL frequency of 11.0592MHz.the reason behind such an odd number has to do with the baud rate for serial communication of the 8051.XTAL =11.0592MHz allows the 8051 system to communicate with the IBM PC with no errors. Gate

The other bit of the TMOD register id the GATE bit. Notice in the TMOD register in the below example figure that both Timers 0 and 1 have the GATE bit. What is its purpose? Every timer has a means of starting and stopping. Some timers do this by software, some by hardware, and some have both software and hardware controls. the timers in the 8051 have is achieved by the instructions SETB TR1 and CLR TR1 for Timer 1,and SETB TR0 and CLR TR0 for Timer0.the SETB instruction starts it, and it is stopped by the CLR instruction. These instructions start and stop the timers as long as GATE =0 in the TMOD register. The hardware way of starting and stopping the timer by an external source GATE =0, meaning that no external hardware is needed to start and stop the timers. in using software to start and stop the timer where GATE=0,all we need are the instructions SETB TRx and CLR TRx. Now that we have this basic understanding of the role of the TMOD register, we will look at the timers modes and how they are programmed to create a time delay. Because modes 1 and 2 are so widely used, we describe each of them in detail.

40

EX: How are timers 0 and 1 started and stopped by instruction? Solution: The timers are started by using instructions to set timer start bits TR0 and TR1,which are called timer run control bits. They can be cleared by clearing these bits. When a timer counts to its maximum value, it sets a flag TF0 or TF1.at this point, it is necessary to know more about the bits TF and TR for timers 0 and 1.while TMOD controls the timer modes, another register called the TCON controls the timer/counter operations. The lower four bits of TCON cater to interrupt functions, but the upper four bits are for timer operations. The details of the TCON register are shown below.

MSB

LSB

TF1

TR1

TF0

TR0

IE1

IT1

IE0

IT0

BIT TCON.7 TCON.6 TCON.5 TCON.4

SYMBOL TF1 TR1 TF0 TR0

FUNCTION Timer 1 overflows flag Timer 1 run control bit Timer 0 overflows flag Timer 0 run control bit

Some assemblers dont allow the use of TF0, TR0, etc.in programs, but instead need the use of these as bits of TON. For example, TF1 is TCON.7 and TR1 is TCON.6.

41

Mode 1 programming

The following are the characteristic and operations of mode 1: 1. it is a 16-bit timer: therefore, it allows values of 0000 to FFFFH to be loaded into the timers registers TL and TH. 2. After TH and TL are loaded with 16-bit initial value, the timer must be started. This is done by SETB TR0 for Timer 0 and SET TR1 for Timer1. 3. After the timer is started, it starts to count up. it counts up until it reaches its limit of FFFFH. When it rolls over from FFFFH to 0000, it sets high a flag bit called TF (timer flag).this timer flag can be monitored. When this timer flag is raised, one option would be to stop the timer with the instructions CLR TR0 or CLR TR1 for Timer 0 and Timer 1, respectively.again, it must be noted that each timer has its own timer flag: TF0 for Timer 0, and TF1 for Timer 1. 4. After the timer reaches its limit its limit and rolls over, in order to repeat the process the registers TH and TL must be reloaded with the original value and TF must be reset to 0

XTAL oscillat or .

/12 _ C/T =0 TR

TH

TL

TF

TF goes high When FFFF0

overflow flag

42

Steps to program in mode 1


1. Load the TMOD value register indicating which timer (Timer 0 or Timer 1) is to be used and which timer mode (0 or 1) is selected. 2. Load register TL and TH with initial count values. 3. Start the timer. 4. Keep monitoring the timer flag (TF) with the JNB TFx, target instruction to see if it is raised. Get out of the loop when TF becomes high. 5. Stop the timer. 6. Clear the TF flag for the next round 7. Go back to Step 2 to load TH and TL again.

43

EX: In the following program, we are creating a square wave of 50% duty cycle (with equal portion high and low) on the P1.5 bit. Timer 0 is used to generate the time delay. Analyze the program. Solution: MOV HERE: MOV MOV CPL SJMP TMOD, # 01 TL0, #0F2H TH0, #0FFH P1.5 HERE ; Timer 0, mode 1 (16 bit mode) ; TL0 =F2H, the low byte ; TH0 =FFH, the High byte ;toggle P1.5 ; load TH , TL again

ACALL DELAY ; ------------ delay using Timer 0 DELAY: SETB AGAIN: JNB CLR CLR RET TR0 TF0, AGAIN TR0 TF0 ; start Timer 0 ; monitor Timer 0 flag until ; It rolls over ; stop Timer 0 ; clear Timer 0 flag

Finding values to be loaded into the timer Assuming that we know the amount of timer delay we need, the question is how to find the values needed for the TH, TL registers. To calculate the values to be loaded into the TL and TH registers. 1. Divide the desired time delay by 1.085s. 2. Perform 65536-n, where n is the decimal value we got in step 1. 44

3. Convert the result of step 2 to hex, where yyxx is the initial hex value to be loaded into the timers registers. 4. Set TL=xx and TH=yy.

Generating a large time delay


Size of the time delay depends on two factors; (a) the crystal frequency and (b) the timers 16-bit register in mode 1.both of these factors are beyond the control of the 8051 programmer. We saw earlier that the largest time delay is achieved by making both TH and TL zero. what if that is not enough? See the below example. Ex: Assuming XTAL = 2MHz,write a program to generate a pulse train 2 seconds period on pin P2.4.USse Timer 1 in mode 1. Solution: MOV REPT: BACK: MOV CPL MOV MOV SETB AGAIN: JNB CLR CLR DJNZ SJMP TMOD, #10H R0, #28 P2.4 TL1, #00H TH1, #00H TR1 TF1, AGAIN TR1 TF1 R0, BACK REPT ; Timer 1, mode 1 ; counter for multiple delays ; complement P2.4 ; load count value in TL1 ; load count value in th1 ; start timer ; stay until timer roller over ; stop timer ; clear timer flag ; if R0 is not zero, reload timer ; repeat for continuous pulse generation Calculation = 28x 35.75ms =1001 ms.

45

Mode 0

Mode 0 is exactly like mode 1 except that it is a 13-bit timer instead of 16-bit.the 13-bit counter can hold values between 0000 to 1FFFH in TH-TL. Therefore, when the timer reaches its maximum of 1FFH, it rolls over to 0000, and TF is raised.

Mode 2 programming The following are the characteristics and operations of mode 2. 1. It is 8-bit timer; therefore, it allows only values if 00 to FFH to be loaded into the timers register TH.

46

2. After TH is loaded with the 8-bit value, the 8051 gives a copy of it to TL. Then the timer must be started. This is done by the instruction SETB TR0 for Timer 0 and SETB TR1 for Timer 1.this is just like mode 1. 3. After the timer is started, it started, it start to count up by incrementing the TL register. It counts up until it reaches its limit of FFH. When it rolls over from FFH to 00, it sets high the TF (timer flag).if we are using Timer 0, TF0 goes high; if we are using Timer 1, and TF1 is raised.

Overflow flag

XTAL Oscillator

TL /12

TF

TH TR TF goes high when FF---0 4. When the TL registers rolls from FFH to 0 and TF is set to 1, TL is reloaded automatically with the original value kept by the TH register. To repeat the process, we must simply clear TF and let it go without any need by the programmer to reload the original value. This makes mode 2 an auto-reload, in contrast with mode 1 in which the programmer has to reload TH and TL.

47

It must be emphasized that mode 2 is an 8-bit timer. However, it has an auto-reloading capability. In auto-reload TH is loaded with the initial count and a copy of it is given to TL. This reloading leaves TH unchanged, still holding a copy of the original value. This mode has many applications, including setting the baud rate in serial communication.

Steps to program in mode 2 To generate a time delay using the timers mode 2 take the following steps. 1. Load the TMOD value register indicting which timer (Timer 0 or Timer 1) is to be used, and select the timer mode(mode 2). 2. Load the TH registers with the initial count value. 3. start the timer 48

4. Keep monitoring the timer flag (TF) with the JNB TFx, target instruction to see whether it is raised. get out of the loop when TF goes high. 5. clear the TF flag 6. Go back to step 4, since mode 2 is auto-reload.

SERIAL COMMUNICATION: Computers can transfer data in two ways: parallel and serial. In parallel data transfers, often 8 or more lines (wire conductors) are used to transfer data to a device that is only a few feet away. Examples of parallel transfers ae printers and hard disks; each uses cables with many wire strips. Although in such cases a lot of data can be transferred in a short amount of time by using many wires in parallel, the distance cannot be great. To transfer to a device located many meters away, the serial method is used. In serial communication, the data is sent one bit at a time, in contrast to parallel communication, in which the data is sent a byte or more at a time. Serial communication of the 8051 is the topic of this chapter. The 8051 has serial communication capability built into it, there by making possible fast data transfer using only a few wires. If data is to be transferred on the telephone line, it must be converted from 0s and 1s to audio tones, which are sinusoidal-shaped signals. This conversion is performed by a peripheral device called a modem, which stands for modulator/demodulator. Serial data communication uses two methods, asynchronous and synchronous. The synchronous method transfers a block of data at a time, while the asynchronous method transfers a single byte at a time. In data transmission if the data can be transmitted and received, it is a duplex transmission. This is in contrast to simplex transmissions such as with printers, in which the computer only sends data. Duplex transmissions can be half or full duplex, depending on whether or not the data transfer can be simultaneous. If data is transmitted one way at a time, it is referred to as half duplex. If the data can go both ways at the same time, it is full duplex. Of course, full duplex requires two wire conductors for the data lines, one for transmission and one for reception, in order to transfer and receiv e data simultaneously. Asynchronous serial communication and data framing 49

The data coming in at the receiving end of the data line in a serial data transfer is all 0s and 1s; it is difficult to make sense of the data unless the sender and receiver agree on a set of rules, a protocol, on how the data is packed, how many bits constitute a character, and when the data begins and ends. Start and stop bits Asynchronous serial data communication is widely used for character-oriented transmissions, while block-oriented data transfers use the synchronous method. In the asynchronous method, each character is placed between start and stop bits. This is called framing. In the data framing for asynchronous communications, the data, such as ASCII characters, are packed between a start bit and a stop bit. The start bit is always one bit, but the stop bit can be one or two bits. The start bit is always a 0 (low) and the stop bit (s) is 1 (high). Data transfer rate The rate of data transfer in serial data communication is stated in bps (bits per second). Another widely used terminology for bps is baud rate. However, the baud and bps rates are not necessarily equal. This is due to the fact that baud rate is the modem terminology and is defined as the number of signal changes per second. In modems a single change of signal, sometimes transfers several bits of data. As far as the conductor wire is concerned, the baud rate and bps are the same, and for this reason we use the bps and baud interchangeably. The data transfer rate of given computer system depends on communication ports incorporated into that system. For example, the early IBMPC/XT could transfer data at the rate of 100 to 9600 bps. In recent years, however, Pentium based PCS transfer data at rates as high as 56K bps. It must be noted that in asynchronous serial data communication, the baud rate is generally limited to 100,000bps. RS232 Standards To allow compatibility among data communication equipment made by various manufacturers, an interfacing standard called RS232 was set by the Electronics Industries Association (EIA) in 1960. In 1963 it was modified and called RS232A. RS232B AND RS232C were issued in 1965 and 1969, respectively. Today, RS232 is the most widely used serial I/O interfacing standard. This standard is used in PCs and numerous types of 50

equipment. However, since the standard was set long before the advert of the TTL logic family, its input and output voltage levels are not TTL compatible. In RS232, a 1 is represented by -3 to -25V, while a 0 bit is +3 to +25V, making -3 to +3 undefined. For this reason, to connect any RS232 to a microcontroller system we must use voltage converters such as MAX232 to convert the TTL logic levels to the RS232 voltage levels, and vice versa. MAX232 IC chips are commonly referred to as line drivers. RS232 pins RS232 cable, commonly referred to as the DB-25 connector. In labeling, DB-25P refers to the plug connector (male) and DB-25S is for the socket connector(female). Since not all the pins are used in PC cables, IBM introduced the DB-9 Version of the serial I/O standard, which uses 9 pins only, as shown in table. DB-9 pin connector

12345 6789 (Out of computer and exposed end of cable) Pin Functions: Pin 1 2 3 4 5 6 7 8 9 Description Data carrier detect (DCD) Received data (RXD) Transmitted data (TXD) Data terminal ready(DTR) Signal ground (GND) Data set ready (DSR) Request to send (RTS) Clear to send (CTS) Ring indicator (RI)

Note: DCD, DSR, RTS and CTS are active low pins. The method used by RS-232 for communication allows for a simple connection of three lines: Tx, Rx, and Ground. The three essential signals for 2 way RS-232

51

Communications are these: TXD: carries data from DTE to the DCE. RXD: carries data from DCE to the DTE SG: signal ground

8051 connection to RS232


The RS232 standard is not TTL compatible; therefore, it requires a line driver such as the MAX232 chip to convert RS232 voltage levels to TTL levels, and vice versa. The interfacing of 8051 with RS232 connectors via the MAX232 chip is the main topic. The 8051 has two pins that are used specifically for transferring and receiving data serially. These two pins are called TXD and RXD and a part of the port 3 group (P3.0 and P3.1). pin 11 of the 8051 is assigned to TXD and pin 10 is designated as RXD. These pins are TTL compatible; therefore, they require a line driver to make them RS232 compatible. One such line driver is the MAX232 chip. MAX232 converts from RS232 voltage levels to TTL voltage levels, and vice versa. One advantage of the MAX232 chip is that it uses a +5V power source which, is the same as the source voltage for the 8051. In the other words, with a single +5V power supply we can power both the 8051 and MAX232, with no need for the power supplies that are common in many older systems. The MAX232 has two sets of line drivers for transferring and receiving data. The line drivers used for TXD are called T1 and T2, while the line drivers for RXD are designated as R1 and R2. In many applications only one of each is used.

TXD

RXD TXD

2 3 5

Embedded Controller

RXD GND

MAX 232

52

Baud rate in the 8051 The 8051 transfers and receives data serially at many different baud rates. The baud rate in the 8051 is programmable. The is done with the help of Timer1. The 8051 divides the crystal frequency by 12 to get the machine cycle frequency. In the case of XTAL=11.0592MHZ, the machine cycle frequency is 921.6 KHz (11.0592MHz/12=921.6KHz). the 8051s serial communication UART circuitry divides the machine cycle frequency of 921.6khz divided by 32 once more before it is used by Timer 1 to set the Baud rate. Therefore, 921.6 kHz divided by 32 gives 28,800 Hz. This is the number well use to find the Timer 1 value to set baud rate. Baud rate 9600 4800 2400 1200 TH1(Decimal) -3 -6 -12 -24 TH1(Hex) FD FA F4 E8

NOTE: XTAL=11...592MHz SBUF register SBUF is an 8-bit register used solely for serial communication in the 8051. for a byte of data to be transferred via the TXD line, it must be placed in the SBUF register. Similarly, SBUF holds the byte of data when it is received by the 8051s RXD line. SBUF can be accessed like any other register in the 8051. Look at the following the examples of how this register is accessed.
MOV MOV MOV SBUF, #D SBUF, A A, SBUF ; load SBUF=44h, ASCII for D ; copy accumulator into SBUF ; copy SBUF into accumulator

The moment a byte is written into SBUF, it is framed with the start and stop bits and transferred serially via the TXD pin. Similarly, when the bits are received serially via RXD, the 8051 defames it by eliminating the stop and start bits, making a byte out of the data received, and then placing it in the SBUF.

53

SCON (serial control) register The SCON register is an 8-bit register used to program the start bit, stop bit, and data bits of data framing, among other things. The following describes various bits of the SCON register.

SM0 SM1 SM2 REN TB8 RB8 TI RI SM0 SM1 SM2 REN TB8 RB8 TI RI software. Note: Make SM2, TB8, and RB8=0. SCON.7 SCON.6 SCON.5 SCON.4 SCON.3 SCON.2 SCON.1 SCON.0 Serial port mode specifier Serial port mode specifier Used for multiprocessor communication. (make it 0.) Set/cleared by software to enable/disable reception Not widely used Not widely used Transmit interrupt flag. Set by hardware at the beginning Of the stop bit in mode 1. Must be cleared by software. Receive interrupt flag. Set by hardware halfway through the stop bit time mode 1. Must be cleared by

SM0, SM1
SM0 and SM1 are D7 and D6 of the SCON register, respectively. These two bits determine the framing of data by specifying the number of bits per character and the start and stop bits. They take the following combinations. SM0 0 0 1 1 SM1 0 1 0 1 FUNCTION Serial Mode 0 Serial Mode 1, 8-bit data, 1 stop bit, 1 start bit Serial Mode 2 Serial Mode 3 54

Of the 4 serial modes, only mode 1 is of interest to us. In the SCON register, when serial mode 1 is chosen, the data framing is 8 bits, 1 stop bit, and 1 start bit, which makes it compatible with the COM port of IBM/compatible PCs. More importantly, serial mode 1 allows the baud rate to be variable and is set by Timer 1 of the 8051. In serial mode 1, for each character a total of 10 bits are transferred, where the first bit is the start bit, followed by 8 bits of data, and finally 1 stop bit.

MODE 0 In mode 0, the data are transferred through the RXD pin, while clock pulses appear on the TXD pin. The bout rate is fixed at 1/12 the quartz oscillator frequency. On transmit, the least significant bit (LSB bit) is being sent/received first. (received). TRANSMIT Data transmission in form of pulse train automatically starts on the pin RXD at the moment the data has been written to the SBUF register.In fact, this process starts after any instruction being performed on this register. Upon all 8 bits have been sent, the bit TI in the SCON register is automatically set.

RECEIVE

55

Starts data receiving through the pin RXD once two necessary conditions are met: bit REN=1 and RI=0 (both bits reside in the SCON register). Upon 8 bits have been received, the bit RI (register SCON) is automatically set, which indicates that one byte is received.

Since, there are no START and STOP bits or any other bit except data from the SBUF register, this mode is mainly used on shorter distance where the noise level is minimal and where operating rate is important. A typical example for this is I/O port extension by adding cheap IC circuit ( shift registers 74HC595, 74HC597 and similar).

Mode 1

56

In Mode1 10 bits are transmitted through TXD or received through RXD in the following manner: a START bit (always 0), 8 data bits (LSB first) and a STOP bit (always 1) last. The START bit is not registered in this pulse train. Its purpose is to start data receiving mechanism. On receive the STOP bit is automatically written to the RB8 bit in the SCON register. TRANSMIT A sequence for data transmission via serial communication is automatically started upon the data has been written to the SBUF register. End of 1 byte transmission is indicated by setting the TI bit in the SCON register.

57

RECEIVE Receiving starts as soon as the START bit (logic zero (0)) appears on the pin RXD. The condition is that bit REN=1and bit RI=0. Both of them are stored in the SCON register. The RI bit is automatically set upon receiving has been completed.

The Baud rate in this mode is determined by the timer 1 overflow time.

MODE 2 SM2 SM2 is the D5 bit of the SCON register. This bit enables the multiprocessing capability of the 8051. For our applications, we will make SM2=0 since we are not using the 8051 in a multi processor environment. REN The REN (receive enable) bit is D4 of the SCON register. The REN bit is also referred to as SCON.4 since SCON is a bit-addressable register. When the REN bit is high, it allows the 8051 to receive data on the RXD pin of the 8051. As a result if we want the 8051 to both transfer and receive data, REN must be set to 1. By making REN=0, the receiver is disabled. Making REN=1 or REN=0 can be achieved by the instructions SETB SCON.4 and CLR SCON.4, respectively. Notice that these instructions use the bitaddressable features of the register SCON. This bit can be used to block any serial data reception and is an extremely important in the SCON register. 58

TB8 TB8 (transfer bit 8) is bit D3 of SCON. It is used for serial modes 2 and 3. we make TB8=0 since it is not used in our applications. RB8 RB8 (receive bit 8) is bit D2 of the SCON register. In serial mode 1, this bit gets a copy of the stop bit when an 8-bit data is received. This is (as is the case for TB8) is rarely used anymore. In all our applications we will make RB8=0. Like TB8, the RB8 bit is also used in serial modes 2 and 3.

TRANSMIT TI (transmit interrupt) is bit D1 of the SCON register. This is an extremely important flag bit in the SCON register. When the 8051 finishes the transfer of the 8-bit character, it raises the TI flag to indicate that it is ready to transfer another byte. The TI bit is raised at the beginning of the stop bit. 59

RECEIVE RI (receive interrupt) is the D0 of the SCON register. This is another extremely important flag bit in the SCON register. When the 8051 receives data serially via RXD, it gets rid of the start and stop bits and places the byte in the SBUF register. Then it raises the RI flag bit to indicate that a byte has been received and should be picked up before it is lost. RI is raised halfway through the stop bit.

Mode 3 Mode 3 is the same as Mode 2 except the baud rate. In Mode 3 is variable and can be selected.

60

FLOW CHART: TX Loop:


START Initialization: Load SFRs with Respective values Copy data into Accumulator (or) memory location

Copy into SBUF

Is TI = = 1 Clr TI STOP

RX Loop:
START Initialization: Load SFRs with Respective values

Is RI = = 1 Clr RI

Copy SBUF into M emory STOP

61

BAUD RATE CALCULATION:


Internal timer stages are as fallows

XClk

Divided by 12

Divided by 32

Divided by X Baud Rate UART

Divided by X box can be replaced with T1 timer so that by changing the value of timer we can obtain the required baud rate.
Let XClk Baud Rate For attaining 9600 baud Rate, X can be calculated as = = 11.0592 x 106 / 12 / 16 / 2 / 9600 3 = = 11.0592 Mhz (XClk / 12 / 16 / 2 / X )

So set the 2s Complement of 3 in Timer 1 so that we can achieve 9600 baud rates. Note: Assuming 8-bit Auto reload mode and 8-bit variable baud rate modes. Doubling the baud rate in the 8051: There are two ways to increase the baud rate to data transfer in the 8051. 1. Use a higher- frequency crystal. 2. Change a bit in the PCON register, shown below. SMOD -- -- -- GF1 GF0 PD IDL Option1 is not feasible in many situations since the system crystal is fixed. More 62

Importantly, it is not feasible because the new crystal may not be compatible with the IBM PC serial COM ports baud rate. Therefore, we will explore option2. there is a software way to double the baud rate of the 8051 while the crystal frequency is fixed. This is done with the register called PCON (power control). The PCON register is an 8-bit register. Of the 8 bits, some are unused, and some are used for the power control capability of the 8051. The bit that is used for the serial communication is D7, the SMOD (serial mode) bit. When the 8051 is powered up, D7 (SMOD) of this PCON register is zero. We can set it to high by software and thereby double the baud rate. The following sequence of instructions must be used to set high D7 of PCON, since it is not a bit-addressable register:
MOV A, PCON ; place a copy a of PCON in ACC SETB ACC.7 ; make D7=1 MOV PCON, A ; changing any other bits

To see how the baud rate is double with this method, we show the role of the SMOD bit (D7 bit of the PCON register), which can be 0 or 1. we discuss each case.

Baud rates for SMOD =0 When SMOD=0, the 8051 divides 1/12 of the crystal frequency by 32 and uses that frequency for Timer 1 to set the baud rate. In the case of XTAL=11.0592MHZ we have:
Machine cycle freq.=11.0592 MHz/12 = 921.6KHz And 921.6 KHz/32 = 28,800 Hz since SMOD=0

This is the frequency used by Timer 1 to set the baud rate. This has been the basis of all the examples so far since it is the default when the 8051 is powered up. The baud rate for SMOD=0 was listed in above table. Baud rates for SMOD = 1 With the fixed crystal frequency, we can double the baud rate by making SMOD=1. When the SMOD bit (D7 of the PCON register) is set to 1, 1/12 of XTAL is divided by 16 (instead of 32) and that is the frequency used by Timer 1 to set the baud rate. In the case of XTAL=11.0592 MHz, we have:
Machine cycle freq. = 11.0592 MHz / 12 = 921.6 KHz And

63

921.6 KHz / 16 = 57,600 Hz since SMOD = 1

This is the frequency used by Timer 1 to set the baud rate. Table: Baud Rate comparison for SMOD = 0 and SMOD = 1 TH1 (Decimal) (Hex) SMOD = 0 -3 FD 9,600 -6 FA 4,800 -12 F4 2,400 -24 E8 1,200 Note: XTAL=11.0592 MHz. baud rates are doubled when SMOD=1. SMOD = 1 19,200 9,600 4,800 2,400

Table: shows that the values loaded into TH1 are the same for both cases; however, the

INTERRUPTS: Interrupts are hardware signals that are used to determine conditions that exist in external and internal circuits. Any interrupt can cause the 8051 to perform a hardware call to an interrupt handling subroutine that is located at a predetermined absolute address in the program memory. Five interrupts are provided in the 8051. Three of these are generated automatically by the internal operations: Timer flag 0, Timer Flag 1, and the serial port interrupt (RI or TI) Two interrupts are triggered by external signals provided by the circuitry that is connected to the pins INTO 0 and INTO1. The interrupts maybe enable or disabled, given priority or otherwise controlled by altering the bits in the Interrupt Enabled (IE) register, Interrupt Priority (IP) register, and the Timer Control (TCON) register. . These interrupts are mask able i.e. they can be disabled. Reset is a non maskable interrupt which has the highest priority. It is generated when a high is applied to the reset pin. Upon reset, the registers are loaded with the default values. Each interrupt source causes the program to do store the address in PC onto the stack and causes a hardware call to one of the dedicated addresses in the program memory. The appropriate memory locations for each for each interrupt are as follows:

64

Interrupt RESET IE0 (External interrupt 0) TF0 (Timer 0 interrupt) IE1 (External interrupt 1) TF1 (Timer 1 interrupt) SERIAL Functions of micro controller in main unit are 1. 2. 3. 4. 5. 6. of

Address 0000 0003 000B 0013 001B 0023

Sends appropriate commands to ADC to start conversion, Collects the output of ADC for every 10 sec and stores in buffer, Sends command to the modem for dialing the base every 80 sec, Sends data in a serial manner to MODEM, After data gets transmitted sends command for disconnection. Sends appropriate information to the display unit as per status the communication medium.

RELAY: A relay is an electrical switch that opens and closes under the control of another electrical circuit. In the original form, the switch is operated by an electromagnet to open or close one or many sets of contacts. It was invented by Joseph Henry in 1835. Because a relay is 65

able to control an output circuit of higher power than the input circuit, it can be considered to be, in a broad sense, a form of an electrical amplifier. Operation When a current flows through the coil, the resulting magnetic field attracts an armature that is mechanically linked to a moving contact. The movement either makes or breaks a connection with a fixed contact. When the current to the coil is switched off, the armature is returned by a force approximately half as strong as the magnetic force to its relaxed position. Usually this is a spring, but gravity is also used commonly in industrial motor starters. Most relays are manufactured to operate quickly. In a low voltage application, this is to reduce noise. In a high voltage or high current application, this is to reduce arcing. If the coil is energized with DC, a diode is frequently installed across the coil, to dissipate the energy from the collapsing magnetic field at deactivation, which would otherwise generate a spike of voltage and might cause damage to circuit components. Some automotive relays already include that diode inside the relay case. Alternatively a contact protection network, consisting of a capacitor and resistor in series, may absorb the surge. If the coil is designed to be energized with AC, a small copper ring can be crimped to the end of the solenoid. This "shading ring" creates a small out-of-phase current, which increases the minimum pull on the armature during the AC cycle.[1] By analogy with the functions of the original electromagnetic device, a solid-state relay is made with a thyristor or other solid-state switching device. To achieve electrical isolation an optocoupler can be used which is a light-emitting diode (LED) coupled with a photo transistor.

66

Types of relay

Small relay as used in electronics Latching relay A latching relay has two relaxed states (bistable). These are also called 'keep' relays. When the current is switched off, the relay remains in its last state. This is achieved with a solenoid operating a ratchet and cam mechanism, or by having two opposing coils with an over-center spring or permanent magnet to hold the armature and contacts in position while the coil is relaxed, or with a remnant core. In the ratchet and cam example, the first pulse to the coil turns the relay on and the second pulse turns it off. In the two coil example, a pulse to one coil turns the relay on and a pulse to the opposite coil turns the relay off. This type of relay has the advantage that it consumes power only for an instant, while it is being switched, and it retains its last setting across a power outage. Reed relay A reed relay has a set of contacts inside a vacuum or inert gas filled glass tube, which protects the contacts against atmospheric corrosion. The contacts are closed by a magnetic field generated when current passes through a coil around the glass tube. Reed relays are capable of faster switching speeds than larger types of relays, but have low switch current and voltage ratings. See also reed switch.

67

Mercury-wetted relay A mercury-wetted reed relay is a form of reed relay in which the contacts are wetted with mercury. Such relays are used to switch low-voltage signals (one volt or less) because of its low contact resistance, or for high-speed counting and timing applications where the mercury eliminates contact bounce. Mercury wetted relays are position-sensitive and must be mounted vertically to work properly. Because of the toxicity and expense of liquid mercury, these relays are rarely specified for new equipment. See also mercury switch. Polarized relay A Polarized Relay placed the armature between the poles of a permanent magnet to increase sensitivity. Polarized relays were used in middle 20th Century telephone exchanges to detect faint pulses and correct telegraphic distortion. The poles were on screws, so a technician could first adjust them for maximum sensitivity and then apply a bias spring to set the critical current that would operate the relay. Machine tool relay A machine tool relay is a type standardized for industrial control of machine tools, transfer machines, and other sequential control. They are characterized by a large number of contacts (sometimes extendable in the field) which are easily converted from normallyopen to normally-closed status, easily replaceable coils, and a form factor that allows compactly installing many relays in a control panel. Although such relays once were the backbone of automation in such industries as automobile assembly, the programmable logic controller mostly displaced the machine tool relay from sequential control applications. Contactor relay A contactor is a very heavy-duty relay used for switching electric motors and lighting loads. With high current, the contacts are made with pure silver. The unavoidable arcing causes the contacts to oxidize and silver oxide is still a good conductor. Such devices are 68

often used for motor starters. A motor starter is a contactor with overload protection devices attached. The overload sensing devices are a form of heat operated relay where a coil heats a bi-metal strip, or where a solder pot melts, releasing a spring to operate auxiliary contacts. These auxiliary contacts are in series with the coil. If the overload senses excess current in the load, the coil is de-energized. Contactor relays can be extremely loud to operate, making them unfit for use where noise is a chief concern. Solid state contactor relay

25 amp or 40 amp solid state contactors A solid state contactor is a very heavy-duty solid state relay, including the necessary heat sink, used for switching electric heaters, small electric motors and lighting loads; where frequent on/off cycles are required. There are no moving parts to wear out and there is no contact bounce due to vibration. They are activated by AC control signals or DC control signals from Programmable logic controller (PLCs), PCs, Transistor-transistor logic (TTL) sources, or other microprocessor controls. Buchholz relay A Buchholz relay is a safety device sensing the accumulation of gas in large oil-filled transformers, which will alarm on slow accumulation of gas or shut down the transformer if gas is produced rapidly in the transformer oil.

69

Forced-guided contacts relay A forced-guided contacts relay has relay contacts that are mechanically linked together, so that when the relay coil is energized or de-energized, all of the linked contacts move together. If one set of contacts in the relay becomes immobilized, no other contact of the same relay will be able to move. The function of forced-guided contacts is to enable the safety circuit to check the status of the relay. Forced-guided contacts are also known as "positive-guided contacts", "captive contacts", "locked contacts", or "safety relays".

A solid state relay, which has no moving parts Solid-state relay A solid state relay (SSR) is a solid state electronic component that provides a similar function to an electromechanical relay but does not have any moving components, increasing long-term reliability. With early SSR's, the tradeoff came from the fact that every transistor has a small voltage drop across it. This collective voltage drop limited the amount of current a given SSR could handle. As transistors improved, higher current SSR's, able to handle 100 to 1,200 amps, have become commercially available. Compared to electromagnetic relays, they may be falsely triggered by transients. Overload protection relay One type of electric motor overload protection relay is operated by a heating element in series with the electric motor . The heat generated by the motor current operates a bi-metal strip or melts solder, releasing a spring to operate contacts. Where the overload relay is

70

exposed to the same environment as the motor, a useful though crude compensation for motor ambient temperature is provided.

Pole & Throw

Circuit symbols of relays. "C" denotes the common terminal in SPDT and DPDT types. Since relays are switches, the terminology applied to switches is also applied to relays. A relay will switch one or more poles, each of whose contacts can be thrown by energizing the coil in one of three ways:

Normally-open (NO) contacts connect the circuit when the relay is activated; the circuit is disconnected when the relay is inactive. It is also called a Form A contact or "make" contact.

71

Normally-closed (NC) contacts disconnect the circuit when the relay is activated; the circuit is connected when the relay is inactive. It is also called a Form B contact or "break" contact.

Change-over, or double-throw, contacts control two circuits: one normally-open contact and one normally-closed contact with a common terminal. It is also called a Form C contact or "transfer" contact. If this type of contact utilizes a "make before break" functionality, then it is called a Form D contact.

The following types of relays are commonly encountered:

SPST - Single Pole Single Throw. These have two terminals which can be connected or disconnected. Including two for the coil, such a relay has four terminals in total. It is ambiguous whether the pole is normally open or normally closed. The terminology "SPNO" and "SPNC" is sometimes used to resolve the ambiguity.

SPDT - Single Pole Double Throw. A common terminal connects to either of two others. Including two for the coil, such a relay has five terminals in total. DPST - Double Pole Single Throw. These have two pairs of terminals. Equivalent to two SPST switches or relays actuated by a single coil. Including two for the coil, such a relay has six terminals in total. It is ambiguous whether the poles are normally open, normally closed, or one of each.

The diagram on the package of a DPDT AC coil relay

72

DPDT - Double Pole Double Throw. These have two rows of change-over terminals. Equivalent to two SPDT switches or relays actuated by a single coil. Such a relay has eight terminals, including the coil.

QPDT - Quadruple Pole Double Throw. Often referred to as Quad Pole Double Throw, or 4PDT. These have four rows of change-over terminals. Equivalent to four SPDT switches or relays actuated by a single coil, or two DPDT relays. In total, fourteen terminals including the coil.

Applications Relays are used:

to control a high-voltage circuit with a low-voltage signal, as in some types of modems, to control a high-current circuit with a low-current signal, as in the starter solenoid of an automobile, to detect and isolate faults on transmission and distribution lines by opening and closing circuit breakers (protection relays),

A DPDT AC coil relay with "ice cube" packaging

to isolate the controlling circuit from the controlled circuit when the two are at different potentials, for example when controlling a mains-powered device from a low-voltage switch. The latter is often applied to control office lighting as the low voltage wires are easily installed in partitions, which may be often moved as needs 73

change. They may also be controlled by room occupancy detectors in an effort to conserve energy,

to perform logic functions. For example, the boolean AND function is realised by connecting NO relay contacts in series, the OR function by connecting NO contacts in parallel. The change-over or Form C contacts perform the XOR (exclusive or) function. Similar functions for NAND and NOR are accomplished using NC contacts. The Ladder programming language is often used for designing relay logic networks.
o

Early computing. Before vacuum tubes and transistors, relays were used as logical elements in digital computers. See ARRA (computer), Harvard Mark II, Zuse Z2, and Zuse Z3. Safety-critical logic. Because relays are much more resistant than semiconductors to nuclear radiation, they are widely used in safety-critical logic, such as the control panels of radioactive waste-handling machinery.

to perform time delay functions. Relays can be modified to delay opening or delay closing a set of contacts. A very short (a fraction of a second) delay would use a copper disk between the armature and moving blade assembly. Current flowing in the disk maintains magnetic field for a short time, lengthening release time. For a slightly longer (up to a minute) delay, a dashpot is used. A dashpot is a piston filled with fluid that is allowed to escape slowly. The time period can be varied by increasing or decreasing the flow rate. For longer time periods, a mechanical clockwork timer is installed.

Relay application considerations

A large relay with two coils and many sets of contacts, used in an old telephone switching system.

74

Several 30-contact relays in "Connector" circuits in mid 20th century 1XB switch and 5XB switch telephone exchanges; cover removed on one Selection of an appropriate relay for a particular application requires evaluation of many different factors:

Number and type of contacts - normally open, normally closed, changeover (double-throw) In the case of changeover, there are two types. This style of relay can be manufactured two different ways. "Make before Break" and "Break before Make". The old style telephone switch required Make-before-break so that the connection didn't get dropped while dialing the number. The railroad still uses them to control railroad crossings.

Rating of contacts - small relays switch a few amperes, large contactors are rated for up to 3000 amperes, alternating or direct current Voltage rating of contacts - typical control relays rated 300 VAC or 600 VAC, automotive types to 50 VDC, special high-voltage relays to about 15,000 V Coil voltage - machine-tool relays usually 24 VAC or 120 VAC, relays for switchgear may have 125 V or 250 VDC coils, "sensitive" relays operate on a few milliamperes

Package/enclosure - open, touch-safe, double-voltage for isolation between circuits, explosion proof, outdoor, oil-splashresistant Mounting - sockets, plug board, rail mount, panel mount, through-panel mount, enclosure for mounting on walls or equipment 75

Switching time - where high speed is required "Dry" contacts - when switching very low level signals, special contact materials may be needed such as gold-plated contacts Contact protection - suppress arcing in very inductive circuits Coil protection - suppress the surge voltage produced when switching the coil current Isolation between coil circuit and contacts Aerospace or radiation-resistant testing, special quality assurance Expected mechanical loads due to acceleration - some relays used in aerospace applications are designed to function in shock loads of 50 g or more Accessories such as timers, auxiliary contacts, pilot lamps, test buttons Regulatory approvals Stray magnetic linkage between coils of adjacent relays on a printed circuit board.

Protective relay A protective relay is a complex electromechanical apparatus, often with more than one coil, designed to calculate operating conditions on an electrical circuit and trip circuit breakers when a fault was found. Unlike switching type relays with fixed and usually illdefined operating voltage thresholds and operating times, protective relays had wellestablished, selectable, time/current (or other operating parameter) curves. Such relays were very elaborate, using arrays of induction disks, shaded-pole magnets, operating and restraint coils, solenoid-type operators, telephone-relay style contacts, and phase-shifting networks to allow the relay to respond to such conditions as over-current, over-voltage, reverse power flow, over- and under- frequency, and even distance relays that would trip for faults up to a certain distance away from a substation but not beyond that point. An important transmission line or generator unit would have had cubicles dedicated to protection, with a score of individual electromechanical devices. The various protective functions available on a given relay are denoted by standard ANSI Device Numbers. For example, a relay including function 51 would be a timed overcurrent protective relay.

76

These protective relays provide various types of electrical protection by detecting abnormal conditions and isolating them from the rest of the electrical system by circuit breaker operation. Such relays may be located at the service entrance or at major load centers. Design and theory of these protective devices is an important part of the education of an electrical engineer who specializes in power systems. Today these devices are nearly entirely replaced (in new designs) with microprocessor-based instruments (numerical relays) that emulate their electromechanical ancestors with great precision and convenience in application. By combining several functions in one case, numerical relays also save capital cost and maintenance cost over electromechanical relays. However, due to their very long life span, tens of thousands of these "silent sentinels" are still protecting transmission lines and electrical apparatus all over the world.

Top, middle: reed switches, bottom: reed relay Over current relay An "Over current Relay" is a type of protective relay which operates when the load current exceeds a preset value. The ANSI Device Designation Number is 50 for an Instantaneous over Current (IOC), 51 for a Time over Current (TOC). In a typical application the over current relay is used for over current protection, connected to a current transformer and calibrated to operate at or above a specific current level. When the relay operates, one or more contacts will operate and energize a trip coil in a Circuit Breaker and trip (open) the Circuit Breaker.

77

Distance relay It is a protective relay used to protect power transmission and distribution lines against different fault types. The relay monitors line impedance by measuring line voltage and current. Once a fault occurs, the voltage drops to zero and thus the measured impedance become less than the setting value ``reach``. As a result the relay issues a trip command

TRANSFORMER: A transformer is a device that transfers electrical energy from one circuit to another through inductively coupled electrical conductors. A changing current in the first circuit (the primary) creates a changing magnetic field; in turn, this magnetic field induces a changing voltage in the second circuit (the secondary). By adding a load to the secondary circuit, one can make current flow in the transformer, thus transferring energy from one circuit to the other. The secondary induced voltage VS is scaled from the primary VP by a factor ideally equal to the ratio of the number of turns of wire in their respective windings: By appropriate selection of the numbers of turns, a transformer thus allows an alternating voltage to be stepped up by making NS more than NP or stepped down, by making it less. Transformers are some of the most efficient electrical 'machines', with some large units able to transfer 99.75% of their input power to their output. Transformers come in a range of sizes from a thumbnail-sized coupling transformer hidden inside a stage microphone to huge units weighing hundreds of tons used to interconnect portions of national power grids. 78

All operate with the same basic principles, though a variety of designs exist to perform specialized roles throughout home and industry. Applications A key application of transformers is to reduce the current before transmitting electrical energy over long distances through wires. Most wires have resistance and so dissipate electrical energy at a rate proportional to the square of the current through the wire. By transforming electrical power to a high-voltage, and therefore low-current form for transmission and back again afterwards, transformers enable the economic transmission of power over long distances. Consequently, transformers have shaped the electricity supply industry, permitting generation to be located remotely from points of demand. All but a fraction of the world's electrical power has passed through a series of transformers by the time it reaches the consumer Basic principles The transformer is based on two principles: first, that an electric current can produce a magnetic field (electromagnetism) and, second, that a changing magnetic field within a coil of wire induces a voltage across the ends of the coil (electromagnetic induction). By changing the current in the primary coil, one changes the strength of its magnetic field; since the changing magnetic field extends into the secondary coil, a voltage is induced across the secondary.

An ideal step-down transformer showing magnetic flux in the core A simplified transformer design is shown to the left. A current passing through the primary coil creates a magnetic field. The primary and secondary coils are wrapped around a core of very high magnetic permeability, such as iron; this ensures that most of the magnetic

79

field lines produced by the primary current are within the iron and pass through the secondary coil as well as the primary coil. Induction law The voltage induced across the secondary coil may be calculated from Faraday's law of induction, which states that: where VS is the instantaneous voltage, NS is the number of turns in the secondary coil and equals the total magnetic flux through one turn of the coil. If the turns of the coil are oriented perpendicular to the magnetic field lines, the flux is the product of the magnetic field strength B and the area A through which it cuts. The area is constant, being equal to the cross-sectional area of the transformer core, whereas the magnetic field varies with time according to the excitation of the primary. Since the same magnetic flux passes through both the primary and secondary coils in an ideal transformer,[5] the instantaneous voltage across the primary winding equals Taking the ratio of the two equations for VS and VP gives the basic equation[6] for stepping up or stepping down the voltage Ideal power equation

The ideal transformer as a circuit element If the secondary coil is attached to a load that allows current to flow, electrical power is transmitted from the primary circuit to the secondary circuit. Ideally, the transformer is perfectly efficient; all the incoming energy is transformed from the primary circuit to the magnetic field and thence to the secondary circuit. If this condition is met, the incoming electric power must equal the outgoing power

80

Pincoming = IPVP = Poutgoing = ISVS giving the ideal transformer equation Thus, if the voltage is stepped up (VS > VP), then the current is stepped down (IS < IP) by the same factor. In practice, most transformers are very efficient (see below), so that this formula is a good approximation. The impedance in one circuit is transformed by the square of the turns ratio.[5] For example, if an impedance ZS is attached across the terminals of the secondary coil, it appears to the primary circuit to have an impedance of . This relationship is reciprocal, so that the impedance ZP of the primary circuit appears to the secondary to be . Detailed operation The simplified description above avoids several complicating factors, in particular the primary current required to establish a magnetic field in the core, and the contribution to the field due to current in the secondary circuit. Models of an ideal transformer typically assume a core of negligible reluctance with two windings of zero resistance.[7] When a voltage is applied to the primary winding, a small current flows, driving flux around the magnetic circuit of the core.[7]. The current required to create the flux is termed the magnetizing current; since the ideal core has been assumed to have near-zero reluctance, the magnetizing current is negligible, although a presence is still required to create the magnetic field. The changing magnetic field induces an electromotive force (EMF) across each winding. [8] Since the ideal windings have no impedance, they have no associated voltage drop, and so the voltages VP and VS measured at the terminals of the transformer, are equal to the corresponding EMFs. The primary EMF, acting as it does in opposition to the primary voltage, is sometimes termed the "back EMF".[9] This is due to Lenz's law which states that the induction of EMF would always be such that it will oppose development of any such change in magnetic field 81

The AMF Control Panel is a specially designed panel for standby generators. It consists of a state of the art microcontroller based AMF controller for monitoring, indicating and controlling the Mains and Generator for AMF operation. The AMF Control Panel can be operated in following modes: AUTO In this mode the AMF controller takes command of the total system operation. Sequence of operation: i.] At power ON, if Mains is healthy the Mains contactor is turned ON and load gets power from Mains. ii]. If Mains is unhealthy or if the load is above the rated voltage of the transformer; the controller starts the generator and transfers the load on the generator (In this project we are using transformer). iii.] If the Mains recover or the load is below the rated voltage, the controller switches the load back onto Mains and shuts down the generator after cooling time.

MANUAL In this mode the starting / stopping of the generator and load ON/OFF can be done manually from the AMF controller. In this mode if any fault occurs in the generator while running the AMF controller takes necessary action by indicating alarms and/or tripping the generator. TEST this mode is used to check the health of the generator. In TEST mode the generator is started and kept ON for a fixed duration. During this period the AMF controller checks for any faults in the generator. If any fault is sensed the controller displays the same. If the generator is found healthy GENSET OK is indicated on the display. BYPASS In BYPASS mode the AMF controller acts just as an indicating instrument. The system is 82

operated from the external switches provided on the Control Panel. The AMF controller in case of faults in this mode takes no action. HOLD INDICATIONS ON LCD DISPLAY The LCD display of AMF Controller indicates following parameters in scrolling mode: i.) Over Voltage ii.) Normal voltage

POWER SUPPLY UNIT Introduction: When dealing with electronic circuits, we have to meet the basic requirement of providing electrical power for them to work. Without that power, your circuit is no more useful or meaningful than a single raindrop in a hurricane. The basic purpose of a power supply is to provide one or more fixed voltages to the working circuit, with sufficient current-handling capacity to maintain the operating conditions of the circuit. The power source doesn't have to be fancy; the typical hand-held transistor radio uses a 9-volt battery as its power source. A flashlight uses cells that are physically much larger, but provide a lower voltage. Major electronic appliances such as television sets, VCRs, and microwave ovens have electronic circuits built in that take power from a wall socket and convert it to the form and voltages required by the other internal circuits of the appliance. Although each power supply has its own individual specifications and characteristics, all power supplies have certain characteristics in common. We'll look at the main parts of a 83

power supply on this page and see how they work together. Then, on subsequent pages, we'll take a more detailed look at each of the parts we haven't seen before, and explore the major variations that are commonly used in modern power supplies.

The Main Sections: A basic power supply consists of three main sections, as shown in the block diagram below and to the right. Depending on the requirements for a given power supply, the sections can be very simple or extremely complex, or even left out altogether in certain circumstances. Each of the sections serves one or more specific purposes, as follows:

Transformer: In general, the ac line voltage present in your house wiring is not suitable for electronic circuits. Most circuits require a considerably lower voltage, while a few require higher voltages. The transformer serves to convert the ac line voltage to a voltage level more appropriate to the needs of the circuit to be powered. At the same time, the transformer provides electrical isolation between the ac line and the circuit being powered, which is an important safety consideration. However, a line transformer is generally large and heavy, and is rather expensive. Therefore, some power supplies (notably for PCs) are deliberately designed to operate directly from the ac line without a line transformer. The output of the transformer is still an ac voltage, but now of an appropriate magnitude for the circuit to be powered.

84

Rectifier: The next step is to force current to flow in one direction only, preventing the alternations that occur in the transformer and the ac line. This process is known as rectification, and the circuit that accomplishes the task is the rectifier. There are many different rectifier configurations that may be used according to the requirements of the circuit. The output of the rectifier is a pulsating dc, which still has some of the variations from the ac line and transformer. Filter: The pulsating dc from the rectifier is generally still not suitable to power the actual load circuit. The pulsations typically vary from 0 volts to the peak output voltage of the transformer. Therefore, we insert a circuit to store energy during each voltage peak, and then release it to the load when the rectifier output voltage drops. This circuit is called a filter, and its job is to reduce the pulses from the rectifier to a much smaller ripple voltage. No filter configuration can be absolutely perfect, but a properly designed filter will provide a dc output voltage with only a small ac ripple. Each of the three sections identified above can have a number of variations even the transformer, which we covered in an earlier page on transformers. Regardless of these variations, each section performs its specific task. However, some circuits do the job more effectively than others, or pick different trade-offs between possible alternatives. To measure the effectiveness of each circuit, we compare the magnitude of the remaining ac component, or ripple, with the dc component of the total voltage appearing at the output of that section. The ratio of ac voltage to dc voltage is known as the ripple factor. The goal of any power supply design is to reduce the ripple factor as much as possible, or at least to the point where the load circuit will not be adversely affected by the remaining ac ripple voltage. In the remaining pages in this group, we will examine typical circuits and variations used for rectifiers and filters, and compare their performance.

85

As we have noted when looking at the Elements of a Power Supply, the purpose of the rectifier section is to convert the incoming ac from a transformer or other ac power source to some form of pulsating dc. That is, it takes current that flows alternately in both directions as shown in the first figure to the right, and modifies it so that the output current flows only in one direction, as shown in the second and third figures below. The circuit required to do this may be nothing more than a single diode, or it may be considerably more complex. However, all rectifier circuits may be classified into one of two categories, as follows:

Half-Wave Rectifiers: An easy way to convert ac to pulsating dc is to simply allow half of the ac cycle to pass, while blocking current to prevent it from flowing during the other half cycle. The figure to the right shows the resulting output. Such circuits are known as halfwave rectifiers because they only work on half of the incoming ac wave.

Full-Wave Rectifiers: The more common approach is to manipulate the incoming ac wave so that both halves are used to cause output current to flow in the same direction. The resulting waveform is shown to the right. Because these circuits operate on the entire incoming ac wave, they are known as full-wave rectifiers.

86

Rectifier circuits may also be further classified according to their configuration, as we will see below.

The Half-Wave Rectifier:

The simplest rectifier circuit is nothing more than a diode connected in series with the ac input, as shown to the right. Since a diode passes current in only one direction, only half of the incoming ac wave will reach the rectifier output. Thus, this is a basic half-wave rectifier. The orientation of the diode matters; as shown, it passes only the positive half-cycle of the ac input, so the output voltage contains a positive dc component. If the diode were to be reversed, the negative half-cycle would be passed instead, and the dc component of the output would have a negative polarity. In either case, the DC component of the output waveform is vp/ = 0.3183vp, where vp is the peak voltage output from the transformer secondary winding.

87

It is also quite possible to use two half-wave rectifiers together, as shown in the second figure to the right. This arrangement provides both positive and negative output voltages, with each output utilizing half of the incoming ac cycle. Note that in all cases, the lower transformer connection also serves as the common reference point for the output. It is typically connected to the common ground of the overall circuit. This can be very important in some applications. The transformer windings are of course electrically insulated from the iron core, and that core is normally grounded by the fact that it is bolted physically to the metal chassis (box) that supports the entire circuit. By also grounding one end of the secondary winding, we help ensure that this winding will never experience even momentary voltages that might overload the insulation and damage the transformer. The Full-Wave Rectifier:

While the half-wave rectifier is very simple and does work, it isn't very efficient. It only uses half of the incoming ac cycle, and wastes all of the energy available in the other half. For greater efficiency, we would like to be able to utilize both halves of the incoming ac. One way to accomplish this is to double the size of the secondary winding and provide a 88

connection to its center. Then we can use two separate half-wave rectifiers on alternate half-cycles, to provide full-wave rectification. The circuit is shown to the right. Because both half-cycles are being used, the DC component of the output waveform is now 2vp/ = 0.6366vp, where vp is the peak voltage output from half the transformer secondary winding, because only half is being used at a time. This rectifier configuration, like the half-wave rectifier, calls for one of the transformer's secondary leads to be grounded. In this case, however, it is the center connection, generally known as the center tap on the secondary winding.

The full-wave rectifier can still be configured for a negative output voltage, rather than positive. In addition, as shown to the right, it is quite possible to use two full-wave rectifiers to get outputs of both polarities at the same time. The full-wave rectifier passes both halves of the ac cycle to either a positive or negative output. This makes more energy available to the output, without large intervals when no energy is provided at all. Therefore, the full-wave rectifier is more efficient than the halfwave rectifier. At the same time, however, a full-wave rectifier providing only a single output polarity does require a secondary winding that is twice as big as the half-wave rectifier's secondary, because only half of the secondary winding is providing power on any one half-cycle of the incoming ac.

89

Actually, it isn't all that bad, because the use of both half-cycles means that the current drain on the transformer winding need not be as heavy. With power being provided on both half-cycles, one half-cycle doesn't have to provide enough power to carry the load past an unused half-cycle. Nevertheless, there are some occasions when we would like to be able to use the entire transformer winding at all times, and still get full-wave rectification with a single output polarity.

The Full-Wave Bridge Rectifier:

The four-diode rectifier circuit shown to the right serves very nicely to provide fullwave rectification of the ac output of a single transformer winding. The diamond configuration of the four diodes is the same as the resistor configuration in a Wheatstone Bridge. In fact, any set of components in this configuration is identified as some sort of bridge, and this rectifier circuit is similarly known as a bridge rectifier. If you compare this circuit with the dual-polarity full-wave rectifier above, you'll find that the connections to the diodes are the same. The only change is that we have removed the center tap on the secondary winding, and used the negative output as our ground reference instead. This means that the transformer secondary is never directly grounded,

90

but one end or the other will always be close to ground, through a forward-biased diode. This is not usually a problem in modern circuits.

To understand how the bridge rectifier can pass current to a load in only one direction, consider the figure to the right. Here we have placed a simple resistor as the load, and we have numbered the four diodes so we can identify them individually. During the positive half-cycle, shown in red, the top end of the transformer winding is positive with respect to the bottom half. Therefore, the transformer pushes electrons from its bottom end, through D3 which is forward biased, and through the load resistor in the direction shown by the red arrows. Electrons then continue through the forward-biased D2, and from there to the top of the transformer winding. This forms a complete circuit, so current can indeed flow. At the same time, D1 and D4 are reverse biased, so they do not conduct any current. During the negative half-cycle, the top end of the transformer winding is negative. Now, D1 and D4 are forward biased, and D2 and D3 are reverse biased. Therefore, electrons move through D1, the resistor, and D4 in the direction shown by the blue arrows. As with the positive half-cycle, electrons move through the resistor from left to right. In this manner, the diodes keep switching the transformer connections to the resistor so that current always flows in only one direction through the resistor. We can replace the resistor with any other circuit, including more power supply circuitry (such as the filter), and still see the same behavior from the bridge rectifier.

CURRENT TRANSFORMER

91

In electrical engineering, a current transformer (CT) is used for measurement of electric currents. Current transformers, together with voltage transformers (VT) (potential transformers (PT)), are known as instrument transformers. When current in a circuit is too high to directly apply to measuring instruments, a current transformer produces a reduced current accurately proportional to the current in the circuit, which can be conveniently connected to measuring and recording instruments. A current transformer also isolates the measuring instruments from what may be very high voltage in the monitored circuit. Current transformers are commonly used in metering and protective relays in the electrical power industry.

Design
Like any other transformer, a current transformer has a primary winding, a magnetic core, and a secondary winding. The alternating current flowing in the primary produces a magnetic field in the core, which then induces a current in the secondary winding circuit. A primary objective of current transformer design is to ensure that the primary and secondary circuits are efficiently coupled, so that the secondary current bears an accurate relationship to the primary current.

The most common design of CT consists of a length of wire wrapped many times around a silicon steel ring passed over the circuit being measured. The CT's primary circuit therefore consists of a single 'turn' of conductor, with a secondary of many hundreds of turns. The 92

primary winding may be a permanent part of the current transformer, with a heavy copper bar to carry current through the magnetic core. Window-type current transformers are also common, which can have circuit cables run through the middle of an opening in the core to provide a single-turn primary winding. When conductors passing through a CT are not centered in the circular (or oval) opening, slight inaccuracies may occur.

Current transformers used in metering equipment for three-phase 400 ampere electricity supply Shapes and sizes can vary depending on the end user or switchgear manufacturer. Typical examples of low voltage single ratio metering current transformers are either ring type or plastic moulded case. High-voltage current transformers are mounted on porcelain bushings to insulate them from ground. Some CT configurations slip around the bushing of a high-voltage transformer or circuit breaker, which automatically centers the conductor inside the CT window. The primary circuit is largely unaffected by the insertion of the CT. The rated secondary current is commonly standardized at 1 or 5 amperes. For example, a 4000:5 CT would provide an output current of 5 amperes when the primary was passing 4000 amperes. The secondary winding can be single ratio or multi ratio, with five taps being common for multi ratio CTs. The load, or burden, of the CT should be of low resistance. If the voltage time integral area is higher than the core's design rating, the core goes into saturation towards the end of each cycle, distorting the waveform and affecting accuracy.

Usage
93

Current transformers are used extensively for measuring current and monitoring the operation of the power grid. Along with voltage leads, revenue-grade CTs drive the electrical utility's watt-hour meter on virtually every building with three-phase service and single-phase services greater than 200 amp. The CT is typically described by its current ratio from primary to secondary. Often, multiple CTs are installed as a "stack" for various uses. For example, protection devices and revenue metering may use separate CTs to provide isolation between metering and protection circuits, and allows current transformers with different characteristics (accuracy, overload performance) to be used for the different purposes.

Safety precautions
Care must be taken that the secondary of a current transformer is not disconnected from its load while current is flowing in the primary, as the transformer secondary will attempt to continue driving current across the effectively infinite impedance. This will produce a high voltage across the open secondary (into the range of several kilovolts in some cases), which may cause arcing. The high voltage produced will compromise operator and equipment safety and permanently affect the accuracy of the transformer.

What Are the Functions of a Current Transformer?

What Are the Functions of a Current Transformer?

94

A current transformer (CT) is a transformer which measures the current of another circuit. It is coupled to an ammeter (A in the diagram) in its own circuit to perform this measurement. Measuring high-voltage current directly would require insertion of measuring instrumentation into the measured circuit--an unnecessary difficulty which would draw down the very current meant to be measured. Also, the heat generated in the measuring equipment from the high current could give false readings. Measuring current indirectly with a CT is much more practical.

Relation to Voltage Transformer

1. Voltage Transformer The function of a current transformer (CT) can be understood better by comparing it to the more commonly known voltage transformer (VT). Recall that in a voltage transformer, an alternating current in one circuit sets up an alternating magnetic field in a coil in the circuit. The coil is wrapped around an iron core, which spreads the magnetic field, nearly undiminished, to another coil in a different circuit, one without a power source. The difference with a CT is that the circuit with power has, effectively, one loop. The powered circuit goes through the iron core only once. A CT is, therefore, a step-up transformer.

CT & VT Formulae

95

2. Solenoid Magnetic Field Recall also that the current and number of turns in the coils in a VT can be related as: i1 --N1 = i2 --- N2. This is because for a coil (solenoid), B = mu --- i --- n, where mu here means the magnetic permeability constant. Little intensity of B is lost from one coil to the other with a good iron core, so the B equations for the two coils are effectively equal, giving us i1 --N1 = i2 --N2.

However, N1 = 1 for the primary in the case of the current transformer. Is the single power line effectively the equivalent of one loop? Does the last equation reduce to i1 = i2 --- N2? No, because it was based on solenoid equations. For N1 = 1, the following formula is more appropriate: B = mu --- i/(2r), where r is the distance of the center of the wire to the point where B is measured or sensed (the iron core, in the transformer case). So i1/(2r) = i2 --N2. i1 is, therefore, merely proportional to the ammeter-measured value i2, reducing current measurement to a simple conversion.

Common Uses

3. Electric Meter (Courtesy: Oak Ridge Nat'l Lab) 96

The one central function of a CT is to determine the current in a circuit. This is especially useful for monitoring high-voltage lines throughout the power grid. Another ubiquitous use of CTs is in domestic electric meters. A CT is coupled with a meter to measure what electrical usage to charge the customer.

Instrument Safety

4. Current Transformer (Courtesy: tradeindia.com) Another function of CTs is protection of sensitive measuring equipment. By increasing the number of (secondary) windings, N2, the current in the CT can be made much smaller than the current in the primary circuit being measured. In other words, as N2 in the formula i1/ (2r) = i2 --N2 goes up, i2 goes down.

This is relevant because high current produces heat which can damage sensitive measuring equipment, such as the resistor in an ammeter. Reducing i2 protects the ammeter. It also prevents heat from throwing off the accuracy of the measurement.

Protective Relays

5. CT Mounted Over Bushing of Circuit Recloser (Courtesy: emadrlc.blogspot.com) 97

CTs also protect the main lines of the power grid. An overcurrent relay is a type of protective relay (switch) that trips a circuit breaker if a high-voltage current exceeds a certain preset value. Overcurrent relays use a CT to measure the current, since the current of a high-voltage line could not be measured directly.

(OR)
CURRENT TRANSFORMERS

Basics of Operation and In-Service Testing


1. INTRODUCTION

Current transformers are used in electric metering for large load situations to reduce the current level presented to the metering circuit in order to make it more manageable and safe. This paper presents the basics of operation of current transformers and discusses the in-service testing of current transformers to assure accurate performance. 2. 2.1 BASICS OF OPERATION Ratio

A current transformer (henceforth called a CT) is designed to produce a secondary current, Is, that is directly proportional to its primary current, Ip, which is also called the load current. In metering this proportionality is called the ratio of the CT and is represented by: Ip Ratio = Is 2.2 Rated Ratio x 5

The ratio of a CT is referenced to a 5 amp secondary output for nominal full value input current such that a CT ratio of 200 to 5 means that the CT would produce a secondary 98

current of 5 amps when exposed to a primary current of 200 amps. The CT manufacturer classifies its CTs by its ratio value called the rated ratio which is stamped on the nameplate of the CT and that is the certified operating value of the CT. 2.3. Accuracy Class

The CT accuracy is determined by its certified accuracy class which is also stamped on its nameplate. For example, a CT accuracy class of 0.3 means that the CT is certified by the manufacturer to be accurate to within 0.3 percent of its rated ratio value for a primary current of 100 percent of rated ratio. For primary currents of 10 percent of rated ratio the specified accuracy for a given classification is double that of the 100 percent value or 0.6 percent for the above-stated case. The accuracy is relatively linear between these two points. Hence a CT with a rated ratio of 200 to 5 with accuracy class of 0.3 would operate within 0.45 percent of its rated ratio value for a primary current of 100 amps. To be more explicit, for a primary current of 100.00 amps it is certified to produce a secondary current between 2.489 amps and 2.511 amps. 2.4. Rating Factor

Some CTs are certified to be accurate for primary current values greater than 100 percent of the rated ratio, called over-range. This over-range is designated by a rating factor representing the factor by which the upper limit of the primary current can be increased and still remain within certified accuracy. Hence a 200 to 5 rated ratio CT with a rating factor of 2 will remain within its accuracy certification up to 400 amps (200 amps times 2). The rating factor of the CT is stamped on the nameplate of the CT. Typical rating factors are 1, 1.5, 2, 3, and 4. Voltage Transformers: Instrument transformers are used for measurement and protective application, together with equipment such as meters and relays. Their role in electrical systems is of primary 99

importance as they are a means of "stepping down" the current or voltage of a system to measurable values, such as 5A or 1A in the case of a current transformers or 110V or 100V in the case of a voltage transformer. This offers the advantage that measurement and protective equipment can be standardized on a few values of current and voltage.

Voltage transformers Current transformers

Voltage transformers Principle of operation The standards define a voltage transformer as one in which "the secondary voltage is substantially proportional to the primary voltage and differs in phase from it by an angle which is approximately zero for an appropriate direction of the connections." This, in essence, means that the voltage transformer has to be as close as possible to the "ideal" transformer. In an "ideal" transformer, the secondary voltage vector is exactly opposite and equal to the primary voltage vector, when multiplied by the turns ratio. In a "practical" transformer, errors are introduced because some current is drawn for the magnetization of the core and because of drops in the primary and secondary windings due to leakage reactance and winding resistance. One can thus talk of a voltage error, which is the amount by which the voltage is less than the applied primary voltage, and the phase error, which is the phase angle by which the reversed secondary voltage vector is displaced from the primary voltage vector.

100

LIQUID CRYSTAL DISPLAY:

The alphanumeric 16character X 2line LCD requires 8data lines and also 3 control signals. By using 2 ports, port 0&3 data pins are connected to LCD as data bus. Port0 can be basically used as I/O port i.e. it can be programmed as an input or as an output port. That means if it is programmed as output port, suppose if it is required to read data from LCD immediately it is not possible. Before reading the data it is required to make the port as an input port. Data reading from LCD gives an erroneous reading & should not be implemented. Because of this port5 is made as input / output port depending on the situation. The control signals are connected to port 3 pins. They are EN bar & RS bar, RW bar. At different instance such as data write / command write / data read etc. Various signals are to be provided as indicated by the by the LCD manufacturers. To interface the LCD, to the Micro controller it require an 8 bit and also three control signals differentiate the data from the control words send to the LCD. The Micro controller has to send the necessary control words followed by the data to be displayed. Depending on the operation to be performed the control words are selected and passes to the LCD. The data to be displayed on the LCD is to be sent in the ASCII format. Thus all the character to be displayed are converted into ASCII form and then sent to the LCD along with different control words. The control word differentiated the various operations and is executed. It is also possible to read the LCD data if required. The control signals to the LCD are also provided by the Micro controller. This is also done through pins 3.5,3.6&3.7.Through program necessary control signals are passed to the LCD by using the bits of the port. The remaining can be used for some other purpose if there is a need. The software controls the necessary ports and performs the task it is designed for. The soft ware and associated hardware perform the LCD interface. 101

LCD DISPLAY
Gnd vcc preset rs rw en d0 d1 d2 d3 d4 d5 d6 d7 vcc Gnd

A liquid crystal is a material (normally organic for LCDs) that will flow like a liquid but whose molecular structure has some properties normally associated with solids. The Liquid Crystal Display (LCD) is a low power device. The power requirement is typically in the order of microwatts for the LCD. However, an LCD requires an external or internal light source. It is limited to a temperature range of about 0C to 60C and lifetime is an area of concern, because LCDs can chemically degrade. There are two major types of LCD s which are: 1) Dynamic-scattering LCD s 2) Field-effect LCD s Field-effect LCD s are normally used in such applications where source of energy is a prime factor (e.g., watches, portable instrumentation etc.).They absorb considerably less power than the light-scattering type. However, the cost for field-effect units is typically higher, and their height is limited to 2 inches. On the other hand, light-scattering units are available up to 8 inches in height. Field-effect LCD is used in the project for displaying the appropriate information. The turn-on and turn-off time is an important consideration in all displays. The response time of LCD s is in the range of 100 to 300ms.The lifetime of LCD s is steadily increasing beyond 10,000+hours limit. Since the colour generated by LCD units is dependent on the source of illumination, there is a wide range of colour choice.

102

LCD is a type of display used in digital watches and many portable computers. LCD displays utilize to sheets of polarizing material with a liquid crystal solution between them. An electric current passed through the liquid causes the crystals to align so that light cannot pass through them. LCD technology has advanced very rapidly since its initial inception over a decade ago for use in laptop computers. Technical achievement has resulted in brighter displace, higher resolutions, reduce response times and cheaper manufacturing process. The liquid crystals can be manipulated through an applied electric voltage so that light is allowed to pass or is blocked. By carefully controlling where and what wavelength (color) of light is allowed to pass, the LCD monitor is able to display images. A backlight provides LCD monitors brightness.

Over the years many improvements have been made to LCD to help enhance resolution, image, sharpness and response times. One of the latest such advancements is TFT or Thin Film Transistor. TFT-LCDs make use of a very thin transistor that is applied to glass during acts as switch allowing control of light at the pixel level, greatly enhancing image sharpness and resolution. This has been particularly important for improving LCDs ability to display small-sized fonts and image clearly.

Other advances have allowed LCDs to greatly reduce liquid crystal cell response times. Response time is basically the amount of time it takes for a pixel to change colors. In reality response time is the amount of time it takes a liquid crystal cell to go from being active to inactive.

LCD interfacing with 8052 is a real-world application. In recent years the LCD is finding widespread use replacing LEDs (seven segment LEDs or other multisegment LEDs). This is due to following reasons: The declining prices of LCDs. 103

The ability to display numbers, characters and graphics. This is in contrast to LEDs, which are limited to numbers and a few characters. An intelligent LCD display of two lines, 20 characters per line, that is interfaced to the 8051.

PIN DIAGRAM Most of the LCD modules conform to a standard interface specification. A 14pin access is provided having eight data lines, three control lines and three power lines. The connections are laid out in one of the two common configurations, either two rows of seven pins, or a single row of 14 pins. One of the, pins are numbered on the LCDs print circuit board (PCB), but if not, it is quite easy to locate pin1. Since this pin is connected to ground, it often has a thicker PCB track, connected to it, and it is generally connected to metalwork at same point.

PIN DESCRIPTIONS

Vcc, Vss and Vee While Vcc and Vss provide +5V and ground respectively, Vee is used for controlling LCD contrast. RS, register select There are two very important registers inside the LCD. The RS pin is used for their selection as follows. If RS=0, the instruction command code register is selected, allowing the user to send a command such as clear display, cursor at home, etc., If RS=1 the data register is selected, allowing the user to send data to be displayed on the LCD. 104

R/W, read/write R/W input allows the user to write information to the LCD or read information from it. R/W=1 when reading; R/W=0 when writing. EN, Enable The LCD to latch information presented to its data pins uses the enable pin. When data is supplied to data pins, a high-to-low pulse must be applied to this pin in order for the LCD to latch in the data present at the data pins. This pulse must be a minimum of 450ns wide. The 8-bit data pins, D0-D7, are used to send information to the LCD or read the contents of the LCDs internal registers. To display letters and numbers, we send ASCII codes for the letters A-Z, a-z, and numbers 0-9 to these pins while making RS=1. There are also instruction command codes that can be sent to the LCD to clear the display or force the cursor to the home position or blink the instruction command codes. We also use RS=0 to check the busy flag bit to see if the LCD is ready to receive information. The busy flag is D7 and can be read when R/W=1 and RS=0, as follows: if R/W=1,RS=0. When D7=1 (busy flag=1), the LCD is busy taking care of internal operations and will not accept any information.

Basic commands of LCD: When LCD is powered up, the display should show a series of dark squares, possibly only on part of display. These characters are actually in their off state, so the contrast control should be adjusted anti-clockwise until the squares are just visible. The display module resets itself to an initial state when power is applied, which curiously has the display blanked off so that even if characters are entered, they cannot be seen. It is therefore necessary to issue a command at this point, to switch the display on.

105

Prototype circuit: For a LCD module to be used effectively in any piece of equipment, a microprocessor or a micro controller is usually required to drive it. However, before attempting to wire the two together, some initial experiments can be performed by connecting a series of switches to the pins of the module. This can be a quite beneficial step, if even you are thoroughly conversant with the workings of microprocessors.

OPERATING INSTRUCTIONS INSTRUCTION CODE EXPLANATIONS The two registers 1) Instruction Register (IR) and the 2) Data Register (DR) in the KS0066 controller chip are directly controlled by the MPU. Control information is temporarily stored in these registers prior to internal operation start. This allows interface to various types of MPUs which operate at different speeds from that of the KS0066, and allows interface from peripheral control ICs. Internal operations of the KS0066 are determined from the signals sent from the MPU. These signals, including register selection signals (RS), Read/Write (R/W) and data bus signals (DBO - DB7) are polled instructions.

Tab 6.6.1 Register Selection ADDRESS COUNTER (AC)

106

The counter specifies an address when data is written into DD RAM or CG RAM and the data stored in DD RAM or CG RAM is read out. If an Address Set instruction (for DD RAM or CG RAM) is written in the IR, the address information is transferred from the IR to the AC. When display data is written into or read from DD RAM or CG RAM, the AC are output to DBO to DB6; refer to above Register Selection Table when RS = 0 and R/W= 1.

Clear all display memory and return the cursor to the home position. In other words, the cursor returns to the first character block on the first line on all 1, 2, and 4 line character modules except L4044. If the above is entered on E2 (the second controller for lines 3 and 4), the cursor will return to the first character on the third line.

Returns cursor to home position. First line first character blocks on all 1, 2 and 4 line display; except L4044 refer clear display: (Address 0; A,, 80). The contents of DD

107

RAM remain unchanged.

Display & Clear Instructions

ENTRY MODE SET

I/D: Increments (I/D = 1) or decrements (I/D = 0) the DD RAM address by one block when writing or reading a character code from DD RAM or CG RAM. The cursor automatically moves to the right when incremented by one or to the left if decremented by one. DISPLAY AND CURSOR ON/OFF CONTROL

108

D: Display is turned ON when D = 1 and OFF when D =0. When display is OFF, display data in DD RAM remains unchanged. Information comes back immediately when D = 1 is entered. C: Cursor is displayed when C = 1 and not displayed when C = 0. If the cursor disappears, function of I/D etc. S: Shifts the entire display to either the right or left when S = 1 (high). When S = 1 and I/D = 1 the display shifts one position to the left. When S = 1 and I/D = 0 the display shifts one position to the right. This right or left shift occurs after each data write to DD RAM. Display is not shifted when reading from DD RAM. Display is not shifted when S = 0. In a 5 x 7 dot matrix there is an eighth line which functions as the cursor. B: When B = 1, the character at the cursor position starts blinking. When B = 0 the cursor does not blink. The blink is done by stitching between the all black dot matrix and displayed character at 0.4 second intervals. The cursor and the blink can be set at the same time (fosc = 250 kHz).

5 X 7 DOT MATRIX C = 1 (cursor display) B = 1 (blinking)

Cursor Conditions

109

CURSOR OR DISPLAY SHIFT

Cursor/Display Shift moves the cursor or shifts the display without changing the DD RAM contents. The cursor position and the AC contents match. This instruction is available for display correction and retrieval because the cursor position or display can be shifted without writing or reading display data. In case of a 2-line display, the cursor is shifted from character block 40 of line 1 to character block 1 of line 2. Displays of lines 1 and 2 are shifted at the same time. In case of a 4-line display, the cursor does not move continuously from line 2 to line 3. The cursor is shifted from character block 40 of line 3 to character block 1 of line 4. Displays of lines 3 and 4 are shifted at the same time. The display pattern of line 2 or 4 is not shifted to line 1 or 3.

110

ADC MODULE
THEORY: ADC is short for Analog Digital Converter, Sometimes called a A-D or A to D Converter. An ADC is a device that converts a continuous analog signal to a multi-level digital signal without altering its content. The signals that are monitored are sounds, movement, and temperature into binary code for the PC. (or) Analog to digital (A/D, ADC) converters are electrical circuit devices that convert continuous signals, such as voltages or currents, from the analog domain to the digital domain where the signals are represented by numbers Most processing equipment today are digital in nature, and they work with signals which are binary valued. In a digital or binary representation, a signal is represented by a word, which is composed of a finite number of bits. The processing of signals is preferably carried out in the digital domain because digital processing is fast, accurate and reliable. Analog to digital converters are widely used for converting analog signals to corresponding digital signals for many electronic circuits. Analog to digital converters allow the use of sophisticated digital signal processing systems to process analog signals, which are common in the real world. Many modern electronic systems require conversion of signals from analog to digital or from digital to analog form. Circuits for performing these functions are now required in numerous common consumer devices such as digital cameras, cellular telephones, wireless data network equipment, audio devices such as MP3 players, and video equipment such as digital video disk (DVD) players, high definition digital television (HDTV), and numerous other products. Analog to digital converters (ADC's) form an essential link in the signal processing pathway at the interface between the analog and digital domains. Advances in ADC technology have increased the speed, lowered the cost, and reduced the power requirements of analog to digital converters, and resulted in a proliferation of ADC applications. 111

Conversion involves quantizing and encoding. Quantizing means partitioning the analog signal range into a number of discrete quanta and determining to which quantum the input signal belongs. Encoding means assigning a unique digital code to each quantum and determining the code that corresponds to the input signal. The most common system is binary, in which there are 2n quanta (where n is some whole number), numbered consecutively; the code is a set of n physical two-valued levels or bits (1 or 0) corresponding to the binary number associated with the signal quantum. The illustration shows a typical three-bit binary representation of a range of input signals, partitioned into eight quanta. For example, a signal in the vicinity of 3/8; full scale (between 5/16 and 7/16) will be coded 011 (binary 3).

A three-bit binary representation of a range of input signals.

There are four commonly used ADCs: Parallel converter Successive approximation ADC Voltage-to-Frequency ADC Integrating ADC

Applications of ADC: Digital camera or scanner uses A/D converters to transform the variable charges in CCD and CMOS chips into the binary data that represent pixels. Cell phone and digital desk phone has an ADC converter that converts the pressure of sound waves into PCM code Etc.

ADC0808: 112

This is 8-Bit P Compatible A/D Converters with 8-Channel Multiplexer. The ADC0808 data acquisition component is a monolithic CMOS device with an 8-bit analogto-digital converter,8-channel multiplexer and microprocessor compatible Control logic. The 8-bit A/D converter uses successive approximation as the conversion technique. The converter features a high impedance chopper stabilized comparator, a 256R voltage divider with analog switch tree and a successive approximation register. The 8-channel multiplexer can directly access any of 8-single-ended analog signals. The device eliminates the need for external zero and full-scale adjustments. Easy interfacing to microprocessors is provided by the latched and decoded multiplexer address inputs and latched TTL TRI-STATE outputs. Features Easy interface to all microprocessors Operates ratio metrically or with 5 VDC or analog span adjusted voltage reference No zero or full-scale adjust required 8-channel multiplexer with address logic 0V to 5V input range with single 5V power supply Outputs meet TTL voltage level specifications ADC0808 equivalent to MM74C949 ADC0809 equivalent to MM74C949-1

Key Specifications Resolution 8 Bits Total Unadjusted Error 12 LSB and 1 LSB Single Supply 5 VDC Low Power 15 mW Conversion Time

FUNCTIONAL DESCRIPTION: 113

The ADC0808 shown in figure can be functionally divided into 2 basic sub circuits. These two sub circuits are an analog multiplexer and an A/D converter. The multiplexer uses 8 standard CMOS analog switches to provide to up to 8 analog inputs. The switches are selectively turned on, depending on the data latched into a 3-bit multiplexer address register.

The second functional block, the successive approximation A/D converter, transforms the analog output of the multiplexer to an 8-bit digital word. The output of the multiplexer goes to one of two comparator inputs. The other input is derived from a 256R resistor ladder, which is tapped by a MOSFET transistor switch tree. The converter control logic controls the switch tree, funneling a particular tap voltage to comparator. Based on the result of this comparison, the control logic and the successive approximation register (SAR) will decide whether the next tap to be selected should be higher or lower than the present tap on the resistor ladder. This algorithm is executed 8 times per conversion, once every 8-clock period, yielding a total conversion time of clock periods. When the conversion cycle is complete the resulting data is loaded into the TRISTATE output latch. The data in the output latch can be then be read by the host system any time before the end of the next conversion. The TRI-STATE capability of the latch allows easy interfaces to bus oriented systems. The operation on these converters by a microprocessor or some control logic is very simple. The controlling device first selects the desired input channel. To do this, a 3-bit channel address is placed on the A, B, C in and out pins; and the ALE input is pulsed positively, clocking the address into the multiplexer address register. To begin the conversion, the START pin is pulsed. On the rising edge of this pulse the internal registers are cleared and on the falling edge the start conversion is initiated. As mentioned earlier, there are 8 clock periods per approximation. Even though there is no conversion in progress the ADC0808 is still internally cycling through these 8 clock periods. A start pulse can occur any time during this cycle but the conversion will not actually begin until the converter internally cycles to the beginning of the next 8 clock 114

period sequence. As long as the start pin is held high no conversion begins, but when the start pin is taken low the conversion will start within 8 clock periods. The EOC output is triggered on the rising edge of the start pulse. It, too, is controlled by the 8 clock period cycle, so it will go low within 8 clock periods of the rising edge of the start pulse. One can see that it is entirely possible for EOC to go low before the conversion starts internally, but this is not important, since the positive transition of EOC, which occurs at the end of a conversion, is what the control logic is looking for. Once EOC does go high this signals the interface logic that the data resulting from the conversion is ready to be read. The output enable(OE) is then raised high. This enables the TRI-STATE outputs, allowing the data to be read. Figure shows the timing diagram.
C NR L O T O

MX U ad ress d reg ister

C N R LL G O T O O IC

S R A 8x1 an alog MX U T I R SAE T T O tp t u u L atch

Fig : - Functional block diagram of ADC

PIN DIAGRAM:

115

CONNECTION DIAGRAM:

SC IN0 IN1 IN2 IN3 IN4 IN5 IN6 IN7 ALE EOC CHA CHB

ADC

EMBEDDED CONTROLLER

CHC

Data(D0-D7)

116

SC (Chip Selection): By using this selection Bit you can select the Chip. After selecting this bit the chip is ready to do operation. By using HIGH (1) you can select this pin as an active high. ALE (Address Latch Enable): ALE is to enable address latch of ADC, so that the selected channel is activated. In normal operation, ALE is emitted at a constant rate of 1/6 the oscillator frequency, and can be used for external timing or clocking. Note that one ALE pulse is skipped during each access to external data memory. This pin is also the Program Pulse input (PROG) during Flash programming.

EOC (End of Conversion): After End of ADC Conversion EOC bit is set to high. CHANNEL SELECTION:

117

118

FLOW CHART:
START

CONFIGURE PINS

SELECT ADC CHANNEL (CHA, CHB, CHC)

SET & CLEAR SC BIT TO INITIATE THE CHIP

SET & CLEAR ALE BIT TO ENABLE THE ALE

IS EOC=1

COPY THE ADC PORT DATA INTO MEMORY

STOP

119 Set callCSF

CIRCUIT DESCRIPTION:
This section gives an overview of the whole circuitry and hardware involved in the project. The aim of the project is to protect the failing or damage of transformers having applied more loads on it and to share these overloads with another transformer. In this project we are giving power supply to all units, it basically consists of a Transformer to step down the 230V ac to 18V ac followed by diodes. Here diodes are used to rectify the ac to dc. After rectification the obtained rippled dc is filtered using a capacitor Filter. A positive voltage regulator is used to regulate the obtained dc voltage. for Microcontroller and the other is to supply control voltage for Relays In this project, we are using two transformers instead of one transformer. Whenever applying the more loads on one transformer exceeding the particular limit then it will not broke down but the excess load must be shared by the another transformer. Therefore, no failure of transformers will occurs. In this project, we are using two transformers for sharing of power upon exceeding the loads. Through the micro controller, we are controlling this sharing of power with the help of relay. The relays will trips to another transformer upon exceeding the limit of load, if totally overload occurs then automatically all loads will be shutdown. Here, we are using current transformer, it will measure the current of the loads. The ADC is an analog to digital converter which converts the values of analog current value to the digital value. This will be displayed as load status on the LCD display. But here in this project two power supplies are used one is meant to supply operating voltage

120

SOFTWARE DESCRPITION:
ABOUT SOFTWARE Softwares used are: *Keil software for C programming *Express PCB for lay out design *Express SCH for schematic design What's New in Vision3? Vision3 adds many new features to the Editor like Text Templates, Quick Function Navigation, and Syntax Coloring with brace high lighting Configuration Wizard for dialog based startup and debugger setup. Vision3 is fully compatible to Vision2 and can be used in parallel with Vision2. What is Vision3? Vision3 is an IDE (Integrated Development Environment) that helps you write, compile, and debug embedded programs. It encapsulates the following components: A project manager. A make facility. Tool configuration. Editor. A powerful debugger.

To help you get started, several example programs (located in the \C51\Examples, \C251\Examples, \C166\Examples, and \ARM\...\Examples) are provided. HELLO is a simple program that prints the string "Hello World" using the Serial Interface. MEASURE is a data acquisition system for analog and digital systems. 121

TRAFFIC is a traffic light controller with the RTX Tiny operating system. SIEVE is the SIEVE Benchmark. DHRY is the Dhrystone Benchmark. WHETS is the Single-Precision Whetstone Benchmark.

Additional example programs not listed here are provided for each device architecture. Building an Application in Vision2 To build (compile, assemble, and link) an application in Vision2, you must: 1. Select Project -(forexample,166\EXAMPLES\HELLO\HELLO.UV2). 2. Select Project - Rebuild all target files or Build target. Vision2 compiles, assembles, and links the files in your project. Creating Your Own Application in Vision2 To create a new project in Vision2, you must: 1. Select Project - New Project. 2. Select a directory and enter the name of the project file. 3. Select Project - Select Device and select an 8051, 251, or C16x/ST10 device from the Device Database. 4. Create source files to add to the project. 5. Select Project - Targets, Groups, Files. Add/Files, select Source Group1, and add the source files to the project. 6. Select Project - Options and set the tool options. Note when you select the target device from the Device Database all special options are set automatically. You typically only need to configure the memory map of your target hardware. Default memory model settings are optimal for most applications. 7. Select Project - Rebuild all target files or Build target. Debugging an Application in Vision2 To debug an application created using Vision2, you must: 1. Select Debug - Start/Stop Debug Session. 2. Use the Step toolbar buttons to single-step through your program. You may enter G, main in the Output Window to execute to the main C function. 122

3. Open the Serial Window using the Serial #1 button on the toolbar. Debug your program using standard options like Step, Go, Break, and so on. Starting Vision2 and creating a Project Vision2 is a standard Windows application and started by clicking on the program icon. To create a new project file select from the Vision2 menu Project New Project. This opens a standard Windows dialog that asks you for the new project file name. We suggest that you use a separate folder for each project. You can simply use the icon Create New Folder in this dialog to get a new empty folder. Then select this folder and enter the file name for the new project, i.e. Project1. Vision2 creates a new project file with the name PROJECT1.UV2 which contains a default target and file group name. You can see these names in the Project Window Files. Now use from the menu Project Select Device for Target and select a CPU for your project. The Select Device dialog box shows the Vision2 device database. Just select the microcontroller you use. We are using for our examples the Philips 80C51RD+ CPU. This selection sets necessary tool options for the 80C51RD+ device and simplifies in this way the tool Configuration Building Projects and Creating a HEX Files Typical, the tool settings under Options Target are all you need to start a new application. You may translate all source files and line the application with a click on the Build Target toolbar icon. When you build an application with syntax errors, Vision2 will display errors and warning messages in the Output Window Build page. A double click on a message line opens the source file on the correct location in a Vision2 editor window.Once you have successfully generated your application you can start debugging. After you have tested your application, it is required to create an Intel HEX file to download the software into an EPROM programmer or simulator. Vision2 creates HEX files with each build process when Create HEX files under Options for Target Output is enabled. You may start your PROM programming utility after the make process when you specify the program under the option Run User Program #1. CPU Simulation

123

Vision2 simulates up to 16 Mbytes of memory from which areas can be mapped for read, write, or code execution access. The Vision2 simulator traps and reports illegal memory accesses. In addition to memory mapping, the simulator also provides support for the integrated peripherals of the various 8051 derivatives. The on-chip peripherals of the CPU you have selected are configured from the Device Database selection You have made when you create your project target. Refer to page 58 for more Information about selecting a device. You may select and display the on-chip peripheral components using the Debug menu. You can also change the aspects of each peripheral using the controls in the dialog boxes. Start Debugging You start the debug mode of Vision2 with the Debug Start/Stop Debug Session command. Depending on the Options for Target Debug Configuration, Vision2 will load the application program and run the startup code Vision2 saves the editor screen layout and restores the screen layout of the last debug session. If the program execution stops, Vision2 opens an editor window with the source text or shows CPU instructions in the disassembly window. The next executable statement is marked with a yellow arrow. During debugging, most editor features are still available. For example, you can use the find command or correct program errors. Program source text of your application is shown in the same windows. The Vision2 debug mode differs from the edit mode in the following aspects: _ The Debug Menu and Debug Commands described on page 28 are Available. The additional debug windows are discussed in the following. _ The project structure or tool parameters cannot be modified. All build Commands are disabled. Disassembly Window The Disassembly window shows your target program as mixed source and assembly

124

program or just assembly code. A trace history of previously executed instructions may be displayed with Debug View Trace Records. To enable the trace history, set Debug Enable/Disable Trace Recording. If you select the Disassembly Window as the active window all program step commands work on CPU instruction level rather than program source lines. You can select a text line and set or modify code breakpoints using toolbar buttons or the context menu commands. You may use the dialog Debug Inline Assembly to modify the CPU instructions. That allows you to correct mistakes or to make temporary changes to the target program you are debugging.

SOFTWARE DESCRPITION:
SOURCE CODE

1. 2.

Click on the Keil uVision Icon on DeskTop The following fig will appear

3. 4.

Click on the Project menu from the title bar Then Click on New Project 125

5.

Save the Project by typing suitable project name with no extension in u r own folder sited in either C:\ or D:\

6. 7. 8.

Then Click on Save button above. Select the component for u r project. i.e. Atmel Click on the + Symbol beside of Atmel

126

9.

Select AT89C52 as shown below

10. 11.

Then Click on OK The Following fig will appear

127

12. 13. 14.

Then Click either YES or NOmostly NO

Now your project is ready to USE Now double click on the Target1, you would get another option Source group 1 as shown in next page.

15.

Click on the file option from menu bar and select new 128

16.

The next screen will be as shown in next page, and just maximize it by double clicking on its blue boarder.

17. 18.

Now start writing program in either in C or ASM For a program written in Assembly, then save it with extension . asm and for C based program save it with extension .C

129

19.

Now right click on Source group 1 and click on Add files to Group Source

20.

Now you will get another window, on which by default C files will appear.

130

21. 22. 23.

Now select as per your file extension given while saving the file Click only one time on option ADD Now Press function key F7 to compile. Any error will appear if so happen.

24. 25.

If the file contains no error, then press Control+F5 simultaneously. The new window is as follows 131

26. 27.

Then Click OK Now Click on the Peripherals from menu bar, and check your required port as shown in fig below

28.

Drag the port a side and click in the program file.

132

29. 30.

Now keep Pressing function key F11 slowly and observe. You are running your program successfully

133

CONCLUSION

The project AUTO MAIN FAILURE AND AUTOMATIC TRANSFER SWITCH has been successfully designed and tested. Integrating features of all the hardware components used have developed it. Presence of every module has been reasoned out and placed carefully thus contributing to the best working of the unit. Secondly, using highly advanced ICs and with the help of growing technology the project has been successfully implemented.

134

BIBLIOGRAPHY The 8051 Micro controller and Embedded Systems -Muhammad Ali Mazidi Janice Gillispie Mazidi The 8051 Micro controller Architecture, Programming & Applications -Kenneth J.Ayala Fundamentals Of Micro processors and Micro computers -B.Ram Micro processor Architecture, Programming & Applications -Ramesh S.Gaonkar Electronic Components -D.V.Prasad Wireless Communications - Theodore S. Rappaport

135

Mobile Tele Communications - William C.Y. Lee References on the Web:

www.national.com www.atmel.com www.microsoftsearch.com www.geocities.com

136

Das könnte Ihnen auch gefallen