Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
11 years ago

Traffic Light display on VGA

Hi everyone!

I am planning to make a verilog project on traffic lights similar as found in this video https://www.youtube.com/watch?v=ieBteoMly7w. This is my code but it won't display something on the screen. Somebody help me with this.

This is my code for it to display on the screen..

always @(posedge clk)

begin

if(reset == 1)

q <= 0;

else

q <= q + 1;

end

assign clk3 = q[24]; // 3 Hz

always @(posedge clk3)

begin

if (reset == 1)

begin

state <= S0;

count <= 0;

end

else

case(state)

S0: if(count < SEC5)

begin

state <= S0;

count <= count + 1;

end

else

begin

state <= S1;

count <= 0;

end

S1: if(count < SEC2)

begin

state <= S1;

count <= count + 1;

end

else

begin

state <= S2;

count <= 0;

end

S2: if(count < SEC2)

begin

state <= S2;

count <= count + 1;

end

else

begin

state <= S3;

count <= 0;

end

S3: if(count < SEC5)

begin

state <= S3;

count <= count + 1;

end

else

begin

state <= S4;

count <= 0;

end

S4: if(count < SEC2)

begin

state <= S4;

count <= count + 1;

end

else

begin

state <= S5;

count <= 0;

end

S5: if(count < SEC2)

begin

state <= S5;

count <= count + 1;

end

else

begin

state <= S0;

count <= 0;

end

default state <= S0;

endcase

end

always @(posedge clk3)

begin

case(state)

S0: begin out <= 4'd5;

if(out != 0)

begin

out <= out - 4'd1;

end

end

S1: begin out <= 4'd2;

if(out != 0)

begin

out <= out - 4'd1;

end

end

S2: begin out <= 4'd2;

if(out != 0)

begin

out <= out - 4'd1;

end

end

S3: begin out <= 4'd5;

if(out != 0)

begin

out <= out - 4'd1;

end

end

S4: begin out <= 4'd2;

if(out != 0)

begin

out <= out - 4'd1;

end

end

S5: begin out <= 4'd2;

if(out != 0)

begin

out <= out - 4'd1;

end

end

default state <= S0;

endcase

end

//************************Setting the Blinking of Lights************************//

always @(posedge clk3)

begin

case(state)

S0: begin

if(Auto5 || Auto8)

begin

VGA_R = 3'b000 & inDisplayArea;

VGA_G = 3'b111 & inDisplayArea;

VGA_B = 2'b00 & inDisplayArea;

end

else if(Auto9 || Auto12)

begin

VGA_R = 3'b111 & inDisplayArea;

VGA_G = 3'b000 & inDisplayArea;

VGA_B = 2'b00 & inDisplayArea;

end

else if (Auto1 || Auto2 != Auto3 != Auto4 != Auto5 != Auto6 != Auto7 != Auto8 != Auto9 != Auto10 != Auto11 != Auto12 != Auto13 != Auto14)

begin

VGA_R = 3'b111 & inDisplayArea;

VGA_G = 3'b111 & inDisplayArea;

VGA_B = 2'b11 & inDisplayArea;

end

else

begin

VGA_R = 0 & inDisplayArea;

VGA_G = 0 & inDisplayArea;

VGA_B = 0 & inDisplayArea;

end

end

S1: begin

if(Auto4 || Auto7)

begin

VGA_R = 3'b111 & inDisplayArea;

VGA_G = 3'b111 & inDisplayArea;

VGA_B = 2'b00 & inDisplayArea;

end

else if(Auto9 || Auto12)

begin

VGA_R = 3'b111 & inDisplayArea;

VGA_G = 3'b000 & inDisplayArea;

VGA_B = 2'b00 & inDisplayArea;

end

else if (Auto1 || Auto2 != Auto3 != Auto4 != Auto5 != Auto6 != Auto7 != Auto8 != Auto9 != Auto10 != Auto11 != Auto12 != Auto13 != Auto14)

begin

VGA_R = 3'b111 & inDisplayArea;

VGA_G = 3'b111 & inDisplayArea;

VGA_B = 2'b11 & inDisplayArea;

end

else

begin

VGA_R = 0 & inDisplayArea;

VGA_G = 0 & inDisplayArea;

VGA_B = 0 & inDisplayArea;

end

end

S2: begin

if(Auto3 || Auto6)

begin

VGA_R = 3'b111 & inDisplayArea;

VGA_G = 3'b000 & inDisplayArea;

