You are on page 1of 70




2000/97343 2000/105106 2000/103555 2000/97344

OBIJIOFOR, O.C 20000/103446





To God Almighty, and to our parents for their understanding, perseverance and financial support.

Our sincere gratitude goes to all those who in one way or another contributed to the success of this work. The limit of space will not permit us to mention all. Most especially, we wish to thank our project supervisor Miss Ogechi Iloanusi for her guidance, encouragement and support. We are also very grateful to the following people; Bro Okey Ndu, Emma Guru and CCP who motivated and supported us in the course of this work. For life, health, provision, wisdom, and grace, our heart bursts forth in Praise to the Almighty God who has done awesome things for us.

The incidence of power outages in Nigeria is very frequent. The reasons for this irregularity of supply are numerous and diverse. This is a primary hindrance to economic growth. In an attempt to remedy this situation, several independent power providers are springing up. The result is that in the not too distant future, industries and other places requiring uninterrupted power supply may have multiple sources of power supply to increase the reliability of power supply. The authors see an automation of the selection of the available power sources as an efficient way to manage the situation. In this work, the authors evolved a design of and constructed a microcontrollerbased system that carries out this selection with little or no human supervision. This thesis documents the library research, design, construction, testing, and software development processes carried out by the authors to construct a working prototype of this system. To enhance readability and understanding, the material adopts a top down approach where most concepts are first introduced generally and then later specified in greater detail. To realize this goal, the paper is divided into five chapters. Chapter one discusses the objective of the project as well as the necessity of programmed design. Chapter two was devoted to an in-depth study of the components that constitute this system and their working principles. Chapter three discussed the system hardware design procedure and construction of the different modules and consequently hardware integration and testing. Chapter four is devoted to the software requirements and development as well as the overall system testing. Finally, Chapter five assesses the project, discussing problems encountered and recommendations for subsequent improvement. Relevant components data are provided in the appendix.

Title Page ......i Dedication..ii Acknowledgement....iii Abstract....iv Table of Contents.. ..v

CHAPTER ONE-INTRODUCTION 1.1 Overview of Electric Power Supply in Nigeria ......1 1.2 Objective of the Project .....3 1.3 Emphasis on Programmed Design .....3 1.4 Microprocessing Systems .....4 1.4.1 1.4.2 1.4.3 Microprocessor Specifications ...5 Microcontrollers .7 The 8051\8052 Families of Microcontrollers .8


2.1.1 Transformers ..11 2.1.2 Voltage Rectification .15 2.1.3 Filters ......16 2.1.4 Voltage Regulation..17 2.1.5 Voltage Divider ..17 2.2 2.3 2.4 Multiplexers. ..18 The Analog to Digital Converter........20 The 89C52 Microcontroller24

2.4.1 Memory Organization25 2.4.2 Addressing Modes ... 27 2.4.3 89C52 Pin Configuration . 30 2.5 2.6 2.7 Relays . 32 Seven Segment Displays ...34 Transistors and Capacitors..35

CHAPTER THREE-HARDWARE DEVELOPMENT 3.1 3.2 3.3 3.4 3.5 3.6 3.7 3.8 3.9 System Overview (Block Diagram)42 System Specification and Design43 Voltage Rectification and Regulation 44 The Analog-Digital Switch.45 The Analog-Digital Interface. 46 Microcontroller Module..47 Display Circuitry ....49 The Relay Circuit ...51 Hardware Integration and Testing .....52

CHAPTER FOUR-SOFTWARE DEVELOPMENT AND SYSTEM TESTING 4.1 4.2 4.3 4.4 Software requirement specification..55 Program design (Flowchart).55 Software Development Tools...57 Programming the 89C52..58

4.5 System Integration and Testing.59

CHAPTER FIVE-CONCLUSION 5.1 Summary60 5.2 Challenges Faced...60 5.3 Cost Analysis.61 5.4 Recommendations For Further Study....61



OVERVIEW OF ELECTRIC POWER SUPPLY IN NIGERIA The unpredictability of power supply in many African countries is one of the main hindrances to economic growth. The reasons for this irregularity of supply are numerous and diverse. Wars across the continent have left generation facilities damaged and transmission lines cut. Apart from the physical damage caused by sabotage and war, many governments budgets have been stretched to the extent that maintenance of facilities has become a low priority. In addition, many countries have been left with unreliable, aging equipment with little means of upgrading. Nigeria is a prime example, operating at approximately one-third of its installed capacity due to aging facilities. The demand for power in Nigeria is growing at a rate that is leaving the country unable to keep up. Rural electrification initiatives, low electrification levels at present and high population growth rates all contribute to this high growth in demand. To meet demand, new installations are required on a regular basis. Unfortunately the ailing economy is posing a challenge to this required solution. In an attempt to address the issue of power supply reliability, countries have adopted a number of strategies. Many African governments are starting to view hydroelectric power with scepticism and are viewing a move away from hydropower dependency as the best long-term solution to reliability problems. Photovoltaic power generation is a possible supplement to hydroelectric power. Although its conversion efficiency is not high relative to hydroelectric power, Current conversion efficiencies have surpassed 30% in the laboratory, and 15% in large-scale production.

Ingenious private sector driven power providers exist whose goal is to construct and operate Independent Power Plants (IPP) for the generation, transmission and distribution of power to industrial clusters, commercial entities and the general public in Nigeria. The Geometric Power Limited (GPL) is an example of such companies. It is desirous to complement the Nigerian governments effort to improve the power sector by bridging the energy gap in a timely manner, and to alleviate the pains of several industrialists in the country. Such initiatives will revolutionize the power sector in Nigeria in the near future. The GPLs Aba model plant is strategically located in Aba, the commercial capital city of Abia State, South Eastern Part of Nigeria because of its large cluster of sustainable industries that need reliable electric power. The plant is designed to provide a model for the emergence of high reliability in power supply especially for the industrial sector, and to drive positive economic growth in Nigeria and trade within Sub-Saharan Africa. This privately owned power plant in Nigeria would serve the industrial and commercial customers, as well as residences using a specially installed and designated high quality private distribution network. International investors led by International Finance Corporation finance the project. It is strongly supported by several local and International organizations. These include amongst others, The World Bank; European Investment Bank; Shell Nigeria Gas Company; The Federal Ministry of Power and Steel in Nigeria; The Bureau of Public Enterprises (BPE) Nigeria; Owners of the major Industries in Aba and the Aba Community in general. This project has become a pace setting IPP whose model is expected to be replicated in other parts of Nigeria.


OBJECTIVE OF THE PROJECT The aim of this project is to design a system that will automatically select an optimum power source from multiple sources for an application. The basis of this selection is with reference to an optimum voltage of 220V with a specified tolerance range of 20V.In the event of a power failure, a standby generator is switched on. Power failure in this context implies absence of power supply from the mains or when the power supplied is not within the tolerance range. We will employ programmed design to measure and effectively select one out of six possible ac voltage sources for an application. Its aim is to improve reliability of power supply to residences, industries, football pitches, hospital theatres, telephone exchanges and any other situation requiring uninterrupted power supply.


THE EMPHASIS ON PROGRAMMED DESIGN Digital systems design can be carried out in two ways; programmed design and hard-wired approach. In programmed design, the functions realized reside in the program while that of the hard-wired approach resides in the interconnections of logic components. Although programmed designs are slower than the hard-wired because of the fetch, decode and execute of instruction process, it has the following advantages over the hard-wired Small Scale Integration/Medium Scale Integration (SSI/MSI) IC approach. Flexibility The functions realized in the programmed design system reside in the program. The system is flexible because the program conditions its behaviour and as a result modifications are easily actualised at less cost. A hard-wired system will need to be redesigned and reconstructed.

Reliability Programmed design systems are more reliable than hard-wired logic. This is as a result of very few large-scale integrated circuits employed in their implementation. Too many devices cause faults and make troubleshooting difficult. Less cost The products realized from the programmed approach require less number of components than the hardwired logic as they use very few large-scale integrated circuit ICs. This is cost effective especially when considering large-scale production. Less time Programmed design technique offers minimized project implementation duration because so many device functions are easily incorporated into the software without loss of functionality and designers time. Design complexity is also reduced. A microprocessor-based solution is considered whenever an application involves making calculations, making decisions based on external stimulus, and maintaining memory of past events.


MICROPROCESSING SYSTEMS A system consists of several components interconnected in a specific way to fulfill a specific function. A microprocessing system is a system in which a microprocessor is a component providing computational control. It is also called a microcomputer, which is a complete stand-alone computer capable of functioning without any additional equipment. A microprocessor is a general-purpose digital device that is driven by software instructions and communicates with several external support chips to perform the necessary input/output of a specified task. It reads program instructions from memory and executes those instructions that drive the three external buses with the proper levels and timing to make the connected devices to perform specific operations. It is

