-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFSM.v
More file actions
122 lines (110 loc) · 2.49 KB
/
FSM.v
File metadata and controls
122 lines (110 loc) · 2.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
`timescale 1ns / 1ps
module FSM(
input Sensor_Sync,
input WR,
output reg WR_Reset,
output reg [6:0] LEDs,
output reg [1:0] interval,
output reg start_timer,
input expired,
input Prog_Sync,
input Reset_Sync,
input clk
);
localparam tbase = 2'b00,//tBASE
textended = 2'b01,//tEXT
tyellow = 2'b10,//tYEL
tbasex2 = 2'b11;//2*tBASE
reg deviate;
reg checkSensor_sync;
localparam S1 = 7'b0011000, //Main green and side red
S2 = 7'b0101000, //Main yellow and side red
S3 = 7'b1000010, //Side green and main red
S4 = 7'b1000100, //Side yellow and main red
S5 = 7'b1001001; //walk, main and side red
always@(posedge clk)
begin
start_timer = 0;
if (Prog_Sync | Reset_Sync) begin
LEDs = S1;
interval = tbasex2;
WR_Reset = 0;
start_timer = 1;
checkSensor_sync = 1;
end
if (expired)
begin
case (LEDs)
S1: begin
if (deviate) begin
if (Sensor_Sync & checkSensor_sync)begin
LEDs = S1;
interval = textended;
start_timer = 1;
checkSensor_sync = 0;
end
else begin
LEDs = S1;
interval = tbase;
start_timer = 1;
end
deviate = 0;
end
else begin
LEDs = S2;
interval = tyellow;
start_timer = 1;
end
end
S2: begin
if (WR) begin
LEDs = S5;
interval = textended;
start_timer = 1;
WR_Reset = 1;
end
else begin
LEDs = S3;
interval = tbase;
start_timer = 1;
end
checkSensor_sync = 1;
end
S3: begin
if (Sensor_Sync & checkSensor_sync) begin
LEDs = S3;
interval = textended;
start_timer = 1;
checkSensor_sync = 0;
end
else begin
LEDs = S4;
interval = tyellow;
start_timer = 1;
checkSensor_sync = 1;
end
end
S4: begin
LEDs = S1;
interval = tbase;
start_timer = 1;
deviate = 1;
checkSensor_sync = 1;
end
S5: begin
LEDs = S3;
interval = tbase;
start_timer = 1;
WR_Reset = 0;
end
default :
begin
LEDs = S1;
interval = tbase;
deviate = 1;
start_timer = 1;
end
endcase
end
end
endmodule