54 lines
626 B
Coq
54 lines
626 B
Coq
|
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
|
||
|
if(in)
|
||
|
state=s1;
|
||
|
out=0;
|
||
|
end
|
||
|
s1:
|
||
|
if(cnt<TARGET)
|
||
|
cnt=cnt+1;
|
||
|
else
|
||
|
begin
|
||
|
if(in)
|
||
|
state=s2;
|
||
|
else
|
||
|
state=s0;
|
||
|
cnt=0;
|
||
|
end
|
||
|
s2:
|
||
|
begin
|
||
|
if(in)
|
||
|
state=s2;
|
||
|
else
|
||
|
state=s3;
|
||
|
out=1;
|
||
|
end
|
||
|
s3:
|
||
|
if(cnt<TARGET)
|
||
|
cnt=cnt+1;
|
||
|
else
|
||
|
begin
|
||
|
if(in)
|
||
|
state=s2;
|
||
|
else
|
||
|
state=s0;
|
||
|
cnt=0;
|
||
|
end
|
||
|
endcase
|
||
|
|
||
|
|
||
|
endmodule
|