an electronic circuit that functions as the central processing unit (CPU) of a computer, providing computational control. The microprocessor is an ultra-large-scale integrated circuit consisting of several different sections: The Arithmetic Logic Unit (ALU) performs calculations on numbers and makes logical decisions; the registers are special memory locations for storing temporary information; the control unit deciphers programs; buses carry digital information throughout the chip and computer; and local memory supports on-chip computation. More complex microprocessors often contain other sectionssuch as sections of specialized memory, called cache memory, to speed up access to external datastorage devices.


MICROPROCESSOR SPECIFICATIONS For the purpose of comparing efficiencies, judging compatibilities, both in physical and software, safe and optimal application, and ultimately for the purpose of making a good choice of microprocessors, like in other electronic devices, certain specifications are usually made on each microprocessor model. Specifications provide information about the processors components, capabilities and special features. Such specifications include: 1. Data- bus width 2. Address-bus width 3. Internal register size 4. Speed (in MHZ)/CPU clock multiples 5. Memory specifications Data-bus width The data-bus is a bi-directional set of lines or connectors which carry common signals (Binary Coded Signals) and which are connected commonly to various devices such as ROM, RAM, cache, 10-ports and the CPU of a computer such that any

information represented by binary code form by the ordered presence (or absence) of high (1) or low (0) voltage-sent to the bus by the CPU or vice versa is made available to all other devices which are commonly connected to the bus. If N is the number of connectors that make up the bus, then this can stand for n-bits binary number, which can represent 2n binary coded data, the bus is said to have bus width of n-bits. The greater the value of n (i.e. the data bus width) then the greater the amount of information/data in bytes that can be conveyed in a cycle. Some processors have been designed such that the data bus width (external) corresponds to half the internal register size (Intel 8088), the internal register size (Intel 8088) or twice the internal register size (in Intel Pentiums). Address- bus width The address bus is a set of conductors or lines that represents binary numbers which are codes for memory location addresses. The address bus is used by the microprocessor to select a particular memory location or IC to be active. It is unidirectional. An n bit wide address bus is capable of uniquely specifying (2n ) different addresses. The greater the width of the address bus the greater the size of the addressable hardware memory. Internal register size This has two aspects, the size of the register and the number of registers. The size of the register determines the amount of data that can be processed at a time. As registers are closer and faster than main memory, the higher the number of internal registers, the faster the processor is likely to be. Registers could be general purpose or special purpose. Clock speed There are two sides to the speed rating of a microprocessor. The first is the clock speed, the second is the average instruction execution time.

The clock speed is the frequency of the clock. This frequency is measured in Megahertz, which means the number of cycles per second. A pulse cycle represents the smallest unit of time or interval of any operation in a system. Hence, the higher the frequency, the faster its operation which include instruction execution and data transfer. On the other hand, average instruction execution time expresses the number of instruction a given processor can execute in one cycle. It can as well be seen as the number of cycles on the average that it takes for the processor to execute a single instruction. Intel 80286 has an average instruction execution time of 4.5 cycles per instruction, where as 80486 has 2 cycles per instruction. If two of these models, one from each kind are selected which both have the same frequency, then because of the different average instruction execution time the 80486 will perform at a rate double that of the 80286.We can say that if all other variables are equal, including the type of processor, the number of wait-states added to different types of memory accesses, the width of the data bus, one can compare two systems by their respective clock rates. Memory specification This is specifically related to microcontrollers. They have ROM and RAM memory included in the chip. Some of them may be ROM-less, some have masked ROMs and some have on-chip EPROM (UV erasable). One advantage of the ROM-less version is reduced cost.


MICROCONTROLLERS A microcontroller is a single computer chip that executes a user program, normally for the purpose of controlling some device. Its distinguishing feature is the inclusion on a single chip, of all the resources which permit the IC to serve as a controller in a system or an instrument. It is a complete computer on a chip containing all of the elements of the

basic microprocessor along with other specialized functions. Its built in facilities has obvious advantages when building stand-alone front-ends and controllers. A microcontroller is made up of CPU, RAM, ROM, I\O ports, timers, and serial communication ports. It has wide applications in embedded systems that require some amount of computing power but dont require as much as that provided by a complex processor. In an embedded system there is only one application software that is typically burned into ROM. Microcontroller-based systems are generally smaller, more reliable and cheaper. They are ideal for applications where cost and unit size are important considerations. A typical example is the 8051\8052 family, which includes 8031,8051, 8052,8751,8752,8951, 8952, etc. the major producers of microcontrollers are Atmel and Intel. Certain factors are to be considered when choosing a microcontroller for an application. They include: Speed, size of ROM|RAM, number of I|O ports, timers, power consumption and cost per unit. Availability of software development tools like assemblers, debuggers, compilers, simulators and technical support. Availability and reliable sources of microcontrollers. The 8051\8052 families are readily available.


THE 8051\8052 FAMILIES OF MICROCONTROLLERS The 8051 is a standard controller widely employed for many applications. It is manufactured with three variations, 8031,8051,and 8751.The 8031 is a ROM-less version, requiring external ROMs for making a complete system. The 8051 has masked program ROM while the 8751contains on-chip EPROM (UV erasable) The main hardware features of the 8051 series are the on-chip incorporation of

Data RAM (128 Bytes) Special Function Registers (at least 21) 32 bit programmable I\O port UART (Universal Asynchronous Receiver Transmitter) for serial data input and output

Two programmable timers and counters Two external interrupts with priority and masking Four banks of eight temporary registers The 8052 series of microcontrollers is very similar to the 8051.The 8052 is an 8-bit

microcontroller originally developed by Intel in the late 1970s.It included an instruction set of 255 operation codes (opcodes), 32 input\output lines, three user controllable timers, an integrated and automatic serial port, and 256 bytes of on-chip RAM as opposed to the 8051s 128 bytes of RAM with only two timers. The 8052 was designed such that control of the microcontroller and all input\output devices is accomplished via Special Function Registers (SFRs). Each SFR has an address between 128 and 255.Additional functions can be added to new derivative microcontrollers by adding additional SFRs while remaining compatible with the original 8052.This allows the developers to use the same software with any derivative microcontroller chip that is 8052-compatible. A derivative chip will generally be able to execute a standard 8052 program without modification. A derivative chip must be based on the 8052 instruction set and support the appropriate SFRs which is at least 26 for an 8052.


2.1 POWER SUPPLIES A power supply unit (PSU) is a device or system that supplies electrical or other types of energy to an output load or group of loads. The term is most commonly applied to electrical energy supplies. Constraints that commonly affect power supplies are the amount of power they can supply, how long they can supply it without needing some kind of refueling or recharging, how stable their output voltage or current is under varying load conditions, and whether they provide continuous power or pulses. Forms of Electrical power supplies Electrical power supplies include the mains power distribution system together with any other primary or secondary sources of energy such as: Batteries Chemical fuel cells and other forms of energy storage systems Solar power Generators or alternators A simple AC power supply uses a transformer to convert the voltage from the wall outlet to a lower voltage. A diode circuit then rectifies the AC voltage to pulsating DC. A capacitor smoothens out most of the pulsating of the rectified waveform to give a DC voltage with some ripple. Finally depending on the requirements of the load a linear regulator may be used to reduce the voltage to the desired output voltage and remove the majority of the remaining ripple. It may also provide other features such as current limiting. This process is shown in figure 2.1 below:

Figure2.1: Block Diagram Showing Parts Of A Regulated Power Supply 2.1.1 TRANSFORMERS A transformer is an electrical device that transfers energy from one circuit to another by magnetic coupling with no moving parts. It comprises of two or more coupled windings or a single tapped winding and, in most cases, a magnetic core to concentrate magnetic flux. An alternating current in one winding creates a time-varying magnetic flux in the core, which induces a voltage in the other windings. Transformers are used to convert between high and low voltages, to change impedance, and to provide electrical isolation between circuits. All transformers operate with the same basic principles and with many similarities in their parts. Basic Principles of Operation of a transformer A simple transformer consists of two electrical conductors called the primary winding and the secondary winding. These two windings can be considered as a pair of mutually coupled coils. Energy is coupled between the windings by the time-varying magnetic flux that passes through (links) both primary and secondary windings.

Figure 2.2: A Transformer Showing Magnetising Flux In The Core

If a time-varying voltage

is applied to the primary winding of


