-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathseq_detect_1011.v
More file actions
73 lines (67 loc) · 1.49 KB
/
seq_detect_1011.v
File metadata and controls
73 lines (67 loc) · 1.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
// See LICENSE.vyoma for more details
// Verilog module for Sequence detection: 1011
module seq_detect_1011(seq_seen, inp_bit, reset, clk);
output seq_seen;
input inp_bit;
input reset;
input clk;
parameter IDLE = 0,
SEQ_1 = 1,
SEQ_10 = 2,
SEQ_101 = 3,
SEQ_1011 = 4;
reg [2:0] current_state, next_state;
// if the current state of the FSM has the sequence 1011, then the output is
// high
assign seq_seen = current_state == SEQ_1011 ? 1 : 0;
// state transition
always @(posedge clk)
begin
if(reset)
begin
current_state <= IDLE;
end
else
begin
current_state <= next_state;
end
end
// state transition based on the input and current state
always @(inp_bit or current_state)
begin
case(current_state)
IDLE:
begin
if(inp_bit == 1)
next_state = SEQ_1;
else
next_state = IDLE;
end
SEQ_1:
begin
if(inp_bit == 1)
next_state = SEQ_1; // Bug - 1 Fixed
else
next_state = SEQ_10;
end
SEQ_10:
begin
if(inp_bit == 1)
next_state = SEQ_101;
else
next_state = IDLE;
end
SEQ_101:
begin
if(inp_bit == 1)
next_state = SEQ_1011;
else
next_state = SEQ_10; // Bug - 2 Fixed
end
SEQ_1011:
begin
next_state = IDLE; // Bug - 3
end
endcase
end
endmodule