2022-05-17 13:33:03 +00:00
|
|
|
module jyh_4490_7_is(f2,f1,f0,clk,p,sta);
|
|
|
|
input p,sta,f0,clk;
|
|
|
|
output reg f2,f1;
|
|
|
|
|
|
|
|
reg flag,flag2;//counter enable flag
|
|
|
|
parameter TARGET=15000; //0.3ms
|
|
|
|
parameter TARGET2=5000; //0.1ms
|
|
|
|
reg [13:0] count;//2^14=16384
|
|
|
|
reg [14:0] count2;//2^15=32768
|
|
|
|
reg negf0; //whether f0 enter low level
|
|
|
|
initial begin
|
|
|
|
flag=0;
|
|
|
|
flag2=0;
|
|
|
|
count=0;
|
|
|
|
negf0=0;
|
|
|
|
end
|
|
|
|
|
|
|
|
always@(posedge clk)
|
|
|
|
begin
|
|
|
|
if(!f0)
|
|
|
|
negf0<=1;
|
|
|
|
if(f0&&negf0)
|
|
|
|
begin
|
|
|
|
negf0<=0;
|
|
|
|
flag<=1;
|
|
|
|
flag2<=1;
|
|
|
|
f1<=1;
|
|
|
|
f2<=1;
|
|
|
|
end
|
|
|
|
else
|
|
|
|
begin
|
|
|
|
//xinchong
|
|
|
|
if(count>=TARGET)
|
|
|
|
begin
|
|
|
|
flag<=0;
|
|
|
|
f1<=0;
|
|
|
|
end
|
|
|
|
|
|
|
|
//shaochong
|
|
|
|
if(p)
|
2022-05-17 14:01:44 +00:00
|
|
|
begin
|
2022-05-17 13:33:03 +00:00
|
|
|
if(sta)
|
|
|
|
begin
|
2022-05-17 14:01:44 +00:00
|
|
|
if(count2>=5*TARGET2)
|
2022-05-17 13:33:03 +00:00
|
|
|
begin
|
|
|
|
f2<=0;
|
|
|
|
flag2<=0;
|
|
|
|
//end of a circle
|
|
|
|
end
|
2022-05-17 14:01:44 +00:00
|
|
|
else if(count2>=4*TARGET2)
|
|
|
|
f2<=1;
|
|
|
|
else if(count2>=3*TARGET2)
|
|
|
|
f2<=0;
|
|
|
|
else if(count2>=2*TARGET2)
|
2022-05-17 13:33:03 +00:00
|
|
|
f2<=1;
|
2022-05-17 14:01:44 +00:00
|
|
|
else if(count2>=TARGET2)
|
|
|
|
f2<=0;
|
2022-05-17 13:33:03 +00:00
|
|
|
end
|
2022-05-17 14:01:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
else if(count>=3*TARGET2)
|
2022-05-17 13:33:03 +00:00
|
|
|
begin
|
|
|
|
f2<=0;
|
2022-05-17 14:01:44 +00:00
|
|
|
flag2<=0;
|
|
|
|
//end of a circle
|
2022-05-17 13:33:03 +00:00
|
|
|
end
|
|
|
|
else if(count>=2*TARGET2)
|
|
|
|
f2<=1;
|
|
|
|
else if(count>=TARGET2)
|
|
|
|
f2<=0;
|
2022-05-17 14:01:44 +00:00
|
|
|
end
|
2022-05-17 13:33:03 +00:00
|
|
|
else
|
|
|
|
f2<=f1;
|
|
|
|
|
|
|
|
|
|
|
|
//whether to add counter
|
|
|
|
if(flag)
|
|
|
|
count<=count+1;
|
|
|
|
else
|
|
|
|
count<=0;
|
2022-05-17 14:01:44 +00:00
|
|
|
|
2022-05-17 13:33:03 +00:00
|
|
|
if(flag2)
|
2022-05-17 14:01:44 +00:00
|
|
|
count2<=count2+1;
|
2022-05-17 13:33:03 +00:00
|
|
|
else
|
|
|
|
count2<=0;
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
endmodule
|