current will flow in it producing a magnetomotive force (MMF). Just as an electromotive force (EMF) drives current around an electric circuit, so MMF tries to drive magnetic flux through a magnetic circuit. The primary MMF produces a varying magnetic flux in

the core, and, with an open circuit secondary winding, induces a back electromotive force (EMF) in opposition to . In accordance with Faraday's law of induction, the voltage

induced across the primary winding is proportional to the rate of change of flux:

and where vP and vS are the voltages across the primary winding and secondary winding, NP and NS are the numbers of turns in the primary winding and secondary winding, dP / dt and dS / dt are the derivatives of the flux with respect to time of the primary and secondary windings. Saying that the primary and secondary windings are perfectly coupled is equivalent to saying that . Substituting and solving for the voltages shows that:

Hence in an ideal transformer, the ratio of the primary and secondary voltages is equal to the ratio of the number of turns in their windings, or alternatively, the voltage per turn is the same for both windings. The ratio of the currents in the primary and secondary circuits is inversely proportional to the turns ratio. This leads to the most common use of the transformer: to convert electrical energy at one voltage to energy at a different voltage by means of windings with different numbers of turns. In a practical transformer, the

higher-voltage winding will have more turns, of smaller conductor cross-section, than the lower-voltage windings. An ideal transformer also has no loss (100% efficient) but in practice, energy is dissipated due both to the resistance of the windings (known as copper loss), and to magnetic effects primarily attributable to the core (known as iron loss). Transformers are, in general, highly efficient. Transformer losses arise from Winding resistance, Hysteresis losses, Magnetostriction, mechanical losses, and Stray losses. Also, not all the magnetic field produced by the primary is intercepted by the secondary. A portion of the leakage flux may induce eddy currents within nearby conductive objects, such as the transformer's support structure, and be converted to heat. Standard Transformer Circuit symbols

Transformer with two windings and iron core.

Transformer with three windings. The dots show the adjacent ends of the windings. Step-down or step-up transformer. The symbol shows which winding has more turns but does not usually show the exact ratio. Transformer with electrostatic screen, which prevents capacitive coupling between the windings.

Table 2.1: Transformer Circuit Synbols Transformer designs Transformers can be designed in many ways such as autotransformer, polyphase transformers, resonant transformers, audio transformers etc. autotransformer design will be discussed in detail.

Autotransformers An autotransformer has only a single winding, which is tapped at some point along the winding. AC or pulsed voltage is applied across a portion of the winding, and a higher (or lower) voltage is produced across another portion of the same winding. While theoretically separate parts of the winding can be used for input and output, in practice the higher voltage will be connected to the ends of the winding, and the lower voltage from one end to a tap. For example, a transformer with a tap at the center of the winding can be used with 230 volts across the entire winding, and 115 volts between one end and the tap. It can be connected to a 230 volt supply to drive 115 volt equipment, or reversed to drive 230 volt equipment from 115 volts. As the same winding is used for input and output, the flux in the core is partially cancelled, and a smaller core can be used. For voltage ratios not exceeding about 3:1, an autotransformer is cheaper, lighter, smaller and more efficient than a true (two-winding) transformer of the same rating. In practice, transformer losses mean that autotransformers are not perfectly reversible; one designed for stepping down a voltage will deliver slightly less voltage than required if used to step up. The difference is usually slight enough to allow reversal where the actual voltage level is not critical. By exposing part of the winding coils and making the secondary connection through a sliding brush, an autotransformer with a nearcontinuously variable turns ratio can be obtained, allowing for very small increments of voltage. Uses of transformers For supplying power from an alternating current power grid to equipment which uses a different voltage. It may be followed by rectification if direct rather than alternating power is needed.

Adaptation of electrical equipment to supply voltages for which it was not made. For example, to use U.S. equipment, designed for 115 V AC, in European countries with 230 V AC. A transformer or autotransformer may be used.

It is also used inside solid-state equipment that requires low voltages to reduce the main electricity voltage to the required value.


