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

72 lines
779 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
2022-05-11 06:25:40 +00:00
out=0;
cnt=0;
2022-05-09 16:05:40 +00:00
if(in)
state=s1;
end
s1:
2022-05-11 06:25:40 +00:00
begin
out=0;
2022-05-09 16:05:40 +00:00
if(cnt<TARGET)
2022-05-11 06:25:40 +00:00
begin
state=s1;
2022-05-09 16:05:40 +00:00
cnt=cnt+1;
2022-05-11 06:25:40 +00:00
end
2022-05-09 16:05:40 +00:00
else
begin
2022-05-11 06:25:40 +00:00
cnt=0;
2022-05-09 16:05:40 +00:00
if(in)
state=s2;
else
state=s0;
end
2022-05-11 06:25:40 +00:00
end
2022-05-09 16:05:40 +00:00
s2:
begin
out=1;
2022-05-11 06:25:40 +00:00
cnt=0;
if(!in)
state=s3;
2022-05-09 16:05:40 +00:00
end
s3:
2022-05-11 06:25:40 +00:00
begin
out=1;
2022-05-09 16:05:40 +00:00
if(cnt<TARGET)
2022-05-11 06:25:40 +00:00
begin
state=s3;
2022-05-09 16:05:40 +00:00
cnt=cnt+1;
2022-05-11 06:25:40 +00:00
end
2022-05-09 16:05:40 +00:00
else
begin
2022-05-11 06:25:40 +00:00
cnt=0;
2022-05-09 16:05:40 +00:00
if(in)
state=s2;
else
state=s0;
end
2022-05-11 06:25:40 +00:00
end
default:
begin
state=s0;
out=0;
cnt=0;
end
2022-05-09 16:05:40 +00:00
endcase
endmodule