VGA_B = 2'b00 & inDisplayArea;

end

else if(Auto9 || Auto12)

begin

VGA_R = 3'b111 & inDisplayArea;

VGA_G = 3'b000 & inDisplayArea;

VGA_B = 2'b00 & inDisplayArea;

end

else if (Auto1 || Auto2 != Auto3 != Auto4 != Auto5 != Auto6 != Auto7 != Auto8 != Auto9 != Auto10 != Auto11 != Auto12 != Auto13 != Auto14)

begin

VGA_R = 3'b111 & inDisplayArea;

VGA_G = 3'b111 & inDisplayArea;

VGA_B = 2'b11 & inDisplayArea;

end

else

begin

VGA_R = 0 & inDisplayArea;

VGA_G = 0 & inDisplayArea;

VGA_B = 0 & inDisplayArea;

end

end

S3: begin

if(Auto3 || Auto6)

begin

VGA_R = 3'b111 & inDisplayArea;

VGA_G = 3'b000 & inDisplayArea;

VGA_B = 2'b00 & inDisplayArea;

end

else if(Auto11 || Auto14)

begin

VGA_R = 3'b000 & inDisplayArea;

VGA_G = 3'b111 & inDisplayArea;

VGA_B = 2'b00 & inDisplayArea;

end

else if (Auto1 || Auto2 != Auto3 != Auto4 != Auto5 != Auto6 != Auto7 != Auto8 != Auto9 != Auto10 != Auto11 != Auto12 != Auto13 != Auto14)

begin

VGA_R = 3'b111 & inDisplayArea;

VGA_G = 3'b111 & inDisplayArea;

VGA_B = 2'b11 & inDisplayArea;

end

else

begin

VGA_R = 0 & inDisplayArea;

VGA_G = 0 & inDisplayArea;

VGA_B = 0 & inDisplayArea;

end

end

S4: begin

if(Auto3 || Auto6)

begin

VGA_R = 3'b111 & inDisplayArea;

VGA_G = 3'b000 & inDisplayArea;

VGA_B = 2'b00 & inDisplayArea;

end

else if(Auto10 || Auto13)

begin

VGA_R = 3'b111 & inDisplayArea;

VGA_G = 3'b111 & inDisplayArea;

VGA_B = 2'b00 & inDisplayArea;

end

else if (Auto1 || Auto2 != Auto3 != Auto4 != Auto5 != Auto6 != Auto7 != Auto8 != Auto9 != Auto10 != Auto11 != Auto12 != Auto13 != Auto14)

begin

VGA_R = 3'b111 & inDisplayArea;

VGA_G = 3'b111 & inDisplayArea;

VGA_B = 2'b11 & inDisplayArea;

end

else

begin

VGA_R = 0 & inDisplayArea;

VGA_G = 0 & inDisplayArea;

VGA_B = 0 & inDisplayArea;

end

end

S5: begin

if(Auto3 || Auto6)

begin

VGA_R = 3'b111 & inDisplayArea;

VGA_G = 3'b000 & inDisplayArea;

VGA_B = 2'b00 & inDisplayArea;

end

else if(Auto9 || Auto12)

begin

VGA_R = 3'b111 & inDisplayArea;

VGA_G = 3'b000 & inDisplayArea;

VGA_B = 2'b00 & inDisplayArea;

end

else if (Auto1 || Auto2 != Auto3 != Auto4 != Auto5 != Auto6 != Auto7 != Auto8 != Auto9 != Auto10 != Auto11 != Auto12 != Auto13 != Auto14)

begin

VGA_R = 3'b111 & inDisplayArea;

VGA_G = 3'b111 & inDisplayArea;

VGA_B = 2'b11 & inDisplayArea;

end

end

else

begin

VGA_R = 0 & inDisplayArea;

VGA_G = 0 & inDisplayArea;

VGA_B = 0 & inDisplayArea;

end

default begin

VGA_R = 0 & inDisplayArea;

VGA_G = 0 & inDisplayArea;

VGA_B = 0 & inDisplayArea;

end

endcase

end

endmodule

Your help is greatly appreciated.

1 Reply

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Have you simulated the code? Software you need is called ModelSim and is supplied with Quartus II.

    This does not look fine: assign clk3 = q[24]; // 3 Hz Use your real clock for rising edge and your newly derived clk3 with an if-statement like this:

    always @(posedge clk)

    begin

    if (clk3)

    begin...