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

54 lines
626 B
Coq
Raw Normal View History

2022-05-09 16:05:40 +00:00
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