I am trying to write a verilog code to implement census transform on an image of 640X480 pixels.I wrote the complete code in behavioral form. But the code is taking too long to synthesize. I understand that the reason might be the long register arrays and loops but I am not sure how to handle that.
Here is my code:
module test(in,clk,out
);
input clk;
input [7:0] in;
output [119:0]out;
reg [7:0]matrix[0:639][0:479];
//reg [119:0]win[0:10][0:10];
reg [9:0] i = 0;
reg [8:0] j = 0;
reg [12:0] count = 0;
integer p,q = 6;
integer a,b = -6;
reg [119:0]censusTransformedImage;
reg [119:0]census=0;
always@ (posedge clk)
begin
if(count<=6411)
count = count+1;
end
always @ (posedge clk )
begin
if(i<=639)
begin
matrix[i][j]=in;
i=i+1;
end
else if(i==639 && j<=479)
begin
i=0;
j=j+1;
end
//end
end
always @ (posedge clk)
begin
if(count > 6411)
begin
if(p<=634)
begin
if(q<=479)
begin
//census = 0;
if(a<=6)
begin
if(b<=6)
begin
if(~(a==0 && b==0))
census=census<<1;
if (matrix[p+a][q+b] > matrix[p][q])
census=census+1;
b = b+1;
end
else
begin
b=-6;
a=a+1;
end
end
else
begin
censusTransformedImage=census;
census=0;
a=-6;
q=q+1;
end
end
else
begin
q=0;
p=p+1;
end
end
end
end
assign out = censusTransformedImage;
endmodule