I am writing Verilog code to convert 8 bit pixels into half tone pixels using Floyd-Stiengburg algorithm. Below is the code to convert 6 pixels (8 bit) to half tone pixels. I have complied this code successfully on Modelsim, but on simulation, the output (half tone pixel value) is XXXXXX (undefined).
module half_tone(pixel,htpv);
input [0:47]pixel;
output reg [1:6]htpv;
reg [8:1]error[1:6];
reg [8:1]pixel_1;
reg [9:0]cpv,cpv_round,e_av;
parameter threshold =128;
integer i=1;
initial
begin
error[0]=8'b00;
for(i=0;i<6;i=i+1)
begin
e_av=(2*error[i])>>4;
cpv=pixel[(i*8)+:8]+e_av;
cpv_round=(cpv<threshold)?0:255;
htpv[i]=(cpv_round==0)?0:1;
error[i]=cpv-cpv_round;
#10;
end
end
endmodule
I am unable to sort out why the output is XXXXXX(undefined).
When I compiled your code with the Incisive simulator, I got this warning message:
You need to initialize
errorproperly. Maybeerror[1]=8'b00;?