Embedded system for traffic light control

12,261 views

Published on

documentation

Published in: Engineering, Business, Technology
0 Comments
5 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
12,261
On SlideShare
0
From Embeds
0
Number of Embeds
74
Actions
Shares
0
Downloads
637
Comments
0
Likes
5
Embeds 0
No embeds

No notes for slide

Embedded system for traffic light control

  1. 1. EMBEDDED SYSTEMS FOR TRAFFIC LIGHT CONTROL A main project report submitted to JNTUH in partial fulfillment of the requirements for the award of the degree Bachelor of Technology in Electronics and Communication Engineering Submitted by B.SRUTHI 10L01A0466 K.DHARMARAJ 10L01A0491 G.MADHU 10L01A0480 Under the guidance of Ms. A. Sushma Assistant Professor Department of Electronics and Communication Engineering TRR COLLEGE OF ENGINEERING (Affiliated to JNTUH) Inole(V), Patancheru(M), Medak District, A. P. 2013-2014. Department of Electronics and Communication Engineering
  2. 2. TRR COLLEGE OF ENGINEERING (Affiliated to JNTUH) Inole(V), Patancheru(M), Medak District, A. P. CERTIFICATE This is to certify that the main project entitled “EMBEDDED SYSTEMS FOR TRAFFIC LIGHT CONTROL” has been submitted by B.Sruthi, K.Dharma raj, G.Madhu in partial fulfillment of the requirements for the award of Bachelor of Technology in Electronics and Communication Engineering. This record of bonafide work carried out by them under my guidance and supervision. The result embodied in this project report has not been submitted to any other University or Institute for the award of any degree. Internal Guide Head of the Department Ms. A. Sushma Prof. G. Rajender, Assistant Professor M.Tech.,(Ph.D) External Examiner
  3. 3. ACKNOWLEDGEMENT: With great pleasure we want to take this opportunity to express our heartfelt gratitude to all the people who helped us in making this project a great success. We are grateful to Ms. A.Sushma, Assistant Professor for giving us moral support throughout the period of execution of the project. We are highly debted to Prof. G. Rajender, M.Tech.,(Ph.D),Professor and Head of the Department of Electronics and Communication Engineering for giving us permission to carry out this project. We are grateful to the principal Dr. K. Srinivasa Rao, M.E., Ph.D, for giving us to carry out this project. We would like to thank the TEACHING and NON TEACHING STAFF and also those who have directly or indirectly helped in the completion of this project NAMES ROLL NO SIGNS B.SRUTHI 10L01A0466 K.DHARMARAJ 10L01A0491 G.MADHU 10L01A0480
  4. 4. CONTENTS Abstract List of Figures List of Tables 1 Introduction to Embedded Systems 1 1.1 History 1 1.2 Overview 1 1.3 Embedded Systems 3 1.4 Basic block of Embedded Systems 4 2 Embedded Systems For Traffic Control 10 2.1 Introduction 10 2.2 System Modelling 11 2.3 Transmitter 14 2.4 Receiver 15 2.5 Power Supplies 17 3 ARM7 Microprocessor 23 3.1 Introduction 23 3.2 The Instruction Pipeline 23 3.3 Memory Access 24 3.4 Memory Interface 25 3.5 Architechture 27 4 LPC2148 MICRO CONTROLLER 30 4.1 Introduction 30 4.2 Features 30 4.3 PIN Description 34 4.4 General purpose input,output Registers 40 4.5 Memory Maps 45
  5. 5. 4.6 Testing Traffic lights with LPC2148 47 5 AT89C51 CONTROLLER 48 5.1 Pin description 50 6 IR SENSORS 51 6.1 IR Transmitter 52 6.2 IR Receiver 53 7 SOFTWARE DESCRIPTION 55 7.1 KEIL Compiler 55 7.2 Proload 62 8 RESULT ANALYSIS 63 8.1 Source code 66 CONCLUSION 77 BIBLIOGRAPHY 78
  6. 6. LIST OF FIGURES S.NO Page. NO 1.1 Block Diagram Of Embedded Systems 5 2.1 Proto type of Road 12 2.2 Block Diagram Of Traffic Lights 14 2.3 Block Diagram Of Power Supply 17 2 .4 Smoothing Capacitor and Output 20 2.5 Regulator 22 2.6 Circuit Of Power Supply 22 3.1 The Instruction Pipeline 23 3.2 Block Diagram Of ARM7 24 3.3 ARM7TDMI Processor 25 4.1 PIN diagram of LPC2148 33 4.2 Block diagram of UART0 42 4.3 Block diagram of UART1 44 4.4 System Memory Map 45 5.1 AT89C51 PIN diagram 49 7.1 Creating New Project 56 7.2 Creating a Target 57 7.3 Creating A File 58 7.4 Adding files to Source group 59 7.5 Rebuilding Target 60 7.6 Debugging 61 8.1 Road 1 Analysis 63 8.2 Road 2 Analysis 64 8.3 Road 3 Analysis 64 8.4 Road 4 Analysis 65
  7. 7. LIST OF TABLES S.NO Page. NO 2.1 Positive Voltage Regulator in 7800 series 21 3.1 ARM7TDMI Register set and operating modes 26 4.1 GPIO PIN Description 40 4.2 UARTO PIN Description 41
  8. 8. ABSTRACT In the present scenario, vehicular traffic is increasing throughout the world, especially in large urban areas. As the number of road users constantly increase and resources provided by current infrastructures being limited, a smart traffic control will become a very important issue in the future. These needs have led to an ever increasing demand for an “intelligent” traffic control system. Therefore, optimization of traffic control to better accommodate this increasing demand is needed. In this project, we will demonstrate the optimization of traffic light controller in a city using wireless sensors. Traffic light optimization is a complex problem. With multiple junctions, the problem becomes even more complex as the state of one light node influences the flow of traffic towards many other nodes. We have proposed a traffic light controller and simulator that allow us to study different situations of traffic density. Using wireless sensors, we can easily sense the density of traffic because the general architecture of wireless sensors is an infrastructure -less communication network. The brain behind the implementation is an ARM 7(LPC2148) programmed using Embedded C, which performs processing of the real time data provided by the wireless sensors, eventually controlling the traffic flow via the LED traffic lights.
  9. 9. CHAPTER 1 INTRODUCTION TO EMBEDDED SYSTEMS 1.1History: In the present scenario, vehicular traffic is increasing throughout the world, especially in large urban areas. As the number of road users constantly increase and resources provided by current infrastructures being limited, a smart traffic control will become a very important issue in the future. These needs have led to an ever increasing demand for an “intelligent” traffic control system. Therefore, optimization of traffic control to better accommodate this increasing demand is needed. In this project, we will demonstrate the optimization of traffic light controller in a city using wireless sensors. Traffic light optimization is a complex problem. With multiple junctions, the problem becomes even more complex as the state of one light node influences the flow of traffic towards many other nodes. We have proposed a traffic light controller and simulator that allow us to study different situations of traffic density. Using wireless sensors, we can easily sense the density of traffic because the general architecture of wireless sensors is an infrastructure -less communication network. it is observed that the proposed intelligent Traffic Light controller is more efficient than the convenctional controller in respect of less waiting time, more distance travelled by average vehicles and efficient operation during emergency mode and GSM designed system as simple architecture, fast response time,user friendliness and scope for further expansion. 1.2 Overview The main objective of this project to control the traffic lights based on the density of the vehicles .In this system IR sensors are used to measure the density of the vechicles which are fixed with in a fixed distance. All the sensors are interfaced with the microcontroller which in turn controls the traffic signals system according to density detected by the sensors. The traffic density is high on particular side more priority is given for that side The sensors continuously keep sensing density on all sides and the green signal is given to the side on priority basis, where the sensors detect high density.The side with next priority
  10. 10. level follows the first priority level. By using this system traffic can be cleared without irregularities and time delay seven though there is on the other side can be avoided 1.3 Embedded System: An embedded system is a special-purpose computer system designed to perform one or a few dedicated functions, sometimes with real-time computing constraints. It is usually embedded as part of a complete device including hardware and mechanical parts. In contrast, a general- purpose computer, such as a personal computer, can do many different tasks depending on programming. Embedded systems have become very important today as they control many of the common devices we use. Since the embedded system is dedicated to specific tasks, design engineers can optimize it, reducing the size and cost of the product, or increasing the reliability and performance. Some embedded systems are mass-produced, benefiting from economies of scale. Physically, embedded systems range from portable devices such as digital watches and MP3 players, to large stationary installations like traffic lights, factory controllers, or the systems controlling nuclear power plants. Complexity varies from low, with a single microcontroller chip, to very high with multiple units, peripherals and networks mounted inside a large chassis or enclosure. In general, "embedded system" is not an exactly defined term, as many systems have some element of programmability. For example, Handheld computers share some elements with embedded systems such as the operating systems and microprocessors which power them but are not truly embedded systems, because they allow different applications to be loaded and peripherals to be connected. An embedded system is some combination of computer hardware and software, either fixed in capability or programmable, that is specifically designed for a particular kind of application device. Industrial machines, automobiles, medical equipment, cameras, household appliances, airplanes, vending machines, and toys (as well as the more obvious cellular phone and PDA) are among the myriad possible hosts of an embedded system. Embedded systems that
  11. 11. are programmable are provided with a programming interface, and embedded systems programming is a specialized occupation. Certain operating systems or language platforms are tailored for the embedded market, such as Embedded Java and Windows XP Embedded. However, some low-end consumer products use very inexpensive microprocessors and limited storage, with the application and operating system both part of a single program. The program is written permanently into the system's memory in this case, rather than being loaded into RAM (Random Access Memory), as programs on a personal computer. In recent days, you are showered with variety of information about these embedded controllers in many places. All kinds of magazines and journals regularly dish out details about latest technologies, new devices; fast applications which make you believe that your basic survival is controlled by these embedded products. Now you can agree to the fact that these embedded products have successfully invaded into our world. You must be wondering about these embedded controllers or systems. The computer you use to compose your mails, or create a document or analyze the database is known as the standard desktop computer. These desktop computers are manufactured to serve many purposes and applications. You need to install the relevant software to get the required processing facility. So, these desktop computers can do many things. In contrast, embedded controllers carryout a specific work for which they are designed. Most of the time, engineers design these embedded controllers with a specific goal in mind. So these controllers cannot be used in any other place. Theoretically, an embedded controller is a combination of a piece of microprocessor based hardware and the suitable software to undertake a specific task. These days designers have many choices in microprocessors/microcontrollers. Especially, in 8 bit and 32 bit, the available variety really may overwhelm even an experienced designer. Selecting a right microprocessor may turn out as a most difficult first step and it is getting complicated as new devices continue to pop-up very often.
  12. 12. 1.4 Basic Blocks of Embedded System: Now, the details of the various building blocks of the hardware of an embedded system as shown in Fig 1.1 are . Central Processing Unit (CPU) · Memory (Read-only Memory and Random Access Memory) · Input Devices · Output devices · Communication interfaces · Application-specific circuitry Central Processing Unit (CPU): The Central Processing Unit (processor, in short) can be any of the following: microcontroller, microprocessor or Digital Signal Processor (DSP). A micro-controller is a low- cost processor. Its main attraction is that on the chip itself, there will be many other components such as memory, serial communication interface, analog-to digital converter etc. So, for small applications, a micro-controller is the best choice as the number of external components required will be very less. On the other hand, microprocessors are more powerful, but you need to use many external components with them. DSP is used mainly for applications in which signal processing is involved such as audio and video processing.
  13. 13. Figure.1.1: Block Diagram of Embedded System Memory: The memory is categorized as Random Access Memory (RAM) and Read Only Memory (ROM). The contents of the RAM will be erased if power is switched off to the chip, whereas ROM retains the contents even if the power is switched off. So, the firmware is stored in the ROM. When power is switched on, the processor reads the ROM; the program is executed. Input devices: Unlike the desktops, the input devices to an embedded system have very limited capability. There will be no keyboard or a mouse, and hence interacting with the embedded system is not an easy task. Many embedded systems will have a small keypad-you press one key to give a specific command. A keypad may be used to input only the digits. Many embedded
  14. 14. systems used in process control do not have any input device for user interaction; they take inputs from sensors or transducers and produce electrical signals that are in turn fed to other systems. Output devices: The output devices of the embedded systems also have very limited capability. Some embedded systems will have a few Light Emitting Diodes (LEDs) to indicate the health status of the system modules, or for visual indication of alarms. A small Liquid Crystal Display (LCD) may also be used to display some important parameters. Communication interfaces: The embedded systems may need to, interact with other embedded systems at they may have to transmit data to a desktop. To facilitate this, the embedded systems are provided with one or a few communication interfaces such as RS232, RS422, RS485, Universal Serial Bus (USB), and IEEE 1394, Ethernet etc. Application-specific circuitry: Sensors, transducers, special processing and control circuitry may be required for an embedded system, depending on its application. This circuitry interacts with the processor to carry out the necessary work. The entire hardware has to be given power supply either through the 230 volts main supply or through a battery. The hardware has to design in such a way that the power consumption is minimized. Security is the condition of being protected against danger or loss. In the general sense, security is a concept similar to safety. The nuance between the two is an added emphasis on being protected from dangers that originate from outside. Individuals or actions that encroach upon the condition of protection are responsible for the breach of security. The word "security" in general usage is synonymous with "safety," but as a technical term "security" means that something not only is secure but that it has been secured. One of the best options for providing good security is by using a technology named EMBEDDED SYSTEMS.
  15. 15. 1.5 Microcontroller: In the Literature discussing microprocessors, we often see the term Embedded System. Microprocessors and Microcontrollers are widely used in embedded system products. An embedded system product uses a microprocessor (or Microcontroller) to do one task only. A printer is an example of embedded system since the processor inside it performs one task only, namely getting the data and printing it. Contrast this with a Pentium based PC can be used for any number of applications such as word processor, print-server, bank teller terminal, Video game, network server, or Internet terminal. Software for a variety of applications can be loaded and run. Of course the reason a pc can perform myriad tasks is that it has RAM memory and an operating system that loads the application software into RAM memory and lets the CPU run it. In an Embedded system, there is only one application software that is typically burned into ROM. An x86 PC contains or is connected to various embedded products such as keyboard, printer, modem, disk controller, sound card, CD-ROM drives, mouse, and so on. Each one of these peripherals has a Microcontroller inside it that performs only one task. For example, inside every mouse there is a Microcontroller to perform the task of finding the mouse position and sending it to the PC. Application Areas Nearly 99 per cent of the processors manufactured end up in embedded systems. The embedded system market is one of the highest growth areas as these systems are used in very market segment- consumer electronics, office automation, industrial automation, biomedical engineering, wireless communication, data communication, telecommunications, transportation, military and so on. Consumer appliances: At home we use a number of embedded systems which include digital camera, digital diary, DVD player, video recorders etc. Office automation: The office automation products using embedded systems are copying machine, fax machine, key telephone, modem, printer, scanner etc
  16. 16. Industrial automation: Today a lot of industries use embedded systems for process control. In hazardous industrial environment, where human presence has to be avoided, robots are used, which are programmed to do specific jobs. Medical electronics: Almost every medical equipment in the hospital is an embedded system. These equipments include diagnostic aids such as ECG, EEG, blood pressure measuring devices, radiation, colonoscopy, endoscopy etc. Computer networking: Computer networking products such as bridges, routers, Integrated Services Digital Networks (ISDN), Asynchronous Transfer Mode (ATM), X.25 and frame relay switches are embedded systems which implement the necessary data communication protocols Telecommunications: In the field of telecommunications, the embedded systems can be categorized as subscriber terminals and network equipment. The subscriber terminals such as key telephones, ISDN phones, terminal adapters, web cameras are embedded systems. The network equipment includes multiplexers, multiple access systems, Packet Assemblers Dissemblers (PADs), sate11ite modems etc. Security: Security of persons and information has always been a major issue. We need to protect our homes and offices; and also the information we transmit and store. Developing embedded systems for devices at homes, offices, airports etc. for authentication and verification are embedded systems security applications is one of the most lucrative businesses nowadays. Microprocessors Vs Microcontrollers: • Microprocessors are single-chip CPUs used in microcomputers. • Microcontrollers and microprocessors are different in 3 main aspects: hardware architecture, applications, and instruction set features. • Hardware architecture: A microprocessor is a single chip CPU while a microcontroller is a single IC contains a CPU and much of remaining circuitry of a complete computer (e.g., RAM, ROM, serial interface, parallel interface, timer, interrupt handling circuit).
  17. 17. • Applications: Microprocessors are commonly used as a CPU in computers while microcontrollers are found in small, minimum component designs performing control oriented activities. • Microprocessor instruction sets are processing Intensive. • Their instructions operate on nibbles, bytes, words, or even double words. • Addressing modes provide access to large arrays of data using pointers and offsets. • They have instructions to set and clear individual bits and perform bit operations. • They have instructions for input/output operations, event timing, enabling and setting priority levels for interrupts caused by external stimuli. • Processing power of a microcontroller is much less than a microprocessor. CHAPTER 2
  18. 18. EMBEDDED SYSTEMS FOR TRAFFIC CONTROL 2.1 INTRODUCTION In the present scenario the vehicle problem is increasing and Traffic congestion is a severe problem in many modern cities all over the world. To overcome the problem, we have come up with an exclusive idea for a dynamic and automatic traffic light control expert system combined with a simulation mode. Traffic research has the goal to optimize traffic flow, as the roads have become overloaded with increasing number of vehicles and resources are limited. However, still there are some limitations in existing traffic control which are not environmental and economical. There are several models which give solutions for traffic simulation. In our research we have focussed on optimization of traffic light controller in a city using wireless sensor. Traffic light optimization is a big problem. Even for single junction there is no optimal solution. The problem becomes even more complex with multiple junctions, as the state of one light is responsible for the flow of traffic of that road only. Another complication is that the flow of traffic density frequently changes, depending on the time of day, the day of the week, and the time new year. Nowadays congestion in traffic is a serious issue. The traffic congestion can also be caused by large Red light de-lays, etc. The delay of respective light is hard coded in the traffic light and it is not dependent on traffic. Therefore for simulating and optimizing traffic control to better accommodate this increasing demand is arises. In this paper we studied the optimization of traffic light controller in a City using microcontroller. Thus I propose multiple traffic light control and monitoring system. The system tries to reduce possibilities of traffic jams, caused by traffic lights, to an extent. The system is based on microcontroller. The micro-controller used in the system is 89C51 which is MCS-51 family based. The system contains IR transmitter and IR receiver which are mounted on the either sides of roads respectively. The IR system gets activated whenever any vehicle passes on road between IR transmitter and IR receiver. Microcontroller controls the IR system and counts number of vehicles passing on road. Microcontroller also store vehicles count in its memory. Based on different vehicles count, the microcontroller takes decision and updates the traffic light
  19. 19. delays as a result. The traffic light is situated at a certain distance from the IR system. Thus based on vehicle count, microcontroller defines different ranges for traffic light delays and updates those accordingly. In this system IR sensors are used to measure the density of the vehicles which are fixed within a fixed distance. All the sensors are interfaced with the microcontroller which in turn controls the traffic signals system according to density detected by the sensors if the traffic density is high on particular side more priority is given for that side. The sensors continuously keep sensing density on all sides and the green signal is given on priority basis, where the sensors detect high density. The side with next priority level follows the first priority level. By using this system traffic can be cleared without irregularities and time delay even though there is no traffic on the other side can be avoided 2.2 SYSTEM MODELLING In this section, we focus on the use of ULTRASONIC SENSOR and wireless N/W in traffic control. A lot of scope can be gained in this idea, and intelligent traffic control attracted several governments and commercial companies. Our main aim is to provide more secure roads with less travel time. Such improvements will lead to health benefits, economy, and the environment.
  20. 20. Figure 2.1: Prototype Of Road  Basically in our proposed system on one side of a single lane road, the ultrasonic sound transmitters are placed which produces ultrasonic waves and these ultrasonic transmitters are placed at a distance ( approx 10- 15 meter gap). On the opposite side of same road the ultrasonic receivers are placed at the same gap as that of irtransmitters which receives the waves .  This system will keep track of the road and whenever the series of irreceivers does not receive the sound than it indicates the microcontroller about the density of traffic jam.  In our proposed system ultrasonic sensors are placed on the road. When their transmittance is disturbed by the moving vehicles they convey that message to the microcontroller for generating results. Which will be described below in upcoming topics.
  21. 21.  Unlike all others system for measuring traffic density where sensors are placed on the road here we are installing ir sensors above the road on the foot-path and railings in between the roads.  The advantage of this technique is that the ultrasound will not pass below the vehicles and conveying a wrong message to controller is be avoided.  After that this system will also work when there is excess of water flowing on road during rain or also above the sensors , because ultrasound can also travel in water or we say travels faster in water according to science.  The chances of failing this technique is very less because this system overcomes all the possibilities that affects a signalling system. BLOCK DIAGRAM  In this paper we are mainly interested in the optimization of traffic flow, thus effectively minimizing the Average travelling time of cars. A common tool for analyzing traffic is the traffic simulator. In this section we will first describe block diagram to model traffic controllers. We will then describe how this models can be used to obtain real-time traffic information or predict traffic conditions. After that in this paper we describe how information is communicated as a means of controlling traffic, and what is the effect of the communicated data on traffic conditions will be.
  22. 22. Figure 2.2. Block Diagram Basics of IR transmitter and receiver Transmitter and receiver are commonly used in Engineering projects for remote control of objects. In particularly, in Robotic system uses transmitter and receiver. Here i would like to describe the basics if IR transmitter and receiver. 2.3Transmitter: An electro luminescent IR LED is a product which requires care in use. IR LEDs are fabricated from narrow band hetero structures with energy gap from 0.25 to 0.4 eV. Infra red transmitter emits IR rays in planar wave front manner. Even though Infrared rays spreads in all directions, it propagates along straight line in forward direction. IR rays have the characteristics of producing secondary wavelets when it collides with any obstacles in its path. This property of IR is used here.
  23. 23. When IR rays gets emitted from LED, it moves in the direction it is angled. When any obstacle interferes in the path, the IR rays get cut and it produces secondary wavelets which propagates mostly in return direction or in a direction opposite to that of the primary waves, which produces the net result like reflection of IR rays. 2.4 IR receiver. Infrared photo receiver is a two terminal PN junction device, which operates in a reverse bias. It has a small transparent window, which allows light to strike the PN junction. A photodiode is a type of photo detector capable of converting light into either current or voltage, depending upon the mode of operation. Most photodiodes will look similar to a light emitting diode. They will have two leads, or wires, coming from the bottom. The shorter end of the two is the cathode, while the longer end is the anode. A photodiode consists of PN junction or PIN structure. When a photon of sufficient energy strikes the diode, it excites an electron thereby creating a mobile electron and a positively charged electron hole. If the absorption occurs in the junction's depletion region, or one diffusion length away from it, these carriers are swept from the junction by the built-in field of the depletion region. Thus holes move toward the anode, and electrons toward the cathode, and a photocurrent is produced.
  24. 24. 2.5 POWER SUPPLIES The present chapter introduces the operation of power supply circuits built using filters, rectifiers, and then voltage regulators. Starting with an ac voltage, a steady dc voltage is obtained by rectifying the ac voltage, then filtering to a dc level, and finally, regulating to obtain a desired fixed dc voltage. The regulation is usually obtained from an IC voltage regulator unit, which takes a dc voltage and provides a somewhat lower dc voltage, which remains the same even if the input dc voltage varies, or the output load connected to the dc voltage changes. Block diagram The ac voltage, typically 220V rms, is connected to a transformer, which steps that ac voltage down to the level of the desired dc output. A diode rectifier then provides a full-wave rectified voltage that is initi-+ally filtered by a simple capacitor filter to produce a dc voltage. This resulting dc voltage usually has some ripple or ac voltage variation.
  25. 25. Figure 2.3: Block diagram (Power supply) TRANSFORMER: Transformers convert AC electricity from one voltage to another with little loss of power. Transformers work only with AC and this is one of the reasons why mains electricity is AC. Step-up transformers increase voltage, step-down transformers reduce voltage. Most power supplies use a step-down transformer to reduce the dangerously high mains voltage (230V in UK) to a safer low voltage. The input coil is called the primary and the output coil is called the secondary. There is no electrical connection between the two coils, instead they are linked by an alternating magnetic field created in the soft-iron core of the transformer. The two lines in the middle of the circuit symbol represent the core. Transformers waste very little power so the power out is (almost) equal to the power in. Note that as voltage is stepped down current is stepped up. Turns ratio = Vp / Vs = Np / Ns Power out = power in => Vs x Is = Vp x Ip Where,Vp = primary (input) voltage Vs = secondary (output) voltage
  26. 26. Np = number of turns on primary coil Ns = number of turns on secondary coil Ip = primary (input) current Is = secondary (output) current Figure 2.4: Transformer and its output The low voltage AC output is suitable for lamps, heaters and special AC motors. It is not suitable for electronic circuits unless they include a rectifier and a smoothing capacitor. A regulator circuit removes the ripples and also remains the same dc value even if the input dc voltage varies, or the load connected to the output dc voltage changes. This voltage regulation is usually obtained using one of the popular voltage regulator IC units. Bridge rectifier When four diodes are connected as shown in figure, the circuit is called as bridge rectifier. The input to the circuit is applied to the diagonally opposite corners of the network, and the output is taken from the remaining two corners. Let us assume that the transformer is working properly and there is a positive potential, at point A and a negative potential at point B. the positive potential at point A will forward bias D3 and reverse bias D4. The negative potential at point B will forward bias D1 and reverse D2. At this time D3 and D1 are forward biased and will allow current flow to pass through them; D4 and D2 are reverse biased and will block current flow.
  27. 27. The path for current flow is from point B through D1, up through RL, through D3, through the secondary of the transformer back to point B. this path is indicated by the solid arrows. Waveforms (1) and (2) can be observed across D1 and D3. One-half cycle later the polarity across the secondary of the transformer reverse, forward biasing D2 and D4 and reverse biasing D1 and D3. Current flow will now be from point A through D4, up through RL, through D2, through the secondary of T1, and back to point A. This path is indicated by the broken arrows. Waveforms (3) and (4) can be observed across D2 and D4. The current flow through RL is always in the same direction. In flowing through RL this current develops a voltage corresponding to that. Since current flows through the load (RL) during both half cycles of the applied voltage, this bridge rectifier is a full-wave rectifier. One advantage of a bridge rectifier over a conventional full-wave rectifier is that with a given transformer the bridge rectifier produces a voltage output that is nearly twice that of the conventional full-wave circuit. This may be shown by assigning values to some of the components shown in views A and B. assume that the same transformer is used in both circuits. The peak voltage developed between points X and y is 1000 volts in both circuits. In the conventional full-wave circuit shown—in view A, the peak voltage from the center tap to either X or Y is 500 volts. Since only one diode can conduct at any instant, the maximum voltage that can be rectified at any instant is 500 volts. The maximum voltage that appears across the load resistor is nearly-but never exceeds- 500 v0lts, as result of the small voltage drop across the diode. In the bridge rectifier shown in view B, the maximum voltage that can be rectified is the full secondary voltage, which is 1000 volts. Therefore, the peak output voltage across the load resistor is nearly 1000 volts. With both circuits using the same transformer, the bridge rectifier circuit produces a higher output voltage than the conventional full-wave rectifier circuit. Smoothing circuit Smoothing is performed by a large value electrolytic capacitor connected across the DC supply to act as a reservoir, supplying current to the output when the varying DC voltage from the rectifier is falling. The diagram 2.11 shows the unsmoothed varying DC (dotted line) and the
  28. 28. smoothed DC (solid line). The capacitor charges quickly near the peak of the varying DC, and then discharges as it supplies current to the output. Figure 2.5 smoothing capacitor and its output Smoothing is not perfect due to the capacitor voltage falling a little as it discharges, giving a small ripple voltage. IC voltage regulators Voltage regulators comprise a class of widely used ICs. Regulator IC units contain the circuitry for reference source, comparator amplifier, control device, and overload protection all in a single IC. IC units provide regulation of either a fixed positive voltage, a fixed negative voltage, or an adjustably set voltage. The regulators can be selected for operation with load currents from hundreds of milli amperes to tens of amperes, corresponding to power ratings from milli watts to tens of watts. A fixed three-terminal voltage regulator has an unregulated dc input voltage, Vi, applied to one input terminal, a regulated dc output voltage, Vo, from a second terminal, with the third terminal connected to ground. The series 78 regulators provide fixed positive regulated voltages from 5 to 24 volts. Similarly, the series 79 regulators provide fixed negative regulated voltages from 5 to 24 volts. Voltage regulators comprise a class of widely used ICs. Regulator IC units contain the circuitry for reference source, comparator amplifier, control device, and overload protection all in a single IC. IC units provide regulation of either a fixed positive voltage, a fixed negative voltage, or an adjustably set voltage. The regulators can be selected for operation with load
  29. 29. currents from hundreds of milli amperes to tens of amperes, corresponding to power ratings from milli watts to tens of watts. A fixed three-terminal voltage regulator has an unregulated dc input voltage, Vi, applied to one input terminal, a regulated dc output voltage, Vo, from a second terminal, with the third The series 78 regulators provide fixed positive regulated voltages from 5 to 24 volts. Similarly, the series 79 regulators provide fixed negative regulated voltages from 5 to 24 volts. Table 2.1. Positive Voltage Regulators in 7800 series Voltage regulator ICs are available with fixed (typically 5, 12 and 15V) or variable output voltages. They are also rated by the maximum current they can pass. Negative voltage regulators are available, mainly for use in dual supplies. Most regulators include some automatic protection from excessive current ('overload protection') and overheating ('thermal protection'). IC Part Output Voltage (V) Minimum Vi (V) 7805 +5 7.3 7806 +6 8.3 7808 +8 10.5 7810 +10 12.5 7812 +12 14.6 7815 +15 17.7 7818 +18 21.0 7824 +24 27.1
  30. 30. Figure 2.6 Regulator  For ICs, microcontroller, LCD --------- 5 volts  For alarm circuit, op-amp, relay circuits ---------- 12 volts Figure2.7 Circuit diagram (Power supply)
  31. 31. CHAPTER-3 ARM7 MICROPROCESSOR 3.1 Introduction: The ARM7TDMI core is a member of the ARM family of general-purpose 32- bitMicroprocessors. The ARM [4] family offers high performance for very low power Consumption and small size. The ARM architecture as shown in fig 2.2 is based on Reduced Instruction Set Computer (RISC) principles. The RISC instruction set and related decode mechanism are much simple than those of Complex Instruction Set Computer (CISC) designs. This simplicity gives: • A high instruction throughput • An excellent real-time interrupt response • A small, cost-effective, processor macro cell. 3.2The instruction pipeline: The ARM7TDMI core uses a pipeline to increase the speed of the flow of instructions to the processor. This enables several operations to take place simultaneously, and the processing and memory systems to operate continuously. A three-stage pipeline is used as shown in fig 2.1, so instructions are executed in three stages Fig 3.1: The instruction pipeline During normal operation, while one instruction is being executed, its successor is being decoded, and a third instruction is being fetched from memory. The program counter points to the instruction being fetched rather than to the instruction being executed. This is important
  32. 32. because it means that the Program Counter (PC) value used in an executing instruction is always two instructions ahead of the address. BLOCK DIAGRAM: Fig 3.2 Block Diagram of ARM 7 interface with micro controller 3.3 Memory access: The ARM7TDMI core has Von Neumann architecture, with a single 32-bit data bus carrying both instructions and data. Only load, store, and swap instructions can access data from memory. Data can be: • 8-bit (bytes) • 16-bit (half words)
  33. 33. • 32-bit (words). Words must be aligned to 4-byte boundaries. Half words must be aligned to 2-byte boundaries. 3.4 Memory interface: The ARM7TDMI processor memory interface has been designed to allow performance potential to be realized, while minimizing the use of memory. Speed-critical control signals are pipelined to enable system control functions to be implemented in standard low-power logic. These control signals facilitate the exploitation of the fast-burst access modes supported by many on-chip and off-chip memory technologies. Fig 3.3:ARM7TDMI processor block diagram CPSR CPSR CPSR CPSR CPSR CPSR SPSR_FIQ SPSR_SVC SPSR_ABT SPSR_IRQ SPSR_UND
  34. 34. Table 3.1: ARM7 TDMI Register Set And Operating Modes USER/ SYSTEM FIQ SUPERVISOR ABORT IRQ UNDEFINED R0 R0 R0 R0 R0 R0 R1 R1 R1 R1 R1 R1 R2 R2 R2 R2 R2 R2 R3 R3 R3 R3 R3 R3 R4 R4 R4 R4 R4 R4 R5 R5 R5 R5 R5 R5 R6 R6 R6 R6 R6 R6 R7 R7 R7 R7 R7 R7 R8 R8_FIQ R8 R8 R8 R8 R9 R9_FIQ R9 R9 R9 R9 R10 R10_FIQ R10 R10 R10 R10 R11 R11_FIQ R11 R11 R11 R11 R12 R12__FIQ R12 R12 R12 R12 R13 R13_FIQ R13_SVC R13_ABT R13_IRQ R13_UND R14 R14_FIQ R14_SVC R14_ABT R14_IRQ R14_UND R15(PC) R15(PC) R15(PC) R15(PC) R15(PC) R15(PC)
  35. 35. The ARM7TDMI core has four basic types of memory cycle: • Idle cycle • Sequential cycle • Non sequential cycle • Coprocessor registers transfer cycle. 3.5 Architecture: The ARM7TDMI processor has two instruction sets: • The 32-bit ARM instruction set • The 16-bit Thumb instruction set. The ARM7TDMI processor is an implementation of the ARMv4T architecture. Instruction compression: Microprocessor architectures traditionally have the same width for instructions and data. In comparison with 16-bit architectures, 32-bit architectures exhibit higher performance when manipulating 32-bit data and can address a large address space much more efficiently. 16-bit architectures typically have higher code density than 32-bit architectures, but approximately half the performance. Thumb implements a 16-bit instruction set on a 32-bit architecture to provide: • Higher performance than a 16-bit architecture • Higher code density than a 32-bit architecture. The Thumb instruction set: The Thumb instruction set is a subset of the most commonly used 32-bit ARM instructions. Thumb instructions are each 16 bits long, and have a corresponding 32-bit ARM instruction that has the same effect on the processor model. Thumb instructions operate with the
  36. 36. standard ARM register configuration, allowing excellent interoperability between ARM and Thumb states. On execution, 16-bit Thumb instructions are transparently decompressed to full 32-bit ARM instructions in real time without performance loss. Thumb has all the advantages of a 32-bit core: • 32-bit address space • 32-bit registers • 32-bit shifter, and Arithmetic Logic Unit (ALU) • 32-bit memory transfer. Thumb therefore offers a long branch range, powerful arithmetic operations, and a large address space. Thumb code is typically 65% of the size of ARM code, and provides 160% of the performance of ARM code when running from a 16-bit memory system. Thumb, therefore, makes the ARM7TDMI core ideally suited to embedded applications with restricted memory bandwidth, where code density and footprint is important. The availability of both 16-bit Thumb and 32-bit ARM instruction sets gives designers the flexibility to emphasize performance or code size on a subroutine level, according to the requirements of their applications. For example, critical loops for applications such as fast interrupts and DSP algorithms can be coded using the full ARM instruction set then linked with Thumb code. Increasingly, embedded systems developers and system-on-chip designers select specific microprocessor cores and a family of tools, libraries, and off-the-shelf components to quickly develop new microprocessor-based products and applications. ARM is one of the major options available for embedded system developer. Over the last few years, the ARM architecture has become the most pervasive 32- bitarchitecture in the world, with wide range of ICs available from various IC manufacturers. ARM processors are embedded in products ranging from cell/mobile phones to automotive braking systems. A worldwide community of ARM partners and third-party vendors
  37. 37. has developed among semiconductor and product design companies,including hardware engineers, system designers, and software developers. ARM7 is one of the widely used micro-controller family in embedded system application. This section is humble effort for explaining basic features of ARM-7. ARM is a family of instruction set architectures for computer processors based on a reduced instruction set computing (RISC) architecture developed by British company ARM Holdings. A RISC-based computer design approach means ARM processors require significantly fewer transistors than typical processors in average computers. This approach reduces costs, heat and power use. These are desirable traits for light, portable, battery-powered devices—including smart phones, laptops, tablet and notepad computers), and other embedded systems. A simpler design facilitates more efficient multi-core CPUs and higher core counts at lower cost, providing higher processing power and improved energy efficiency for servers and supercomputers. In 2005, about 98% of all mobile phones sold used at least one ARM processor. The low power consumption of ARM processors has made them very popular: 37 billion ARM processors have been produced as of 2013, up from 10 billion in 2008. The ARM architecture (32-bit) is the most widely used architecture in mobile devices, and most popular 32-bit one in embedded systems. According to ARM Holdings, in 2010 alone, producers of chips based on ARM arhitectures reported shipments of 6.1 billion ARM Based processors, representing 95% of smartphones, 35% of digital televisions and set-top boxes and 10% of mobile computers. It is the most widely used 32-bit instruction set architecture in terms of quantity produced.
  38. 38. CHAPTER 4 LPC2148 MICROCONTROLLER 4.1 Introduction: The LPC2141/2/4/6/8 microcontrollers are based on a 32/16 bit ARM7TDMI-S CPU with real-time emulation and embedded trace support, that combines the microcontroller with embedded high speed flash memory ranging from 32 kB to 512 kB. A 128-bit wide memory interface and a unique accelerator architecture enable 32-bit code execution at the maximum clock rate. For critical code size applications, the alternative 16-bit Thumb mode reduces code by more than 30 % with minimal performance penalty. Due to their tiny size and low power consumption, LPC2141/2/4/6/8 are ideal for applications where miniaturization is a key requirement, such as access control and point-of-sale. A blend of serial communications interfaces ranging from a USB 2.0 Full Speed device, multiple UARTs, SPI, SSP to I2Cs, and on-chip SRAM of 8 kB up to 40 kB, make these devices very well suited for communication gateways and protocol converters, soft modems, voice recognition and low end imaging, providing both large buffer size and high processing power. Various 32-bit timers, single or dual 10-bit ADC(s),10-bit DAC, PWM channels and 45 fast GPIO lines with up to nine edge or level sensitive external interrupt pins make these microcontrollers particularly suitable for industrial control and medical systems. 4.2 FEATURES:  16/32-bit ARM7TDMI-S microcontroller in a tiny LQFP64 package.  8 to 40 kB of on-chip static RAM and 32 to 512 kB of on-chip flash program  128 bit wide interface/accelerator enables high speed 60 MHz operation.  In-System/In-Application Programming (ISP/IAP) via on-chip boot-loader software.  Single flash sector or full chip erase in 400 ms and programming of 256 bytes in 1ms.  Embedded ICERT and Embedded Trace interfaces offer real-time debugging with the on- chip Real Monitor software and high speed tracing of instruction execution.  USB 2.0 Full Speed compliant Device Controller with 2 kB of endpoint RAM.  In addition, the LPC2146/8 provide 8 kB of on-chip RAM accessible to USB by DMA.
  39. 39.  One or two (LPC2141/2 vs. LPC2144/6/8) 10-bit A/D converters provide a total of6/14 analog inputs, with conversion times as low as 2.44 μs per channel.  Single 10-bit D/A converter provides variable analog output.  Low power real-time clock with independent power and dedicated 32 kHz clock input.  Multiple serial interfaces including two UARTs (16C550), two Fast I2C-bus (400kbits) and SSP with buffering and variable data length capabilities.  Vectored interrupt controller with configurable priorities and vector addresses.  Up to 45 of 5 V tolerant fast general purpose I/O pins in a tiny LQFP64 package.  Up to nine edge or level sensitive external interrupt pins available.  60 MHz maximum CPU clock available from programmable on-chip PLL with settling time of 100 μs.  On-chip integrated oscillator operates with an external crystal in range from 1 MHz to30 MHz and with an external oscillator up to 50 MHz.  Power saving modes include Idle and Power-down.  Individual enable/disable of peripheral functions as well as peripheral clock scaling for a dditional power optimization.  Processor wake-up from Power-down mode via external interrupt, USB, Brown-Out Detect (BOD) or Real-Time Clock (RTC).  Single power supply chip with Power-On Reset (POR) and BOD circuits: CPU operating voltage range of 3.0 V to 3.6 V (3.3 V ± 10 %) with 5 V tolerant I/O pads. ARM7TDMI-S processor: The ARM7TDMI-S is a general purpose 32-bit microprocessor, which offers high performance and very low power consumption. The ARM architecture is based on Reduced Instruction Set Computer (RISC) principles, and the instruction set and related decode mechanism are much simpler than those of micro programmed Complex Instruction Set Computers. This simplicity results in a high instruction throughput and impressive real-time interrupt response from a small and cost-effective processor core. Pipeline techniques are employed so that all parts of the processing and memory systems can operate continuously.
  40. 40. Typically, while one instruction is being executed, its successor is being decoded, and a third instruction is being fetched from memory. The ARM7TDMI-S processor also employs a unique architectural strategy known as THUMB, which makes it ideally suited to high-volume applications with memory restrictions, or applications where code density is an issue. The key idea behind THUMB is that of a super-reduced instruction set. Essentially, the ARM7TDMI-S processor has two instruction sets: • The standard 32-bit ARM instruction set. • A 16-bit THUMB instruction set. The THUMB set’s 16-bit instruction length allows it to approach twice the density of standard ARM code while retaining most of the ARM’s performance advantage over a traditional 16-bit processor using 16-bit registers. This is possible because THUMB code operates on the same 32-bit register set as ARM code. THUMB code is able to provide up to 65% of the code size of ARM, and 160% of the performance of an equivalent ARM processor connected to a 16-bit memory system. The ARM7TDMI-S processor is described in detail in the ARM7TDMI-S Datasheet that can be found on official ARM website. Applications:  Industrial control  Medical systems  Access control  Point-of-sale  Communication gateway  Embedded soft modem  General purpose applications
  41. 41. 4.3 PIN DIAGRAM OF LPC2148: Figure 4.1: Pin Diagram of LPC2148
  42. 42. 4.4 PIN DESCRIPTION:
  43. 43. BLOCK DIAGRAM OF LPC 2148: Fig 4.2 LPC2141/2/4/6/8 block diagram (1) Pins shared with GPIO. (2) LPCC2144/6/8 only. (3) USB DMA controller with 8 kB of RAM accessible as general purpose RAM and/or DMA is available in LPC2146/8 only. (4) LPC2142/4/6/8 only.
  44. 44. 4.5 GENERAL PURPOSE INPUT/OUTPUT REGISTER (GPIO): FEATURES: • Every physical GPIO port is accessible via either the group of registers providing the features and accelerated port access or the legacy group of registers • Accelerated GPIO functions: GPIO registers are relocated to the ARM local bus so that the fastest possible I/O timing can be achieved. Mask registers allow treating sets of port bits as a group, leaving other bits unchanged. All registers are byte and half-word addressable. Entire port value can be written in one instruction • Bit-level set and clear registers allow a single instruction set or clear of any number of bits in one port • Direction control of individual bits • All I/O default to inputs after reset • Backward compatibility with other earlier devices is maintained with legacy registers appearing at the original addresses on the APB. Applications: • General purpose I/O • Driving LEDs, or other indicators • Controlling off-chip devices • Sensing digital inputs Pin description: Table 4.1: GPIO pin description UART0: Features: • 16 byte Receive and Transmit FIFOs • Register locations conform to ‘550 industry standard. • Receiver FIFO trigger points at 1, 4, 8, and 14 bytes. • Built-in fractional baud rate generator with auto bauding capabilities.
  45. 45. • Mechanism that enables software and hardware flow control implementation Pin description: Table 4.2: UART0 pin description Architecture: The architecture of the UART0 is shown below in the block diagram. The APB interface provides a communications link between the CPU or host and the UART0. The UART0 receiver block, U0RX, monitors the serial input line, RXD0, for valid input. The UART0 RX Shift Register (U0RSR) accepts valid characters via RXD0. After a valid character is assembled in the U0RSR, it is passed to the UART0 RX Buffer Register FIFO to await access by the CPU or host via the generic host interface. The UART0 transmitter block, U0TX, accepts data written by the CPU or host and buffers the data in the UART0 TX Holding Register FIFO (U0THR). The UART0 TX Shift Register (U0TSR) reads the data stored in the U0THR and assembles the data to transmit via the serial output pin, TXD0. The UART0 Baud Rate Generator block, U0BRG, generates the timing enables used by the UART0 TX block. The U0BRG clock input source is the APB clock (PCLK). The main clock is divided down per the divisor specified in the U0DLL and U0DLM registers. This divided down clock is a 16x oversample clock, NBAUDOUT. The interrupt interface contains registers U0IER and U0IIR. The interrupt interface receives several one clock wide enables from the U0TX and U0RX blocks. Status information from the U0TX and U0RX is stored in the U0LSR. Control information for the U0TX and U0RX is stored in the U0LCR.
  46. 46. BLOCK DIAGRAM OF UART 0: Figure 4.3: Block Diagram of UART0
  47. 47. UART1: Features: • UART1 is identical to UART0, with the addition of a modem interface. • 16 byte Receive and Transmit FIFOs. • Register locations conform to ‘550 industry standard. • Receiver FIFO trigger points at 1, 4, 8, and 14 bytes. • Built-in fractional baud rate generator with auto bauding capabilities. • Mechanism that enables software and hardware flow control implementation. • Standard modem interface signals included with flow control (auto-CTS/RTS) fully supported in hardware (LPC2144/6/8 only). Architecture: The architecture of the UART1 is shown below in the block diagram. The APB interface provides a communications link between the CPU or host and the UART1. The UART1 receiver block, U1RX, monitors the serial input line, RXD1, for valid input. The UART1 RX Shift Register (U1RSR) accepts valid characters via RXD1. After a valid character is assembled in the U1RSR, it is passed to the UART1 RX Buffer Register FIFO to await access by the CPU or host via the generic host interface. The UART1 transmitter block, U1TX, accepts data written by the CPU or host and buffers the data in the UART1 TX Holding Register FIFO (U1THR). The UART1 TX Shift Register (U1TSR) reads the data stored in the U1THR and assembles the data to transmit via the serial output pin, TXD1. The UART1 Baud Rate Generator block, U1BRG, generates the timing enables used by the UART1 TX block. The U1BRG clock input source is the APB clock (PCLK). The main clock is divided down per the divisor specified in the U1DLL and U1DLM registers. This divided down clock is a 16x oversample clock, NBAUDOUT. The modem interface contains registers U1MCR and U1MSR. This interface is responsible for handshaking between a modem peripheral and the UART1.The interrupt interface contains registers U1IER and U1IIR. The interrupt interface receives several one clock wide enables from the U1TX and U1RX blocks. Status information from the
  48. 48. U1TX and U1RX is stored in the U1LSR. Control information for the U1TX and U1RX is stored in the U1LCR. BLOCK DIAGRAM OF UART1: Figure 4.4 Block Diagram of UART1
  49. 49. 4.6 Memory Maps: The LPC2141/2/4/6/8 incorporates several distinct memory regions, shown in the following figures. Figure below shows the overall map of the entire address space from the user program viewpoint following reset. The interrupt vector area supports address remapping, which is described later in this section. Fig 4.5: System Memory Map Memory re-mapping: In order to allow for compatibility with future derivatives, the entire Boot Block is mapped to the top of the on-chip memory space. In this manner, the use of larger or smaller flash modules will not require changing the location of the Boot Block (which would require changing the Boot Loader code itself) or changing the mapping of the Boot Block interrupt vectors.
  50. 50. Memory spaces other than the interrupt vectors remain in fixed locations. Figure below shows the on-chip memory mapping in the modes defined above. The portion of memory that is re-mapped to allow interrupt processing in different modes includes the interrupt vector area (32 bytes) and an additional 32 bytes, for a total of 64 bytes. The re-mapped code locations overlay addresses 0x0000 0000 through 0x0000 003F. A typical user program in the Flash memory can place the entire FIQ handler at address 0x0000 001C without any need to consider memory boundaries. The vector contained in the SRAM, external memory, and Boot Block must contain branches to the actual interrupt handlers, or to other instructions that accomplish the branch to the interrupt handlers. There are three reasons this configuration was chosen: 1.To give the FIQ handler in the Flash memory the advantage of not having to take a memory boundary caused by the remapping into account 2. Minimize the need to for the SRAM and Boot Block vectors to deal with arbitrary boundaries in the middle of code space. To provide space to store constants for jumping beyond the range of single word branch instructions. Re-mapped memory areas, including the Boot Block and interrupt vectors, continue to appear in their original location in addition to the re-mapped address. Source Code The Interfacing Traffic Light Control with LPC2148 program is very simple and straight forward, which controls Traffic Light in certain time period. The C program is written in Keil software. To compile the C code, you must need the KEIL software. They must be properly set up and a project with correct settings must be created in order to compile the code. To compile the C code, the C file must be added to the project. In Keil, you want to develop or debug the project without any hardware setup. You must compile the code for generating HEX file. In debugging Mode, you want to check the port output without LPC2148 Primer Board. The Flash Magic software is used to download the hex file into your microcontroller IC LPC2148 through UART0.
  51. 51. 4.7 Testing the Traffic Light Controller with LPC2148 Give +3.3V power supply to LPC2148 Primer Board; the LED is connected with LPC2148 Primer Board. When the program is downloading into LPC2148 in Primer Board, the LED output is working that some LED is ON and some LED is OFF in the Traffic Light format. If you not reading any output from LED, then you just check the jumper connections & check the LED is working.
  52. 52. CHAPTER 5 AT89C51 Controller AT89C51 is an 8-bit microcontroller and belongs to Atmel's 8051 family. ATMEL 89C51 has 4KB of Flash programmable and erasable read only memory (PEROM) and 128 bytes of RAM. It can be erased and program to a maximum of 1000 times. In 40 pin AT89C51, there are four ports designated as P1, P2, P3 and P0. All these ports are 8-bit bi-directional ports, i.e., they can be used as both input and output ports. Except P0 which needs external pull-ups, rest of the ports have internal pull-ups. When 1s are written to these port pins, they are pulled high by the internal pull-ups and can be used as inputs. These ports are also bit addressable and so their bits can also be accessed individually. Port P0 and P2 are also used to provide low byte and high byte addresses, respectively, when connected to an external memory. Port 3 has multiplexed pins for special functions like serial communication, hardware interrupts, timer inputs and read/write operation from external memory. AT89C51 has an inbuilt UART for serial communication. It can be programmed to operate at different baud rates. Including two timers & hardware interrupts, it has a total of six interrupts. Pin Diagram:
  53. 53. Figure 5.1 AT89C51 5.1 Pin Description:
  54. 54. Pin No Function Name 1 8 bit input/output port (P1) pins P1.0 2 P1.1 3 P1.2 4 P1.3 5 P1.4 6 P1.5 7 P1.6 8 P1.7 9 Reset pin; Active high Reset 10 Input (receiver) for serial communication RxD 8 bit input/output port (P3) pins P3.0 11 Output (transmitter) for serial communication TxD P3.1 12 External interrupt 1 Int0 P3.2 13 External interrupt 2 Int1 P3.3 14 Timer1 external input T0 P3.4 15 Timer2 external input T1 P3.5 16 Write to external data memory Write P3.6 17 Read from external data memory Read P3.7 18 Quartz crystal oscillator (up to 24 MHz) Crystal 2 19 Crystal 1 20 Ground (0V) Ground 21 8 bit input/output port (P2) pins / High-order address bits when interfacing with external memory P2.0/ A8 22 P2.1/ A9 23 P2.2/ A10 24 P2.3/ A11 25 P2.4/ A12 26 P2.5/ A13
  55. 55. Table 5.1 AT89C51pin CHAPTER 6 IR SENSORS 27 P2.6/ A14 28 P2.7/ A15 29 Program store enable; Read from external program memory PSEN 30 Address Latch Enable ALE Program pulse input during Flash programming Prog 31 External Access Enable; Vcc for internal program executions EA Programming enable voltage; 12V (during Flash programming) Vpp 32 8 bit input/output port (P0) pins Low-order address bits when interfacing with external memory P0.7/ AD7 33 P0.6/ AD6 34 P0.5/ AD5 35 P0.4/ AD4 36 P0.3/ AD3 37 P0.2/ AD2 38 P0.1/ AD1 39 P0.0/ AD0 40 Supply voltage; 5V (up to 6.6V) Vcc
  56. 56. Basics of IR transmitter and receiver Transmitter and receiver are commonly used in Engineering projects for remote control of objects. In particularly, in Robotic system uses transmitter and receiver. Here i would like to describe the basics if IR transmitter and receiver. 6.1 Transmitter: An electro luminescent IR LED is a product which requires care in use. IR LEDs are fabricated from narrow band hetero structures with energy gap from 0.25 to 0.4 eV. Infra red transmitter emits IR rays in planar wave front manner. Even though Infra red rays spreads in all directions, it propagates along straight line in forward direction. IR rays have the characteristics of producing secondary wavelets when it collides with any obstacles in its path. This property of IR is used here. When IR rays gets emitted from LED, it moves in the direction it is angled. When any obstacle interferes in the path, the IR rays get cut and it produces secondary wavelets which propagates mostly in return direction or in a direction opposite to that of the primary waves, which produces the net result like reflection of IR rays. 6.2 IR receiver. Infrared photo receiver is a two terminal PN junction device, which operates in a reverse bias. It has a small transparent window, which allows light to strike the PN junction. A
  57. 57. photodiode is a type of photo detector capable of converting light into either current or voltage, depending upon the mode of operation. Most photodiodes will look similar to a light emitting diode. They will have two leads, or wires, coming from the bottom. The shorter end of the two is the cathode, while the longer end is the anode. A photodiode consists of PN junction or PIN structure. When a photon of sufficient energy strikes the diode, it excites an electron thereby creating a mobile electron and a positively charged electron hole. If the absorption occurs in the junction's depletion region, or one diffusion length away from it, these carriers are swept from the junction by the built-in field of the depletion region. Thus holes move toward the anode, and electrons toward the cathode, and a photocurrent is produced. Theydodozensofdifferentjobsandarefoundinallkindsofdevices.Amongother things, they form the numbers on digital clocks, transmit information from remote controls, light up watches and tell you when yourappliancesareturnedon.Collectedtogether,theycanformimagesonajumbotelevisionscreenorilluminate atrafficlight.
  58. 58. Figure 6.1 IR Sensors
  59. 59. CHAPTER 6 SOFTWARE DESCRIPTION 6.1 KEIL COMPILER Keil compiler is software used where the machine language code is written and compiled. After compilation, the machine source code is converted into hex code which is to be dumped into the microcontroller for further processing. Keil compiler also supports C language code. It’s important that you know C language for microcontroller which is commonly known as Embedded C. As we are going to use Keil C51 Compiler, hence we also call it Keil C. Keil C is not much different from a normal C program. If you know assembly, writing a C program is not a crisis. In keil, we will have a main function, in which all your application specific work will be defined. In case of embedded C, you do not have any operating system running in there. So you have to make sure that your program or main file should never exit. This can be done with the help of simple while (1) or for (;;) loop as they are going to run infinitely. We have to add header file for controller you are using, otherwise you will not be able to access registers related to peripherals. #include <REG51.h> //header file for 89C51 To create a project, write and test the previous example source code, follow the following steps: 1. Open Keil and start a new project as shown in figure 6.1
  60. 60. Figure 6.1 Creating new project 2. You will be prompted to choose a name for your new project, Create a separate folder where all the files of your project will be stored, choose a name and click save. The following figure 6.2 will appear where you will be asked to select a device for Target 'Target 1':
  61. 61. Figure 6..2 Creating target 3. From the list at the left, seek for the brand name ATMEL, then under ATMEL, select AT89S52. You will notice that a brief description of the device appears on the right. Leave the two upper check boxes unchecked and click OK. The AT89S52 will be called your 'Target device', which is the final destination of your source code. You will be asked whether to 'copy standard 8051 startup code' click No.
  62. 62. 4. Click File, New, and something similar to the following figure 6.3 should appear. The box named 'Text1' is where your code should be written later. Figure 6.3 Creating a file 5. Now you have to click 'File, Save as' and choose a file name for your source code ending with the letter '.c'. You can name as 'code.c' for example and click save. Then you have to add this file to your project work space at the left as shown in the following figure 6.4.
  63. 63. Fig 6.4 Adding files to the source group 6.After right-clicking on 'source group 1', click on 'Add files to group...', then you will be prompted to browse the file to add to 'source group 1', choose the file that you just saved, eventually 'code.c' and add it to the source group. You will notice that the file is added to the project. 7. In some versions of this software you have to turn ON manually the option to generate HEX files. make sure it is turned ON, by right-clicking on target 1, Options for target 'target 1', then under the 'output' tab, by checking the box 'generate HEX file'. This step is very important
  64. 64. as the HEX file is the compiled output of your project that is going to be transferred to the microcontroller. 8. You can then start to write the source code in the figure 6.5 titled 'code.c' then before testing your source code; you have to compile your source code, and correct eventual syntax errors. In KEIL IDE, this step is called 'rebuild all targets' and has this icon. Fig 6.5 Rebuilding targets 9. If after rebuilding the targets, the 'output window' shows that there is 0 errors, then you are ready to test the performance of your code. In keil, like in most development environment, this
  65. 65. step is called Debugging, and has this icon. After clicking on the debug icon, you will notice that some part of the user interface will change; some new icons will appear, like the run icon circled in the following figure 6.6. Figure 6.6Debugging 10. You can click on the 'Run' icon and the execution of the program will start. In our example, you can see the behavior of the pin 0 or port one, but clicking on 'peripherals, I/O ports, Port 1'. You can always stop the execution of the program by clicking on the stop button and you can
  66. 66. simulate a reset by clicking on the 'reset' button. You can also control the execution of the program using the following icons: which allows you to follow the execution step by step. Then, when you're finished with the debugging, you can always return to the programming interface by clicking again on debug button 6.2 PROLOAD Proload is software which accepts only hex files. Once the machine code is converted into hex code, that hex code has to be dumped into the microcontroller and this is done by the Proload. Proload is a programmer which itself contains a microcontroller in it other than the one which is to be programmed. This microcontroller has a program in it written in such a way that it accepts the hex file from the keil compiler and dumps this hex file into the microcontroller which is to be programmed. As the proload programmer kit requires power supply to be operated, this power supply is given from the power supply circuit designed above. It should be noted that this programmer kit contains a power supply section in the board itself but in order to switch on that power supply, a source is required. Thus this is accomplished from the power supply board with an output of 12volts. CHAPTER 7
  67. 67. Result Analysis Results include the successful operation of the traffic control and monitoring system. The system contains three IR transmitter and IR receiver for traffic density measurement which are mounted on the either sides of roads respectively. The IR system gets activated whenever any vehicle passes on road between IR sensors. When one sensor will be ON at that time density will be less when two sensors will be ON at that traffic density is medium when all 3 sensor will be ON at that time density will be high. Microcontroller controls the IR system and counts number of vehicles passing on road. Based on different vehicles count, the microcontroller takes decision and updates the traffic light delays as a result. Case 1:In the first case road one has density and green light appears for road 1 Figure 7.1 Road 1 analysis
  68. 68. Case 2:In this case density occurs at road 2 and remaining road 1, road 3, road 4 has red lights. Figure 7.2 Road 2 analysis Case 3:In this case density occurs at road 3 and red light occurs for road1,road2,road4. Figure 7.3 Road 3 analysis
  69. 69. Case4:In this case density occurs at road 4 and red light occurs for road 1,road2 road3. Figure 7.4 Road 4 analysis
  70. 70. PROGRAM: #include <LPC214X.H> //P1.16 TO P1.27 G1,O1,R1,G2,R2,R2,G3,O3.R3 #define g1 0x00010000 #define o1 0x00020000 #define r1 0x00040000 #define g2 0x00080000 #define o2 0x00100000 #define r2 0x00200000 #define g3 0x00400000 #define o3 0x00800000 #define r3 0x01000000 #define g4 0x02000000 #define o4 0x04000000 #define r4 0x08000000 //sensors to po.o to po.7 void green1on(void) { IOCLR1 = g1; //g1=0; IOSET1 = r1; //r1=1; IOSET1 = g2; IOSET1 = g3; IOSET1 = g4;//g2=g3=g4=1; IOCLR1 =r2; IOCLR1 = r3; IOCLR1 =r4; //r2=r3=r4=0; } void green2on(void) { IOCLR1 = g2;//g2=0;
  71. 71. IOSET1 = r2;//r2=1; IOSET1 = g1; IOSET1 = g3; IOSET1 = g4;//g1=g3=g4=1; IOCLR1 =r1; IOCLR1 = r3; IOCLR1 =r4; //r1=r3=r4=0; } void green3on(void) { IOCLR1 = g3;//g3=0; IOSET1 = r3;//r3=1; IOSET1 = g1; IOSET1 = g2; IOSET1 = g4;//g1=g2=g4=1; IOCLR1 =r1; IOCLR1 = r2; IOCLR1 =r4; //r1=r2=r4=0; } void green4on(void) { IOCLR1 = g4;//g4=0; IOSET1 = r4;//r4=1; IOSET1 = g1; IOSET1 = g2; IOSET1 = g3;//g1=g2=g3=1; IOCLR1 =r1; IOCLR1 = r2; IOCLR1 =r3; //r1=r2=r3=0; } void intelligent(void)
  72. 72. { int x; x=IOPIN0; x=x&0x00000040; while(x==0x00000040)//while(sen41==1) { IOSET1 = 0X04920000; //o1=o2=o3=o4=1; x=IOPIN0; x=x&0x00000001; if(x==0x00000001)//if(sen11==1) break; x=IOPIN0; x=x&0x00000002; if(x==0x00000002)//if(sen12==1) { x=IOPIN0; x=x&0x00000001; if(x==0x00000001)//if(sen11==1) break; } x=IOPIN0; x=x&0x00000004; if(x==0x00000004)//if(sen21==1) break; x=IOPIN0; x=x&0x00000008; if(x==0x00000008)//if(sen22==1) { x=IOPIN0; x=x&0x00000004; if(x==0x00000004)//if(sen21==1)
  73. 73. break; } x=IOPIN0; x=x&0x00000010; if(x==0x00000010)//if(sen31==1) break; x=IOPIN0; x=x&0x00000020; if(x==0x00000020)//if(sen32==1) { x=IOPIN0; x=x&0x00000010; if(x==0x00000010)//if(sen31==1) break; } x=IOPIN0; x=x&0x00000080; //if(x==0x00000080)//if(sen42==1) //break; green4on(); x=IOPIN0; x=x&0x00000040; } x=IOPIN0; x=x&0x00000010; while(x==0x00000010)//while(sen31==1) { x=IOPIN0; x=x&0x00000001; if(x==0x00000001)//if(sen11==1) break;
  74. 74. x=IOPIN0; x=x&0x00000002; if(x==0x00000002)//if(sen12==1) { x=IOPIN0; x=x&0x00000001; if(x==0x00000001)//if(sen11==1) break; } x=IOPIN0; x=x&0x00000004; if(x==0x00000004)//if(sen21==1) break; x=IOPIN0; x=x&0x00000008; if(x==0x00000008)//if(sen22==1) { x=IOPIN0; x=x&0x00000004; if(x==0x00000004)//if(sen21==1) break; } //x=IOPIN0; //x=x&0x00000020; //if(x==0x00000020)//if(sen32==1) //break; x=IOPIN0; x=x&0x00000080; if(x==0x00000080)//if(sen42==1)
  75. 75. { x=IOPIN0; x=x&0x00000040; if(x==0x00000040)//if(41 senses) break; IOSET1 = 0X04920000; //o1=o2=o3=o4=1; green3on(); x=IOPIN0; x=x&0x00000010; } x=IOPIN0; x=x&0x00000004; while(x==0x00000004)//while(sen21==1) { x=IOPIN0; x=x&0x00000001; if(x==0x00000001)//if(sen11==1) break; x=IOPIN0; x=x&0x00000002; if(x==0x00000002)//if(sen12==1) break; x=IOPIN0; x=x&0x00000008; if(x==0x00000008)//if(sen22==1) break; x=IOPIN0; x=x&0x00000020; if(x==0x00000020)//if(sen32==1) break; x=IOPIN0;
  76. 76. x=x&0x00000080; if(x==0x00000080)//if(sen42==1) break; IOSET1 = 0X04920000; //o1=o2=o3=o4=1; green2on(); x=IOPIN0; x=x&0x00000004; } x=IOPIN0; x=x&0x00000001; while(x==0x00000001)//while(sen11==1) { x=IOPIN0; x=x&0x00000002; if(x==0x00000002)//if(sen12==1) break; x=IOPIN0; x=x&0x00000008; if(x==0x00000008)//if(sen22==1) break; x=IOPIN0; x=x&0x00000020; if(x==0x00000020)//if(sen32==1) break; x=IOPIN0; x=x&0x00000080; if(x==0x00000080)//if(sen42==1) break; IOSET1 = 0X04920000; //o1=o2=o3=o4=1; green1on();
  77. 77. x=IOPIN0; x=x&0x00000001; } x=IOPIN0; x=x&0x000000C0; while(x==0x000000C0)//while(sen42==1 && sen41==1) { x=IOPIN0; x=x&0x00000002; if(x==0x00000002)//if(sen12==1) break; x=IOPIN0; x=x&0x00000008; if(x==0x00000008)//if(sen22==1) break; x=IOPIN0; x=x&0x00000020; if(x==0x00000020)//if(sen32==1) break; IOSET1 = 0X04920000; //o1=o2=o3=o4=1; green4on(); x=IOPIN0; x=x&0x000000C0; } x=IOPIN0; x=x&0x00000030; while(x==0x00000030)//while(sen32==1 && sen31==1) { x=IOPIN0; x=x&0x00000002; if(x==0x00000002)//if(sen12==1)
  78. 78. break; x=IOPIN0; x=x&0x00000008; if(x==0x00000008)//if(sen22==1) break; IOSET1 = 0X04920000; //o1=o2=o3=o4=1; green3on(); x=IOPIN0; x=x&0x00000030; } x=IOPIN0; x=x&0x0000000C; while(x==0x0000000C)//while(sen22==1 && sen21==1) { x=IOPIN0; x=x&0x00000002; if(x==0x00000002)//if(sen12==1) break; IOSET1 = 0X04920000; //o1=o2=o3=o4=1; green2on(); x=IOPIN0; x=x&0x0000000C; } x=IOPIN0; x=x&0x00000003; while(x==0x00000003)//while(sen12==1 && sen11==1) { IOSET1 = 0X04920000; //o1=o2=o3=o4=1; green1on(); x=IOPIN0; x=x&0x00000003;
  79. 79. } } void delay(int i) { int k,j; for(j=0;j<i;j++) { intelligent(); for(k=0;k<5000;k++) intelligent(); for(k=0;k<5000;k++) intelligent(); for(k=0;k<5000;k++) intelligent(); for(k=0;k<5000;k++) intelligent(); } } int main() { IODIR0 = 0X00000000; IODIR1 = 0X0FFF0000; IOPIN1 = 0X00000000; IOPIN0 = 0X00000000; PINSEL0 = 0X00000000; while(1) { IOSET1 = 0X04920000; //o1=o2=o3=o4=1; intelligent(); green1on(); delay(120);
  80. 80. IOSET1 = g1;//g1=1; IOCLR1 = o1;//o1=0; delay(15); IOSET1 = o1;//o1=1; intelligent(); green2on(); delay(120); IOSET1 = g2;//g2=1; IOCLR1 = o2;//o2=0; delay(15); IOSET1 = o2;//o2=1; intelligent(); green3on(); delay(120); IOSET1 = g3;//g3=1; IOCLR1 = o3;//o3=0; delay(15); IOSET1 = o3;//o3=1; intelligent(); green4on(); delay(120); IOSET1 = g4;//g4=1; IOCLR1 = o4;//o4=0; delay(15); IOSET1 = o4;//o4=1; intelligent(); } }
  81. 81. CONCLUSIONS AND FUTURE SCOPE: In this paper we have studied the optimization of traffic light controller in a City using ARM7 and microcontroller. The ARM7 based traffic control system works on traffic related problems such as traffic jam; unreasonable latency time of stoppage of vehicle, emergency vehicles or forcibly passing, etc can be solved. By using this system configuration we tries to reduce the possibilities of traffic jams, caused by traffic lights. Number of passing vehicle in the fixed time slot on the road decide the density range of traffics and on the basis of vehicle density calculation, microcontroller decide the traffic light delays.
  82. 82. Bibiliography  Fundamentals of Micro processors and Micro computers -B.Ram  Electronic Components -D.V. Prasad  Wireless Communications - Theodore S .Rappaport  Embedded System By Raj Kamal Web References:  http://www.national.com  http://www.nxp.com  http://www.microsoftsearch.com  http://www.geocities.com  http://www.Electronic projects.com

×