Traffic Light Code Explanation

Embed Size (px)

Citation preview

  • 8/12/2019 Traffic Light Code Explanation

    1/10

    Code Explanation:

    The Traffic_Controller is responsible for handling the state machine. There is a single state machine

    divided into 2 parts namely: 1.) output 2.) state transition. The output is responsible for outputting what

    colors the traffic lights for Traffic light 1, 2, 3 and 4. The state transition is responsible for handling the

    sequence of states and is responsible for checking the status of sensors/switches. The delay is

    responsible for how long or how short the transition is from red to yellow and yellow to green.

    The VGA_Controller is responsible for outputting the necessary signals to the VGA monitor. It uses a set

    of values called VGA timings to match specified resolution which is 800 x 600.

    module

    Traffic_Controller(CLOCK_50,CLEAR,R1,R2,R3,R4,X1,X2,X3,X4,state,next_state,g2ydelay,y2rdelay);

    output reg [2:0] R1,R2,R3,R4;

    input X1,X2,X3,X4;

    input CLOCK_50,CLEAR;

    output reg [2:0] state;

    output reg [2:0] next_state;

    output reg [31:0] g2ydelay;

    output reg [31:0] y2rdelay;

    parameter RED = 3'b100;

    parameter YELLOW = 3'b010;

    parameter GREEN = 3'b001;

    parameter gg2y = 100_000_000;

    parameter yy2r = 100_000_000;

  • 8/12/2019 Traffic Light Code Explanation

    2/10

  • 8/12/2019 Traffic Light Code Explanation

    3/10

    begin

    R1

  • 8/12/2019 Traffic Light Code Explanation

    4/10

    R1

  • 8/12/2019 Traffic Light Code Explanation

    5/10

    always@(posedge CLOCK_50)

    begin

    if(CLEAR)

    next_state

  • 8/12/2019 Traffic Light Code Explanation

    6/10

    else

    begin

    if(y2rdelay == yy2r)

    begin

    y2rdelay

  • 8/12/2019 Traffic Light Code Explanation

    7/10

    end

    else

    y2rdelay

  • 8/12/2019 Traffic Light Code Explanation

    8/10

    if(y2rdelay == yy2r)

    begin

    y2rdelay

  • 8/12/2019 Traffic Light Code Explanation

    9/10

    S7:

    begin

    if(~X1)

    begin

    if(y2rdelay == yy2r)

    begin

    y2rdelay

  • 8/12/2019 Traffic Light Code Explanation

    10/10

    Block Diagram Explanation:

    The input pins L21,M22,V12,W12,L1,L22 are connected to the Traffic Controller. The Traffic Controller

    also outputs the V22,U21,U22,Y22,W21,W22,etc (these are the respective LEDs). The VGA Controller is

    responsible for the VSYNC, HSYNC, RGB outputs going to the monitor.