├── Logic_Diagram.png ├── README.md ├── RTL Code_Traffic Light Controller.txt ├── RTL Schematic View.jpeg ├── Report_Traffic light controller.pdf ├── StateTable.png ├── State_Diagram.png ├── TestBench-Traffic Light Controller.txt └── directions.png /Logic_Diagram.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Devipriya1921/Traffic-Light-Controller-using-Verilog/ece305e992e8d4b7ff0298e1ea1edccb10e2bebf/Logic_Diagram.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Traffic Light Controller Using Verilog 2 | * The purpose of this project is to design a methodology using Verilog to control the traffic with specified time delays for a T-Shaped road.* 3 | 4 | # Table of Contents 5 | 6 | 1. [Introduction](#Introduction) 7 | 2. [Methodology](#Methodology) 8 | - [Directions Considered](#directions-considered) 9 | - [Problem Statement](#problem-statement) 10 | - [State Diagram](#state-diagram) 11 | - [State Table](#state-table) 12 | 3. [RTL Code](#rtl-code) 13 | - [RTL Schematic View](#rtl-schematic-view) 14 | 4. [TESTBENCH](#testbench) 15 | 5. [Output Waveforms](#output-waveforms) 16 | 6. [Result](#result) 17 | 7. [Future work](#future-work) 18 | 8. [References](#references) 19 | 9. [Author](#author) 20 | 21 | 22 | ## Introduction 23 | 24 | Traffic control is a challenging problem in many cities. This is due to the large number of vehicles and the high dynamics of the traffic system. Poor traffic systems are the big reason for accidents, time losses. In this method of approach, it will reduce the waiting time of the vehicles at traffic signals. The hardware design has been developed using Verilog Hardware Description Language (HDL) programming. 25 | 26 | Verilog designing is hardware descriptive language, the name itself suggest that it deals with the hardware designing and simulation. Basically, it becomes very difficult to mount the various electronic components on breadboard or PCB circuit. It also takes too much time for the simulation and sometimes many errors occur because of improper connection of components onto the circuit. 27 | And thus, to overcome this factor hardware descriptive language comes into conclusion. we can code the process using Verilog and we can mount it on a circuit or just upload it to the circuit accordingly so that particular circuit will work as according to the code we have written. 28 | 29 | HDL language is often used for sequential circuits like shift register, combinational logic circuit like adder, subtractor etc. Basically it describes the digital systems like microprocessor or a memory. Whatever design that is described in HDL are independent, it has its unique state of work, very much easy to simulate, designing and debugging, and very useful than schematics, especially for large circuits thus, to overcome difficulties or problems to design the circuits manually with breadboard and PCB, use of Verilog designing in this complex world is increasing a way better. 30 | 31 | This project deals with a basic design of a T - Shaped road for traffic light control. The output of system has been tested using Xilinx 14.5. 32 | 33 | A traffic light system is an electronic device that assigns right of way at an intersection or crossing or street crossing by means of displaying the standard red, yellow and green colored indications. In addition, it also works in conjunction with pedestrian displays to assign pedestrian crossing right of way. 34 | 35 | A traffic light, also known as traffic signal, stop light, stop-and-go lights, is a signaling device positioned at a road intersection, pedestrian crossing, or other location in order to indicate when it is safe to drive, ride, or walk using a universal colour code. 36 | Nowadays, 37 | 38 | 1. A red light meant traffic in all directions had to stop. 39 | 2. A yellow light meant cross-town traffic would have to slow and, 40 | 3. A green light would to go or proceed. 41 | 42 | The problem of heavy jam is happened because of never configure the level of jam in each way and set the delay time. Another problem represents when there is no jam, but the waiting still continues. The solution for these problems is to determine the level of jam and set the delay time. This problem need of evaluation of the traffic policeman, and then there is need for manual control of the traffic. 43 | The target of this paper is to propose system provide solution for all above problems with least possible cost. Traffic light controller (TLC) can be implemented using microcontroller, FPGA, and ASIC design. FPGA has many advantages over microcontroller, some of these advantages are; the speed, number of input/output ports and performance which are all very important in TLC design, at the same time ASIC design is more expensive than FPGA. 44 | Nowadays, FPGA becomes one of the most successful of today’s technologies for developing the systems which require a real time operation. FPGA is a re-configurable integrated circuit that consists of two dimensional arrays of logic blocks and flip-flops with an electrically programmable interconnection between logic blocks. 45 | The reconfiguration property enables fast prototyping and updates for hardware devices even after market launch. Most of the TLCs implemented on FPGA are simple ones that have been implemented as examples of Finite State Machine (FSM). 46 | 47 | #### The Verilog language has been selected for programming the FPGA to fill two important needs in the design process. 48 | 49 | - Firstly, it gives full description of the structure of a design that is how it is decomposed into sub-designs, and how those sub-designs are interconnected. 50 | - Secondly, it allows simulating the design before starting the manufacturing. 51 | - Accordingly, the designers can quickly compare alternatives and test for correctness without the delay and expense of hardware prototyping. 52 | 53 | #### Benefits of Using Verilog HDL (Hardware Description Language) : 54 | 55 | Verilog is a widely used Hardware Description Language (HDL) for designing digital circuits. It can also be used for modeling analog circuits. Verilog is a descriptive language that describes a relationship between signals in a circuit. 56 | 57 | A Verilog model describes a unit of digital hardware in terms of : 58 | - Interconnections of other hardware unit whose models prescribe their behavior in a 59 | simulation. 60 | - Behavioral / procedural algorithms that abstractly describe input/output behavior 61 | that could be personified in a hardware unit. 62 | 63 | Hardware description language (HDL) is divided by two types, Verilog and VHDL (VHSIC – Very High Speed Integrated Circuit Hardware Description Language). Both have its advantages and its disadvantage. 64 | In this project, Verilog HDL was chosen because it’s used for synthesis of logic circuits (synthesizable code), used for verification purposes of a circuit (can be analog or digital or mixed signal), can be used by combining synthesis & verification (synthesizable & behavioral code) and it used for netlist representation of a synthesizable circuit (structural code). 65 | 66 | #### The advantages using Verilog HDL are shown below : 67 | - Easy to write. 68 | - Easy to understand as it similar to C program. 69 | - Easier to learn compared with VHDL. 70 | 71 | 72 | ## Methodology 73 | 74 | ### Directions Considered 75 | 76 | ![directions](https://user-images.githubusercontent.com/83152452/131366734-67c76e3c-b53d-49ca-a5ba-fb058d19d578.png) 77 | 78 | The directions, M1, MT, M2, S, that is been considered for analysis of our problem is shown in the figure. And, the problem statement is explained in the figure. 79 | Six states, S1, S2, S3, S4, S5, S6 are taken into consideration and state diagram, state table is made using the following logic explained in the figure. 80 | 81 | ### Problem Statement 82 | 83 | ![Logic_Diagram](https://user-images.githubusercontent.com/83152452/131366783-8c025386-8011-4ef9-a766-d0a07e4244ac.png) 84 | 85 | - Green light indicates that there is no traffic and there is easy flow of vehicles in that route/direction. 86 | - Red light indicates that there is a traffic jam and that route is blocked for the vehicles to move and, 87 | - Yellow light indicates that the route has medium flow of vehicles. 88 | 89 | Time delays for changing from one state to another is considered as, TMG(from S1 to S2), TY(from S2 to S3), TTG(from S3 to S4), TY(from S4 to S5), TSG(from S5 to S6) 90 | and TY(from S6 to S1) and the cycle continues. 91 | 92 | 93 | ### State Diagram 94 | 95 | ![State_Diagram](https://user-images.githubusercontent.com/83152452/131366795-bc45473d-4398-47bb-bad9-a520a779c8bc.png) 96 | 97 | In Figure, The time delays are considered as follows : 98 | 99 | - TMG = 7 seconds 100 | - TY = 2 seconds 101 | - TTG = 5 seconds 102 | - TSG = 3 seconds 103 | 104 | Until TMG seconds, the signal will remain in S1 state, and after TMG seconds, it will move to S2 state. Until TY seconds it will remain in S2 state and after TY seconds, 105 | it will move to S3 state, and so on. After TY seconds, in state S6, it will go back to S1 state and the cycle continues. 106 | 107 | 108 | ### State Table 109 | 110 | ![StateTable](https://user-images.githubusercontent.com/83152452/131366804-309b6e9a-4c9c-442b-8753-281a933254f6.png) 111 | 112 | In Figure, 113 | - R = RED, 114 | - Y = YELLOW and, 115 | - G = GREEN. 116 | 117 | ST = State Transition; A, B and C are considered as the present state. 118 | The state table is made, considering the Logic diagram/problem statement given in Figure. 119 | From the Figure it is understood that, 120 | 121 | In state S1(001); 122 | 123 | ``` 124 | 1. M1 = GREEN, implies, RYG value = 001, 125 | 2. MT = RED, implies, RYG value = 100, 126 | 3. M2 = GREEN, implies, RYG value = 001 and, 127 | 4. S = RED, implies, RYG value = 100. 128 | 129 | ``` 130 | 131 | After TMG seconds, 132 | 133 | In state S2(010); 134 | 135 | ``` 136 | 1. M1 = GREEN, implies, RYG value = 001, 137 | 2. MT = RED, implies, RYG value = 100, 138 | 3. M2 = YELLOW, implies, RYG value = 010 and, 139 | 4. S = RED, implies, RYG value = 100. 140 | 141 | ``` 142 | 143 | After TY seconds, 144 | 145 | In state S3(011); 146 | 147 | ``` 148 | 1. M1 = GREEN, implies, RYG value = 001, 149 | 2. MT = GREEN, implies, RYG value = 001, 150 | 3. M2 = RED, implies, RYG value = 100 and, 151 | 4. S = RED, implies, RYG value = 100. 152 | 153 | ``` 154 | 155 | After TTG seconds, 156 | 157 | In state S4(100); 158 | 159 | ``` 160 | 1. M1 = YELLOW, implies, RYG value = 010, 161 | 2. MT = YELLOW, implies, RYG value = 010, 162 | 3. M2 = RED, implies, RYG value = 100 and, 163 | 4. S = RED, implies, RYG value = 100. 164 | 165 | ``` 166 | 167 | After TY seconds, 168 | 169 | In state S5(101); 170 | 171 | ``` 172 | 1. M1 = RED, implies, RYG value = 100, 173 | 2. MT = RED, implies, RYG value = 100, 174 | 3. M2 = RED, implies, RYG value = 100 and, 175 | 4. S = GREEN, implies, RYG value = 001. 176 | 177 | ``` 178 | 179 | After TSG seconds, 180 | 181 | In state S6(110); 182 | 183 | ``` 184 | 1. M1 = RED, implies, RYG value = 100, 185 | 2. MT = RED, implies, RYG value = 100, 186 | 3. M2 = RED, implies, RYG value = 100 and, 187 | 4. S = YELLOW, implies, RYG value = 010. 188 | 189 | ``` 190 | 191 | And after S6 state, the cycle repeats and goes to S1 state. 192 | 193 | 194 | 195 | 196 | ## RTL Code 197 | 198 | ``` 199 | 200 | `timescale 1ns / 1ps 201 | module Traffic_Light_Controller( 202 | input clk,rst, 203 | output reg [2:0]light_M1, 204 | output reg [2:0]light_S, 205 | output reg [2:0]light_MT, 206 | output reg [2:0]light_M2 207 | ); 208 | 209 | parameter S1=0, S2=1, S3 =2, S4=3, S5=4,S6=5; 210 | reg [3:0]count; 211 | reg[2:0] ps; 212 | parameter sec7=7,sec5=5,sec2=2,sec3=3; 213 | 214 | always@(posedge clk or posedge rst) 215 | begin 216 | if(rst==1) 217 | begin 218 | ps<=S1; 219 | count<=0; 220 | end 221 | else 222 | case(ps) 223 | S1: if(count