-
Notifications
You must be signed in to change notification settings - Fork 7
/
125. Simple FSM3 (synchronous reset).v
59 lines (51 loc) · 1.46 KB
/
125. Simple FSM3 (synchronous reset).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
module top_module(
input clk,
input in,
input reset,
output out); //
// State transition logic
parameter A = 2'b00, B = 2'b01, C = 2'b10, D = 2'b11;
reg [1:0] state, next_state;
always @(*) begin
state <= next_state;
end
// State flip-flops with synchronous reset
always @(posedge clk) begin
if(reset)
next_state <= A;
else
begin
case(state)
A : begin
if(in)
next_state <= B;
else
next_state <= A;
end
B : begin
if(in)
next_state <= B;
else
next_state <= C;
end
C : begin
if(in)
next_state <= D;
else
next_state <= A;
end
D : begin
if(in)
next_state <= B;
else
next_state <= C;
end
default : begin
next_state <= A;
end
endcase
end
end
// Output logic
assign out = (state == D)?1:0;
endmodule