-
Notifications
You must be signed in to change notification settings - Fork 0
/
fsm_1.v
55 lines (44 loc) · 860 Bytes
/
fsm_1.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
module fsm_1( clk, rst, inp, outp);
input clk, rst, inp;
output outp;
reg [1:0] state;
reg outp;
always @( posedge clk, posedge rst )
begin
if( rst )
state <= 2'b00;
else
begin
case( state )
2'b00:
begin
if( inp ) state <= 2'b11;
else state <= 2'b01;
end
2'b01:
begin
if( inp ) state <= 2'b10;
else state <= 2'b11;
end
2'b10:
begin
if( inp ) state <= 2'b10;
else state <= 2'b11;
end
2'b11:
begin
if( inp ) state <= 2'b11;
else state <= 2'b11;
end
endcase
end
end
always @(posedge clk, posedge rst)
begin
if( rst )
outp <= 0;
else if( state == 2'b10 )
outp <= 1;
else outp <= 0;
end
endmodule