Index: trunk/3DEES/classifier.v
===================================================================
--- trunk/3DEES/classifier.v	(revision 183)
+++ trunk/3DEES/classifier.v	(revision 184)
@@ -5,13 +5,13 @@
 	(
 		input	wire					clock, frame, reset,
-		input	wire	[14*width-1:0]	cfg_data,
+		input	wire	[18*width-1:0]	cfg_data,
 		input	wire	[6*width-1:0]	inp_data, // {D3, D2, D1, S2, S1_S, S1_F}
 		input	wire	[5:0]			inp_flag,
-		output	wire	[5:0]			out_data,
+		output	wire	[6:0]			out_data,
 		output	wire					out_flag
 	);
 
 	reg					out_flag_reg [2:0], out_flag_next [2:0];
-	reg		[5:0]		out_data_reg [2:0], out_data_next [2:0];
+	reg		[6:0]		out_data_reg [2:0], out_data_next [2:0];
 	reg		[5:0]		inp_flag_reg, inp_flag_next;
 	reg		[width-1:0]	inp_data_reg [5:0], inp_data_next [5:0];
@@ -22,5 +22,5 @@
 	wire	[width-1:0]	inp_data_wire [5:0];
 	wire	[3:0]		int_pipe_wire [5:0];
-	wire	[13:0]		int_comp_wire;
+	wire	[15:0]		int_comp_wire;
 
 	integer i;
@@ -35,11 +35,15 @@
 
 	generate
-		assign int_comp_wire[0] = (inp_data_reg[0] > cfg_data[width-1:0]);
-		assign int_comp_wire[1] = (inp_data_reg[1] > cfg_data[2*width-1:width]);
+		assign int_comp_wire[0] = inp_flag_reg[0] & (inp_data_reg[0] < cfg_data[width-1:0]);
+		assign int_comp_wire[1] = inp_flag_reg[0] & (inp_data_reg[0] > cfg_data[2*width-1:1*width]) & (inp_data_reg[0] < cfg_data[3*width-1:2*width]);
+
+		assign int_comp_wire[2] = inp_flag_reg[1] & (inp_data_reg[1] < cfg_data[4*width-1:3*width]);
+		assign int_comp_wire[3] = inp_flag_reg[1] & (inp_data_reg[1] > cfg_data[5*width-1:4*width]) & (inp_data_reg[1] < cfg_data[6*width-1:5*width]);
+
 		for (j = 0; j < 4; j = j + 1)
 		begin : CLASSIFIER_COMPARTORS
-			assign int_comp_wire[j*3+0+2] = (inp_data_reg[j+2] > cfg_data[(j*3+0+2)*width+width-1:(j*3+0+2)*width]);
-			assign int_comp_wire[j*3+1+2] = (inp_data_reg[j+2] > cfg_data[(j*3+1+2)*width+width-1:(j*3+1+2)*width]);
-			assign int_comp_wire[j*3+2+2] = (inp_data_reg[j+2] > cfg_data[(j*3+2+2)*width+width-1:(j*3+2+2)*width]);
+			assign int_comp_wire[j*3+0+4] = (inp_data_reg[j+2] > cfg_data[(j*3+0+6)*width+width-1:(j*3+0+6)*width]);
+			assign int_comp_wire[j*3+1+4] = (inp_data_reg[j+2] > cfg_data[(j*3+1+6)*width+width-1:(j*3+1+6)*width]);
+			assign int_comp_wire[j*3+2+4] = (inp_data_reg[j+2] > cfg_data[(j*3+2+6)*width+width-1:(j*3+2+6)*width]);
 		end
 	endgenerate
@@ -168,7 +172,9 @@
 				out_flag_next[2] = out_flag_reg[1] & (out_data_reg[1] > out_data_reg[0]);
 
-				int_pipe_next[0] = {int_pipe_reg[0][14:0], int_comp_wire[0]};
-				int_pipe_next[1] = {int_pipe_reg[1][14:0], int_comp_wire[1]};
-				for (i = 2; i < 8; i = i + 1)
+				for (i = 0; i < 4; i = i + 1)
+				begin
+					int_pipe_next[i] = {int_pipe_reg[i][14:0], int_comp_wire[i]};
+				end
+				for (i = 4; i < 8; i = i + 1)
 				begin
 					int_pipe_next[i] = {int_pipe_reg[i][14:0], inp_flag_reg[i-2]};
@@ -176,5 +182,5 @@
 				for (i = 8; i < 20; i = i + 1)
 				begin
-					int_pipe_next[i] = {int_pipe_reg[i][14:0], int_comp_wire[i-6]};
+					int_pipe_next[i] = {int_pipe_reg[i][14:0], int_comp_wire[i-4]};
 				end
 
@@ -182,20 +188,20 @@
 				begin
 					case (int_pipe_wire[i+2][2:0])
-						3'b000: int_data_next[i] = 2'd0;
-						3'b001: int_data_next[i] = 2'd1;
-						3'b011: int_data_next[i] = 2'd2;
-						3'b111: int_data_next[i] = 2'd3;
+						3'b000: int_data_next[i] = 2'b00;
+						3'b001: int_data_next[i] = 2'b01;
+						3'b011: int_data_next[i] = 2'b10;
+						3'b111: int_data_next[i] = 2'b11;
 						default: int_data_next[i] = 2'd0;
 					endcase
 				end
 
-				int_temp_next[0] = {int_pipe_wire[1], int_pipe_wire[0][3]^int_pipe_wire[0][2]};
+				int_temp_next[0] = {int_pipe_wire[1], ^int_pipe_wire[0]};
 				int_temp_next[1] = {1'b0, int_pipe_wire[0]};
 
 				case (int_temp_reg[0][4:0])
-					5'b00011: out_data_next[0][3:0] = {2'd0, int_data_next[0]};
-					5'b00111: out_data_next[0][3:0] = {2'd1, int_data_next[1]};
-					5'b01111: out_data_next[0][3:0] = {2'd2, int_data_next[2]};
-					5'b11111: out_data_next[0][3:0] = {2'd3, int_data_next[3]};
+					5'b00011: out_data_next[0][3:0] = {2'b00, int_data_next[0]};
+					5'b00111: out_data_next[0][3:0] = {2'b01, int_data_next[1]};
+					5'b01111: out_data_next[0][3:0] = {2'b10, int_data_next[2]};
+					5'b11111: out_data_next[0][3:0] = {2'b11, int_data_next[3]};
 					default: out_flag_next[0] = 1'b0;
 				endcase
@@ -203,14 +209,14 @@
 				case (int_temp_reg[1][3:0])
 					// S1_F, electron
-					4'b0100: out_data_next[0][5:4] = 2'd0;
+					4'b0001: out_data_next[0][6:4] = 3'b100;
 
 					// S1_F, proton
-					4'b0101: out_data_next[0][5:4] = 2'd1;
+					4'b0010: out_data_next[0][6:4] = 3'b101;
 
 					// S1_S, electron
-					4'b1000: out_data_next[0][5:4] = 2'd2;
+					4'b0100: out_data_next[0][6:4] = 3'b110;
 
 					// S1_S, proton
-					4'b1010: out_data_next[0][5:4] = 2'd3;
+					4'b1000: out_data_next[0][6:4] = 3'b111;
 
 					default: out_flag_next[0] = 1'b0;
