Index: trunk/3DEES/Paella.v
===================================================================
--- trunk/3DEES/Paella.v	(revision 177)
+++ trunk/3DEES/Paella.v	(revision 178)
@@ -34,5 +34,5 @@
 	);
 
-	localparam	N		=	12;
+	localparam	N		=	6;
 
 	//	Turn output ports off
@@ -83,4 +83,12 @@
 	);
 		
+/*
+	reg		[31:0]	led_counter;
+	always @(posedge CLK_50MHz)
+	begin
+		led_counter = led_counter + 32'd1;
+	end
+	assign LED = led_counter[28];
+*/	
 	wire	[11:0]	osc_mux_data [4:0];
 
@@ -88,13 +96,13 @@
 	wire			trg_flag;
 
-	wire	[2:0]	coi_data;
-	wire			coi_flag;
-
 	wire	[4*12-1:0]	int_mux_data [N-1:0];
 
-	wire			amp_flag [N-1:0];
-	wire	[11:0]	amp_data [N-1:0];
-
-	wire			cnt_good [N-1:0];
+	wire	[1:0]	amp_flag [3*N-1:0];
+	wire	[12: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;
 
@@ -105,14 +113,23 @@
 	wire	[11:0]	tst_data;
 
-    wire	[11:0]	cmp_data;
-    wire	[11:0]	del_data;
-
-	wire	[20:0]	cic_data [N-1:0];
+    wire	[3:0]	cmp_data;
+    wire	[1:0]	del_data;
+
+	wire	[19:0]	cic_data [N-1:0];
 
 	wire	[11:0]	dec_data [N-1:0];
-	wire	[11:0]	clp_data [N-1:0];
-	wire	[11:0]	tmp_data [1:0];
+	wire	[12:0]	clp_data [N-1:0];
+	wire	[11:0]	tmp_data;
+
 
 	wire			i2c_reset;
+
+	assign	tmp_data	=	12'h000;
+	assign	sys_clock	=	CLK_100MHz;
+/*
+	sys_pll sys_pll_unit(
+		.inclk0(CLK_100MHz),
+		.c0(sys_clock));
+*/
 /*
 	sys_pll sys_pll_unit(
@@ -124,36 +141,22 @@
 	wire			ADC_DCO, ADC_FCO;
 
+
 	test test_unit(
 		.clock(ADC_FCO),
 		.data(tst_data));
+*/
 
 	adc_lvds #(
-		.size(3),
+		.size(6),
 		.width(12)) adc_lvds_unit (
 		.clock(sys_clock),
 		.lvds_dco(ADC_DCO),
 		.lvds_fco(ADC_FCO),
-		.lvds_d(36'd0),
-		.test(tst_data),
-		.trig(12'd0),
-		.adc_frame(sys_frame),
-		.adc_data({cmp_data, adc_data[2], adc_data[1], adc_data[0]}));
-*/
-	sys_pll sys_pll_unit(
-		.inclk0(CLK_100MHz),
-		.c0(sys_clock));
-
-	adc_lvds #(
-		.size(6),
-		.width(24)) adc_lvds_unit (
-		.clock(sys_clock),
-		.lvds_dco(ADC_DCO),
-		.lvds_fco(ADC_FCO),
-		.lvds_d({ADC_D[5], ADC_D[4], ADC_D[3], ADC_D[2], ADC_D[1], ADC_D[0]}),
+		.lvds_d(ADC_D),
+//		.test(tst_data),
 		.adc_frame(sys_frame),
 		.adc_data({
-			adc_data[11], adc_data[10], adc_data[9], adc_data[8],
-			adc_data[7], adc_data[6], adc_data[5], adc_data[4],
-			adc_data[3], adc_data[2], adc_data[1], adc_data[0]}));
+			adc_data[5], adc_data[4], adc_data[3],
+			adc_data[2], adc_data[1], adc_data[0]}));
 
 	wire	[15:0]		cfg_bits [63:0];
@@ -174,5 +177,5 @@
 	wire 			mrg_bus_busy;
 
-	wire 	[12*16-1:0]	int_bus_miso;
+	wire 	[11*16-1:0]	int_bus_miso;
 
 	genvar j;
@@ -197,10 +200,10 @@
 
 	generate
-		for (j = 0; j < 12; j = j + 1)
+		for (j = 0; j < 6; j = j + 1)
 		begin : MUX_DATA
 			assign int_mux_data[j] = {
-				amp_data[j],
-				clp_data[j],
-				cic_data[j][19:8],
+				{4'd0, amp_flag[j][0], 7'd0},
+				amp_data[j][11:0],
+				clp_data[j][11:0],
 				sys_data[j]};
 		end
