-
Notifications
You must be signed in to change notification settings - Fork 8
/
119. Simple FSM 1 (synchronous reset).v
52 lines (41 loc) · 1.48 KB
/
119. Simple FSM 1 (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
// Note the Verilog-1995 module declaration syntax here:
module top_module(clk, reset, in, out);
input clk;
input reset; // Synchronous reset to state B
input in;
output out;//
reg out;
// Fill in state name declarations
reg [1:0] present_state, next_state;
parameter state_b = 2'b01, state_a = 2'b10;
always @ (*)
begin
present_state = next_state;
end
always @ (posedge clk)
begin
if(reset)
next_state <= state_b[1:0];
else
begin
case(present_state[1:0])
state_b : begin
if(~in)
next_state <= state_a[1:0];
else
next_state <= state_b[1:0];
end
state_a : begin
if(~in)
next_state <= state_b[1:0];
else
next_state <= state_a[1:0];
end
endcase
end
end
assign out = (present_state == state_b[1:0]);
endmodule
//But in this code, its doesn't take advantage of the recommended scheme.
//So if you have a better way to solve this problem, please pull a request so I can merge it.
//THX