design phase 3 report 2

Upload: irshad-bassa

Post on 07-Apr-2018

219 views

Category:

Documents


1 download

TRANSCRIPT

  • 8/6/2019 Design Phase 3 Report 2

    1/21

    1

    SCHOOL OF ELECTRICAL, ELECTRONIC AND COMPUTER ENGINEERING

    ELECTRONIC DESIGN 2GROUP 8

    TRAFFIC LIGHT CONTROLLERPHASE THREE REPORT

    We hereby declare that the contents of this report are our own original and unaided work, except wherespecific mention is made to the contrary in the form of a numbered reference

    Full Name Student Number Signature

    Imraan Vawda 208507942

    Irshad Bassa 208502448

    Wayne Frederick 208504648

    28/09/2010

  • 8/6/2019 Design Phase 3 Report 2

    2/21

    2

    Abstract

    This phase three report of the Electronic design 2 project documents the complete design andproduction of a Traffic Light Controller system. The controller is based on an AVR AT mega 162microcontroller interfaced with internal and external circuitry to perform the control of traffic flow at a

    four-way intersection.In section one of the report, the final basic and advanced specifications for the controller are specified.These specifications are in agreement with the requests of the client. Revisions to the original proposalare also discussed in detail with valid reasons. Revisions include removal of the uninterrupted powersupply from the basic specifications as well as minor changes to the advanced specifications from phaseone of the design.Discussion of the full hardware design of the controller forms the next section. It must be noted thatthe hardware was designed with a product implementation of the final controller board insight. Thecomplete hardware design is discussed with the phase two changes made to phase one included forclarity.Design of an internal main controller board interfacing with the external circuitry is the basis of the

    hardware design. The Real Time Clock, USB-UART interface and all inputs and outputs to andfrom the microcontroller form the main controller board.Section four discusses the physical implementation of the controller. Decisions taken toimprove the construction of the design from the phase two prototype are highlighted. The finaltest/demo board designed for demonstrating the capabilities of the traffic light controller isshown in this section. A resolution to the problems with the Maxwell-Wien bridge inductiveloop is discussed as well. The successful hardware implementation of the various circuitries isthe main focus of this section.Focus on the successful software design and implementation forms the main part of phase three. Themicrocontroller and PC software are discussed thoroughly in section five of this report.Finally, the budget of the controller design concludes the report and is within the maximum allowable

    expenses.

  • 8/6/2019 Design Phase 3 Report 2

    3/21

    3

    T able of ContentsAbstract ............................................................................................................................................................... 2

    Table of Contents ................................................................................................................................................. 3

    1. Introduction ................................ ........................ .............................. ............................. ....................... .. 4

    2. The Traffic Control System Overview ........................... ................................ ...................... ...................... 53 . Hardware Design Overview .......................... ................................ ....................... ................................ ..... 6

    3 .1 Hardware Design of the Main Controller Board........................................................................................... 6

    3 .1.1 The AT Mega 162 Microcontroller ........................................................................................................ 6

    3 .1.2 Serial Communication .......................................................................................................................... 6

    3 .1. 3 Time of Day Clock ................................................................................................................................ 7

    3 .1.4 Traffic Light Outputs ............................................................................................................................ 8

    3 .2 External Circuitry ........................................................................................................................................ 9

    3.2.1 Inductive Vehicle Loop Sensor.............................................................................................................. 9

    3 .2.2 Pedestrian Push Button ........................ ................................ ...................... ................................ .... 10

    3 .2. 3 Countdown Timer .......................................................................................................................... 10

    3 .2.4 Buzzer for blind pedestrians ............................ ................................ ...................... ......................... 10

    4. Hardware Prototyping ........................... ............................ ....................... ................................ ............. 11

    4.1 The FT2 3 2R Prototype .............................................................................................................................. 11

    4.2 The Main Board ........................................................................................................................................ 11

    4.3 The Test (Demo) Board ............................................................................................................................. 12

    4.4 General Testing ........................................................................................................................................ 12

    4.5 Further Improvements .......................................................................................................................... 12

    5. Software Design and Implementation ......................... ................................ ....................... .................... 1 3

    5.1 System Software ................................................................................................................................... 1 3

    5.2 USB/USART PC Interface ........................... ................................ ...................... ............................... 14

    6. Budget ............................... ........................ ................................ ...................... ................................ ...... 15

    7. Conclusion .............................. ........................ ................................ ...................... ............................... .. 15

    8. References............................ ......................... ................................ ....................... ................................ . 15

    Appendix A......................................................................................................................................................... 16

    Appendix B ......................................................................................................................................................... 16

    Appendix C ......................................................................................................................................................... 17

  • 8/6/2019 Design Phase 3 Report 2

    4/21

    4

    1. I ntroductionThis traffic control system was designed to be a solution to the existing four-way stop system wheredrivers are in control. These systems are simply unable to cope with the increase in traffic during peaktimes and often lead to dangerous situations for both motorists and pedestrians.

    The safety of the pedestrians was considered of utmost importance in the design of this system and thisalso includes the implementation of various features to assist disabled pedestrians. Thereafter, driversafety and satisfaction is prioritized. A very detailed outline of all the possible scenarios encountered bythis system was considered and a requirements analysis was performed after speaking to discerningclients. Thereafter a full hardware paper design was developed in the first phase.

    This report highlights the design tasks performed in phase three including important details from phaseone and two required to produce the final fully functioning Traffic Light Controller.

    Section two of the report details the original specifications and the revised advanced specifications.Included is a block diagram showing the traffic control system with the AVR AT mega 162microcontroller interfacing with the both the internal and external components of the system.

    Thereafter, the complete revised hardware design is promptly discussed in section three and changesfrom phase one and two are highlighted. Phase two hardware implementation left room forimprovement and the relevant PCB design upgrades are highlighted in this section. PCB designs for theimplementation of the complete demo board are also included in this section.

    Section four of the report discusses, in detail, the final construction of the Traffic Light Controller anddemo board. The physical realization of the main controller board into an actual product is detailed andthe problems encountered are discussed. Pictures of the controller and demo boards are included.

    In section five, the very high level software design shown in phase two is developed into a full software

    design. The implementation of this design for both the microcontroller and PC software componentsare thereafter shown.

    Finally, section six of the report comprises the budget for the complete controller.

  • 8/6/2019 Design Phase 3 Report 2

    5/21

    5

    2 . Th e T raffic Control System Overview

    Figure 1 Revised Block Diagram of Traffic Light Controller

    The basic specifications required, originally, that an alternative power supply be designed tocompensate for a power outage. This was removed from the second phase of the design becauserechargeable batteries were the most feasible solution to provide an uninterrupted power supply butwas too expensive.

    In terms of the advanced specification, the original design included WALK/DON T WALK signals to assistcolour blind pedestrians. These had to be implemented using 14-segment displays. Unfortunately, thisfeature could not be included as it does not conform to SABS standards. It also proved difficult to obtainmultiple 14-segment displays and they did not fit into the budget.

    Apart from the above specifications, the rest of the controller remained the same as the hardwaredesign specified in phase one apart from certain minor modifications which are discussed later. Figureone includes, importantly, the internal specifications which are found on the main controller board andthe external circuitry which interfaces with the board. The specifications are marked accordingly.

  • 8/6/2019 Design Phase 3 Report 2

    6/21

    6

    3 . H ardware Design Overview

    In phase one, the various components of the system making up all the basic and advanced specificationswere discussed. Schematics were developed for each of the features that the system includes. In phasetwo, when PCB design was considered, the realization arose that this system had to be fully integrated

    with all the components interfacing without problems. Unfortunately, this integration was not fullycovered in the first phase of hardware design. However, upon further inspection, a decision was takento integrate the system on two levels. The main controller board was developed on PCB with some of the basic circuitry included on this. The next level was the external circuitry which would interface withthe first level.

    3 .1 H ardware Design of t h e Main Controller Board

    It was imperative that the main controller board be designed with the vision of a final consumer productin mind. For this reason, the board was developed to include all of the essential features that includethe USB serial communication port, the real time clock, and interface circuitry for the N/S and E/Wtraffic lights.

    3 .1.1 Th e AT Mega 16 2 Microcontroller

    Of the many AVR microcontrollers available, the three that suited the task were the ATmega8515, ATmega 85 3 5, and ATmega 162. The table below is a comparison between these threemicrocontrollers.Name EEPROM(Bytes) Max I/O Pins F.max(Mhz) RTC Ext. InterruptsATmega 8515 512 3 5 16 No 3 ATmega 85 3 5 512 3 2 16 No 3 ATmega 162 512 3 5 16 Yes 3

    Table 1. Comparison of the Microcontrollers

    From the above table, it was decided that the ATmega 162 was the most suitablemicrocontroller for the task. It has an internal real time clock which saves the task of implementing extra circuitry for an external RTC.

    3 .1. 2 Serial Communication

    Since newer laptops and computers are not manufactured with serial ports (COM), it was chosen to useUSB to interface with the microcontroller. The USB was a feature that built upon the basic requirementof communications between the microcontroller and the operator s user interface. A bus poweredconfiguration was chosen to allow the FT2 3 2R to be supplied by the PC connected. This would savebattery power on the controller side. The schematic for this component is seen below.

  • 8/6/2019 Design Phase 3 Report 2

    7/21

    7

    Figure 2 FT2 3 2R Based USB-to-Serial Communications (Texas Instruments)

    This circuit was designed on PCB. This can be seen in Appendix A1. This circuit had to be built on aseparate PCB (Mr. Greg Laubscher s design) from the main board but this board had to be mounted ontothe main controller board. This was done as communication to the main board was classified as anessential part of the internal system. The PC interface is discussed later in the software section.

    3 .1. 3 T ime of Day Clock

    The construction of a clock to indicate the time of day will enable traffic timings to coordinate accordingto peak and off peak time schedules. The implementation of a time of day utilizes the asynchronous

    operation of the RTC module of the AT Mega 162. In this mode, Timer/Counter2 runs independentlyfrom the CPU clock. The asynchronous counter operates from an external 3 2.768 kHz crystal which isconnected as below. The real time clock is able to run during sleep modes and power save modes. [2] Thesoftware implementation of the various modes of operation is discussed in section five of the report.

    Figure 3 Schematic of Real Time Clock Implementation

    1

    2

    RXD

    TXD

    VCC

    5V

    R2

    2205%

    R1

    2205%

    LED1

    3

    LED2

    4

    56

    U1

    FT232r

    TXDDTR#RTS#VCCIORXDRI#GND1NC1DSR#DCD#CTS#CBUS4CBUS2CBUS3 USBDP

    USBDM3V3OUT

    GND3RESET#

    VCCGND

    CBUS1CBUS0

    NC2AGNDTESTOSC1OSCO

    USB Connector

    7 8

    C1100nF

    C2100nF

    9 C34.7uF

    USB Serial Communication

    GN D

    GN D

    VCC

    C

    p

    C

    p

    a

    m ga

    PB0PB1PB2PB3PB4PB5PB6PB7-RESETPD0PD1PD2(INT0)PD3(INT1)PD4(TOSC1)PD5(TOSC2)PD6PD7XTAL2XTAL1GND PC0

    PC1PC2PC3PC4PC5PC6PC7PE2PE1

    PE0(INT2)PA7PA6PA5PA4PA3PA2PA1PA0VCC

    X14MHz

    U232.768kHz

    3

    4

    VCC

    5VVCC

    1

    2

    0

    0

  • 8/6/2019 Design Phase 3 Report 2

    8/21

    8

    The addition of the 3 2.768 kHz crystal was a simple addition to the PCB design. The addition of thiscrystal to the main board also provided stability to the crystal which can be troublesome underoperating conditions if moved aggressively.

    3 .1.4 T raffic Lig h t Outputs

    The diagram below indicates the pins of the ATmega 162 that will be used to drive the LED s. Thedatasheet of the ATmega 162 states that the microcontroller can drive LED s directly and source 20mAof current (Atmel, 2010) with the pull up resistors activated. It was decided that these would beactivated by a signal low from the microcontroller.

    Figure 4 Traffic Light Hardware Implementation

    The main Controller Board Schematic is shown below with the above hardware implemented directly onthe board.

    Figure 5 Main Controller Board Schematic

    RED

    ORANGE

    GREEN

    VCC5V VCC5V

    ORANGE_TURN

    GREEN_TURN

    RED1

    ORANGE1

    GREEN1

    E/W Vehicle CrossingN/S Vehicle Crossing

    PinB2

    PinB1

    PinB0

    PinB7

    PinB5

    PinB3PinB4

    PinB6

    C1

    22pF

    C2

    22pF

    X14MHz

    U1932.768kHz

    U1

    atmega162

    PB0PB1PB2PB3PB4PB5PB6PB7-RESETPD0PD1PD2(INT0)PD3(INT1)PD4(TOSC1)PD5(TOSC2)PD6PD7XTAL2XTAL1GND PC0

    PC1PC2PC3PC4PC5PC6PC7PE2PE1

    PE0(INT2)PA7PA6PA5PA4PA3PA2PA1PA0VCC

    J 3J 4

    J1

    1

    2

    J5

    H

    X8

    J 6

    J 2

    Imraan Vawda (2010-08-18):

    Header J1 is f or Vcc and Ground

    Imraan Vawda (2010-08-18):

    Header J3 is for the LED'sImraan Vawda (2010-08-18):

    Header J4 is for the SSD's

    Imraan Vawda (2010-08-18):

    Header J5 is f or the pedestrian crossings:- Push buttons- Lights- Buzzer

    Imraan Vawda (2010-08-19):

    Header J2 is for USB-USARTcommunication

    Imraan Vawda (2010-08-19):

    Header J6 for PortE- INT2- Additional pins

  • 8/6/2019 Design Phase 3 Report 2

    9/21

    9

    The above schematic was transferred to Ultiboard, which was used to design the PCB. The tracks for thePCB were routed manually ( follow-me tool) and not via the auto-routing function. Auto-routing tendsto make a board bigger than required, which is not efficient as it does not minimize on costs, especiallywhen there is large scale production. The PCB design of this schematic is shown in Appendix A. TheUSB/USART external PCB is mounted onto the main controller PCB and thus forms part of the internalcircuit.

    3 .2 External Circuitry

    In terms of external circuitry, it can be seen from the above schematic, (Figure 5) that all I/Ocomponents, i.e. LED s, SSD s, Buzzers and Push buttons, are replaced by headers. The following circuitsthat are discussed were designed on separate PCB s that connect via headers to the main PCB.

    3 .2 .1 I nductive Ve h icle Loop SensorDuring off-peak hours, the microcontroller will be in sleep mode to minimise power consumption.Hence, one intersection will remain green while the other is red. In order for traffic to still flow throughthe other intersection, a simple vehicle sensor will be used to initiate a quick change of traffic signal for

    a single car waiting at the intersection. The circuit originally chosen was the Maxwell Bridge InductiveSensor (Petruzzelis, 2009). However the design was changed after problems with prototyping which areexplained in section 4.

    Figure 6 Maxwell Wien Bridge Inductive Sensor (Fraden)

    This sensor is designed such that a car passing over the air core inductor causes an imbalance in theMaxwell-Wien Bridge (Petruzzelis, 2009). This change in inductance across the air conductor is used totrigger the interrupt and allow the microcontroller to perform the necessary operations (timingchanges). This circuit is designed to send a 5V logic signal to header J6 on the main controller board toactivate the interrupt. The software implementation of the interrupt signal from this circuit is discussedin section 5 of the report. The new test/demo board developed includes this PCB which is shown in theappendix.

    U1

    LM311N

    B/STBVS+

    GND

    BAL

    VS-

    2

    3

    4

    8

    7

    1

    5 6

    U3

    LM555CN

    GND

    1

    DIS7

    OUT 3RST4

    VCC

    8

    THR6

    CON5

    TRI2

    U2

    741

    3

    2

    4

    7

    6

    51

    R1

    100

    R2100

    R3

    100

    R4 4.7k

    R51k

    R6

    1k

    VCC

    5V

    3

    1

    C1 33uF

    2

    R7 50%

    L1

    3.6mH

    6

    GND

    R850%

    4

    C2100nF C3

    100nF

    5

    GND

    8

    R9

    5k

    R1050%

    9

    7

    VCC

    R1150%

    11

    10

    OUTPUT

  • 8/6/2019 Design Phase 3 Report 2

    10/21

    10

    3 .2 .2

    edestrian Pus h ButtonPush button technology will be employed to allow for changes in timing for pedestrians waiting a longtime to cross at the intersection. The push buttons send an active low signal to the microcontrollerwhen pressed which cause an interrupt. The signals go to external interrupt pins INT0 and INT1. Thecircuit is shown below. The software for these interrupts is discussed in section five.

    Figure 7 Push Button DesignSmall PCB s were designed for the push buttons to be included in the final demo board.

    3 .2 .3 Countdown T imerThis display will be implemented to provide the driver with the time left for the next green signal toactivate. Two seven segment displays are multiplexed as this method is more efficient and requires lessI/O ports from the AVR. One of the key advantages of this design is that it is purely software orientatedand requires no external chips for decoding.

    Figure 8 Multiplexed SSD sThe PCB designed for the countdown timer is shown in Appendix A. New test boards were designedafter phase two to provide a better outlook on the functions of the traffic controller. This PCB connectsto the main controller board via header J4.

    3 .2 .4 Buzzer for blind pedestrians

    Several buzzers of varying frequencies are available for purchase. A 200Hz buzzer was chosento adhere to South African blind and deaf standards. The buzzer would be grounded at one end

    Key = Space

    Key = Space

    Key = Space

    VCC

    5V

    3305%

    VCC

    INT0

    Key = Space

    3

    GND

    GND

    N/S Pedestrain Push Button

    A B

    D E F G

    K

    A B

    D E F G

    K

    Countdown Timer Display

    N 7S

    4_

    PortA

  • 8/6/2019 Design Phase 3 Report 2

    11/21

    11

    and have the other end connected to the output pin of the microcontroller. This would beimplemented in programming to sound the buzzer when the WALK signal turns on.

    Figure 9 Buzzer for Blind Pedestrians

    Other display boards for the LED s were also developed on PCB and are shown in Appendix A. Thebuzzer is also implemented on PCB. These boards that were developed in phase two were prototypesfor the new test board in phase three. This is highlighted in section four of the report.

    4. H ardware Prototyping

    4.1 Th e F T 232R PrototypeThe first PCB built was the USB to UART interface chip. This had to be specially built by Mr. GregLaubscher as it included a surface mount FT2 3 2R chip. This chip was tested using an AT Mega 8515 onbreadboard. Initial problems experienced were communication with this chip as it was unable toconnect to the At Mega 8515. This problem was solved by first programming the chip using an STK 500board and then using the FT 2 3 2R chip to control to communicate with the chip and monitor itsfunctions. A program called Termite was used to facilitate communication with the AT mega 162. Theword Hello was sent to the microcontroller via the USB cable and the microcontroller transmitted theword back. The main purpose of this chip is to allow for the operator of the Traffic controller to inputvariable timing changes via a PC to the microcontroller. The software implementation of this PC-Controller interface is discussed thoroughly in section five.

    4. 2 Th e Main BoardOnce the PCB was produced for the main board, the components were soldered into place. Animportant consideration here was the use of blue screw terminals to interface this board with the

    external boards. In phase two, it was decided to use ribbon cable soldered to headers which fit onto theterminals of the main board. This was a much neater and easier solution to the use of blue screwterminals and multiple untidy wires. Another advantage of ribbon cables is that they are more effectivefor transmitting logic signals and this was crucial to the design. In phase three, a new controller boardwas constructed which includes the proper headers for plugging in the ribbon cable connectors. Thisproved to be very neat and no soldering was required.

  • 8/6/2019 Design Phase 3 Report 2

    12/21

    12

    4. 3 Th e T est (Demo) Board

    To correctly exhibit the full functionality of the Traffic Controller interfacing with all the external circuitry,a new test board was designed and constructed. This test board was used to simulate a real four-wayintersection. The demo boards developed in phase two were used as prototypes for this test board. All

    the PCB s designed for this new board are shown in appendix A and the figure below is a picture of thetest board. The test board includes the N/S and E/W traffic lights, turning arrows and countdown timers.The push buttons and buzzers are all strategically located to produce a realistic four-way stop. Theinductive loop sensor is located under the E/W road on the test board. Positioning of the maincontroller board was deeply scrutinized as the distance for the logic signals to travel had to beminimised. The product implementation of the board was also considered here.(Include Photo of Final Demo Board)

    4.4 General T esting

    Test points were included on the PCB to allow for continuity checks to be performed. The MaxwellBridge inductive loop sensor was prototyped in phase two. However, there were problems with the

    sensitivity of the device and it would have failed to trigger an interrupt. Further research was done anda revised circuit was designed. This circuit was then successfully built in phase three after much trial andtribulation with the coil of the sensor. Overall, the hardware design was successful and produced aproduct that was robust and could be sold to the public.

    4.5 Furt h er I mprovements

    One must consider that the main controller board faces the possibility of harsh working environments.To be protected from outside elements, it had to be stored within a suitable enclosure. Many optionswere considered and research done showed that the IP65 ingress protection standard had to be

    conformed to. This standard ensures that the main controller is protected against dust and low pressurewater jets from all directions. Outdoor temperatures ranging from -10 oC to 55 oC will need to bewithstood by the casing. The enclosure would need to be roughly 150x100x50mm 3 in size.Unfortunately, the current budget of R 3 50 does not allow for such an enclosure to be purchased butthese future improvements can further improve the design.

    Figure 10 Protection for main controller board

  • 8/6/2019 Design Phase 3 Report 2

    13/21

    13

    5. Software Design and I mplementation

    5.1 System Software

    Figure 11 Software Design flow chart

    Figure 11 shows the high level design of the internal system software which is programmed into themicrocontroller. The C programming language was used as it provided an easier means of implementation. The following software specifications were used.Regular Timing Control:

    y Basis of the programming design is the use of timer2y Timer2 is operating in asynchronous mode and uses 3 2.768 kHz crystal connected to Pins TOSC1

    and TOSC2.y 128 Prescaler used which gives 1 second timing when using timer2 overflow interrupt.y Use of selection statements gives desired timingsy Regular Timing Control:

    Count-Down Timers:y Uses multiplexing to combine two SSD sy Uses timer0 to refresh displays 60 times a second to give an illusion of both on at the same time.

  • 8/6/2019 Design Phase 3 Report 2

    14/21

    14

    Interrupt Control:

    y INT0, INT1 and INT2 are used.y Triggered on rising edge for sensor.y Triggered on falling edge for switch.

    Night Mode:y During late hours, put into idle state. Microcontroller in sleep modey Activated by time of day clock

    The full program for the internal software is included in appendix C.

    5. 2 U SB/ U SAR T PC I nterface

    A basic requirement of operation was to give the operator of the traffic light controller the ability tochange the timing sequence of the lights. The USB-USART communication was implemented for modernday computers which often lack a serial port. A Visual Basic program was designed to provide a userinterface which is installed on the operator s PC. The program allows the user to change timing for thetwo intersections up-down numerical boxes. When the user inputs the new times and clicks send, themicrocontroller s timings are adjusted accordingly. The graphical user interface for this procedure canbe seen below.

    (Visual Basic Screen Shot)

  • 8/6/2019 Design Phase 3 Report 2

    15/21

    15

    6. Budget

    This design was required to be both efficient and cost effective. A balance between performance andlow cost had to be achieved. Fortunately, the total amount spent on the design was R 3 10.20 which issignificantly less than the allowed R 3 50. The detailed budget can be seen in Appendix B.

    7 . Conclusion

    Development of the traffic controller unit took a full eight weeks. In phase one, much research wasperformed with the goal of creating an ideal design that included all aspects of the hardwareimplementation. This phase, taking two weeks, produced a paper design of a Traffic light controller unitwith capabilities far exceeding the requirements of a normal four-way intersection. Safety forpedestrians and drivers was the main priority and innovative design ideas provided the relevantsolutions.

    Phase two, taking approximately three weeks, included creating a prototype for the main controllerboard and test/demo boards. A system design on two levels was considered here and the hardwaredesign was revised slightly to include an internal main controller board and external interfacing circuitrywith the main board. This helped further the quest of creating a final product suitable for consumers.The test programs in phase two provided a prelude to the full software design in phase three.Phase three proved to be the most trying as software integration and implementation on themicrocontroller was complex. However, the process followed as indicated in section 5.1 of the reportproduced a clean and effective solution. The USB-USART PC interface program developed on VisualBasic provided many challenges but was eventually successful and allowed for the user to input variabletimings for the various lights on the microcontroller. Also, this phase included the construction of a veryelaborate demo board. The demo board highlighted all the functions of the traffic controllersuccessfully. The Maxwell-Wien bridge sensor was also implemented in this phase and produced therequired pulse to activate the interrupt on the microcontroller.Finally, it must be stated that the design challenges faced in this project were overcome and exceeded.There is much room for improvement to the design of the traffic light controller such as lightning andrain protection which is discussed in section 4.5. However, the Traffic Light Controller designed anddeveloped in this phase met all the basic and advanced specifications proposed to the client and is readyfor product implementation in the real world.

    8 . R eferences

    Atmel. (2010). Atmel Datasheets . Retrieved 07 29, 2010, fromwww.atmel.com/atmel/acrobat/doc251 3 .pdf

    Fraden, J. Handbook of Modern Sensors 3rd Edition. Springer.Petruzzelis, T. (2009). Alarm, Sensor and Security Cookbook. McGraw Hill.Texas Instruments. (n.d.). Datasheets . Retrieved 07 29, 2010, from All Datasheets:

    www.alldatasheet.com/pdf

  • 8/6/2019 Design Phase 3 Report 2

    16/21

    16

    Appendix A

    Figure A1. Main Controller Board

    Include other PCB designs here

    Appendix BTraffic Controller Budget

  • 8/6/2019 Design Phase 3 Report 2

    17/21

    17

    Appendix C

    #include

    #include #include #include #define USART_BAUDRATE 9600#define BAUD_PRESCALE (((F_CPU /

    (USART_BAUDRATE * 16UL))) - 1)int init(void);//function prototypeint offpeak(void);int peak(void);int offpeaksensor(void);int updatevar(void);int display(int temp, int dis);//Function

    Prototype//variable declaration and initialisationint back=0;unsigned int ref =0;unsigned int units=10;unsigned int tens=10;volatile unsigned int count1=0;volatile unsigned int gns=12;volatile unsigned int y=2;volatile unsigned int t=4;volatile unsigned int rns=10;

    volatile unsigned int hr=12;//time is initialisedto 12 o'clock midday for peak timings

    volatile unsigned int min=0;volatile unsigned int sec=0;volatile char buffer[12];volatile unsigned int j=0;volatile unsigned int k=0;volatile unsigned int flag=0;

    // Interrupt Service Routine Section//*************************************

    *************************************

    ISR(TIMER2_OVF_vect)// 1 sec increments{

    sec++;if (sec==60){sec=0;min++;}

    if (min==60){min=0;hr++;}if (hr==24){hr=0;}count1=count1+1;

    }

    ISR(TIMER0_OVF_vect) //refreshes 7segdisplays

    {TCNT0=0;

    if (ref==0){display(units,1);ref=1;}if (ref==1){display(tens,0);ref=0;}

    }

    ISR(USART0_RXC_vect){

    buffer[j] = UDR0; // Fetch the byte j++;if (j==12){

    j=0;flag=1;}

    }

    ISR(INT0_vect) //push buttons ISR{

    //add}

    ISR(INT1_vect) //push buttons ISR{

  • 8/6/2019 Design Phase 3 Report 2

    18/21

    18

    //add}

    ISR(INT2_vect) //sensor ISR{

    offpeaksensor();}

    //********************************************************************************

    int init(void){

    MCUCR=0x0A;// setting up externalinterrupt 0 and 1 for falling edgetriggering

    EMCUCR|=(1

  • 8/6/2019 Design Phase 3 Report 2

    19/21

  • 8/6/2019 Design Phase 3 Report 2

    20/21

    20

    PORTB=0x0C;}if

    ((count1(gns+t+rns+y))){ //phase(yellow e/w)

    PORTB=0x0A;

    }if (count1>=(gns+y+t+rns+y+1)){

    count1=0;}

    return 1;}

    int offpeak(void){

    count1=0;

    TIMSK&=~(1

  • 8/6/2019 Design Phase 3 Report 2

    21/21

    21

    }if ((hr>21)&(hr