-
Notifications
You must be signed in to change notification settings - Fork 0
/
fsm_det.v
95 lines (86 loc) · 2.88 KB
/
fsm_det.v
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
module fsm_det (
reset,clock,serial_in,start,
seq_out);
input reset;
input clock,start;
input serial_in;
tri0 reset;
tri0 serial_in;
output seq_out;
reg seq_out;
reg [4:0] fstate;
reg [4:0] reg_fstate;
parameter s0=0,s1=1,s2=2,s3=3,s4=4;
always @(posedge clock)
begin
if (clock) begin
fstate <= reg_fstate;
end
end
always @(fstate or reset or serial_in)
begin
if (reset) begin
reg_fstate <= s0;
seq_out <= 1'b0;
end
else if(start) begin
seq_out <= 1'b0;
case (fstate)
s0: begin
if ((serial_in == 1'b1))
reg_fstate <= s1;
else if ((serial_in == 1'b0))
reg_fstate <= s0;
// Inserting 'else' block to prevent latch inference
else
reg_fstate <= s0;
seq_out <= 1'b0;
end
s1: begin
if ((serial_in == 1'b0))
reg_fstate <= s2;
else if ((serial_in == 1'b1))
reg_fstate <= s1;
// Inserting 'else' block to prevent latch inference
else
reg_fstate <= s1;
seq_out <= 1'b0;
end
s2: begin
if ((serial_in == 1'b0))
reg_fstate <= s0;
else if ((serial_in == 1'b1))
reg_fstate <= s3;
// Inserting 'else' block to prevent latch inference
else
reg_fstate <= s2;
seq_out <= 1'b0;
end
s3: begin
if ((serial_in == 1'b1))
reg_fstate <= s4;
else if ((serial_in == 1'b0))
reg_fstate <= s2;
// Inserting 'else' block to prevent latch inference
else
reg_fstate <= s3;
seq_out <= 1'b0;
end
s4: begin
if ((serial_in == 1'b0))
reg_fstate <= s0;
else if ((serial_in == 1'b1))
reg_fstate <= s1;
// Inserting 'else' block to prevent latch inference
else
reg_fstate <= s4;
seq_out <= 1'b1;
end
default: begin
seq_out <= 1'bx;
$display ("Reach undefined state");
end
endcase
end
end
endmodule // SM1