Index: trunk/MultiChannelUSB/Paella.v
===================================================================
--- trunk/MultiChannelUSB/Paella.v	(revision 161)
+++ trunk/MultiChannelUSB/Paella.v	(revision 162)
@@ -116,11 +116,11 @@
 	wire	[4*12-1:0]	int_mux_data [N-1:0];
 
-	wire	[1:0]	amp_flag [2*N-1:0];
-	wire	[11:0]	amp_data [2*N-1:0];
-
-	wire	[1:0]	amp_mux_flag [1:0];
-	wire	[11:0]	amp_mux_data [1:0];
-
-	wire			cnt_good [N-1:0];
+	wire	[1:0]	amp_flag [3*N-1:0];
+	wire	[11:0]	amp_data [3*N-1:0];
+
+	wire	[1:0]	amp_mux_flag [2:0];
+	wire	[11:0]	amp_mux_data [2:0];
+
+	wire			cnt_good [3:0];
 	wire	[15:0]	cnt_bits_wire;
 
@@ -228,8 +228,8 @@
 		.lpm_width(14),
 		.lpm_widths(2)) amp_mux_unit_1 (
-		.sel(cfg_bits[8][1:0]),
+		.sel(cfg_bits[6][1:0]),
 		.data({
-			{amp_flag[4], amp_data[4]},
 			{amp_flag[2], amp_data[2]},
+			{amp_flag[1], amp_data[1]},
 			{amp_flag[0], amp_data[0]}}),
 		.result({amp_mux_flag[0], amp_mux_data[0]}));
@@ -240,10 +240,22 @@
 		.lpm_width(14),
 		.lpm_widths(2)) amp_mux_unit_2 (
-		.sel(cfg_bits[8][5:4]),
+		.sel(cfg_bits[6][5:4]),
 		.data({
 			{amp_flag[5], amp_data[5]},
-			{amp_flag[3], amp_data[3]},
-			{amp_flag[1], amp_data[1]}}),
+			{amp_flag[4], amp_data[4]},
+			{amp_flag[3], amp_data[3]}}),
 		.result({amp_mux_flag[1], amp_mux_data[1]}));
+
+	lpm_mux #(
+		.lpm_size(3),
+		.lpm_type("LPM_MUX"),
+		.lpm_width(14),
+		.lpm_widths(2)) amp_mux_unit_3 (
+		.sel(cfg_bits[6][9:8]),
+		.data({
+			{amp_flag[8], amp_data[8]},
+			{amp_flag[7], amp_data[7]},
+			{amp_flag[6], amp_data[6]}}),
+		.result({amp_mux_flag[2], amp_mux_data[2]}));
 
 	generate
@@ -329,9 +341,9 @@
 				.frame(sys_frame),
 				.reset(1'b0),
-				.cfg_data(cfg_bits[6][11:0]),
+				.cfg_data(cfg_bits[7][11:0]),
 //				.cfg_data(cfg_bits[6+2*j][11:0]),
 				.inp_data(clp_data[j]),
-				.out_flag(amp_flag[0+2*j]),
-				.out_data(amp_data[0+2*j]));
+				.out_flag(amp_flag[0+j]),
+				.out_data(amp_data[0+j]));
 
 			amplitude #(.width(12)) amplitude_unit_2 (
@@ -339,14 +351,24 @@
 				.frame(sys_frame),
 				.reset(1'b0),
-				.cfg_data(cfg_bits[7][11:0]),
+				.cfg_data(cfg_bits[8][11:0]),
 //				.cfg_data(cfg_bits[7+2*j][11:0]),
 				.inp_data(clp_data[j]),
-				.out_flag(amp_flag[1+2*j]),
-				.out_data(amp_data[1+2*j]));
+				.out_flag(amp_flag[3+j]),
+				.out_data(amp_data[3+j]));
+
+			amplitude #(.width(12)) amplitude_unit_3 (
+				.clock(sys_clock),
+				.frame(sys_frame),
+				.reset(1'b0),
+				.cfg_data(cfg_bits[9][11:0]),
+//				.cfg_data(cfg_bits[7+2*j][11:0]),
+				.inp_data(clp_data[j]),
+				.out_flag(amp_flag[6+j]),
+				.out_data(amp_data[6+j]));
 
 		end
 	endgenerate
 