@@ -210,13 +213,12 @@
 
 	lpm_mux #(
-		.lpm_size(4*12),
+		.lpm_size(4*6),
 		.lpm_type("LPM_MUX"),
 		.lpm_width(12),
-		.lpm_widths(6)) trg_mux_unit (
-		.sel(cfg_bits[4][13:8]),
+		.lpm_widths(5)) trg_mux_unit (
+		.sel(cfg_bits[4][12:8]),
 		.data({
-			int_mux_data[11], int_mux_data[10], int_mux_data[9], int_mux_data[8],
-			int_mux_data[7], int_mux_data[6], int_mux_data[5], int_mux_data[4],
-			int_mux_data[3], int_mux_data[2], int_mux_data[1], int_mux_data[0]}),
+			int_mux_data[5], int_mux_data[4], int_mux_data[3],
+			int_mux_data[2], int_mux_data[1], int_mux_data[0]}),
 		.result(trg_mux_data));
 
@@ -226,13 +228,12 @@
 		
 			lpm_mux #(
-				.lpm_size(4*12),
+				.lpm_size(4*6),
 				.lpm_type("LPM_MUX"),
 				.lpm_width(12),
-				.lpm_widths(6)) osc_mux_unit (
-				.sel(cfg_mux_selector[j*8+5:j*8]),
+				.lpm_widths(5)) osc_mux_unit (
+				.sel(cfg_mux_selector[j*8+4:j*8]),
 				.data({
-					int_mux_data[11], int_mux_data[10], int_mux_data[9], int_mux_data[8],
-					int_mux_data[7], int_mux_data[6], int_mux_data[5], int_mux_data[4],
-					int_mux_data[3], int_mux_data[2], int_mux_data[1], int_mux_data[0]}),
+					int_mux_data[5], int_mux_data[4], int_mux_data[3],
+					int_mux_data[2], int_mux_data[1], int_mux_data[0]}),
 				.result(osc_mux_data[j]));
 		end
@@ -264,53 +265,66 @@
 		.bus_busy(bus_busy[1]));
 
-	new_filter #(.size(12), .width(12)) filter_unit (
+	filter #(.size(6), .width(12)) filter_unit (
 		.clock(sys_clock),
 		.frame(sys_frame),
 		.reset(1'b0),
-		.inp_data({
-			sys_data[11], sys_data[10], sys_data[9], sys_data[08],
-			sys_data[7], sys_data[6], sys_data[5], sys_data[4],
-			sys_data[3], sys_data[2], sys_data[1], sys_data[0]}),
-		.out_data({
-			cic_data[11], cic_data[10], cic_data[9], cic_data[8],
-			cic_data[7], cic_data[6], cic_data[5], cic_data[4],
-			cic_data[3], cic_data[2], cic_data[1], cic_data[0]}));
-
-	generate
-		for (j = 0; j < 3; j = j + 1)
+		.inp_data({sys_data[5], sys_data[4], sys_data[3],
+			sys_data[2], sys_data[1], sys_data[0]}),
+		.out_data({cic_data[5], cic_data[4], cic_data[3],
+			cic_data[2], cic_data[1], cic_data[0]}));
+/*  
+  new_filter #(.size(6), .width(12)) filter_unit (
+		.clock(sys_clock),
+		.frame(sys_frame),
+		.reset(1'b0),
+		.inp_data({sys_data[5], sys_data[4], sys_data[3],
+			sys_data[2], sys_data[1], sys_data[0]}),
+		.out_data({cic_data[5], cic_data[4], cic_data[3],
+			cic_data[2], cic_data[1], cic_data[0]}));
+*/
+
+	generate
+		for (j = 0; j < 2; j = j + 1)
 		begin : DECONV_CHAIN
 
