I wrote a simple school project traffic light and I want to add a new state of "red-yellow" lights !https://ibb.co/vDw4DTN This picture shows how it should look like I do not know what the "if-else" statement looks like. Thank you in advance for your help
1 | `timescale 1ns / 1ps |
2 | module Traffic |
3 | (
|
4 | input reset, |
5 | input clk, |
6 | input NS_VEHICLE_DETECT, |
7 | input EW_VEHICLE_DETECT, |
8 | output wire NS_RED, |
9 | output wire NS_YELLOW, |
10 | output wire NS_GREEN, |
11 | output wire EW_RED, |
12 | output wire EW_YELLOW, |
13 | output wire EW_GREEN |
14 | );
|
15 | |
16 | reg [5:0] lights; // {NS_RED, NS_YELLOW, NS_GREEN, EW_RED, EW_YELLOW, EW_GREEN} |
17 | reg [4:0] nsCounter; |
18 | reg [3:0] ewCounter; |
19 | reg [1:0] yellowCounter; |
20 | |
21 | |
22 | assign {NS_RED, NS_YELLOW, NS_GREEN, EW_RED, EW_YELLOW, EW_GREEN} = lights; |
23 | |
24 | |
25 | always @(posedge clk) |
26 | if (reset) |
27 | lights <= 6'b001100; |
28 | else
|
29 | if (nsCounter == 31 & EW_VEHICLE_DETECT & NS_GREEN) |
30 | lights <= 6'b010100; |
31 | else
|
32 | if (ewCounter == 15 & EW_GREEN) |
33 | lights <= 6'b100010; |
34 | else
|
35 | if (yellowCounter == 3 & NS_YELLOW) |
36 | lights <= 6'b100001; |
37 | else
|
38 | if (yellowCounter == 3 & EW_YELLOW) |
39 | lights <= 6'b001100; |
40 | //------------------------------------
|
41 | |
42 | always @(negedge clk) |
43 | if (reset) |
44 | begin
|
45 | nsCounter <= 5'h0; |
46 | ewCounter <= 4'h0; |
47 | yellowCounter <= 2'h0; |
48 | end
|
49 | else
|
50 | begin
|
51 | nsCounter <= nsCounter + 1'b1; |
52 | ewCounter <= ewCounter + 1'b1; |
53 | yellowCounter <= yellowCounter + 1'b1; |
54 | end
|
55 | //------------------------------------
|
56 | |
57 | endmodule
|
58 | //====================================
|