-	histogram32 histogram32_unit (
+	histogram32 histogram32_unit_1 (
 		.clock(sys_clock),
 		.frame(sys_frame),
@@ -361,5 +383,5 @@
 		.bus_busy(bus_busy[2]));
 
-	counter hst_counter_unit (
+	counter hst_counter_unit_1 (
 		.clock(sys_clock),
 		.frame((sys_frame) & (~amp_mux_flag[0][1])),
@@ -376,9 +398,37 @@
 		.cnt_good(cnt_good[0]));
 
+	histogram32 histogram32_unit_2 (
+		.clock(sys_clock),
+		.frame(sys_frame),
+		.reset(cfg_bits[0][5]),
+		.hst_good((amp_mux_flag[0][0]) & (cnt_good[1]) & (cfg_bits[14][1])),
+		.hst_data(amp_mux_data[0]),
+		.bus_ssel(bus_ssel[3]),
+		.bus_wren(bus_wren),
+		.bus_addr(bus_addr[12:0]),
+		.bus_mosi(bus_mosi),
+		.bus_miso(bus_miso[3]),
+		.bus_busy(bus_busy[3]));
+
+	counter hst_counter_unit_2 (
+		.clock(sys_clock),
+		.frame((sys_frame) & (~amp_mux_flag[0][1])),
+//		.frame(sys_frame),
+		.reset(cfg_bits[0][8]),
+		.setup(cfg_bits[14][0]),
+		.count(cfg_bits[14][1]),
+		.bus_ssel(bus_ssel[6]),
+		.bus_wren(bus_wren),
+		.bus_addr(bus_addr[1:0]),
+		.bus_mosi(bus_mosi),
+		.bus_miso(bus_miso[6]),
+		.bus_busy(bus_busy[6]),
+		.cnt_good(cnt_good[1]));
+
 	histogram16 histogram16_unit (
 		.clock(sys_clock),
 		.frame(sys_frame),
 		.reset(cfg_bits[0][11]),
-		.hst_good((cnt_good[2]) & (~cnt_good[1])),
+		.hst_good((cnt_good[3]) & (~cnt_good[2])),
 		.hst_data(cnt_bits_wire),
 		.bus_ssel(bus_ssel[8]),
@@ -394,6 +444,6 @@
 //		.frame(sys_frame),
 		.reset(cfg_bits[0][12]),
-		.setup((sys_frame) & (~cnt_good[1])),
-		.count((cnt_good[2]) & (cfg_bits[16][1])),
+		.setup((sys_frame) & (~cnt_good[2])),
+		.count((cnt_good[3]) & (cfg_bits[16][1])),
 		.bus_ssel(bus_ssel[9]),
 		.bus_wren(bus_wren),
@@ -402,9 +452,9 @@
 		.bus_miso(bus_miso[9]),
 		.bus_busy(bus_busy[9]),
-		.cnt_good(cnt_good[1]));
+		.cnt_good(cnt_good[2]));
 
 	counter rmt_counter_2 (
 		.clock(sys_clock),
-		.frame((sys_frame) & (~cnt_good[1])),
+		.frame((sys_frame) & (~cnt_good[2])),
 		.reset(cfg_bits[0][13]),
 		.setup(cfg_bits[16][0]),
@@ -416,5 +466,5 @@
 		.bus_miso(bus_miso[10]),
 		.bus_busy(bus_busy[10]),
-		.cnt_good(cnt_good[2]));
+		.cnt_good(cnt_good[3]));
 
 	lpm_counter	#(
@@ -423,7 +473,7 @@
 		.lpm_type("LPM_COUNTER"),
 		.lpm_width(16)) lpm_counter_component (
-		.sclr(((sys_frame) & (cnt_good[2]) & (~cnt_good[1])) | (cfg_bits[0][11])),
-		.clock(sys_clock),
-		.cnt_en((sys_frame) & (amp_mux_flag[1][0]) & (cnt_good[1]) & (cnt_good[2]) & (cfg_bits[16][1])),
+		.sclr(((sys_frame) & (cnt_good[3]) & (~cnt_good[2])) | (cfg_bits[0][11])),
+		.clock(sys_clock),
+		.cnt_en((sys_frame) & (amp_mux_flag[1][0]) & (cnt_good[2]) & (cnt_good[3]) & (cfg_bits[16][1])),
 		.q(cnt_bits_wire));
 