-			clip #(.shift(22), .width(20), .widthr(12)) clip_unit (
+			clip #(.shift(22), .width(19), .widthr(12)) clip_unit (
 				.clock(sys_clock),
 				.frame(sys_frame),
 				.reset(1'b0),
-//				.del_data({6'd14, 6'd14, 6'd14, 6'd14}),
-				.del_data({cfg_bits[39+8*j][5:0], cfg_bits[37+8*j][5:0], cfg_bits[35+8*j][5:0], cfg_bits[33+8*j][5:0]}),
-				.amp_data({6'd17, 6'd17, 6'd17, 6'd17}),
-//				.tau_data({16'd17193, 16'd17193, 16'd17193, 16'd17193}), /* exp(-14/1125)*1024*17 */
-				.tau_data({cfg_bits[38+8*j], cfg_bits[36+8*j], cfg_bits[34+8*j], cfg_bits[32+8*j]}),
+				.del_data({6'd0, 6'd32, 6'd32, 6'd32}),
+//				.del_data({6'd0, cfg_bits[37+6*j][5:0], cfg_bits[35+6*j][5:0], cfg_bits[33+6*j][5:0]}),
+				.amp_data({6'd0, 6'd20, 6'd20, 6'd20}),
+				.tau_data({16'd0, 16'd19835, 16'd19835, 16'd19835}),
+// exp(-32/1000)*1024*20
+//				.tau_data({16'd0, cfg_bits[36+6*j], cfg_bits[34+6*j], cfg_bits[32+6*j]}),
 				.inp_data({
-					cic_data[j*4+3][19:0], cic_data[j*4+2][19:0],
-					cic_data[j*4+1][19:0], cic_data[j*4+0][19:0]}),
+					19'd0, cic_data[j*3+2][18:0], cic_data[j*3+1][18:0], cic_data[j*3+0][18:0]}),
 				.out_data({
-					clp_data[j*4+3], clp_data[j*4+2], 
-					clp_data[j*4+1], clp_data[j*4+0]}));
-
-		end
-	endgenerate
-
-	generate
-		for (j = 0; j < 12; j = j + 1)
+					tmp_data, clp_data[j*3+2], clp_data[j*3+1], clp_data[j*3+0]}));
+
+		end
+	endgenerate
+
+	generate
+		for (j = 0; j < 6; j = j + 1)
 		begin : MCA_CHAIN
-
-			assign sys_data[j] = (cfg_bits[1][j]) ? (adc_data[j] ^ 12'hfff) : (adc_data[j]);
-
-			amplitude #(.width(12)) amplitude_unit_2 (
+/*
+			shift #(.shift(11), .width(19), .widthr(13)) shift_unit (
 				.clock(sys_clock),
 				.frame(sys_frame),
 				.reset(1'b0),
-				.cfg_data({1'b0, 12'd0, 12'd5}),
-//				.cfg_data({cfg_bits[7+2*j][12:0], cfg_bits[6+2*j][11:0]}),
-//				.inp_data(dec_data[j]),
+				.amp_data(6'd21),
+				.inp_data(cic_data[j][18:0]),
+				.out_data(clp_data[j]));    
+*/
+			assign sys_data[j] = (cfg_bits[1][j]) ? (adc_data[j] ^ 12'hfff) : (adc_data[j]);
+
+			amplitude #(.width(13)) amplitude_unit (
+				.clock(sys_clock),
+				.frame(sys_frame),
+				.reset(1'b0),
+				.min_data({1'b0, cfg_bits[7][11:0]}),
+				.max_data(13'd4095),
+//				.cfg_data(cfg_bits[6+2*j][11:0]),
 				.inp_data(clp_data[j]),
 				.out_flag(amp_flag[j]),
@@ -323,10 +337,6 @@
 		.frame(sys_frame),
 		.reset(cfg_bits[0][5]),
-		.hst_good((amp_flag[0]) & (cnt_good[0]) & (cfg_bits[13][1])),
+		.hst_good((amp_flag[0][1]) & (cnt_good[0]) & (cfg_bits[13][1])),
 		.hst_data(amp_data[0]),
-/*
-		.hst_good((amp_flag[j]) & (cnt_good[j]) & (cfg_bits[13][1])),
-		.hst_data(amp_data[j]),
-*/
 		.bus_ssel(bus_ssel[2]),
 		.bus_wren(bus_wren),
@@ -338,6 +348,6 @@
 	counter hst_counter_unit (
 		.clock(sys_clock),
-//		.frame((sys_frame) & (~ana_dead[0])),
-		.frame(sys_frame),
+		.frame((sys_frame) & (~amp_flag[0][1])),
+//		.frame(sys_frame),
 		.reset(cfg_bits[0][8]),
 		.setup(cfg_bits[13][0]),
@@ -395,5 +405,5 @@
 
 	lpm_mux #(
-		.lpm_size(12),
+		.lpm_size(11),
 		.lpm_type("LPM_MUX"),
 		.lpm_width(16),
