1 module fsm(A,Reset,K2,K1,clk,state);
2 input A,Reset,clk;
3 output K2,K1;
4 output [4:0]state;
5 reg [4:0]state;
6 assign K2=state[4];
7 assign K1=state[0];
8 parameter Idel = 5'b0_000_0,
9 start = 5'b0_010_0,
10 stop = 5'b0_010_0,
11 stoptoclear=5'b1_100_0,
12 clear = 5'b0_101_0,
13 cleartoIdel=5'b0_011_1;
14 always @(posedge clk)
15 if (!Reset)
16 begin
17 state<=Idel;
18 end
19 else
20 case(state)
21 Idel: if (A) state<=start;
22 else state<=Idel;
23 start:if(!A) state<=stop;
24 else state<=start;
25 stop: if(A) state<=stoptoclear;
26 else state<=stop;
27 stoptoclear: state<=clear;
28 clear:if(!A) state<=cleartoIdel;
29 else state<=clear;
30 cleartoIdel: state<=Idel;
31 default:state<=Idel;
32 endcase
33 endmodule