This repository has been archived on 2024-01-06. You can view files and clone it, but cannot push or open issues or pull requests.
justhomework/Quartus/v6/jyh_4490_mstate.v
2022-05-11 14:25:40 +08:00

71 lines
779 B
Verilog

module jyh_4490_mstate(clk,in,en,out,cnt);
input clk,in,en;
output reg out;
output reg [19:0] cnt=0;
reg[1:0] state=0;
parameter s0=0,s1=1,s2=2,s3=3;
parameter TARGET=750000; //50mhz 15ms
always @(posedge clk)
if(!en)
state=s0;
else
case(state)
s0:
begin
out=0;
cnt=0;
if(in)
state=s1;
end
s1:
begin
out=0;
if(cnt<TARGET)
begin
state=s1;
cnt=cnt+1;
end
else
begin
cnt=0;
if(in)
state=s2;
else
state=s0;
end
end
s2:
begin
out=1;
cnt=0;
if(!in)
state=s3;
end
s3:
begin
out=1;
if(cnt<TARGET)
begin
state=s3;
cnt=cnt+1;
end
else
begin
cnt=0;
if(in)
state=s2;
else
state=s0;
end
end
default:
begin
state=s0;
out=0;
cnt=0;
end
endcase
endmodule