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
|
//FSM1
localparam IDLE = 0,
S1 = 1,
S2 = 2;
[email protected](posedge clk, negedge rst_n)
begin
if (!rst_n)
cs <= IDLE;
else
if (reset)
cs <= IDLE;
else
cs <= ns;
end
[email protected]*
begin
ns = IDLE;
case (cs)
IDLE: if (a) ns = S1 else
ns = IDLE;
S1: if (b) ns = S2 else
ns = S1;
S2: ns = IDLE;
default : ns = IDLE;
endcase
end
//FSM2
localparam IDLE = 0,
S1 = 1,
S2 = 2;
[email protected](posedge clk, negedge rst_n)
begin
if (!rst_n)
cs <= IDLE;
else
cs <= ns;
end
[email protected]*
begin
ns = IDLE;
case (cs)
IDLE: if (reset) ns = IDLE; else
if (a) ns = S1 else
ns = IDLE;
S1: if (reset) ns = IDLE; if (b) ns = S2 else
ns = S1;
S2: if (reset) ns = IDLE; ns = IDLE;
default : ns = IDLE;
endcase
end
|