input Ain, Clock, Reset;
output reg Yout;
output reg[3:0] Count;
reg [2:0] State;
parameter S0 = 3'b000,
S1 = 3'b001,
S2 = 3'b010,
S3= 3'b011;
// State Logic
always @ ( posedge Clock or posedge Reset )
begin
if (Reset)
begin
State <= S0;
Count=0;
end
else case (State)
S0: if (Ain==1)
begin
State= S1;
Count<= Count+1;
end
else State<=S0;
S1: if (Ain==1)
begin
State= S2;
Count<= Count+1;
end
else State<= S1;
S2: if (Ain==1)
begin
State= S3;
Count<= Count+1;
end
else State<= S2;
S3: if (Ain==1)
begin
State= S1;
Count<= Count+1;
end
else State<= S3;
default: State <= S0;
endcase
end
// Output Logic
always @ (State)
begin
if (State== S0) Yout =!(1*!Reset);
if (State== S1) Yout = 1'b0;
if (State== S2) Yout = 1'b0;
if (State== S3) Yout = 1'b1;
end
endmodule
No comments:
Post a Comment