forked from M-HHH/HDLBits_Practice_verilog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
122. Simple state transitions 3.v
46 lines (39 loc) · 1.01 KB
/
122. Simple state transitions 3.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
module top_module(
input in,
input [1:0] state,
output [1:0] next_state,
output out); //
parameter A=0, B=1, C=2, D=3;
// State transition logic: next_state = f(state, in)
always @(*)
begin
case(state)
A : begin
if(in == 1'b0)
next_state <= A;
else
next_state <= B;
end
B : begin
if(in == 1'b0)
next_state <= C;
else
next_state <= B;
end
C : begin
if(in == 1'b0)
next_state <= A;
else
next_state <= D;
end
D : begin
if(in == 1'b0)
next_state <= C;
else
next_state <= B;
end
endcase
end
// Output logic: out = f(state) for a Moore state machine
assign out = (state == D )?1:0;
endmodule