|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?注册
x
module OutMod(
rst,
clk,
clkp,
clkv,
clkh,
Din,
max,
switch,
Dclk,
Dout
);
input rst;
input clk;
input clkp;
input clkv;
input clkh;
input max;
input switch;
input[7:0] Din;
output Dclk;
output[8:0] Dout;
reg[8:0] Dout;
reg[2:0] OutOrder;
reg copy_v;
reg copy_h;
reg hen;
reg Yen;
reg frame_logo;
reg time_en;
reg[1:0] outByte;
reg AnalysisEnd;
reg[8:0] y_Num;
reg[9:0] x_Num;
reg Byte_add;
reg[8:0] yBuf;
reg[9:0] xBufA;
reg[9:0] xBufB;
reg[9:0] y_out;
reg[9:0] x_out;
reg[7:0] max_Dbuf;
wire Den_value;
wire Add_en;
wire Dclk;
wire en_v;
wire en_h;
wire max_begin;
wire[10:0] BxNum_sum;
wire[10:0] ABNum_sum;
parameter YUYV = 1'b0;
parameter S0 = 3'b000, S1 = 3'b001, S2 = 3'b010, S3 = 3'b011, S4 = 3'b100 ;
parameter SS0 = 2'b00, SS1 = 2'b01, SS2 = 2'b10, SS3 = 2'b11;
assign Add_en = !Byte_add & y_Num[5];
assign en_v = !copy_v & clkv;
assign en_h = !copy_h & clkh;
assign Dclk = Byte_add;
assign Den_value = ((x_Num[9:6] == 1'b0)||(x_Num[9:6] == 4'b1001))? 1'b0 : 1'b1;
assign max_begin = (Din >= max_Dbuf)? 1'b1 : 1'b0;
assign BxNum_sum = xBufB + x_Num;
assign ABNum_sum = xBufA + xBufB;
always @(posedge clkp) begin
if(rst == 1'b0) begin
OutOrder <= 1'b0; //
frame_logo <= 1'b0;
end
else begin
copy_v <= clkv;
if(en_v == 1'b1) begin
frame_logo <= !frame_logo;
if((OutOrder[2] == 1'b1)||(switch == 1'b0))
OutOrder <= 1'b0;
else
OutOrder <= OutOrder + 1'b1;
end
end
end
always @(posedge clkp) begin
if(clkv == 1'b0) begin
y_Num <= 1'b0;
end
else begin
copy_h <= clkh;
if(en_h == 1'b1)
y_Num <= y_Num + 1'b1;
end
if(clkh == 1'b0) begin
x_Num <= 1'b0;
Yen <= 1'b0;
end
else begin
Yen <= !Yen;
if(Yen == YUYV)
x_Num <= x_Num + 1'b1;
end
end
reg[7:0] Reference;
always @(posedge clkp) begin
if(clkh == 1'b0) begin
max_Dbuf <= 1'b0;
if(switch == 1'b0)
Reference <= max_Dbuf[7:1] + max_Dbuf[7:2]; // Refernce is 3/4 of max_Dbuf
end
else begin
if(Den_value == 1'b1) begin
if(max_begin == 1'b1)
max_Dbuf <= Din;
end
end
end
reg[1:0] CoordNum;
reg[1:0] famerNum;
reg two_en;
reg AorB;
always @(posedge clkp) begin
if(en_h == 1'b1) begin
CoordNum <= 1'b0;
famerNum <= CoordNum;
if((famerNum != CoordNum)&&(famerNum[0] != 1'b1))
yBuf <= y_Num;
if(two_en== 1'b0)
two_en <= famerNum[1];
else
two_en <= |famerNum;
end
else if(AnalysisEnd == 1'b0) begin
if(max == 1'b1) begin
CoordNum <= CoordNum + !CoordNum[1];
if(CoordNum == 1'b0) begin
if(famerNum == 1'b0) begin // coordinate of the first appear point
xBufA <= x_Num;
AorB <= 1'b1;
end
else if({famerNum[1],two_en} == 2'b10) begin
if(xBufA >= BxNum_sum[10:1]) begin // Coordinates exchange
xBufA <= x_Num;
xBufB <= xBufA;
AorB <= 1'b0;
end
end
////////////////////////////////////////////////////////// the up Part is to determine A/B
else if(two_en == 1'b1)begin // coordinate of the first disappeared point
if(x_Num <= ABNum_sum[10:1]) begin
xBufA <= x_Num;
AorB <= 1'b0;
end
else begin
xBufB <= x_Num;
AorB <= 1'b1;
end
end
end
else if({famerNum[1],two_en} != 2'b10) //
xBufB <= x_Num;
end
end
end
always @(posedge clkp) begin
if(clkv == 1'b0) begin
AnalysisEnd <= 1'b0;
if(AnalysisEnd != 1'b0) begin
if(OutOrder == 1'b0) begin
x_out <= max_Dbuf;
y_out <= {frame_logo, max_Dbuf};
end
else begin
x_out <= (OutOrder[0] == 1'b1) ? xBufA : xBufB;
y_out <= (AorB == 1'b1) ? {frame_logo, yBuf} : {frame_logo, y_Num};
end
end
end
else if({en_h,AnalysisEnd} == 2'b10) begin
if(OutOrder != 1'b0) begin
if(OutOrder[1] != OutOrder[0])
AnalysisEnd <= CoordNum[1] & famerNum[1];
else if({two_en,CoordNum} == 3'b100)
AnalysisEnd <= 1'b1;
end
end
end
always @(posedge clkp) begin
if(clkv == 1'b0) begin
outByte <= 1'b0;
end
else begin
Byte_add <= y_Num[5];
if(Add_en == 1'b1) begin
if(outByte == 2'b11)
time_en <= 1'b0;
else begin
time_en <= 1'b1;
outByte <= outByte + 1'b1;
end
end
end
end
always @(posedge clkp) begin
if(Add_en == 1'b1) begin
case(outByte)
SS0 : if(OutOrder == S1)
Dout <= {y_out[9],8'hff};
else
Dout <= {y_out[9],6'b0, x_out[9:8]};
SS1 : if(OutOrder == S1)
Dout <= {y_out[9],8'hff};
else
Dout <= {y_out[9],x_out[7:0]};
SS2 : Dout <= {y_out[9],7'b0, y_out[8]};
SS3 : Dout <= {y_out[9],y_out[7:0]};
default : ;
endcase
end
end
endmodule |
|