VOLTAGE RECTIFICATION Rectification is a process whereby an alternating current is converted into direct current. A rectifier is used to achieve that. A rectifier is an electrical device, comprising one or more semiconductive devices (such as diodes arranged for converting alternating current to direct current. One diode can be used to rectify AC by blocking the negative or positive portion of the waveform.The difference between the term diode and the term rectifier is merely one of usage, e.g. the term rectifier describes a diode that is being used to convert AC to DC. All rectifiers comprise a number of diodes in a specific arrangement for more efficient conversion from AC to DC than is possible with just a single diode. Rectification can be achieved using only one diode (half wave rectification) or more than one diode (full wave rectification). Half-wave rectification Half wave rectification is the process of removing one half of the input signal to establish a dc level. Either the positive or negative half of the AC wave is passed while the other half is blocked, depending on the polarity of the rectifier. Because only one half of the input waveform reaches the output, it is very inefficient if used for power transfer.

Figure 2.3: Waveform For Half Wave Rectification

Full-wave rectification Full-wave rectification converts both polarities of the input waveform to DC, and is more efficient. It can be realized using two rectifiers or four rectifiers (bridge rectifier).

Figure2.4: Waveform For Full Wave Rectification Using A Bridge Rectifier A full wave rectifier converts the whole of the input waveform to one of constant polarity (positive or negative) at its output by reversing the negative (or positive) portions of the alternating current waveform. The positive (negative) portions thus combine with the reversed negative (positive) portions to produce an entirely positive (negative) voltage/current waveform. For single phase AC, if the AC is center-tapped, then two diodes back-to-back (i.e. anodes-to-anode or cathode-to-cathode) form a full wave rectifier.

Figure 2.5: Waveform For Full Wave Rectification Using 2 Diodes


FILTERS Half- wave and full-wave rectification delivers a form of DC output, neither produces constant voltage DC. In order to produce steady DC from a rectified AC supply, a smoothing circuit is required. In its simplest form this can be what is known as a

reservoir capacitor or smoothing capacitor, placed at the DC output of the rectifier. There will still remain an amount of AC ripple voltage where the voltage is not completely smoothed. To further reduce this ripple, a capacitor-input filter can be used. This complements the reservoir capacitor with a choke and a second filter capacitor, so that a steadier DC output can be obtained across the terminals of the filter capacitor. The choke presents a high impedance to the ripple current.

Figure 2.6: A Simple Capacitor Filter


VOLTAGE REGULATION Another factor of importance in a power supply is the amount by which the dc output voltage changes over a range of circuit operation. The function of the voltage regulator is to keep the terminal voltage of the dc supply constant when the input voltage to the transformer varies and the load varies. The regulators can be selected for operation with load currents from hundreds of milliamperes to tens of amperes, corresponding to power ratings from milliwatts to tens of watts.


VOLTAGE DIVIDER The voltage divider circuit is used to reduce the regulated voltage value from the power supply unit to different values required by various parts of the electronic system. It completely eliminates the need of providing separate dc power supplies to different electronic circuits operating at different dc levels in a given electronic system.


MULTIPLEXERS A multiplexer is a device that encodes information from two or more data sources into a single channel for transmission to another point. It is also known as a data selector. In electronics, the multiplexer combines several electrical signals into a single signal. It selects one of the inputs and then passes it on to the output. There are different types of multiplexers for analog and digital circuits. They are used in situations where the cost of implementing separate channels for each signal is more expensive than the cost and inconvenience of providing the multiplexing/demultiplexing functions. A multiplexer could be a 2-line decoder, a 4-line decoder, an 8-line decoder etc depending on the number of signals to be mulitplexed. The logic circuitry of a four input multiplexer is shown in figure 2.7 below.

Figure 2.7: Logic Diagram For A 4 Line Multiplexer The truth table for the logic diagram can also be realized thus; S0 and S1, which are the control pins are responsible for determining the data input (D0 D3) that is selected to transmitted to the data output line.

0 0 1 1

S1 Data input selected

0 1 0 1 D0 D1 D2 D3

Table 2.2: Data Select For A 4 - Line Multiplexer Multiplexers can be packaged using Small Scale Integration (SSI) or Medium Scale Integration (MSI). They can be fabricated using Complementary Metal Oxide Semiconductor (CMOS), and Transistor Transistor Logic (TTL). Types of multiplexers There are different types of multiplexers for analog and digital circuits. Digital multiplexers: In digital signal processing, the multiplexer takes several separate digital data streams and combines them together into one data stream of a higher data rate. This allows multiple data streams to be carried from one place to another over one physical link. It forwards one of the input streams to the output stream based on the values of one or more "selection inputs" or control inputs. At the receiving end of the link a complementary demultiplexer or demux is normally required to break the high data rate stream back down into the original. Analog multiplexers: In analogue circuit design, a multiplexer is a special type of analogue switch that connects one signal selected from several inputs to a single output. They can input and output levels other than just 1 and 0. The input/output levels can be any analog voltage between the positive and negative supply level. An example is the 4051 manufactured by Philips components.

Applications of multiplexers Multiplexer circuits find varied applications in digital systems of all types. These applications include data selection, data routing, operation sequencing, parallel to serial conversion, waveform generation and logic function generation.


THE ANALOG TO DIGITAL CONVERTER Physical quantities are analog in nature and must be converted into binary form for it to be understood by a digital system. An analog-to-digital converter is employed in this conversion. The digital output consists of a number of bits that represents the value of the analog input. Most analog to digital converters utilizes a digital to analog converter (DAC) in their circuitry. The block diagram is shown in figure 2.8 below:

Figure 2.8: Block Diagram Of An ADC The start command initiates the operation of the ADC and the control unit continually modifies the binary number stored in the register at a rate determined by the clock. The input in the register is converted to an analog voltage by the DAC. The comparator compares the binary number that was converted to an analog voltage VAX with the analog input VA. If VAX < VA the comparator output stays HIGH but when VAX =VA,

the comparator outputs a LOW. The control logic activates the end of converion when the conversion is complete. All ADCs work by sampling their input at discrete intervals of time. This sampling is done at a rate known as Nyquist rate. The analog signal is sampled with a frequency slightly greater than twice the highest frequency of the signal. Sampling at this rate facilitates the perfect reproduction of the original signal by a DAC. Sampling at a rate less than the Nyquists rate causes a problem called aliasing. Examples of analog to digital IC include ADC0801, ADC0802, ADC0803, ADC0804, and ADC0805 etc. Features of an ADC Resolution: The resolution of the converter indicates the number of discrete values it can produce over the range of voltage values. It is usually expressed in bits. For example, an ADC that encodes an analog input to one of 256 discrete values (0255) has a resolution of eight bits, since 28 = 256. Resolution can also be defined electrically, and expressed in volts. The voltage resolution of an ADC is equal to its overall voltage measurement range divided by the number of discrete values. In practice, the resolution of the converter is limited by the signal-to-noise ratio of the signal in question. If there is too much noise present in the analog input, it will be impossible to accurately resolve beyond a certain number of bits of resolution, the "effective number of bits" (ENOB). Accuracy: An ADC has several sources of errors. Quantization error and (assuming the ADC is intended to be linear) non-linearity is intrinsic to any analog-to-digital conversion. There is also aperture error which is due to a clock

jitter and reveals when digitizing a signal (not a single value). These errors are measured in a unit called the LSB, which is an abbreviation for least significant bit. Conversion time: It is the time interval between the end of the start pulse and the activation of the end of conversion output. The value of conversion time depends on the analog signal. A large value will require more steps before the voltage exceeds the analog voltage. ADC structures These are the most common ways of implementing an electronic ADC: Direct conversion ADC or flash ADC: It has a comparator that fires for each decoded voltage range. The comparator bank feeds a logic circuit that generates a code for each voltage range. Direct conversion is very fast, but usually has only 8 bits of resolution (256 comparators) or fewer, as it needs a large, expensive circuit. ADCs of this type have a large die size, a high input capacitance, and are prone to produce glitches on the output (by outputting an out-of-sequence code). They are often used for video or other fast signals. Successive-approximation ADC: It uses a comparator to reject ranges of voltages, eventually settling on a final voltage range. It works by constantly comparing the input voltage to a known reference voltage until the best approximation is achieved. At each step in this process, a binary value of the approximation is stored in a successive approximation register (SAR).The SAR uses a reference voltage (which is predetermined and reflects the conditions for which the ADC is used for) for comparisons. ADCs of this type have good resolutions and quite wide ranges. They are more complex than some other designs. Delta-encoded ADC: has an up-down counter that feeds a digital to analog converter (DAC). The input signal and the DAC both go to a comparator. The

comparator controls the counter. The circuit uses negative feedback from the comparator to adjust the counter until the DAC's output is close enough to the input signal. The number is read from the counter. Delta converters have very wide ranges, and high resolution, but the conversion time is dependent on the input signal level. Delta converters are often very good choices to read real-world signals. Most signals from physical systems do not change abruptly. Some converters combine the delta and successive approximation approaches; this works especially well when high frequencies are known to be small in magnitude. Digital-ramp ADC: It is so named because the waveform is a step by step ramp that is a staircase. When the ramp starts, a timer starts counting. When the ramp voltage matches the input, a comparator fires, and the timer's value is recorded. Timed ramp converters require the least number of transistors. The ramp time is sensitive to temperature because the circuit generating the ramp is often just some simple oscillator. A special advantage of the digital-ramp system is that comparing a second signal just requires another comparator, and another register to store the voltage value. Applications of analog to digital converters ADCs are used virtually everywhere where an analog signal has to be processed, stored, or transported in digital form. They include: Converting analog signal before sending it to any microprocessor/ microcontroller

Figure 2.9: An ADC Connected To Any Processor Digital Signal Processing: A digital Signal Processor performs repetitve calculations on a stream of digitized data. It is the ADC that feeds the digitized data to the digital signal processor. Music recording: ADCs are integral to much current music reproduction technology, since much music production is done on computers; even when analog recording is used, an ADC is still needed to create the PCM data stream that goes onto a compact disc.


THE 89C52 MICROCONTROLLER The 89C52 is an 8-bit microcontroller originally developed by Intel in the late 1970s. It included an instruction set of 255 operation codes (opcodes), 32 input/output lines, three user-controllable timers, an integrated and automatic serial port, and 256 bytes of on-chip RAM. It is an improvement on the 89C51 microprocessor. The 89C52 was designed such that control of the MCU and all input/output between the MCU and external devices is accomplished via Special Function Registers (SFRs). Each SFR has an address between 128 and 255. The 89C52 can be programmed using assembly language or any high level language.


Memory Organization of The 89C52 The 89C52 has three general types of memory. Code memory External memory On-chip memory which include: Internal RAM and special function register (SFR) memory. To program the 89C52 effectively it is necessary to have a basic understanding of these memory types. The code memory holds the actual 89C52 program that is to be run. Code memory which is conventionally limited to a size of 64K comes in various shapes and sizes and may be found on-chip, either burned into the microcontroller as ROM or on an external EPROM. The 89C52 has external RAM that is found off-chip. Since the memory is off-chip the assembly language instructions to access it are slower and less flexible. For example, to increment an Internal RAM location by 1 requires only 1 instruction and 1 instruction cycle. To increment a 1-byte value stored in External RAM requires 4 instructions and 7 instruction cycles. This is because of the type of addressing mode required to access the external RAM. In this case, external memory is 7 times slower and requires 4 times as much program memory. While Internal RAM is normally limited to 256 bytes, the 89C52 supports External RAM up to 64 Kilobytes. The 89C52 has on-chip memory that is further divided into 2: Internal RAM: The 89C52 has a bank of 256 bytes of Internal RAM and so it is the fastest RAM available, and it is also the most flexible in terms of reading, writing, and modifying its contents. Internal RAM is volatile so when the 89C52 is reset, this memory is undefined. It is further divided into stack, register banks and bit memory. The stack is used to store values that the user program manually

pushes onto the stack as well as to store the return addresses for CALLs and interrupt service routines. The register banks are used to assist in manipulating values and moving data from one memory location to another. The 256 bytes of Internal RAM are subdivided as shown in the memory map below:

Figure 2.10: Memory Map Of The 89C52 The first 8 bytes (00H- 07H) are "register bank 0". By manipulating a certain SFR, a program may choose to use register banks 0, 1, 2, or 3. These alternative register banks are located in internal RAM in addresses 08H through 1FH. The bit

memory actually resides in internal RAM, from addresses 20H through 2FH. Also the Internal RAM is byte-wide memory, regardless of whether it is used by register banks or bit memory. Users may use the 208 bytes remaining of the Internal RAM, from addresses 30H through FFH for variables that need to be accessed frequently or at high-speed. This area is also utilized by the microcontroller as a storage area for the operating stack. This fact severely limits the 89C52s stack since, as illustrated in the memory map, the area

reserved for the stack is only 208 bytes--and usually it is less since these 208 bytes have to be shared between the stack and user variables.

Special Function Register (SFR) memory: Special Function Registers (SFRs) are areas of memory that control specific functionality of the 89C52 MCU. For example, four SFRs permit access to the 89C52s 32 input/output lines (8 lines per SFR). Another SFR allows a program to read or write to the 89C52s serial port. Other SFRs allow the user to set the serial baud rate, control and access timers, and configure the 89C52s interrupt system. When programming, SFRs have the illusion of being Internal Memory.


ADDRESSING MODES OF THE 89C52 It refers to how a given memory location is addressed. The instruction set provides several means to address memory locations. There are five basic addressing modes in the 8052 instruction set. Each of these addressing modes provides important flexibility. Immediate Addressing The value to be stored in memory immediately follows the operation code in memory. That is, the instruction itself dictates what value will be stored in memory. For example, the instruction: MOV A, #20h The Accumulator will be loaded with the value that immediately follows; in this case 20 (hexadecimal). Immediate addressing is very fast since the value to be loaded is included in the instruction. However, since the value to be loaded is fixed at compile-time it is not very flexible.

Direct Addressing The value to be stored in memory is obtained by directly retrieving it from another memory location. For example: MOV A, 30h This instruction will read the data out of Internal RAM address 30 (hexadecimal) and store it in the Accumulator. Direct addressing is generally fast because the value to be loaded is not included in the instruction. It is quickly accessible since it is stored in the 89C52s internal RAM. It is also much more flexible than Immediate Addressing since the value to be loaded is whatever is found at the given address--which may be variable. Any instruction that refers to an address between 00h and 7Fh is referring to Internal Memory and any instruction that refers to an address between 80h and FFh is refering to the SFR control registers that control the 89C52 microcontroller itself. Indirect Addressing Indirect addressing is an addressing mode that provides an exceptional level of flexibility. Indirect addressing is also the only way to access the extra 128 bytes of Internal RAM found on an 8052. Indirect addressing appears as follows: MOV A, @R0 This instruction causes the 8052 to analyze the value of the R0 register. The 89C52 will then load the accumulator with the value from Internal RAM that is found at the address indicated by R0. For example, lets say R0 holds the value 40h and Internal RAM address 40h holds the value 67h. When the above instruction is executed the 89C52 will check the value of R0. Since R0 holds 40h the 8051 will get the value out of Internal RAM address 40h

(which holds 67h) and store it in the Accumulator. Thus, the Accumulator ends up holding 67h. External Direct External Memory is accessed using a suite of instructions that use "External Direct" addressing. There are only two commands that use External Direct addressing mode: MOVX A, @DPTR MOVX @DPTR, A Both commands utilize DPTR. In these instructions, DPTR must first be loaded with the address of external memory that you wish to read or write. Once DPTR holds the correct external memory address, the first command will move the contents of that external memory address into the Accumulator. The second command will do the opposite: it will allow you to write the value of the Accumulator to the external memory address pointed to by DPTR. External Indirect External memory can also be accessed using External Indirect addressing. This form of addressing is usually only used in relatively small projects that have a very small amount of external RAM. An example of this addressing mode is: MOVX @R0, A Once again, the value of R0 is first read and the value of the Accumulator is written to that address in External RAM. Since the value of @R0 can only be 00h through FFh, the project would effectively be limited to 256 bytes of External RAM..



Figure 2.11: 89C52 Pin Configuration The 89C52 has a 40-pin DIP pinout. 32 of them are dedicated to I/O lines that have a one-to-one relation with the SFRs P0, P1, P2, and P3. The developer may raise and lower these lines by writing 1s or 0s to the corresponding bits in the SFRs. All of the ports have internal pull-up resistors except for port 0. Port 0 is dual-function in that in some designs, port 0s I/O lines are available to the developer to access external devices while in other designs it is used to access external memory. If the circuit requires external RAM or ROM, the microcontroller will automatically use port 0 to clock in/out the 8-bit data word as well as the low 8 bits of the address in response to a MOVX instruction and port 0 I/O lines may be used for other functions as long as external RAM is not being accessed at the same time. If the circuit requires external code memory, the microcontroller will automatically use the port 0 I/O lines to access each instruction that is to be executed. In

this case, port 0 cannot be utilized for other purposes since the state of the I/O lines are constantly being modified to access external code memory. Port 1 consists of 8 I/O lines that you may use exclusively to interface to external parts. Port 1 is commonly used to interface to external hardware such as LCDs, keypads, and other devices. Like port 0, port 2 is dual-function. In some circuit designs it is available for accessing devices while in others it is used to address external RAM or external code memory. If the circuit requires external code memory, the microcontroller will automatically use the port 2 I/O lines to access each instruction that is to be executed. Port 3 consists entirely of dual-function I/O lines. While the developer may access all these lines from their software by reading/writing to the P3 SFR, each pin has a predefined function that the microcontroller handles automatically when configured to do so and/or when necessary. A crystal connected to XTAL2 and XTAL1 drives the 89C52. Common crystal frequencies are 11.0592 MHz as well as 12 MHz. A TTL clock source may also be attached to XTAL1 and XTAL2 to provide the microcontrollers clock. Pin 9 is the master reset line for the microcontroller. When this pin is brought high for two instruction cycles, the microcontroller is effectively reset. SFRs, including the I/O ports, are restored to their default conditions and the program counter will be reset to 0000H. The Internal RAM is not affected by a reset. The reset line is often connected to a reset button/switch that the user may press to reset the circuit. The address latch enable (ALE) at pin 30 is an output-only pin that is controlled entirely by the microcontroller and allows the microcontroller to multiplex the low-byte of a memory address and the 8-bit data itself on port 0. This is because, while the high-byte of the memory address is sent on port 2, port 0 is used both to send the low byte of the memory address and the data itself. This is accomplished by placing the low-byte of the

address on port 0, exerting ALE high to latch the low-byte of the address into a latch IC (such as the 74HC573), and then placing the 8 data-bits on port 0. In this way the 89C52 is able to output a 16-bit address and an 8-bit data word with 16 I/O lines instead of 24. The Program Store Enable (PSEN) line at pin 29 is exerted low automatically by the microcontroller whenever it accesses external code memory. PSEN will not be exerted by the microcontroller and will remain in a high state if your program is being executed from internal code memory. The External Access (EA) line at pin 31 is used to determine whether the 89C52 will execute your program from external code memory or from internal code memory. If EA is tied high (connected to +5V) then the microcontroller will execute the program it finds in internal/on-chip code memory.


RELAYS A relay is an electrically operated switch. They are used when we need to use a small amount of power in the electromagnet coming from a low power electronic circuit to move an armature that is able to switch a much larger amount of power. In other words, Relays allow one circuit to switch a second circuit that may be completely separate from the first. For example a low voltage battery circuit can use a relay to switch a 230V AC mains circuit. No electrical connection exists inside the relay between the two circuits; the link is magnetic and mechanical. The current flowing through the coil of a relay creates a magnetic field which attracts a lever and changes the switch contacts. The coil current can be on or off. Hence, relays have two switch positions and they are double throw (changeover) switches.

Figure 2.12: Circuit Symbol For A Relay

The relay's switch connections are usually labeled COM, NC and NO: COM = Common; it is the moving part of the switch. NC = Normally Closed, COM is connected to this pin when the relay coil is off. NO = Normally Open, COM is connected to this pin when the relay coil is on. If we want the switched circuit to be on when the relay coil is on, the circuit is connected to COM and NO but if we want it to be on when the relay coil is off, we connect the circuit to COM and NC. Several features are considered when choosing a relay they include: Physical size and pin arrangement: If we are choosing a relay for an existing PCB we will need to ensure that its dimensions and pin arrangement are suitable. This information is usually found in the supplier's catalogue. Coil voltage: The relay's coil voltage rating and resistance and that of the circuit powering the relay coil must match. Many relays have a coil rated for a 12V supply. Some relays however, operate perfectly well with a supply voltage which is a little lower than their rated value. Coil resistance: The circuit must be able to supply the current required by the relay coil. Ohm's law can be used to calculate the current thus: Relay coil current = supply voltage / coil resistance For example: A 12V supply relay with a coil resistance of 400

passes a current of

30mA. This is suitable for a 555 timer IC (maximum output current 200mA), but it is too much for most ICs and they will require a transistor to amplify the current. Switch ratings (voltage and current): The relay's switch contacts must be suitable for the circuit they are to control. The voltage and current ratings must also match. Switch contact arrangement (SPDT, DPDT etc): Most relays are single pole changeover" (SPCO) or "double pole changeover" (DPCO).

Generally, Transistors and ICs (chips) must be protected from the brief high voltage 'spike' produced when the relay coil is switched off. A signal diode (e.g. 1N4148) can be connected across the relay coil to provide this protection. The diode is connected 'backwards' so that conduction only occurs when the relay coil is switched off, at this moment current tries to continue flowing through the coil and it is harmlessly diverted through the diode. Without the diode no current could flow and the coil would produce a damaging high voltage 'spike' in its attempt to keep the current flowing Relays have a number of advantages over other switching devices such as transistors. For instance, Relays can switch AC and DC as well as high voltages. They are a better choice for switching large currents (> 5A). They can also be used to switch many contacts at once. Its drawbacks include bulkiness especially for switching small currents, slow rate of switching as well as more power which is required to drive them due to the current flowing through their coil. Also, most relays require more current than many chips can provide, so a low power transistor may be needed to switch the current for the relay's coil.


SEVEN SEGMENT DISPLAYS Most digital equipment have some means for displaying information in form that can be understood readily by the user or operator. This information is often numerical data but can also be alphanumeric (number and letters). One of the accepted methods for displaying numerical digits is the 7-segment display, which is used to form characters 0-9 and sometimes the hexadecimal characters A-F. The individual segments making up a 7segment display are identified by letters. The decimal point (an eight segment), which

is optional, is used for the display of non-integer numbers. Seven segment displays can be achieved using an arrangement of light- emitting diodes (LEDs) for each segment. By controlling the current through each LED, some

segments will be lighted and others will be dark so that the desired character pattern will be generated. Other types of 7 segment displays exist using alternative technologies such as cold cathode gas discharge, vacuum fluorescent, incandescent filament, liquid crystal display (LCD). The pin connection for an LED based 7-segment display is shown below:

Figure 2.13: Seven-Segment Display Types of 7 segment LED display Common cathode display: Here the cathodes of all the LEDs are joined together and connecting them to a HIGH voltage illuminates the individual segments. Common anode display: Here the anodes of all the LEDs are joined together and connecting them to a LOW voltage illuminates the individual segments. 7 segment displays are designed for applications requiring low power consumption. Drive currents could be as low as 1 mA per segment. The 7-segment display is found in many displays such as microwaves or fancy toaster ovens


TRANSISTORS AND CAPACITORS Passive components are the minor components used in electronic design. For this project only capacitors and resistors will be considered

TRANSISTORS The transistor is a three terminal solid state semiconductor device consisting of either two n-and one p- type layers of material or two p-and one n- type layers of material. The former is called an npn transistor while the latter is called a pnp transistor. Transistors can be used for amplification, switching, voltage stabilization, signal modulation and many other functions. In analog circuits, transistors are used in amplification (direct current amplification, audio amplification, radio frequency amplification), and linear regulated power supplies. Transistors are also used in digital circuits where they function as electrical switches. Digital circuits include logic gates, random access memory (RAM), and microprocessors. Transistors are divided into two main categories: bipolar junction transistors (BJTs) and field effect transistors (FETs). Transistors have three terminals, an input terminal, a common terminal, and an output terminal. Application of current for BJT or voltage for FET between the input terminal and the common terminal increases the conductivity between the common and output terminals, thereby controlling current flow between them. The physics of this "transistor action" is quite different for the BJT and FET. Bipolar Junction Transistors (BJTs) The bipolar junction transistor (BJT) was the first type of transistor to be massproduced. Bipolar transistors are so named because they conduct by using both majority and minority carriers. The three terminals are named emitter, base and collector. Two p-n junctions exist inside an NPN BJT: the base/collector junction and base/emitter junction. The PNP transistor similarly has two n-p junctions.

Figure 2.14: (a) Schematics of a pnp transistor, (b) Schematics of an npn transistor The BJT is commonly described as a current-operated device because the emitter/collector current is controlled by the current flowing between base and emitter terminals. The BJT is a low input-impedance device. Bipolar transistors can be made to conduct with light (photons) as well as current. Devices designed for this purpose are called phototransistors. Field Effect Transistors (FETs) The field-effect transistor (FET), sometimes called a unipolar transistor, uses either electrons (N-channel FET) or holes (P-channel FET) for conduction. The three main terminals of the FET are named source, gate and drain. A voltage applied between the gate and source controls the current flowing between the source and drain. In FETs the source/ drain current flows through a conducting channel near the gate. This channel connects the source region to the drain region. The channel conductivity is varied by the electric field generated by the voltage applied between the gate/source terminals. In this way, the current flowing between the source and drain is controlled. Like bipolar transistors, FETs can be made to conduct with light (photons) as well as voltage. Devices designed for this purpose are called phototransistors.

Field-effect transistor (FET) provides an excellent voltage gain with the added feature of high input impedance. They are considered low- power consumption configurations with good frequency range and minimal side and weight. In summary, while a BJT device controls a large output (collector) current by means of a relatively small input (base) current, the FET device controls an output (drain) current by means of a small input (gate voltage) voltage. In both cases, the output current is the controlled variable.







Figure 2.15: Transistor Symbols For BJT And JFET

CAPACITORS A capacitor is a device that stores energy in the electric field created between a pair of conductors on which electric charges of equal magnitude, but opposite sign, have been placed. A capacitor is occasionally referred to using the older term condenser. Early experiments found that conductor would hold much greater electric charges provided that they were held in close proximitiy to one another yet kept apart. They also found that the greater the surface area the conductors then the greater the stored charge. A capacitor consists of two electrodes, or plates, each of which stores an opposite charge. These two plates are conductive and are separated by an insulator or dielectric.

The charge is stored at the surface of the plates, at the boundary with the dielectric. Because each plate stores an equal but opposite charge, the net charge on the capacitor as a whole is always zero. In the diagram below, the rotated molecules create an opposing electric field that partially cancels the field created by the plates, a process called dielectric polarization. Capacitance in a capacitor When electric charge accumulates on the plates of a capacitor, an electric field is created in the region between the plates that is proportional to the amount of accumulated charge. This electric field creates a potential difference, V = E d between the plates of this simple parallel-plate capacitor. The electrons within dielectric molecules are influenced by the electric field, causing the molecules to rotate slightly from their equilibrium positions. The capacitor's capacitance (C) is a measure of the amount of charge (Q) stored on each plate for a given potential difference or voltage (V) which appears between the plates: that is

In SI units, a capacitor has a capacitance of one farad when one coulomb of charge causes a potential difference of one volt across the plates. Since the farad is a very large unit, values of capacitors are usually expressed in microfarads (F), nanofarads (nF) or picofarads (pF). The capacitance is proportional to the surface area of the conducting plate and inversely proportional to the distance between the plates. It is also proportional to the permittivity of the dielectric (that is, non-conducting) substance that separates the plates. The capacitance of a parallel-plate capacitor is given by:

where is the permittivity of the dielectric, A is the area of the plates and d is the spacing between them. Applications Capacitors are applied in most electronic and electrical systems Energy storage: A capacitor can store electric energy when disconnected from its charging circuit, so it can be used like a temporary battery. Capacitors are commonly used to supply energy to electronic devices without the memory being lost when changing their batteries. Smoothening: Capacitors are used in power supplies where they smooth the output of a full or half wave rectifier. They can also be used in charge pump circuits as the energy storage element in the generation of higher voltages than the input voltage. Capacitors are connected in parallel with the power circuits of most electronic devices and larger systems (such as factories) to shunt away and conceal current fluctuations from the primary power source to provide a "clean" power supply for signal or control circuits. Filtering: Capacitors pass AC but block DC signals (when charged up to the applied dc voltage), and are often used to separate the AC and DC components of a signal. This method is known as AC coupling. Capacitors for this purpose are designed to fit through a metal panel called feed-through capacitors. Capacitors are also used to filter noise. It is usually connected with a resistor in parallel or series. Signal processing: The energy stored in a capacitor can be used to represent information, either in binary form, as in computers, or in analogue form, as in

switched-capacitor circuits and bucket-brigade delay lines. Capacitors can be used in analog circuits as components of integrators or filters that are more complex and in negative feedback loop stabilization. Signal processing circuits also use capacitors to integrate a current signal.


3.1 SYSTEM OVERVIEW The system consists of different modules which include voltage rectification and regulation, analog multiplexing circuit, analog to digital converter (ADC), microcontroller module, display circuitry, relay circuit. The different modules are interconnected as shown in figure 3.1 below.

Figure 3.1: Block Diagram Of An Automatic Power Selector For Multiple Ac Sources The functions of the different blocks will now be treated individually before the actual design of the circuit to realize these functions. The power supply unit consists of an autotransformer and three step down transformers. The function of the autotransformer is to simulate the multiple AC power sources. It generates different voltage levels that will be used to test the system. The step down transformers steps down the input voltage depending on their turns ratio for subsequent rectification.

AC voltage signals from the transformers are fed into the rectifier circuit for rectification. and smoothening. The result is a dc voltage that is analog in nature. Voltage regulation is carried out to ensure that a constant supply voltage is available for the Integrated circuit chips and the relay. The multiplexer is used to eliminate the need for multiple ADCs for the conversion of the individual sources that will be fed to the microcontroller. The signal obtained from rectification is essentially a dc voltage with some ripples; they are inputs to the analog to digital converter (ADC) that converts the analog signal into digital form that can be processed by the microcontroller. The microcontroller scans the input voltages, and measures them against the optimum value, which we set to be 220V 20V. The power source with the least deviation from the optimum value of input voltage that falls within the range is automatically selected to power the light bulb (load). The relay system switches in order to power the load at a given time. The microcontroller also sends a signal that enables the seven segment displays to display the particular power source in use and also the status of all the other sources at any particular time. The microcontroller actualizes these functions through the series of micro programmed instructions that is embedded into it.


SYSTEM SPECIFICATION AND DESIGN We are going to design a system that will automatically carry out selection of a favourable power source to power a load given multiple power sources. The system is expected to measure three input voltages, display their values and appropriately select one for use based on a specified voltage range given as 220V20 for the purpose of this work. In the event that all input voltages are not within this range, the system is expected to issue

a control signal to another circuitry that will turn on a stand by generator. The maximum voltage that the system supports is 300V. However due to the limitation of resources and time, only a display indicating that the generator is to be on will be realized. The blocks were first considered individually and tested to ensure that they satisfied the functional requirements. When the testing of the individual blocks were completed on a bread board, all the blocks were connected together as in the block diagram. At this point, problems rising due to improper interfacing between the blocks were solved.


VOLTAGE RECTIFICATION AND REGULATION The voltage rectification and regulation circuit is as shown in figure 3.2 below.

Figure 3.2: Circuit Diagram For Voltage Rectification And Regulation The step down transformers receives input voltages from the power supply (auto transformer) and steps down the respective voltages in proportion to a turns ratio of 20:1. The voltage rectifier IC carries out full wave rectification to produce a dc output voltage. The advantage of a full wave rectified output is that it has less ripple than a half wave

rectified output. The smaller the ac variation with respect to the dc level, the better the filter circuits operation. The rectified signal is then passed through a capacitive filter to reduce the ripple level and produce a steadier dc voltage. Larger values of capacitance provide less ripple and higher average voltage thereby providing better filter action. The 1000f capacitor performs this function. A dc output voltage changes over a range of circuit operation. The voltage provided at the output under no load condition is reduced when the load current is drawn from the supply. There is need for a constant supply of 5V to the ICs and 12V to power the relay. To realize this, we used three-terminal voltage regulators (7805 and7812); they are fixed positive voltage regulators that produce a steady output voltage of +5V and +12V respectively. The three terminals are the input, common and output. The common is connected to ground. The already rectified and smoothened signal is fed into the input terminal of the regulator and a capacitor is connected at the output terminal to filter noise. The variable resistor functions as a voltage divider to scale down the input voltages such that it falls within the range of 0-5V, which is the maximum range of inputs for the ADC.


THE ANALOG DIGITAL SWITCH Several ADCs would have been necessary to realize the analog to digital conversion of the input dc voltages. This would have led to increased cost and complexity of the circuit. Multiplexing was used to address this problem as shown in figure 3.3. Due to the unavailability of analog multiplexers in the market, a quad bilateral switch (4016) was used to achieve analog multiplexing. Since we are testing only three input voltages at a time, Pin 10,11 and 12 which correspond to the input, output and

control of the fourth input voltage were grounded. Pin 14 (Vcc) is connected to a constant supply of 5V and Pin 7(ground pin) to ground.

Figure 3.3: Pin Connections Of The Analog-Digital Switch The 4016 contains four independent switches SWA, SWB, SWC and SWD. Their respective control pins(ACON, BCON and CCON and DCON) determine the status of each switch. When ACON is high, then SWA is closed and the voltage at pin 1 is sent to the ADC through output pin 2 A0.The same applies to the rest of the switches. The microcontroller determines which control pin is activated at a particular time by sending signals at specified intervals to the control pins. Two control pins cannot be activated at the same time. Thus, time-division multiplexing is successfully achieved.


THE ANALOG-DIGITAL INTERFACE The analog to digital converter ADC0804 provides the interface between the analog and the digital modules of the system. Any of the three inputs selected by the analog to digital switch forms the input to the ADC through its pin 6 (VIN+). The two

analog inputs VIN+ and VIN- allows differential inputs, that is the actual analog input VIN is the difference in the voltages applied to these two pins. In our design, VIN- is connected to ground. Therefore, the VIN = VIN+ - OV. The ADC converts the analog input voltage to an 8-bit digital output.

Figure 3.4: Pin Connections Of The ADC A low pulse is applied to the Pin 3(WR) to signal the start of a conversion. When conversion is complete, the ADC sends an active low interrupt request signal to the microcontroller through Pin 5(INTR) indicating the end of conversion process. The corresponding digital voltage value is currently at the ADCs data port (DB7-DB0). Pins 1, 4,7,8,10 and 19 are grounded as shown in the figure above. Pin 20 is connected to VCC of 5V.A resistor is connected to CLKR to use the internal clock. CLKIN is connected to a capacitor because the internal clock of the ADC is used in this design.

3.6 MICROCONTROLLER MODULE The microcontroller module is as shown in figure 3.5. The microcontroller issues an active low write control signal to the ADC through its Pin 16(WR). Pin 16 is connected

to the WR pin of the ADC. Pin 7(RD) is connected to the interrupt pin of the ADC; a low pulse from the ADC indicates the end of conversion process. The microcontroller then reads the corresponding digital voltage value of the input which is currently at the data port (DB7-DB0) through its Port 0 (P0.0 P0.7).

Figure 3.5: Microcontroller Module Pins 10, 11 and 12 (P3.0 P3.2) are connected to the control pins of the analogdigital switch. It sends binary data that selects the respective switches of the analog multiplexer. Port 1 (P1.0 P1.7) and Port 2(P2.0-P2.7) of the microcontroller is used as an output pin to send the required data that will display the status of each power source. P3.3P3.5 are output ports that are connected to the relay circuit.

The RESET, VCC and EA pins are tied to a 5V VCC. EA is tied high because the microcontroller is not using an external memory. While the GND pin is grounded as shown in the figure above. A crystal oscillator of 16MHz frequency connected to XTAL1 and XTAL2 pins of the microcontroller as shown generates the clock required to sequence all the operations of the system. This high frequency causes the microprocessor to operate at a very high speed.


DISPLAY CIRCUITRY This consists of eight common cathode LED seven segment displays. To illuminate an LED, its cathode must be connected to a high. The common cathodes of the displays are connected through a pull up transistor to port 2 (P2.0 P2.7) of the microcontroller. The pins representing the alphabets (a-g and dot) of each display are connected to port 1 (P1.0 P1.7) of the microcontroller. The binary pattern (data) that is required to display the status of each line as well as the specified line in use is sent to the display circuitry through port 1 (P1.0 P1.7) of the microcontroller as shown in the figure below. Our design employs a scrollable display, the data gets to each of the displays and a binary pattern is also sent to port 2 (P2.0 P2.7) of the microcontroller in order to select which of the displays would have its data displayed. (P2.0 P2.7) is connected to the base of the pull up transistors. A high at the transistor base enables the collector current flow out through the emitter. The truth table of the common cathode seven segment display is as shown in table 3.1 below:

c (Pin a (Pin 1) b (Pin 10) 8) 0 1 2 3 4 5 6 7 8 9 A b C d E F 1 0 1 1 0 1 1 1 1 1 1 0 1 0 1 1 1 1 1 1 1 0 0 1 1 1 1 0 0 1 0 0 1 1 0 1 1 1 1 1 1 1 1 1 0 1 0 0

d (Pin e (Pin 5) f (Pin 2) g (Pin 9) 6) 1 0 1 1 0 1 1 0 1 0 0 1 1 1 1 0 1 0 1 0 0 0 1 0 1 0 1 1 1 1 1 1 1 0 0 0 1 1 1 0 1 1 1 1 1 0 1 1 0 0 1 1 1 1 1 0 1 1 1 1 0 1 1 1


0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

Table 3.1: Truth Table For A Common Cathode 7 Segment Display

Figure 3.6: The Display Circuit


THE RELAY CIRCUIT The relay circuit was designed as shown in the figure below. The relay is connected in the normally open mode such that the relay switches to light the bulb when the relay is ON, and the COM and the NO pins make contact with each other. For the relay circuit to be activated, a base current is required at the base of the PNP transistor for the relay to come ON. When the base current flows into the transistor, the magnetic core of the relay gets magnetized and the normally open (NO) pin of the relay which is connected to the load (bulb), makes contact with the common (COM) pin and thus a complete circuit is formed and the load (bulb) lights.

Figure 3.7: The Relay Circuit The relay is connected in the normally open mode such that the relay switches to light the bulb when the relay is ON, and the COM and the NO pins make contact with each other. The signal diode is connected across the relay to protect it from spikes when the relay coil is switched on. The diode is connected backward so that it will normally not conduct. Conduction only occurs when the relay coil is switched on, at this moment current tries to continue flowing through the coil and it is harmlessly deviated through the diode.


HARDWARE INTEGRATION The different modules specified in the block diagram was designed and tested to ensure their functionality. The output voltages of the autotransformer were measured in

order to ascertain the actual values. Also the output voltages of the 7812 regulator was tested to confirm that it could switch the relay and that of the 7805 to make sure that 5V is supplied to the ICs. The microcontroller, analog digital switch, ADC and display circuit were not be tested at this level because their functionality depends on the software embedded in the microcontroller. The software at this point was yet to be programmed into the 89C52. All the modules were integrated as in figure 3.8.


We employed a top down methodology in building our software. With this approach the design is presented in stages of increasing details. It starts with an overview of the system using the software specification requirement, and then its design details using a flow chart, this last stage is conventionally specified using pseudocodes.


SOFTWARE REQUIREMENT SPECIFICATION The assembly language codes is expected to capture the following functions: Specify the optimum voltage of 220V Maximum deviation from the optimum voltage is set as 20 volts Capture the input voltages (in digital form) and convert and scale to the analog value. Store the analog input voltage values in registers Display the different analog values of the inputs Compare input voltages with the optimum voltage value and obtain the positive difference Determine the input with the least value of positive difference Compare this value with the set value of maximum deviation from optimum voltage If it is less than 20volts, then the input is selected for use and is indicated in the display panel If it is more than 20 volts, a stand by generator is switched on.


PROGRAM DESIGN (FLOW CHART) The flow chart of the automatic power selector is shown in the figure below

Figure 4.1: Flowchart For Automatic Power Selector For Multiple AC Sources


SOFTWARE DEVELOPMENT TOOLS The 8052 can be programmed with any language as long as a translator is available to translate the codes to machine language opcodes (operation codes) of the 8052.Assembly language is a low level language that is closest to machine language because they have one to one relationship with machine language codes. To code in assembly language it is necessary to understand the architecture of the microprocessor. Another way of writing a program for a microcomputer is with a high-level language such as BASIC, Paschal or C. These languages use program statements that are more English-like than those of assembly language. Each high level language may represent many machine code instructions. A compiler program is used to translate higherlevel language statements to machine codes which can be loaded into memory and executed. To code in C for example we need a C compiler for 8052. Programs can usually be written faster in high-level languages than assembly language because the high-level language works with bigger building blocks. However, such programs usually execute more slowly and require more memory than the same programs written in assembly. Therefore, programs that involve a lot of hardware control such as robots and factory control systems or programs that must run as quickly as possible are best written in assembly language. . The following kits are required to program in assembly language PG302 Programmer PG302 Programmer Software ADT 87 Adapter (for programming 89C51, 89C52 etc) ADT 90 Adapter DB9 Serial Port Cable Turbo Assembler (TASM)


PROGRAMMING THE 89C52 Program is written with a text editor It is saved as filename.asm Click the start button on computer Click on run Browse to location of TASM Click on tasm.exe Type in TASM-51 file path\filename.asm filename.hex (this command assembles the code to produce a hex file) The appropriate adapter is connected to the PG302 programmer The programmer is connected to the serial port of the computer using the serial cable The microprocessor chip is plugged in and power is supplied to the programmer The PG302 is loaded and appropriate settings carried out The status of the chip is checked to confirm it is blank. If it is not blank, it must be erased The hex file to be burnt into the chip is located Click on Program device (the programming takes a few seconds) When the process is complete, the chip is unplugged and fixed in the IC socket for in-circuit testing The TASM is an assembler that coverts the coded program into its hexadecimal equivalent by converting the program into hex files, object file and list file. The hex file shows the hexadecimal equivalent of the coded program. The list file shows the list of all the errors that occurred while running the program and the line in which they occurred for

purposes of debugging. The PG302 is the hardware that converts the hex codes into machine language 1s and 0s. The assembly codes are attached in the appendix


SYSTEM TESTING The programmed 89C52 is placed in its socket and in circuit testing was carried out. It was observed that the design objective was realized with a little drawback. When any 3 input voltages were tested, the voltage closet to the optimum voltage within a tolerance of 20 was selected to power the load. When none of the input voltages were within the tolerance range, gen on was displayed. However, due to cost limitations we could not actualize the start up of a generator.


5.5 SUMMARY The aim of this project which is to design and construct a microcontroller based automatic power selector was realized. Programmed designed was employed to reduce design complexity and achieve cost effectiveness in commercial production. An analog digital interface was necessary because supply voltages are analog in nature but digital processing was employed. Digital processing is chosen over the analog because of high efficiency, cost effectiveness and high accuracy of digital systems. The system was designed to operate within a range of 0 300V (ac). The system provides a solution to the problem of managing multiple power sources that arose out of a need for constant power supply in developing countries like Nigeria. It can be used in industries, base stations, football pitch, hospital theatres, residential buildings etc.


CHALLENGES FACED The major challenge faced was that of the unavailability of certain components. A design of this nature required the use of an 89C51 microcontroller which has 128 byte of RAM. However due to its unavailability in the local market, a trade off was made between transport cost and the use of 89C52 with 256 byte of RAM which was under utilized. The ADC0804 was also not available in the east leading to considerable travel expenses. A design alternative was used to implement multiplexing due to scarcity of analog multiplexers. This led to an increase in the size of codes required. Also some components did not produce the nominal values of output specified by the manufacturer.


COST ANALYSIS The estimate of the cost of the individual components is shown in table 5.1 below. From the table, it can be inferred that the total cost for the actualization of this project is put at about N 20,820 .00 including miscellaneous, transportation and other logistic expenses.

1 2


1 3

4000 100

4000 300 4500

Rectifier IC Hire of PG302 Kit

3 4 5 6 7 8 9 10 11 12 13 14 15 16 18 19

4016 ADC(0804) 89C52 microcontroller Dual seven segment displays Relays Resistors Capacitors Crystal Connectors Light bulb Dot Matrix Vero board Transistors Diodes IC Sockets Packaging Transport / Miscellaneous TOTAL

1 1 1 4 3 12 10 1 9yds 1 3 12 6 5

200 1000 2000 200 70 10 10 50 20 60 200 10 5 50

200 1000 2000 800 210 120 100 50 180 60 600 120 30 250 1300 5000 20,820


RECOMMENDATIONS FOR FURTHER STUDY This design is only a model that can be modified in order to accommodate some other specifications that may be required in the future.

The design of a circuit to automatically power on the generator in the event of power failure and the possibility of expanding the number of voltage inputs to the system are left as recommendation for further study and improvement. It is also recommended that an uninterrupted power supply unit be provided for the microcontroller so that in the event of absolute power failure and the unavailability of a stand by generator, the microcontroller can still indicate this status.


Altman, L. and Scrupski, S.E(Ed.), Applying Microprocessors, Electronics Magazine Book Series, McGraw Hill.N.Y.1976.

Boylestad, R.L and Nashelsky, L., Electronic Device and Circuit theory & ed, Hall of India Private Limited, New Delhi, 2003. Hayes, T.C. and Horowitz, P.G., The Art Of Electronics, 2nd ed, Cambridge University Press,Great Britain (1980)

Hordeski, M., Interfacing Microcomputers in Control Systems, Instruments and control Systems,Vol.52, No.5, pp40-48, May 1979. Kleitz, W., Digital and Microprocessor Fundamentals, Theory and Applications, 4th ed, Prentice Hall Inc., Pearson Education, Japan, 2003.

Special Issue on Microprocessors, Proc. IEEE, vol.66. No.2, 1978.

Theraja, A. K and Theraja, B.L., A Textbook of Electrical Technology, S.Chand and CompanyLimited, New Delhi, 1999.

The Online 8052 Resource, 8052 Tutorial and Reference,

Tocci, R.J. and Laskowski, L.P., Microprocessors and Microcomputers: Hardware and Software,Prentice Hall Inc., New Jersey, 1979.

Weller, W.J., Assembly Level Programming for Small Computers, D.C Health and Co., Lexington, Massachusetts, 1975.

Zaks, R., Microprocessor: From Chips to Systems, SYBEX, Berkley, Carlifornia, 1977.