Procházet zdrojové kódy

Merge branch 'fft_filter_coeffs_downloaded_from_mem' of ChStepan/S5244_FFT into master

ChStepan před 1 rokem
rodič
revize
0c0ed0aa41
42 změnil soubory, kde provedl 2983 přidání a 12861 odebrání
  1. 22 34
      src/constrs/S5243Top.xdc
  2. 3 3
      src/src/ExtDspInterface/DspInterface.v
  3. 49 12
      src/src/FftDataFiltering/DecimFilterWrapper.v
  4. 189 0
      src/src/FftDataFiltering/DecimFilterWrapperTest.v
  5. 63 41
      src/src/FftDataFiltering/RomCtrl.v
  6. 101 0
      src/src/FftDataFiltering/cicFilterTest.v
  7. 1 0
      src/src/FftDataFiltering/combFilterBlock.v
  8. 53 0
      src/src/InternalDsp/Description.txt
  9. 15 7
      src/src/InternalDsp/DspPipeline.v
  10. 85 0
      src/src/InternalDsp/GrDelModeMux.v
  11. 50 22
      src/src/InternalDsp/InternalDsp.v
  12. 7 4
      src/src/InternalDsp/MeasCtrlModule.v
  13. 0 1
      src/src/InternalDsp/Win_calc.v
  14. 6 0
      src/src/Math/Description.txt
  15. 27 2
      src/src/Math/SumAcc.v
  16. 3 3
      src/src/MeasDataFifo/OscDataFormer.v
  17. 20 0
      src/src/PulseMeas/Description.txt
  18. 1 1
      src/src/PulseMeas/PulseGen.v
  19. 340 0
      src/src/PulseMeas/PulseGenNew.v
  20. 3 3
      src/src/Sim/BitWidthCalc.m
  21. 59 0
      src/src/Sim/CicModel.asv
  22. 59 0
      src/src/Sim/CicModel.m
  23. 39 40
      src/src/Sim/CicTest.m
  24. 36 4
      src/src/Sim/CicTestMatlab.m
  25. 74 78
      src/src/Sim/DecimFilterWrapperTb.v
  26. 56 52
      src/src/Sim/FFTTest.m
  27. 250 4000
      src/src/Sim/FilteredData.txt
  28. 26 391
      src/src/Sim/FiltersCoeffs.coe
  29. 250 4000
      src/src/Sim/ImpResp.txt
  30. 500 4000
      src/src/Sim/InputSignal.txt
  31. 25 0
      src/src/Sim/R2.txt
  32. 25 64
      src/src/Sim/R2Test.fcf
  33. 64 0
      src/src/Sim/R4.txt
  34. 67 0
      src/src/Sim/R4Test.fcf
  35. 64 0
      src/src/Sim/R6.txt
  36. 67 0
      src/src/Sim/R6Test.fcf
  37. 64 0
      src/src/Sim/R7.txt
  38. 67 0
      src/src/Sim/R7Test.fcf
  39. 19 4
      src/src/Sim/firFilter/systolicFilter.v
  40. 13 49
      src/src/Sim/firFilter/systolicFilterBlock.v
  41. 69 0
      src/src/Sim/fir_filter7Test.coe
  42. 52 46
      src/src/Top/S5243Top.v

Rozdílová data souboru nebyla zobrazena, protože soubor je příliš velký
+ 22 - 34
src/constrs/S5243Top.xdc


+ 3 - 3
src/src/ExtDspInterface/DspInterface.v

@@ -115,8 +115,8 @@ module	DspInterface
 	wire	signed	[AdcDataWidth-1:0]	currDataChannelDecim;
 	wire	currDataChannelDecimVal;
 	
-	wire	signed	[15:0]	filteredDecimDataI;
-	wire	signed	[15:0]	filteredDecimDataQ;
+	wire	signed	[31:0]	filteredDecimDataI;
+	wire	signed	[31:0]	filteredDecimDataQ;
 	wire	filteredDecimDataVal;
 //================================================================================
 //	ASSIGNMENTS
@@ -229,7 +229,7 @@ DspSlaveSpi
 	.Miso_o		(Miso_o)
 );
 
-DecimFilterWrapper	DecimFilter
+DecimFilterWrapperTest	DecimFilter
 (
 	.Clk_i			(Clk_i),
 	.Rst_i			(Rst_i),

+ 49 - 12
src/src/FftDataFiltering/DecimFilterWrapper.v

@@ -59,7 +59,10 @@ module	DecimFilterWrapper
 	
 	wire	[39:0]	firData;
 	wire	firDataVal;
-	wire	bypassFlag = (DecimFactor_i==3'd0 | DecimFactor_i==3'd1);
+	// wire	bypassFlag = (DecimFactor_i==3'd0 | DecimFactor_i==3'd1);
+	reg		[2:0]	currDecimFactor;
+	wire	bypassFlag = (currDecimFactor==3'd1);
+	
 	
 	wire	[17:0]	adcExtData	=	{{extendBitNum{Data_i[AdcDataWidth-1]}},Data_i};
 	
@@ -72,7 +75,7 @@ module	DecimFilterWrapper
 //================================================================================
 //	ASSIGNMENTS
 //================================================================================
-	assign oscWindVal = DataVal_i;
+	assign oscWindVal = DataVal_i&(!coefDataVal);
 
 	assign Data_o	=	(bypassFlag)? adcExtData[LsbForR1-1-:16]:decimData[17-:16];
 	assign DataVal_o	=	(bypassFlag)? DataVal_i:decimDataVal;
@@ -81,15 +84,47 @@ module	DecimFilterWrapper
 //	CODING
 //================================================================================
 
-// RomCtrl	RomCtrl
-// (
-	// .Clk_i		(Clk_i),
-	// .Rst_i		(Rst_i),
-	// .DataVal_i	(DataVal_i),
-	// .CoefDataVal_o	(coefDataVal),
+	always @(posedge Clk_i) begin
+		if (!Rst_i) begin
+			case(DecimFactor_i)
+				3'd0:	begin
+							currDecimFactor <= 3'd1;
+						end
+				3'd1:	begin
+							currDecimFactor <= 3'd1;
+						end
+				3'd2:	begin
+							currDecimFactor <= 3'd2;
+						end
+				3'd3:	begin
+							currDecimFactor <= 3'd4;
+						end
+				3'd4:	begin
+							currDecimFactor <= 3'd4;
+						end
+				3'd5:	begin
+							currDecimFactor <= 3'd6;
+						end
+				3'd6:	begin
+							currDecimFactor <= 3'd6;
+						end
+				3'd7:	begin
+							currDecimFactor <= 3'd7;
+						end
+			endcase
+		end
+	end
+	
+RomCtrl	RomCtrl
+(
+	.Clk_i		(Clk_i),
+	.Rst_i		(Rst_i),
+	.OscWind_i	(DataVal_i),
+	.CoefDataVal_o	(coefDataVal),
 	// .DecimFactor_i	(DecimFactor_i),
-	// .CoefAddr_o	(coefAddr)
-// );
+	.DecimFactor_i	(currDecimFactor),
+	.CoefAddr_o	(coefAddr)
+);
 
 CoefROM CoefRom (
   .a(coefAddr),      // input wire [8 : 0] a
@@ -100,7 +135,8 @@ systolicFilter DataFitler (
 	.Clk_i(Clk_i), 
 	.Rst_i(Rst_i), 
 	.CoefData_i(coefData),
-	.DecimFactor_i(DecimFactor_i),
+	// .DecimFactor_i(DecimFactor_i),
+	.DecimFactor_i(currDecimFactor),
 	.CoefDataVal_i(coefDataVal),
 	.Data_i(adcExtData), 
 	.DataNd_i(oscWindVal), 
@@ -118,7 +154,8 @@ decimBlock
 		(
 			.Clk_i			(Clk_i),
 			.Rst_i			(Rst_i),
-			.DecimFactor_i	(DecimFactor_i),
+			// .DecimFactor_i	(DecimFactor_i),
+			.DecimFactor_i	(currDecimFactor),
 			.Data_i			(filteredData),
 			.DataNd_i		(filteredDataVal),
 			.Data_o			(decimData),

+ 189 - 0
src/src/FftDataFiltering/DecimFilterWrapperTest.v

@@ -0,0 +1,189 @@
+`timescale 1ns / 1ps
+//////////////////////////////////////////////////////////////////////////////////
+// company: 
+// engineer: 
+// 
+// create date:    16:37:06 07/11/2019 
+// design name: 
+// module name:    dsp_linkport_interface 
+// project name: 
+// target devices: 
+// tool versions: 
+// description: 					
+//
+// dependencies: 
+//
+// revision: 
+// revision 0.01 - file created
+// additional comments: 
+//
+//////////////////////////////////////////////////////////////////////////////////
+module	DecimFilterWrapperTest
+#(	
+	parameter	AdcDataWidth		=	14,
+	parameter	N	=	8,
+	parameter	M	=	2,
+	parameter	FilteredDataWidth	=	32,
+	parameter	FirOutDataWidth		=	48,
+	parameter	FirOutCutBit		=	42,
+	parameter	LsbForR1	=	10'd16,
+	parameter	LsbForR2	=	10'd16,
+	parameter	LsbForR4	=	10'd16
+)
+(
+	input	Clk_i,
+	input	[2:0]	DecimFactor_i,
+	input	Rst_i,
+	
+	input	DataVal_i,
+	input	signed	[AdcDataWidth-1:0]	Data_i,
+	
+	// output	signed	[16-1:0]	Data_o,
+	output	signed	[FilteredDataWidth-1:0]	Data_o,
+	output	DataVal_o
+);
+//================================================================================
+//	REG/WIRE
+//================================================================================
+	wire	signed	[FilteredDataWidth-1:0]	filteredData;
+	wire	signed	[FilteredDataWidth-1:0]	decimData;
+	
+	wire	filteredDataVal;
+	wire	decimDataVal;
+	
+	reg		decimDataValR;
+
+	
+	reg		[15:0]	outDataReg;
+	
+	localparam	extendBitNum	=	FilteredDataWidth-AdcDataWidth;
+	
+	wire	[39:0]	firData;
+	wire	firDataVal;
+	// wire	bypassFlag = (DecimFactor_i==3'd0 | DecimFactor_i==3'd1);
+	reg		[2:0]	currDecimFactor;
+	wire	bypassFlag = (currDecimFactor==3'd1);
+	
+	
+	wire	[FilteredDataWidth-1:0]	adcExtData	=	{{extendBitNum{Data_i[AdcDataWidth-1]}},Data_i};
+	
+	wire [8:0] coefAddr;
+	wire [17:0] coefData;
+	wire coefDataVal;
+	
+	wire	oscWindVal;
+	
+//================================================================================
+//	ASSIGNMENTS
+//================================================================================
+	assign oscWindVal = DataVal_i&(!coefDataVal);
+
+	// assign Data_o	=	(bypassFlag)? adcExtData[LsbForR1-1-:16]:outDataReg[15-:16];
+	assign Data_o	=	(bypassFlag)? adcExtData:decimData;
+	// assign Data_o	=	decimData;
+	assign DataVal_o	=	(bypassFlag)? DataVal_i:decimDataVal;
+
+//================================================================================
+//	CODING
+//================================================================================
+	always	@(posedge	Clk_i)	begin
+		if	(!Rst_i)	begin
+			case(DecimFactor_i)
+				3'd0:	begin
+							outDataReg		<=	adcExtData[LsbForR1-1-:16];
+							decimDataValR	<=	DataVal_i;
+						end
+				3'd1:	begin
+							outDataReg		<=	adcExtData[LsbForR1-1-:16];
+							decimDataValR	<=	DataVal_i;
+						end
+				3'd2:	begin
+							outDataReg		<=	decimData[LsbForR2-1-:16];
+							decimDataValR	<=	decimDataVal;
+						end
+				// 3'd3:	begin
+							// outDataReg	<=	decimData[maxWidthForR3-1-:16];
+							// decimDataValR	<=	decimDataVal;
+						// end
+				// 3'd4:	begin
+							// outDataReg	<=	decimDataI[LsbForR4-1-:16];
+							// decimDataValR	<=	decimDataVal;
+						// end
+				// 3'd5:	begin
+							// outDataReg	<=	decimDataI[maxWidthForR5-1-:16];
+							// decimDataValR	<=	decimDataVal;
+						// end
+				// 3'd6:	begin
+							// outDataReg	<=	decimDataI[maxWidthForR6-1-:16];
+							// decimDataValR	<=	decimDataVal;
+						// end
+				// 3'd7:	begin
+							// outDataReg	<=	decimDataI[maxWidthForR7-:16];
+							// decimDataValR	<=	decimDataVal;
+						// end
+			endcase
+		end	else	begin
+			outDataReg	<=	16'd0;
+			decimDataValR	<=	1'b0;
+		end
+	end
+
+	always @(posedge Clk_i) begin
+		if (!Rst_i) begin
+			case(DecimFactor_i)
+				3'd0:	begin
+							currDecimFactor <= 3'd1;
+						end
+				3'd1:	begin
+							currDecimFactor <= 3'd1;
+						end
+				3'd2:	begin
+							currDecimFactor <= 3'd2;
+						end
+				3'd3:	begin
+							currDecimFactor <= 3'd4;
+						end
+				3'd4:	begin
+							currDecimFactor <= 3'd4;
+						end
+				3'd5:	begin
+							currDecimFactor <= 3'd6;
+						end
+				3'd6:	begin
+							currDecimFactor <= 3'd6;
+						end
+				3'd7:	begin
+							currDecimFactor <= 3'd7;
+						end
+			endcase
+		end
+	end
+	
+cicFilterTest 
+#(
+	.N (N),	//filter order
+	.M (M),	//comb delay
+	.filteredDataWidth	(FilteredDataWidth),
+	.inOutDataWidth		(FilteredDataWidth),
+	.decimCntWidth		(7)
+)
+cicFilterInstI
+(
+	.Clk_i			(Clk_i),
+	.Rst_i			(Rst_i),
+	.DecimFactor_i	(currDecimFactor),
+	.Data_i			({{extendBitNum{Data_i[AdcDataWidth-1]}},Data_i}),
+	.DataNd_i		(DataVal_i),
+	.Data_o			(decimData),
+	.DataValid_o	(decimDataVal)
+);
+
+endmodule
+
+
+
+
+
+
+
+

+ 63 - 41
src/src/FftDataFiltering/RomCtrl.v

@@ -21,12 +21,11 @@
 module RomCtrl
 #(	
 	parameter	OutWidth	=	9,
-	parameter [8:0] BaseAddrR2 = 0,
-	parameter [8:0] BaseAddrR3 = 35,
-	parameter [8:0] BaseAddrR4 = 70,
-	parameter [8:0] BaseAddrR5 = 105,
-	parameter [8:0] BaseAddrR6 = 140,
-	parameter [8:0] BaseAddrR7 = 175
+	parameter	Offset		=	24,
+	parameter [8:0] BaseAddrR2 = 9'd0,
+	parameter [8:0] BaseAddrR4 = 9'd64,
+	parameter [8:0] BaseAddrR6 = 9'd128,
+	parameter [8:0] BaseAddrR7 = 9'd192
 )
 (
 	input Clk_i,
@@ -43,18 +42,18 @@ module RomCtrl
 //================================================================================
 reg	[2:0] decimFactor;
 reg [OutWidth-1:0] currBaseAddr;
+reg [OutWidth-1:0] currMaxAddr;
 reg [8:0] coefAddr;
 
 reg	changeFlag;
 reg	coefDataVal;
-reg	coefDataValReg;
 
 //================================================================================
 //	ASSIGNMENTS
 //================================================================================
 // assign changeFlag = (decimFactor!= DecimFactor_i);
 assign CoefAddr_o = coefAddr;
-assign CoefDataVal_o = coefDataValReg;
+assign CoefDataVal_o = coefDataVal;
 	
 //================================================================================
 //	CODING
@@ -84,7 +83,8 @@ always @(posedge Clk_i) begin
 		if (changeFlag) begin
 			coefDataVal <= 1'b1;
 		end 
-		if (coefAddr==currBaseAddr+34) begin
+		// if (coefAddr==currBaseAddr+63) begin
+		if (coefAddr==currMaxAddr) begin
 			coefDataVal <= 1'b0;
 		end
 	end else begin
@@ -94,54 +94,76 @@ end
 
 always @(posedge Clk_i) begin
 	if (!Rst_i) begin
-		coefDataValReg <= coefDataVal;
+		case (DecimFactor_i) 
+			2:	begin
+					currMaxAddr <= 0+Offset;
+				end
+			4:	begin
+					currMaxAddr <= 0+Offset;
+				end
+			6:	begin
+					currMaxAddr <= 0+Offset;
+				end
+			7:	begin
+					currMaxAddr <= 0+Offset;
+				end
+		endcase
 	end else begin
-		coefDataValReg <= 0;
+		currMaxAddr <= 0;
 	end 
-end
+end 
 
+// always @(posedge Clk_i) begin
+	// if (!Rst_i) begin
+		// if (changeFlag) begin
+			// case (DecimFactor_i) 
+				// 1:	begin
+						// currBaseAddr <= 9'd0;
+					// end
+				// 2:	begin
+						// currBaseAddr <= 9'd0;
+					// end
+				// 3:	begin
+						// currBaseAddr <= 9'd64;
+					// end
+				// 4:	begin
+						// currBaseAddr <= BaseAddrR4;
+					// end
+				// 5:	begin
+						// currBaseAddr <= BaseAddrR5;
+					// end
+				// 6:	begin
+						// currBaseAddr <= BaseAddrR6;
+					// end
+				// 7:	begin
+						// currBaseAddr <= BaseAddrR7;
+					// end
+			// endcase
+		// end
+	// end else begin
+		// currBaseAddr <= 0;
+	// end 
+// end 
 
 always @(posedge Clk_i) begin
 	if (!Rst_i) begin
-		if (changeFlag) begin
+		if (coefDataVal) begin
+			coefAddr<=coefAddr+1;
+		end else begin
 			case (DecimFactor_i) 
-				0:	begin
-						currBaseAddr <= BaseAddrR2;
-					end
-				1:	begin
-						currBaseAddr <= BaseAddrR2;
-					end
 				2:	begin
-						currBaseAddr <= BaseAddrR2;
-					end
-				3:	begin
-						currBaseAddr <= BaseAddrR3;
+						coefAddr <= BaseAddrR2;
 					end
 				4:	begin
-						currBaseAddr <= BaseAddrR4;
-					end
-				5:	begin
-						currBaseAddr <= BaseAddrR5;
+						coefAddr <= BaseAddrR2;
 					end
 				6:	begin
-						currBaseAddr <= BaseAddrR6;
+						coefAddr <= BaseAddrR2;
 					end
 				7:	begin
-						currBaseAddr <= BaseAddrR7;
+						coefAddr <= BaseAddrR2;
 					end
 			endcase
-		end
-	end else begin
-		currBaseAddr <= 0;
-	end 
-end 
-
-always @(posedge Clk_i) begin
-	if (!Rst_i) begin
-		if (coefDataValReg) begin
-			coefAddr<=coefAddr+1;
-		end else begin
-			coefAddr <= currBaseAddr;
 		end 
 	end else begin
 		coefAddr <=0;

+ 101 - 0
src/src/FftDataFiltering/cicFilterTest.v

@@ -0,0 +1,101 @@
+module cicFilterTest 
+#(
+	parameter N = 2,	//filter order
+	parameter M = 1,	//comb delay
+	// parameter R = 4,	//decim fartor
+	parameter	filteredDataWidth	=	28,
+	parameter	inOutDataWidth	=	16,
+	parameter	decimCntWidth	=	7
+)
+(
+	input Clk_i,
+	input Rst_i,
+	input [2:0]	DecimFactor_i,
+	input [inOutDataWidth-1:0] Data_i,
+	input DataNd_i,
+	output [filteredDataWidth-1:0] Data_o,
+	output DataValid_o
+);
+	
+wire	[filteredDataWidth-1:0]	inData	[N-1:0];
+
+wire	[filteredDataWidth-1:0]	intFilteredData	[N-1:0];
+wire	intFilteredDataValid	[N-1:0];
+wire	intDataVal	[N-1:0];
+
+wire	[filteredDataWidth-1:0]	decimIntData;
+wire	decimIntDataValid;
+
+wire	[filteredDataWidth-1:0]	combFilteredData	[N-1:0];
+wire	[filteredDataWidth-1:0]	combInData	[N-1:0];
+wire	combDataVal	[N-1:0];
+wire	combFilteredDataVal	[N-1:0];
+
+genvar i,j;
+generate 
+	for (i=0; i<N; i=i+1)	begin: IntFilterGen
+	
+		// assign	inData	[i]		=	(i==0)?{{filteredDataWidth-inOutDataWidth{Data_i[inOutDataWidth-1]}},Data_i}:intFilteredData[i-1][filteredDataWidth-1-:filteredDataWidth];
+		assign	inData	[i]		=	(i==0)?Data_i:intFilteredData[i-1];
+		assign	intDataVal[i]	=	(i==0)?DataNd_i:intFilteredDataValid[i-1];
+		
+		intFilterWrapper
+		#(
+			.filteredDataWidth	(filteredDataWidth),
+			.inOutDataWidth		(filteredDataWidth)
+		)
+		intFilterWrapperInst
+		(
+			.Clk_i		(Clk_i),
+			.Rst_i		(Rst_i),
+			.Data_i		(inData[i]),
+			.DataNd_i	(intDataVal[i]),
+			.Data_o		(intFilteredData[i]),
+			.DataValid_o(intFilteredDataValid[i])
+		);
+	end	
+	
+	for (j=0; j<N; j=j+1)	begin: CombFilterGen
+	
+		assign	combInData	[j]	=	(j==0)?intFilteredData[N-1]:combFilteredData[j-1];
+		assign	combDataVal	[j]	=	(j==0)?intFilteredDataValid[N-1]:combFilteredDataVal[j-1];
+		
+		combFilterWrapper
+		#(
+			.M (M),
+			.filteredDataWidth	(filteredDataWidth),
+			.inOutDataWidth		(filteredDataWidth)
+		)
+		combFilterWrapperInst
+		(
+			.Clk_i		(Clk_i),
+			.Rst_i		(Rst_i),
+			.Data_i		(combInData[j]),
+			.DataNd_i	(combDataVal[j]),
+			.Data_o		(combFilteredData[j]),
+			.DataValid_o(combFilteredDataVal[j])
+		);
+	end
+	
+	decimBlock
+	#(	
+		// .R	(R),
+		.inOutDataWidth	(filteredDataWidth),
+		.decimCntWidth	(decimCntWidth)
+	)
+	decimBlockInst
+	(
+		.Clk_i			(Clk_i),
+		.Rst_i			(Rst_i),
+		.DecimFactor_i	(DecimFactor_i),
+		.Data_i			(combFilteredData[N-1]),
+		.DataNd_i		(combFilteredDataVal[N-1]),
+		.Data_o			(decimIntData),
+		.DataValid_o	(decimIntDataValid)
+	);
+		
+endgenerate
+
+assign	Data_o	=	decimIntData;
+assign	DataValid_o	=	decimIntDataValid;
+endmodule

+ 1 - 0
src/src/FftDataFiltering/combFilterBlock.v

@@ -50,6 +50,7 @@ generate
 				dataValid	<=	1'b1;
 			end	else	begin
 				dataValid	<=	1'b0;
+				sumResult	<=	0;
 			end
 		end	else	begin
 			sumResult	<=	0;

+ 53 - 0
src/src/InternalDsp/Description.txt

@@ -0,0 +1,53 @@
+1. Модуль InternalDsp обертка в котором подключатся модули ЦОС системы.
+   Структура модуля следующая:
+		InternalDsp
+			MeasCtrlModule
+			WinParameters
+			Win_Calc
+			CordicNco
+				CordicRotation
+			ComplPrng
+			DspPipeline
+				SimpleMult
+				SummAcc
+				MyIntToFp
+				FpCustomMultipliter
+			AdcDataCalibration	
+
+2. Модуль ComplPrng генерирует случайную составляющую для подмешивания к полезному сигналу.
+3. Модуль CordicNco генерирует отсчеты Sin и Cos для реализации квадратурного демодулятора. Модуль реализован по алгоритму Cordic (см. в интернете).
+4. Модуль CordicRotation осуществляет поворот фазы при работе модуля CordicNco. 
+
+5. Модуль DspPipeline обертка для основных модулей ЦОС.
+   Модуль реализован в соответствии с документом Блок схема DSP S5435v4port.vsd.
+
+6. Модуль MeasCtrlModule - осуществляет контроль за запуском и остановкой измерений. Определяет режим работы системы из пришедших настроек.
+   
+7. Модуль NcoRstGen генерирует сигнал сброса для CordicNco. Каждый раз когда происходит переключение частоты ПЧ и приходит новое FreuencyTuningWord (FTW) для CordicNco, модуль отслеживает это, и послее переключеня ПЧ генерирует сброс NCO.
+8. Модуль Win_Calc генерирует цифровой фильтр для ЦОСа.
+   
+   Расчет фильтра реализован на основе приближения функции синуса полиномом 4 степени (про приближение полиномом искать в интернете).
+   Модуль может генерировать 3 вида фильтров:
+		1. Прямоугольное окно.
+		2. Sin^2 окно.
+		3. Окно Тьюки.
+   Исходя из выбранного фильтра определяется какое окно будет использоваться ЦОСом.
+   Фильтры 1Гц-300Кгц - окно Тьюки.
+   Фильтры 500КГц-2МГц - Sin^2 окно.
+   Фильтры 3МГц - 10МГц - прямоугольные окна. Прямоугольные окна подобраны по колличеству точек так, чтобы удвоенная составляющая сигнала, попадала строго в полосу подавления фильтра.
+   
+
+      
+9. Модуль WinParameters содержит таблицу с набором фильтров от 1Гц до 10МГц. Модуль выставляет на выходные линии параметры для расчета цифрового фильтра исходя из пришедшей команды.
+   Модуль выдает следующие параметры:
+		1. Фазовый инкремент.
+		2. Стартовый аргумент.
+		3. Колличество точек фильтра.
+		4. Нормировочный коэффициент фильтра.
+		5. Средний шум трассы цифрового фильтра.
+		
+10. Модуль AdcDataCalibration расчитывает постоянную составляющую в пришедшем сигнале. 
+	Алгоритм работы модуля:
+		1. Модуль накапливает в аккумуляторе выборку данных с АЦП.
+		2. Как только выборка накоплена, берется среднее значение по выборке. 
+		3. Значение выдается на выход модуля, чтобы в последствии вычесть её из полезного сигнала от АЦП.

+ 15 - 7
src/src/InternalDsp/DspPipeline.v

@@ -11,12 +11,14 @@ module DspPipeline
 	parameter	WindNormCoefWidth	=	32,
 	parameter	WindCorrCoefWidth	=	32,
 	parameter	IntermediateWidth	=	14,
-	parameter	FracWidth			=	51
+	// parameter	FracWidth			=	51
+	parameter	FracWidth			=	32
 )
 (
     input	Clk_i,
     input	Rst_i,
     input	Val_i,
+    input	MeasWindEnd_i,
     input	StartFpConv_i,
 	
 	input	[WindCorrCoefWidth-1:0]	FilterCorrCoef_i,
@@ -35,7 +37,7 @@ module DspPipeline
 //================================================================================
 //  LOCALPARAMS
 	localparam	NormResultWidth	=	AccWidth+WindNormCoefWidth;
-	localparam	AdcWindWidth	=	37;
+	localparam	AdcWindWidth	=	18;
 //================================================================================
 //  REG/WIRE 
 	wire	[AdcWindWidth-1:0]	adcWindResult;
@@ -47,7 +49,9 @@ module DspPipeline
 	wire	adcWindCosResultVal;
 	
 	wire	[AccWidth-1:0]	AccResultI;
+	wire	resultIVal;
 	wire	[AccWidth-1:0]	AccResultQ;
+	wire	resultQVal;
 	
 	wire	[ResultWidth-1:0]	NormResultI;
 	wire	NormResultIVal;
@@ -92,7 +96,7 @@ AdcWindMult
 (
 	.Rst_i		(Rst_i),
 	.Clk_i		(Clk_i),
-	.Val_i		(valRegReg),
+	.Val_i		(Val_i),
 	.FactorA_i	(AdcData_i),
 	.FactorB_i	(Wind_i),
 	.Result_o	(adcWindResult),
@@ -143,10 +147,12 @@ SummAccQ
 (
     .Clk_i		(Clk_i),
     .Rst_i		(Rst_i),
+	.AccZeroing_i		(MeasWindEnd_i),
     .Val_i		(adcWindSinResultVal),
 	
 	.Data_i		(adcWindSinResult[53:0]),
-	.Result_o	(AccResultQ)
+	.Result_o	(AccResultQ),
+	.ResultVal_o	(resultQVal)
 );
 
 SumAcc
@@ -158,10 +164,12 @@ SummAccI
 (
     .Clk_i		(Clk_i),
     .Rst_i		(Rst_i),
+    .AccZeroing_i		(MeasWindEnd_i),
     .Val_i		(adcWindCosResultVal),
 	
 	.Data_i		(adcWindCosResult[53:0]),
-	.Result_o	(AccResultI)
+	.Result_o	(AccResultI),
+	.ResultVal_o	(resultIVal)
 );
 
 //===============================InToFpConv=======================================
@@ -178,7 +186,7 @@ QToFp32
 	.Rst_i				(Rst_i),
 	.InData_i			(AccResultQ),
 	.AverageNoizeLvl_i	(AverageNoizeLvl_i),
-	.InDataVal_i		(StartFpConv_i),
+	.InDataVal_i		(resultQVal),
 	.OutData_o			(qFp32Result),
 	.OutDataVal_o		(qFp32ResultVal)
 );
@@ -196,7 +204,7 @@ IToFp32
 	.Rst_i				(Rst_i),
 	.InData_i			(AccResultI),
 	.AverageNoizeLvl_i	(AverageNoizeLvl_i),
-	.InDataVal_i		(StartFpConv_i),
+	.InDataVal_i		(resultIVal),
 	.OutData_o			(iFp32Result),
 	.OutDataVal_o		(iFp32ResultVal)
 );

+ 85 - 0
src/src/InternalDsp/GrDelModeMux.v

@@ -0,0 +1,85 @@
+`timescale 1ns / 1ps
+//////////////////////////////////////////////////////////////////////////////////
+// Company: 
+// Engineer: 
+// 
+// Create Date:    10:02:35 04/20/2020 
+// Design Name: 
+// Module Name:    mult_module 
+// Project Name: 
+// Target Devices: 
+// Tool versions: 
+// Description: 
+//
+// Dependencies: 
+//
+// Revision: 
+// Revision 0.01 - File Created
+// Additional Comments: 
+//
+//////////////////////////////////////////////////////////////////////////////////
+module	GrDelModeMux	
+#(	
+	parameter	AdcDataWidth	=	20,
+	parameter	NcoDataWidth	=	18
+)
+(
+	input	Rst_i,
+	
+	input	MuxCtrl_i,
+
+	input	[AdcDataWidth-1:0]	AdcDataOrig_i,
+	input	[AdcDataWidth-1:0]	AdcDataGrDel_i,
+	
+	input	[NcoDataWidth-1:0]	NcoSinOrig_i,
+	input	[NcoDataWidth-1:0]	NcoCosOrig_i,
+	input	[NcoDataWidth-1:0]	NcoSinGrDel_i,
+	input	[NcoDataWidth-1:0]	NcoCosGrDel_i,
+	
+	output	reg	[AdcDataWidth-1:0]	MuxAdcData_o,
+	output	reg	[NcoDataWidth-1:0]	MuxNcoSin_o,
+	output	reg	[NcoDataWidth-1:0]	MuxNcoCos_o
+);	
+
+//================================================================================
+//  LOCALPARAM
+
+//================================================================================
+//	REG/WIRE
+	
+//================================================================================
+//  ASSIGNMENTS
+
+//================================================================================
+//  CODING
+always	@(*)	begin
+	if	(!Rst_i)	begin
+		if	(MuxCtrl_i)	begin
+			MuxAdcData_o = AdcDataGrDel_i;
+			MuxNcoSin_o = NcoSinGrDel_i;
+			MuxNcoCos_o = NcoCosGrDel_i;
+		end else begin
+			MuxAdcData_o = AdcDataOrig_i;
+			MuxNcoSin_o = NcoSinOrig_i;
+			MuxNcoCos_o = NcoCosOrig_i;
+		end 
+	end	else	begin
+		MuxAdcData_o = 0;
+		MuxNcoSin_o = 0;
+		MuxNcoCos_o = 0;
+	end
+end
+
+
+endmodule
+
+
+
+
+
+
+
+
+
+
+

+ 50 - 22
src/src/InternalDsp/InternalDsp.v

@@ -35,8 +35,7 @@ module InternalDsp
 	parameter	CmdDataRegWith		=	24,
 	parameter	IntermediateWidth	=	18,
 	parameter	CorrAdcDataWidth	=	20,
-	parameter	AccWidth			=	80,
-	parameter	FftMode				=	"TRUE"
+	parameter	AccWidth			=	61
 )
 (
 	input	wire	Clk_i,
@@ -99,12 +98,21 @@ module InternalDsp
 	
 	wire	[WindWidth-1:0]	wind;			
 
-	wire	[NcoWidth-1:0]	ncoCos;
-	wire	[NcoWidth-1:0]	ncoSin;
+	wire	[NcoWidth-1:0]	ncoCosFirstTone;
+	wire	[NcoWidth-1:0]	ncoSinFirstTone;
+	
+	wire	[NcoWidth-1:0]	ncoCosSecondTone;
+	wire	[NcoWidth-1:0]	ncoSinSecondTone;
+	
+	wire	[NcoWidth-1:0]	ncoCosMuxedTone	[ChNum-1:0];
+	wire	[NcoWidth-1:0]	ncoSinMuxedTone	[ChNum-1:0];
 	
 	wire	[CorrAdcDataWidth-1:0]	adcDataBus	[ChNum-1:0];
 	wire	[CorrAdcDataWidth-1:0]	adcDataBusExt	[ChNum-1:0];
 	wire	[CorrAdcDataWidth-1:0]	gatedAdcDataBus	[ChNum-1:0];
+	
+	wire	[CorrAdcDataWidth-1:0]	AdcDataBusMuxed	[ChNum-1:0];
+	
 	wire	[CorrAdcDataWidth-1:0]	calAdcData		[ChNum-1:0];
 	wire	[CorrAdcDataWidth-1:0]	prngData;
 	reg		[CorrAdcDataWidth-1:0]	prngDataBus		[ChNum-1:0];
@@ -118,7 +126,7 @@ module InternalDsp
 	wire	[ChNum-1:0]	resultValBus;
 	
 	wire	measWind;
-	wire	measWindDelayed;
+	wire	measWindEnd;
 	wire	stopMeas;
 	wire	[1:0]	tukeyCtrl;
 	
@@ -140,6 +148,7 @@ module InternalDsp
 	
 	wire	[WindNcoPhIncWidth-1:0]	ncoPhInc = {ifFtwHReg[0+:WindNcoPhIncWidth-CmdDataRegWith],ifFtwLReg};
 	
+	wire	grDelayMeasFlag = 1'b1;
 //================================================================================
 //  ASSIGNMENTS
 
@@ -172,8 +181,8 @@ module InternalDsp
 	assign	MeasDataRdy_o	=	&resultValBus;
 	assign	EndMeas_o		=	stopMeas;
 	
-	assign	NcoCos_o	=	ncoCos;
-	assign	NcoSin_o	=	ncoSin;
+	assign	NcoCos_o	=	ncoCosFirstTone;
+	assign	NcoSin_o	=	ncoSinFirstTone;
 	assign	MeasWind_o	=	measWind;
 	
 	assign	CalModeDone_o	=	&calDone;
@@ -229,9 +238,9 @@ MeasCtrlModule
 	.WindPhIncStart_i		(winPhIncStart),
 	.WindArg_o				(windArg),
 		
-	.StartFpConv_o			(StartFpConv),
+	.StartFpConv_o			(),
 	.MeasWind_o				(measWind),
-	.MeasWindDel_o			(measWindDelayed),
+	.MeasWindEnd_o			(measWindEnd),
 	.StopMeas_o				(stopMeas),
 	.MeasEnd_o				(MeasEnd_o),
 	.WinCtrl_o				(winCtrl),
@@ -265,7 +274,6 @@ WinParameters
 Win_calc	WinCalcInst
 (
 	.clk_i			(Clk_i),
-	.wind_clk		(WindCalcClk_i),
 	.filterCmd_i	(measCtrlReg[15-:8]),
 	.reset_i		(Rst_i),
 	.WinCtrl_i		(winCtrl),
@@ -295,10 +303,10 @@ CordicNco
 #(	
 	.ODatWidth	(NcoWidth),
 	.PhIncWidth	(WindNcoPhIncWidth),
-	.IterNum	(15),
+	.IterNum	(13),
 	.EnSinN		(0)
 )
-ncoInst
+ncoInstFirstTone
 (
 	.Clk_i		(Clk_i),
 	.Rst_i		(Rst_i|NcoRst_i),
@@ -307,8 +315,29 @@ ncoInst
 	.WindVal_i	(1'b1),
 	.WinType_i	(),
 	.Wind_o		(),
-	.Sin_o		(ncoSin),
-	.Cos_o		(ncoCos),	
+	.Sin_o		(ncoSinFirstTone),
+	.Cos_o		(ncoCosFirstTone),	
+	.Val_o		()
+);
+
+CordicNco		
+#(	
+	.ODatWidth	(NcoWidth),
+	.PhIncWidth	(WindNcoPhIncWidth),
+	.IterNum	(13),
+	.EnSinN		(0)
+)
+ncoInstSecondTone
+(
+	.Clk_i		(Clk_i),
+	.Rst_i		(Rst_i|NcoRst_i),
+	.Val_i		(1'b1),
+	.PhaseInc_i	({ifFtwHReg[0+:WindNcoPhIncWidth-CmdDataRegWith],ifFtwLReg}),
+	.WindVal_i	(1'b1),
+	.WinType_i	(),
+	.Wind_o		(),
+	.Sin_o		(ncoSinSecondTone),
+	.Cos_o		(ncoCosSecondTone),	
 	.Val_o		()
 );
 
@@ -334,10 +363,7 @@ always @(posedge Clk_i) begin
 end
 //------------------------------------------------
 //Generating needed amount of calculating channels
-
 generate
-
-if (FftMode == "FALSE") begin			
 	for	(g=0;	g<ChNum;	g=g+1)	begin	:DspChannel
 	
 		AdcCalibration 
@@ -356,6 +382,7 @@ if (FftMode == "FALSE") begin
 			.CalibratedAdcData_o	(calAdcData[g])
 		);
 		
+
 		DspPipeline	
 		#(	
 			.AdcDataWidth		(AdcDataWidth),
@@ -372,16 +399,18 @@ if (FftMode == "FALSE") begin
 			.Clk_i				(Clk_i),
 			.Rst_i				(Rst_i),
 			.Val_i				(measWind),
-			.StartFpConv_i		(StartFpConv),
+			.MeasWindEnd_i		(measWindEnd),
+			.StartFpConv_i		(measWindEnd),
 			
 			.FilterCorrCoef_i	({filterCorrCoefHReg[0+:WindNcoPhIncWidth-CmdDataRegWith],filterCorrCoefLReg}),
 			// .FilterCorrCoef_i	(32'h3f800000),
 			.AverageNoizeLvl_i	(averageNoizeLvl),
 			.AdcData_i			(gatedAdcDataBus[g]),
-			// .AdcData_i			({{2{ncoCos[17]}},ncoCos}),
+			// .AdcData_i			(AdcDataBusMuxed[g]),
+			// .AdcData_i			({{2{ncoCosFirstTone[17]}},ncoCosFirstTone}),
 			.Wind_i				(wind),
-			.NcoSin_i			(ncoSin),
-			.NcoCos_i			(ncoCos),	
+			.NcoSin_i			(ncoSinFirstTone),
+			.NcoCos_i			(ncoCosFirstTone),	
 			.NormCoef_i			(windNormCoef),
 			// .NormCoef_i			(32'h3f800000),
 			// .NormCoef_i			(32'h3f03993a),
@@ -391,7 +420,6 @@ if (FftMode == "FALSE") begin
 			.CorrResultVal_o	(resultValBus[g])
 		);
 	end
-end
 endgenerate
 
 endmodule

+ 7 - 4
src/src/InternalDsp/MeasCtrlModule.v

@@ -44,7 +44,7 @@ module MeasCtrlModule
 	
 	output	StartFpConv_o,
 	output	MeasWind_o,
-	output	MeasWindDel_o,
+	output	MeasWindEnd_o,
 	output	StopMeas_o,
 	output	MeasEnd_o,
 	output	WinCtrl_o,
@@ -105,11 +105,14 @@ module MeasCtrlModule
 	wire	wideFilterFlag	=	(FilterCmd_i>=8'h54	&	FilterCmd_i!=8'h70);
 	
 	reg		sampleStrobeGenRst;
+	
+	wire	measWindOr	=	(measWind|measWindR);
 //================================================================================
 //  ASSIGNMENTS
 	assign	StartFpConv_o			=	startFpConvPipe	[2];
-	assign	MeasWind_o				=	measWind;
-	assign	MeasWindDel_o			=	measWindR;
+	// assign	MeasWind_o				=	measWind;
+	assign	MeasWind_o				=	measWindOr;
+	assign	MeasWindEnd_o			=	measWindEnd;
 	assign	StopMeas_o				=	pMeasEnd;
 	assign	MeasEnd_o				=	stopMeasCmd;
 	assign	WindArg_o				=	windArg;
@@ -173,7 +176,7 @@ module MeasCtrlModule
 	always	@(posedge	Clk_i)	begin
 		if	(!Rst_i)	begin
 			if	(measWindR)	begin
-				if	(pNumCnt	==	WindPointsNum_i-1)	begin
+				if	(pNumCnt	==	WindPointsNum_i-2)	begin
 					measWindEnd	<=	1'b1;
 				end	else	begin
 					measWindEnd	<=	1'b0;

+ 0 - 1
src/src/InternalDsp/Win_calc.v

@@ -21,7 +21,6 @@
 //////////////////////////////////////////////////////////////////////////////////
 module Win_calc	(
 	input			clk_i,
-	input			wind_clk,
 	input	[7:0]	filterCmd_i,
 	input			reset_i,
 	input			WinCtrl_i,

+ 6 - 0
src/src/Math/Description.txt

@@ -0,0 +1,6 @@
+1. Модуль FpCustomMultiplier выполняет перемножение чисел в формате fp32. Работа модуля реализована по стандарту перемножения числе в формате fp32. (читай там как работает). 
+2. Модуль MultModule выполняет умножение данных с текущего канала АЦП с сигналами Sin и Cos сгенерированным CordicNco. Умножение знаковых чисел в формате fixedPoint.
+   По сути это квадратурный демодулятор, на выходе модуля две шины данных - результаты перемножения AdcCos (I) и AdcSin(Q).
+3. Модуль MyIntToFp выполняет преобразование чисел в формат fp32 (вообще имеет перестраиваемые параметры числа бит отводимых под экспоненту и мантиссу).
+4. Модуль SimpleMult выполняет умножие знаковых чисел в формате fixedPoint.
+5. Модуль SumAcc является аккумулятором. Реализован как сумматор входных отсчетов. Суммирование ведется с учетом знаков.

+ 27 - 2
src/src/Math/SumAcc.v

@@ -7,9 +7,11 @@ module SumAcc
     input	Clk_i,
     input	Rst_i,
     input	Val_i,
+    input	AccZeroing_i,
 	input	[IDataWidth-1:0]	Data_i,
 	
-	output	[ODataWidth-1:0]	Result_o
+	output	[ODataWidth-1:0]	Result_o,
+	output	ResultVal_o
 );
 
 //================================================================================
@@ -21,18 +23,41 @@ module SumAcc
 	reg		resultVal;
 	wire	[ODataWidth-1:0]	extData	=	{{(ODataWidth - IDataWidth){Data_i[IDataWidth-1]}}, Data_i};	//sign extension
 	
+	reg		accZeroing;
+	reg		accZeroingR;
+	reg		accZeroingRR;
 //================================================================================
 //  ASSIGNMENTS
 	assign	Result_o	=	dataAcc;
+	assign	ResultVal_o	=	resultVal;
 //================================================================================
 //  CODING
+
+	always	@(posedge	Clk_i)	begin
+		if	(Rst_i)	begin
+			accZeroing		<=	0;
+			accZeroingR		<=	0;
+			accZeroingRR		<=	0;
+		end	else	begin
+			accZeroing		<=	AccZeroing_i;
+			accZeroingR		<=	accZeroing;
+			accZeroingRR	<=	accZeroingR;
+		end
+	end
+	
 	always	@(posedge	Clk_i)	begin
 		if	(Rst_i)	begin
 			dataAcc		<=	{ODataWidth{1'b0}};
 		end	else	if	(Val_i)	begin
-			dataAcc		<=	dataAcc+extData;
+			if	(!accZeroingRR)	begin
+				dataAcc		<=	dataAcc+extData;
+			end	else	begin
+				dataAcc		<=	0+extData;
+			end
+		resultVal	<=	accZeroingR;
 		end	else	begin
 			dataAcc		<=	0;
+			resultVal	<=	0;
 		end
 	end
 

+ 3 - 3
src/src/MeasDataFifo/OscDataFormer.v

@@ -2,11 +2,11 @@
 (* keep_hierarchy = "yes" *)	
 module OscDataFormer
 #(	
-	parameter	AdcDataWidth		=	16,	
+	parameter	AdcDataWidth		=	32,	
 	parameter	ExtAdcDataWidth		=	AdcDataWidth+2,	
 	parameter	ChNum				=	1,
-	parameter	DataValCycles		=	16,
-	parameter	OutDataWidth		=	(16*ChNum)*DataValCycles
+	parameter	DataValCycles		=	8,
+	parameter	OutDataWidth		=	(AdcDataWidth*ChNum)*DataValCycles
 )	
 (
 	input	Clk_i, 

+ 20 - 0
src/src/PulseMeas/Description.txt

@@ -0,0 +1,20 @@
+1. Модуль ActivePortSelector замыкает импульсы выбранного импульсного генератора, как модулирующий сигнал для выбранного порта (или нескольких портов).
+2. Модуль MeasStartEventGen выполняет синхронизацию сигналов запуска и генерирует общий, синхроннизированный сигнал зпуска системы.
+3. Модуль Mux является мультиплексором общего назначения. Благодаря наличию таких мультиплексоров система может гибко переконфигурироваться.
+   Все входные сигналы объединяются в шину, а на выход замыкается сигнал исходя из пришедней на модуль настройки.
+4. Модуль PGenRstGenerator генирирует сбросы для импульсных генераторов. Когда в ПО изменяется настройка импульсного генератора, DSP присылает и новые настройки, и команду в которой находятся биты указывающие на необходимость сброса конкретного(ых) генератора(ов).
+   В ответ на пришедшую команду, модуль генерирует сброс(ы) и перезаписывает команду в RegMap модуле. 
+   
+5. Модуль PulseGen генерирует ипульсы для режима импусльных измерений.
+   Всего у модуля есть 5 возможных режимов работы:
+   0 - Выключен.
+   1 - Шаблон 1 импульс.
+   2 - Шаблон 2 импульса.
+   3 - Шаблон 3 импульса.
+   4 - Burst режим для генерации N импульсов.
+   5 - Continious режим для бесконечной генерации импульсов.
+   
+   Про то как отгружаются и интерпретируются настройки ширины и длительности импульсов, а так же как задается период следования импульсов можно прочитать в протоколе обмена между ПО и DSP.
+   
+6. Модуль SampleStrobeGenRstDemux генерирует сброс конкретно для одного генератора, запускающего измерения. Выбор ведется исходя из настроек пришедших в командах конфигурации системы.
+7. Модуль TrigInt2Mux модуль является мультиплексором, который определяет относительно какого из импульсных генераторов будут синхронизироваться зпуски измерений в определенных режимах измерений.

+ 1 - 1
src/src/PulseMeas/PulseGen.v

@@ -72,7 +72,7 @@ module	PulseGen
 	reg		pulseDone;	
 	wire	delayDone	=	(currState	==	DELAY)?	delayCnt==currDelValue-1:1'b0;	
 	
-	wire	zeroDelay	=	(P1Del_i==0);
+	wire	zeroDelay	=	(P1Del_i==0||P1Del_i==1);
 	
 	reg	patternDone;
 

+ 340 - 0
src/src/PulseMeas/PulseGenNew.v

@@ -0,0 +1,340 @@
+//`timescale 1ns / 1ps
+//////////////////////////////////////////////////////////////////////////////////
+// Company: 
+// Engineer: 
+// 
+// Create Date:    10:02:35 04/20/2020 
+// Design Name: 
+// Module Name:    PulseGen 
+// Project Name: 
+// Target Devices: 
+// Tool versions: 
+// Description: 
+//
+// Dependencies: 
+//
+// Revision: 
+// Revision 0.01 - File Created
+// Additional Comments: 
+//
+//////////////////////////////////////////////////////////////////////////////////
+module	PulseGenNew	
+#(	
+	parameter	CmdRegWidth	=	32
+)
+(
+	input	Rst_i,
+	input	Clk_i,
+	input	EnPulse_i,
+	
+	input	PulsePol_i,
+	input	EnEdge_i,
+	input	[CmdRegWidth-29:0]	Mode_i,
+	input	[CmdRegWidth-1:0]	P1Del_i,
+	input	[CmdRegWidth-1:0]	P2Del_i,
+	input	[CmdRegWidth-1:0]	P3Del_i,
+	input	[CmdRegWidth-1:0]	P1Width_i,
+	input	[CmdRegWidth-1:0]	P2Width_i,
+	input	[CmdRegWidth-1:0]	P3Width_i,
+	
+	output	Pulse_o
+);	
+
+//================================================================================
+//  LOCALPARAM
+
+	localparam	IDLE	=	2'h0;
+	localparam	DELAY	=	2'h1;
+	localparam	PULSE	=	2'h2;
+	
+	localparam	DISABLED	=	8'd0;
+	localparam	SINGLE		=	8'd1;
+	localparam	DOUBLE		=	8'd2;
+	localparam	TRIPPLE		=	8'd3;
+	localparam	BURST		=	8'd4;
+	localparam	CONTINIOUS	=	8'd5;
+	
+//================================================================================
+	reg		pulse;
+	wire	[31:0]	delArray	[2:0];
+	wire	[31:0]	widthArray	[2:0];
+	
+	reg	[31:0]	pulseCnt;
+	reg	[31:0]	delayCnt;
+	reg	[31:0]	widthCnt;
+	
+	reg	[31:0]	currWidthValue;
+	reg	[31:0]	currDelValue;
+
+	reg	[1:0]	currState;
+	reg	[1:0]	nextState;
+	
+	reg		pulseDone;	
+	reg		delayDone;	
+	// wire	delayDone	=	(currState	==	DELAY)?	delayCnt==currDelValue-1:1'b0;	
+	
+	// wire	zeroDelay	=	(P1Del_i==0||P1Del_i==1);
+	wire	zeroDelay	=	(P1Del_i==0);
+	wire	singleDelay	=	(P1Del_i==1);
+	
+	reg	patternDone;
+
+	reg	enPulseR;
+	
+	wire	enPulsePos	=	(!enPulseR&EnPulse_i);
+	wire	enPulseNeg	=	(enPulseR&!EnPulse_i);
+	
+	wire	enPulse		=	(EnEdge_i)?	enPulseNeg:enPulsePos;
+	wire	enPulseEn	=	(Mode_i	!=	0)?	enPulse:1'b0;
+//================================================================================
+//  ASSIGNMENTS
+	assign	delArray	[0]	=	P1Del_i;
+	assign	delArray	[1]	=	P2Del_i;
+	assign	delArray	[2]	=	P3Del_i;
+	
+	assign	widthArray	[0]	=	P1Width_i;
+	assign	widthArray	[1]	=	P2Width_i;
+	assign	widthArray	[2]	=	P3Width_i;
+	
+	assign	Pulse_o	=	(PulsePol_i)?	~pulse:pulse;
+
+//================================================================================
+//  CODING
+
+always	@(*)	begin
+	if	(!Rst_i)	begin
+		if	(Mode_i==0)	begin
+			delayDone=1'b0;
+		end	else	if	(Mode_i	>=1 & Mode_i<=3)	begin
+			delayDone=(delayCnt==currDelValue-2);
+		end	else	begin
+			delayDone=(delayCnt==currDelValue-1);
+		end
+	end	else	begin
+		delayDone=1'b0;
+	end
+end
+always	@(posedge	Clk_i)	begin
+	if	(!Rst_i)	begin
+		enPulseR	<=	EnPulse_i;
+	end	else	begin
+		enPulseR	<=	1'b0;
+	end
+end
+
+always	@(posedge	Clk_i)	begin
+	if	(!Rst_i)	begin
+		if	(Mode_i	>=1 & Mode_i<=3)	begin	
+			if	(currState	!=	IDLE)	begin
+				delayCnt	<=	delayCnt+1;
+			end	else	begin
+				delayCnt	<=	0;
+			end
+		end	else	begin
+			if	(currState	==	DELAY)	begin
+				delayCnt	<=	delayCnt+1;
+			end	else	begin
+				delayCnt	<=	0;
+			end
+		end
+	end	else	begin
+		delayCnt	<=	0;
+	end
+end
+
+always	@(posedge	Clk_i)	begin
+	if	(!Rst_i)	begin
+		if	(pulse)	begin
+			widthCnt	<=	widthCnt+1;
+		end	else	begin
+			widthCnt	<=	0;
+		end
+	end	else	begin
+		widthCnt	<=	0;
+	end
+end
+
+always	@(*)	begin
+	if	(!Rst_i)	begin
+		if	(pulse)	begin
+			if	(widthCnt==currWidthValue-1)	begin
+				pulseDone	=	1'b1;
+			end	else	begin
+				pulseDone	=	1'b0;
+			end
+		end	else	begin
+			pulseDone	=	1'b0;
+		end
+	end	else	begin
+		pulseDone	=	1'b0;
+	end
+end
+
+always	@(posedge	Clk_i)	begin
+	if	(!Rst_i)	begin
+		if	(pulseDone)	begin
+			if	(!patternDone)	begin
+				pulseCnt	<=	pulseCnt+1;
+			end	else	begin
+				pulseCnt	<=	0;
+			end
+		end
+	end	else	begin
+		pulseCnt	<=	0;
+	end
+end
+
+always	@(*)	begin
+	if	(!Rst_i)	begin
+		if	(Mode_i	==	0)	begin
+				currDelValue	=	0;
+				currWidthValue	=	0;
+		end	else	begin
+			if	(Mode_i	>=1 & Mode_i<=3)	begin
+				currDelValue	=	delArray[pulseCnt];
+				currWidthValue	=	widthArray[pulseCnt];
+			end	else	begin
+				if	(Mode_i	==	4|Mode_i	==	5)	begin
+					if	(pulseCnt==0)	begin
+						currDelValue	=	delArray[0];
+						currWidthValue	=	widthArray[0];
+					end	else	begin
+						currDelValue	=	delArray[1];
+						currWidthValue	=	widthArray[0];
+					end	
+				end
+			end
+		end
+	end	else	begin
+		currDelValue	=	0;
+		currWidthValue	=	0;
+	end
+end
+
+always	@(*)	begin
+	if	(!Rst_i)	begin
+		// if	(currState	!=	IDLE)	begin
+			case(Mode_i)
+				8'd0:	begin
+							patternDone	=	0;
+						end
+				8'd1:	begin
+							patternDone	=	((pulseCnt==Mode_i-1)&pulseDone);
+						end
+				8'd2:	begin
+							patternDone	=	((pulseCnt==Mode_i-1)&pulseDone);
+						end
+				8'd3:	begin
+							patternDone	=	((pulseCnt==Mode_i-1)&pulseDone);
+						end
+				8'd4:	begin
+							patternDone	=	((pulseCnt==P2Width_i-1)&pulseDone);
+						end
+				8'd5:	begin
+							patternDone	=	0;
+						end
+				default	:begin
+							patternDone	=	0;
+						end
+			endcase
+		// end	else	begin
+			// patternDone	=	0;
+		// end
+	end	else	begin
+		patternDone	=	0;
+	end
+end
+
+	
+always	@(posedge	Clk_i)	begin
+	if	(!Rst_i)	begin
+		currState	<=	nextState;
+	end	else	begin
+		currState	<=	IDLE;
+	end
+end
+
+always	@(*)	begin
+	nextState	=	IDLE;
+	case(currState)
+	IDLE	:	begin
+					if (enPulseEn)	begin
+						if	(zeroDelay)	begin
+							if	(currWidthValue==1)	begin
+								nextState = DELAY;
+							end	else begin
+								nextState = PULSE;
+							end
+						end	else	if	(singleDelay)	begin
+							nextState	=	PULSE;
+						end	else	begin
+							nextState	=	DELAY;
+						end
+					end	else	begin
+						nextState = IDLE;
+					end
+				end
+				
+	DELAY	:	begin
+					if	(delayDone)	begin
+						nextState = PULSE;
+					end	else begin
+						nextState = DELAY;
+					end
+				end
+
+	PULSE	:	begin
+					if	(pulseDone)	begin
+						if	(!patternDone)	begin
+							nextState  = DELAY;
+						end	else begin
+							nextState  = IDLE;
+						end
+					end	else	begin
+						nextState  = PULSE;
+					end
+				end
+	endcase
+end
+
+always	@(*)	begin
+	if	(!Rst_i)	begin
+		if	(Mode_i	!=	0)	begin
+			case(currState)
+				IDLE:	begin
+							if	(zeroDelay&enPulseEn)	begin
+								pulse	=	1'b1;
+							end	else	begin
+								pulse	=	1'b0;
+							end
+						end
+				DELAY:	begin
+							pulse	=	1'b0;
+						end
+				PULSE:	begin
+							pulse	=	1'b1;
+						end
+				default:begin
+							pulse	=	1'b0;
+						end
+			endcase
+		end	else	begin
+			pulse	=	1'b0;
+		end	
+	end	else	begin
+		pulse	=	1'b0;
+	end
+end
+
+endmodule
+
+
+
+
+
+
+
+
+
+
+

+ 3 - 3
src/src/Sim/BitWidthCalc.m

@@ -18,7 +18,7 @@ Bmax = ceil(log2(((R*M)^N)/R)+B);
 MaxWidthR2 = ceil(log2(((2*M)^N)/2)+B);
 MaxWidthR4 = ceil(log2(((4*M)^N)/4)+B);
 
-ReadFilterCoefsId = fopen('C:\S5243_FFT_REPO\src\src\Sim\R3Test.fcf','r');
+ReadFilterCoefsId = fopen('C:\S5243_FFT_REPO\src\src\Sim\R2Test.fcf','r');
 FilterCoefs = fscanf(ReadFilterCoefsId,FormatSpecR);
 fclose(ReadFilterCoefsId);
 
@@ -27,11 +27,11 @@ CorrValue = 2^18;
 CorrCoeffs = FilterCoefs*CorrValue;
 CorrCoeffs = floor(CorrCoeffs);
 
-WriteFilterCoefsId = fopen('C:\S5243_FFT_REPO\src\src\Sim\R3.txt','w');
+WriteFilterCoefsId = fopen('C:\S5243_FFT_REPO\src\src\Sim\R2.txt','w');
 fprintf(WriteFilterCoefsId,'%d\n', CorrCoeffs);
 fclose(WriteFilterCoefsId);
 
-s=64;
+s=25;
 test = 0;
 
 for c=1:s

+ 59 - 0
src/src/Sim/CicModel.asv

@@ -0,0 +1,59 @@
+M = 2;  % Differential delays in the filter.
+N = 1;  % Filter sections
+R = 1;   % Decimation factor
+
+Pnum = 100;
+
+DeltaPulse = double(zeros(Pnum,1)); 
+DeltaPulse(1) = 1;    % Create a 160-point impulse signal
+
+intBlock1 = int32(zeros(Pnum,1));
+intBlock2 = int32(zeros(Pnum,1));
+intBlock3 = int32(zeros(Pnum,1));
+intBlock4 = int32(zeros(Pnum,1));
+intBlock5 = int32(zeros(Pnum,1));
+
+for i = 1:N
+    if i==1
+        intBlock1(i) = intBlock1(i)+DeltaPulse(i);
+        intBlock2(i) = intBlock2(i)+intBlock1(i);
+        intBlock3(i) = intBlock3(i)+intBlock2(i);
+        intBlock4(i) = intBlock4(i)+intBlock3(i);
+        intBlock5(i) = intBlock5(i)+intBlock4(i);
+    else
+        intBlock1(i) = intBlock1(i-1)+DeltaPulse(i);
+        intBlock2(i) = intBlock2(i-1)+intBlock1(i);
+        intBlock3(i) = intBlock3(i-1)+intBlock2(i);
+        intBlock4(i) = intBlock4(i-1)+intBlock3(i);
+        intBlock5(i) = intBlock5(i-1)+intBlock4(i);
+    end
+end
+
+figure('name','In Data Time', 'Numbertitle', 'off')
+subplot(5,1,1)
+plot(intBlock1)
+subplot(5,1,2)
+plot(intBlock2)
+subplot(5,1,3)
+plot(intBlock3)
+subplot(5,1,4)
+plot(intBlock4)
+subplot(5,1,5)
+plot(intBlock5)
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% figure('name','In Data Time', 'Numbertitle', 'off')
+% subplot(2,1,1)
+% plot(DeltaPulse)
+% grid on;
+% grid minor;
+% title('Delta Pulse')
+% xlabel('Time')
+% ylabel('Amp')
+% 
+% subplot(2,1,2)
+% plot(intBlock1)
+% grid on;
+% grid minor;
+% title('Int Block Out')
+% xlabel('Time')
+% ylabel('Amp')  

+ 59 - 0
src/src/Sim/CicModel.m

@@ -0,0 +1,59 @@
+M = 2;  % Differential delays in the filter.
+N = 1;  % Filter sections
+R = 1;   % Decimation factor
+
+Pnum = 100;
+
+DeltaPulse = int32(zeros(Pnum,1)); 
+DeltaPulse(1) = 1;    % Create a 160-point impulse signal
+
+intBlock1 = int32(zeros(Pnum,1));
+intBlock2 = int32(zeros(Pnum,1));
+intBlock3 = int32(zeros(Pnum,1));
+intBlock4 = int32(zeros(Pnum,1));
+intBlock5 = int32(zeros(Pnum,1));
+
+for i = 1:N
+    if i==1
+        intBlock1(i) = intBlock1(i)+DeltaPulse(i);
+        intBlock2(i) = intBlock2(i)+intBlock1(i);
+        intBlock3(i) = intBlock3(i)+intBlock2(i);
+        intBlock4(i) = intBlock4(i)+intBlock3(i);
+        intBlock5(i) = intBlock5(i)+intBlock4(i);
+    else
+        intBlock1(i) = intBlock1(i-1)+DeltaPulse(i);
+        intBlock2(i) = intBlock2(i-1)+intBlock1(i);
+        intBlock3(i) = intBlock3(i-1)+intBlock2(i);
+        intBlock4(i) = intBlock4(i-1)+intBlock3(i);
+        intBlock5(i) = intBlock5(i-1)+intBlock4(i);
+    end
+end
+
+figure('name','In Data Time', 'Numbertitle', 'off')
+subplot(5,1,1)
+plot(intBlock1)
+subplot(5,1,2)
+plot(intBlock2)
+subplot(5,1,3)
+plot(intBlock3)
+subplot(5,1,4)
+plot(intBlock4)
+subplot(5,1,5)
+plot(intBlock5)
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% figure('name','In Data Time', 'Numbertitle', 'off')
+% subplot(2,1,1)
+% plot(DeltaPulse)
+% grid on;
+% grid minor;
+% title('Delta Pulse')
+% xlabel('Time')
+% ylabel('Amp')
+% 
+% subplot(2,1,2)
+% plot(intBlock1)
+% grid on;
+% grid minor;
+% title('Int Block Out')
+% xlabel('Time')
+% ylabel('Amp')  

+ 39 - 40
src/src/Sim/CicTest.m

@@ -1,7 +1,7 @@
 FormatSpec = '%d';
-PointsNum = 2000;
-N = 8;
-R = 2;
+PointsNum = 500;
+N = 1;
+R = 1;
 B = 16;
 M = 1;
 
@@ -15,7 +15,7 @@ ff = 0:1/PointsNum*2:1-1/PointsNum*2;
 Cw = 18;
 N=65;
 
-Bfir = Cw + ceil(log2(N))
+Bfir = Cw + ceil(log2(N));
 
 ReadInDataId = fopen('C:/S5243_FFT_REPO/src/src/Sim/InputSignal.txt','r');
 InDataSignal = fscanf(ReadInDataId,FormatSpec);
@@ -39,7 +39,7 @@ FilteredDataFft = fft(FilteredData);
 FilteredDataFft = FilteredDataFft(1:FilteredDataPNum/2);
 
 CicResp = 20*log10(abs(FilteredDataFft));
-CicResp = CicResp - max(CicResp)
+CicResp = CicResp - max(CicResp);
 
 Freqs = (Fs*(1:(PointsNum/2))/PointsNum);
 FreqsDecim = Fs/R*(1:(FilteredDataPNum/2))/FilteredDataPNum;
@@ -47,54 +47,53 @@ NormFreqs = FreqsDecim/Fs;
 
 FirResponce = 20 * log10(abs(fft(FilterCoefs, FilteredDataPNum)));
 FirResponce = FirResponce(1:FilteredDataPNum/2);
-FirResponce = FirResponce-max(FirResponce)
+FirResponce = FirResponce-max(FirResponce);
 
 CicComp = CicResp + FirResponce;
 CicComp = CicComp - max(CicComp);
 
-##figure('name','CIC/FIR Frequency Response', 'Numbertitle', 'off')
-##  plot(FreqsDecim, FirResponce, '-.', 'LineWidth', 2, 'Color',[0 0 1]);
-##  hold on;
-##
-##  plot(FreqsDecim, CicComp, '--', 'LineWidth', 2, 'Color',[0.2 0.5 0]);
-##  hold on;
-##
-##  plot(FreqsDecim, CicResp, '-', 'LineWidth', 2, 'Color',[1 0 0]);
-##  hold on;
-##
-##  title([{'CIC, Comp. FIR and Result'};{sprintf('Filter Order = %i',N)}]);
-##  xlabel ('Freq (\pi x rad / samples)');
-##  ylabel ('Magnitude (dB)');
-##  legend('Comp. FIR','Sum Response','CIC filter','location','northeast');
-##  grid on;
+figure('name','CIC/FIR Frequency Response', 'Numbertitle', 'off')
+plot(FreqsDecim, FirResponce, '-.', 'LineWidth', 2, 'Color',[0 0 1]);
+hold on;
 
+plot(FreqsDecim, CicComp, '--', 'LineWidth', 2, 'Color',[0.2 0.5 0]);
+hold on;
+
+plot(FreqsDecim, CicResp, '-', 'LineWidth', 2, 'Color',[1 0 0]);
+hold on;
+
+title([{'CIC, Comp. FIR and Result'};{sprintf('Filter Order = %i',N)}]);
+xlabel ('Freq (\pi x rad / samples)');
+ylabel ('Magnitude (dB)');
+legend('Comp. FIR','Sum Response','CIC filter','location','northeast');
+grid on;
 
 
 Hcic = abs((sin(pi*M*R*ff) ./ sin(pi*ff))).^N;
 Hcicdb = 20 * log10(abs(Hcic));
 Hcicdb = Hcicdb - max(Hcicdb);
-HcicdbCut = Hcicdb(1:500);
+HcicdbCut = Hcicdb(1:PointsNum/2);
 
 
 figure('name','Cic Calc and Cic Real', 'Numbertitle', 'off')
-  plot(FreqsDecim,HcicdbCut, '-.', 'LineWidth', 2, 'Color',[0 0 1]);
-  hold on;
-
-  plot(FreqsDecim,CicResp, '--', 'LineWidth', 2, 'Color',[0.2 0.5 0]);
-  hold on;
-
-  title([{'CIC calc, CIC real'};{sprintf('Filter Order = %i',N)}]);
-  xlabel ('Freq (\pi x rad / samples)');
-  ylabel ('Magnitude (dB)');
-  legend('CIC calc','CIC real','location','northeast');
-  grid on;
-
-##figure(1)
-##plot(FreqsDecim,HcicdbCut, '-.', 'LineWidth', 2, 'Color',[0 0 1]);
-##
-##figure(2)
-##plot(FreqsDecim,CicResp, '-.', 'LineWidth', 2, 'Color',[0 0 1]);
-##
+plot(FreqsDecim,HcicdbCut, '-.', 'LineWidth', 2, 'Color',[0 0 1]);
+hold on;
+
+plot(FreqsDecim,CicResp, '--', 'LineWidth', 2, 'Color',[0.2 0.5 0]);
+hold on;
+
+title([{'CIC calc, CIC real'};{sprintf('Filter Order = %i',N)}]);
+xlabel ('Freq (\pi x rad / samples)');
+ylabel ('Magnitude (dB)');
+legend('CIC calc','CIC real','location','northeast');
+grid on;
+
+figure(1)
+plot(FreqsDecim,HcicdbCut, '-.', 'LineWidth', 2, 'Color',[0 0 1]);
+
+figure(2)
+plot(FreqsDecim,CicResp, '-.', 'LineWidth', 2, 'Color',[0 0 1]);
+
 
 
 

+ 36 - 4
src/src/Sim/CicTestMatlab.m

@@ -1,11 +1,43 @@
 m = 2;  % Differential delays in the filter.
 n = 4;  % Filter sections
-r = 8;   % Decimation factor
+r = 1;   % Decimation factor
 x = int16(zeros(160,1)); x(1) = 1;    % Create a 160-point
                                       % impulse signal.
 hm = mfilt.cicdecim(r,m,n); % Expects 16-bit input
                             % by default.
 y = filter(hm,x);
-stem(double(y));    % Plot output as a stem plot.
-xlabel('Samples'); ylabel('Amplitude');
-title('Decimated Signal');
+yCorr = double(y);
+
+% stem(yCorr);    % Plot output as a stem plot.
+% xlabel('Samples'); ylabel('Amplitude');
+% title('Decimated Signal');
+
+FilteredDataFft = abs(fft(yCorr));
+FilteredDataFftDb = 20*log10(FilteredDataFft);
+FilteredDataFftDb = FilteredDataFftDb-max(FilteredDataFftDb);
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+figure('name','In Data Time/Freq', 'Numbertitle', 'off')
+subplot(3,1,1)
+plot(x)
+grid on;
+grid minor;
+title('In Signal')
+xlabel('Time')
+ylabel('Amp')
+
+subplot(3,1,2)
+plot(yCorr)
+grid on;
+grid minor;
+title('Imp Resp')
+xlabel('Time')
+ylabel('Amp')
+
+subplot(3,1,3)
+plot(FilteredDataFftDb)
+grid on;
+grid minor;
+title('Filtered Data')
+xlabel('Time')
+ylabel('Amp')

+ 74 - 78
src/src/Sim/DecimFilterWrapperTb.v

@@ -7,6 +7,7 @@ reg		Rst;
 
 reg		[2:0]	decimFactor;
 
+parameter	MaxWidth	=	32;
 
 reg		[13:0]	adcData;
 real	pi	=	3.14159265358;
@@ -16,8 +17,8 @@ real	signal;
 
 reg		[31:0]	tbCnt;
 reg		[31:0]	pNumCnt;
-// wire	oscWind	=	(tbCnt==4505)?	1'b1:1'b0;
-wire	oscWind	=	(tbCnt>=4500&tbCnt<=4999)||(tbCnt>=5500&tbCnt<=5999)||(tbCnt>=6500&tbCnt<=6999)||(tbCnt>=7500&tbCnt<=7999)||(tbCnt>=8500&tbCnt<=8999)||(tbCnt>=9500&tbCnt<=9999)?	1'b1:1'b0;
+wire	oscWind	=	(tbCnt>=4500&tbCnt<=4999)?	1'b1:1'b0;
+// wire	oscWind	=	(tbCnt>=4500&tbCnt<=4999)||(tbCnt>=5500&tbCnt<=5999)||(tbCnt>=6500&tbCnt<=6999)||(tbCnt>=7500&tbCnt<=7999)||(tbCnt>=8500&tbCnt<=8999)||(tbCnt>=9500&tbCnt<=9999)?	1'b1:1'b0;
 // wire	oscWind	=	(tbCnt>=1&)?	1'b1:1'b0;
 
 wire	signed	[13:0]	ncoSin1;
@@ -25,7 +26,7 @@ wire	signed	[13:0]	ncoSin2;
 wire	signed	[13:0]	ncoSin3;
 
 wire	signed	[15:0]	filteredDataOut;
-wire	signed	[15:0]	impResponse;
+wire	signed	[MaxWidth-1:0]	impResponse;
 
 wire	resultVal;
 wire	respVal;
@@ -46,7 +47,7 @@ reg		signed	[13:0]	currTestData;
 wire	signed	[17:0]	wind;
 
 // wire	signed	[13:0]	singlePulse	=	(tbCnt>=4500&tbCnt<=4550)?	14'h1fff:14'h0;
-wire	signed	[13:0]	singlePulse	=	(tbCnt==5550)?	14'h1fff:14'h0;
+wire	signed	[13:0]	singlePulse	=	(tbCnt==4551)?	14'h1fff:14'h0;
 wire	signed	[17:0]	singlePulseExt	=	(tbCnt==4500)?	18'h1ffff:14'h0;
 // wire	signed	[15:0]	singlePulseExt	=	(tbCnt>=4500&tbCnt<=4501)?	16'h7fff:14'h0;
 wire	inglePulseExtVal	=	(tbCnt==4500)?	1:0;
@@ -55,18 +56,17 @@ wire	inglePulseExtVal	=	(tbCnt==4500)?	1:0;
 always	#10 Clk50	=	~Clk50;
 
 //==========================================================================================
-parameter	N	=	4;
-parameter	M	=	1;
+parameter	N	=	8;
+parameter	M	=	2;
+
 
-parameter	MaxWidth	=	18;
 
 parameter	LsbForR1	=	10'd16;
 parameter	LsbForR2	=	10'd18;
 parameter	LsbForR4	=	10'd18;
 	
-parameter	[31:0]	Nco1PhaseInc	=	32'ha0000000;	
-// parameter	[31:0]	Nco2PhaseInc	=	32'h428f5c28;	
-parameter	[31:0]	Nco2PhaseInc	=	32'hf5c28f5;	
+parameter	[31:0]	Nco1PhaseInc	=	32'h051eb852;	 //3mhz
+parameter	[31:0]	Nco2PhaseInc	=	32'h40000000;	//15
 parameter	[31:0]	Nco3PhaseInc	=	32'h428f5c28;	
 
 initial begin
@@ -111,7 +111,7 @@ end
 always @ (posedge Clk50)	begin
 	if (oscWind)	begin
 			phase = phase + phaseInc;
-			phaseInc <= phaseInc + 0.0005;
+			phaseInc <= phaseInc + 0.003;
 			signal = $sin(2*pi*phase);
 			adcData = 2**12 * signal;
 	end	else	begin
@@ -124,18 +124,23 @@ end
 always	@(posedge	Clk50)	begin
 	if	(!Rst)	begin
 		if (tbCnt == 100) begin
-			decimFactor	<= 1;
-		end else if (tbCnt == 5400) begin
 			decimFactor	<= 2;
-		end else if (tbCnt == 6400) begin
-			decimFactor	<= 3;
-		end else if (tbCnt == 7400) begin
-			decimFactor	<= 5;
-		end else if (tbCnt == 8400) begin
-			decimFactor	<= 6;
-		end else if (tbCnt == 9400) begin
-			decimFactor	<= 7;
-		end 
+		end
+		// end else if (tbCnt == 5400) begin
+			// decimFactor	<= 1;
+		// end else if (tbCnt == 6400) begin
+			// decimFactor	<= 2;
+		// end else if (tbCnt == 7400) begin
+			// decimFactor	<= 3;
+		// end else if (tbCnt == 8400) begin
+			// decimFactor	<= 4;
+		// end else if (tbCnt == 9400) begin
+			// decimFactor	<= 5;
+		// end else if (tbCnt == 10400) begin
+			// decimFactor	<= 6;
+		// end else if (tbCnt == 11400) begin
+			// decimFactor	<= 7;
+		// end
 	end else begin
 	 decimFactor <= 2;
 	end 
@@ -205,7 +210,7 @@ ncoInst3
 );
 
 
-DecimFilterWrapper	
+DecimFilterWrapperTest	
 #(	
 	.AdcDataWidth	(14),
 	.N	(N),
@@ -225,15 +230,15 @@ DecimFilter
 	.DataVal_i		(oscWind),
 
 	// .Data_i		(sinAdd),
-	// .Data_i		(adcDataMixedCut),
+	.Data_i		(adcDataMixedCut),
 	// .Data_i		(adcData),
-	.Data_i		(ncoSin2),
+	// .Data_i		(ncoSin2),
 	
 	.Data_o	(filteredDataOut),
 	.DataVal_o	(resultVal)
 );
 
-DecimFilterWrapper	
+DecimFilterWrapperTest	
 #(	
 	.AdcDataWidth	(14),
 	.N	(N),
@@ -283,8 +288,8 @@ ImpulseResponseFilter
 	
 
 
-// integer inSignal,filteredData, impResp;
-// parameter	PNum	=	5000;
+integer inSignal,filteredData, impResp;
+parameter	PNum	=	5000;
 
 // wire	signed	[17:0]	firDataOut;
 // wire	signed	[17:0]	firRespout;
@@ -311,65 +316,56 @@ ImpulseResponseFilter
 
 
 
-// always	@(posedge	Clk50)	begin
-	// if	(Rst)	begin
-		// inSignal = $fopen("C:/S5243_FFT_REPO/src/src/Sim/InputSignal.txt","w");
-	// end	else	begin
-		// if	(oscWind)	begin
+always	@(posedge	Clk50)	begin
+	if	(tbCnt==32'd1)	begin
+		inSignal = $fopen("C:/S5243_FFT_REPO/src/src/Sim/InputSignal.txt","w");
+	end	else	begin
+		if	(oscWind)	begin
 			// $display("AdcData is %d", sinAdd);
 			// $fwrite(inSignal,"%d\n",   sinAddExt18);
-			// $fwrite(inSignal,"%d\n",   sinAdd);
-		// end	
-	// end	
-// end
+			$fwrite(inSignal,"%d\n",   adcDataMixedCut);
+			// $fwrite(inSignal,"%d\n",   adcData);
+		end	
+	end	
+end
 
-// reg	[31:0]	testCnt;
-// wire	[10:0]	test = N*2+N*2+decimFactor;
-// wire	[10:0]	test1 = N*2+N*2+decimFactor-1;
-// wire	writeEn	=	(oscWindDelay[N*2+N*2+decimFactor]);
+reg	[31:0]	testCnt;
+wire	[10:0]	test = N*2+N*2+decimFactor;
+wire	[10:0]	test1 = N*2+N*2+decimFactor-1;
+wire	writeEn	=	(oscWindDelay[N*2+N*2+decimFactor]);
 
-// always	@(posedge	Clk50)begin
-	// if	(!Rst)	begin
-		// if	(writeEn)	begin
-			// testCnt	<=	testCnt	+1;
-		// end
-	// end	else	begin
-		// testCnt	<=	0;
-	// end
-// end
+always	@(posedge	Clk50)begin
+	if	(!Rst)	begin
+		if	(writeEn)	begin
+			testCnt	<=	testCnt	+1;
+		end
+	end	else	begin
+		testCnt	<=	0;
+	end
+end
 
-// always	@(posedge	Clk50)	begin
-	// if	(Rst)	begin
-		// filteredData = $fopen("C:/S5243_FFT_REPO/src/src/Sim/FilteredData.txt","w");
-	// end	else	begin
-		// if	(firDataVal)	begin
-			// $fwrite(filteredData,"%d\n",   filteredDataOut);
+always	@(posedge	Clk50)	begin
+	if	(tbCnt==32'd1)	begin
+		filteredData = $fopen("C:/S5243_FFT_REPO/src/src/Sim/FilteredData.txt","w");
+	end	else	begin
+		if	(resultVal)	begin
+			$fwrite(filteredData,"%d\n",   filteredDataOut);
 			// $fwrite(filteredData,"%d\n",   firDataOut);
-		// end	
-	// end	
-// end
+		end	
+	end	
+end
  
 
-// always	@(posedge	Clk50)	begin
-	// if	(Rst)	begin
-		// impResp = $fopen("C:/S5243_FFT_REPO/src/src/Sim/ImpResp.txt","w");
-	// end	else	begin
-		// if	(firDataVal)	begin
+always	@(posedge	Clk50)	begin
+	if	(tbCnt==32'd1)	begin
+		impResp = $fopen("C:/S5243_FFT_REPO/src/src/Sim/ImpResp.txt","w");
+	end	else	begin
+		if	(resultVal)	begin
 			// $fwrite(impResp,"%d\n",   firRespout);
-			// $fwrite(impResp,"%d\n",   m_axis_data_tdata_imp);
-		// end	
-	// end
-// end 
-
-// always	@(posedge	Clk50)	begin
-	// if	(Rst)	begin
-		// filteredData = $fopen("C:/Users/Stepan/Desktop/4portCompact/S5443Current/S5443_M/S5443.srcs/sources_1/new/filteredData.txt","w");
-	// end	else	begin
-		// if	(windResultVal)	begin
-			// $fwrite(filteredData,"%d\n",   windResultCut);
-		// end	
-	// end	
-// end 
+			$fwrite(impResp,"%d\n",   impResponse);
+		end	
+	end
+end 
 
 endmodule
 

+ 56 - 52
src/src/Sim/FFTTest.m

@@ -3,14 +3,17 @@ FormatSpec = '%d';
 N = 4;
 R = 2;
 B = 16;
-M = 1;
+M = 2;
 
-PointsNum = 2000;
+PointsNum = 500;
 
-Bmax = ceil(log2(((R*M)^N)/R)+B)
-MaxWidthR2 = ceil(log2(((2*M)^N)/2)+B)
-MaxWidthR4 = ceil(log2(((4*M)^N)/4)+B)
+Bmax = ceil(log2(((R*M)^N)/R)+B);
+MaxWidthR2 = ceil(log2(((2*M)^N)/2)+B);
+MaxWidthR4 = ceil(log2(((4*M)^N)/4)+B);
 
+K = N*20*log10(M);
+BitGrowth = ceil(2^(K/20));
+Bnew = B+BitGrowth;
 
 x = 1:1:PointsNum;
 xDecim = 1:1:PointsNum/R;
@@ -53,7 +56,7 @@ ImpuseRespFft = abs(fft(ImpulseResp));
 ImpuseRespFftDb = 20*log10(ImpuseRespFft);
 ImpuseRespFftDb = ImpuseRespFftDb-max(ImpuseRespFftDb);
 
-Fband = 0:1/PointsNum:1-1/PointsNum;
+Fband = 0:1/PointsNum*R:1-1/PointsNum*R;
 %Fband = 0:1/PointsNum:0.5-1/PointsNum;
 
 %InDataFftDb = InDataFftDb(1:length(Fband));
@@ -61,67 +64,68 @@ Fband = 0:1/PointsNum:1-1/PointsNum;
 %ImpuseRespFftDb = ImpuseRespFftDb(1:length(Fband));
 
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%figure('name','In Data Time/Freq', 'Numbertitle', 'off')
-%subplot(2,1,1)
-%plot(x, InDataSignal)
-%grid on;
-%grid minor;
-%title("In Signal")
-%xlabel("Time")
-%ylabel("Amp")
-%
-%subplot(2,1,2)
-%plot(Fband,InDataFftDb)
-%grid on;
-%grid minor;
-%title("Single-Sided Amplitude Spectrum of InData")
-%xlabel("f (Hz)")
-%ylabel("Amp")
+figure('name','In Data Time/Freq', 'Numbertitle', 'off')
+subplot(2,1,1)
+plot(InDataSignal)
+grid on;
+grid minor;
+title('In Signal')
+xlabel('Time')
+ylabel('Amp')
+
+subplot(2,1,2)
+plot(FilteredData)
+grid on;
+grid minor;
+title('Filtered Data')
+xlabel('Time')
+ylabel('Amp')
 
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 figure('name','Frequency compare', 'Numbertitle', 'off')
 subplot(3,1,1)
-plot(Fband,InDataFftDb)
+plot(InDataFftDb)
 grid on;
 grid minor;
-%axis([0 25 -70 80]);
-title("Single-Sided Amplitude Spectrum of Data before filter")
-xlabel("Time")
-ylabel("Amp")
+% axis([0 25 -70 80]);
+title('Single-Sided Amplitude Spectrum of Data before filter')
+xlabel('Time')
+ylabel('Amp')
 
 subplot(3,1,2)
 plot(Fband,ImpuseRespFftDb)
 grid on;
 grid minor;
-%axis([0 50 -60 1]);
-title("Cic Frequency response")
-xlabel("f (Hz)")
-ylabel("Amp")
+% axis([0 50 -60 1]);
+title('Cic Frequency response')
+xlabel('f (Hz)')
+ylabel('Amp')
 
 subplot(3,1,3)
 plot(Fband,FilteredDataFftDb)
 grid on;
 grid minor;
-%axis([0 25 -70 80]);
-title("Single-Sided Amplitude Spectrum of Data after filter")
-xlabel("f (Hz)")
-ylabel("Amp")
-
-%figure('name','Impulse Response Time/Freq', 'Numbertitle', 'off')
-%subplot(2,1,1)
-%plot(x, ImpulseResp)
-%grid on;
-%grid minor;
-%title("In Signal")
-%xlabel("Time")
-%ylabel("Amp")
-%
-%subplot(2,1,2)
-%plot(Fband,ImpuseRespFftDb)
-%grid on;
-%grid minor;
-%title("Single-Sided Amplitude Spectrum of InData")
-%xlabel("f (Hz)")
-%ylabel("Amp")
+% axis([0 25 -70 80]);
+title('Single-Sided Amplitude Spectrum of Data after filter')
+xlabel('f (Hz)')
+ylabel('Amp')
+
+% figure('name','Impulse Response Time/Freq', 'Numbertitle', 'off')
+% subplot(2,1,1)
+% plot( ImpulseResp)
+% grid on;
+% grid minor;
+% title('In Signal')
+% xlabel('Time')
+% ylabel('Amp')
+
+% subplot(2,1,2)
+% plot(Fband,ImpuseRespFftDb)
+% grid on;
+% grid minor;
+% title('Single-Sided Amplitude Spectrum of InData')
+% xlabel('f (Hz)')
+% ylabel('Amp')
 
 
 

Rozdílová data souboru nebyla zobrazena, protože soubor je příliš velký
+ 250 - 4000
src/src/Sim/FilteredData.txt


+ 26 - 391
src/src/Sim/FiltersCoeffs.coe

@@ -1,391 +1,26 @@
-MEMORY_INITIALIZATION_RADIX =16;
-MEMORY_INITIALIZATION_VECTOR =002fd,
-00f3e,
-013ef,
-006f0,
-3f248,
-3f30a,
-00bcc,
-01664,
-3fa36,
-3de4b,
-3f843,
-02d1e,
-021a2,
-3c919,
-3a7f7,
-03d7b,
-13ec9,
-1c034,
-13ec9,
-03d7b,
-3a7f7,
-3c919,
-021a2,
-02d1e,
-3f843,
-3de4b,
-3fa36,
-01664,
-00bcc,
-3f30a,
-3f248,
-006f0,
-013ef,
-00f3e,
-002fd,
-00496,
-001e6,
-3fbce,
-3f219,
-3ea9f,
-3ec8e,
-3fab5,
-00f11,
-01c25,
-01515,
-3f855,
-3d54e,
-3c728,
-3e5cc,
-03549,
-09eb7,
-0f8b7,
-11c0e,
-0f8b7,
-09eb7,
-03549,
-3e5cc,
-3c728,
-3d54e,
-3f855,
-01515,
-01c25,
-00f11,
-3fab5,
-3ec8e,
-3ea9f,
-3f219,
-3fbce,
-001e6,
-00496,
-3ff9f,
-0022d,
-004f5,
-0067b,
-00592,
-00245,
-3fe3a,
-3fbee,
-3fd27,
-0017c,
-00622,
-0077d,
-003af,
-3fc6b,
-3f67d,
-3f6d3,
-3feb8,
-009e7,
-01063,
-00b8b,
-3fb89,
-3e93d,
-3e2a4,
-3f310,
-01b7e,
-04ffb,
-07c40,
-08d8a,
-07c40,
-04ffb,
-01b7e,
-3f310,
-3e2a4,
-3e93d,
-3fb89,
-00b8b,
-01063,
-009e7,
-3feb8,
-3f6d3,
-3f67d,
-3fc6b,
-003af,
-0077d,
-00622,
-0017c,
-3fd27,
-3fbee,
-3fe3a,
-00245,
-00592,
-0067b,
-004f5,
-0022d,
-3ff9f,
-3fe36,
-3fe08,
-3fe99,
-3ff4e,
-3ffc9,
-3fff0,
-3fffa,
-00026,
-00095,
-0015c,
-00279,
-003c3,
-004e5,
-00573,
-00505,
-00368,
-000c3,
-3fdaa,
-3fb06,
-3f9d3,
-3fac5,
-3fdf0,
-00298,
-00742,
-00a1a,
-0098e,
-004fb,
-3fd20,
-3f436,
-3ed7a,
-3ec58,
-3f350,
-0030c,
-019de,
-033ee,
-04c14,
-05d23,
-0634a,
-05d23,
-04c14,
-033ee,
-019de,
-0030c,
-3f350,
-3ec58,
-3ed7a,
-3f436,
-3fd20,
-004fb,
-0098e,
-00a1a,
-00742,
-00298,
-3fdf0,
-3fac5,
-3f9d3,
-3fb06,
-3fdaa,
-000c3,
-00368,
-00505,
-00573,
-004e5,
-003c3,
-00279,
-0015c,
-00095,
-00026,
-3fffa,
-3fff0,
-3ffe1,
-3ffb4,
-3ff67,
-3fefc,
-3fe7a,
-3fdf6,
-3fd8f,
-3fd6d,
-3fdb6,
-3fe87,
-3ffea,
-001c8,
-003e7,
-005ee,
-0076f,
-007f9,
-00734,
-004fa,
-0016d,
-3fcff,
-3f870,
-3f4b7,
-3f2df,
-3f3d5,
-3f83b,
-0003d,
-00b7b,
-01906,
-0277c,
-03535,
-04082,
-047f1,
-04a89,
-047f1,
-04082,
-03535,
-0277c,
-01906,
-00b7b,
-0003d,
-3f83b,
-3f3d5,
-3f2df,
-3f4b7,
-3f870,
-3fcff,
-0016d,
-004fa,
-00734,
-007f9,
-0076f,
-005ee,
-003e7,
-001c8,
-3ffea,
-3fe87,
-3fdb6,
-3fd6d,
-3fd8f,
-3fdf6,
-3fe7a,
-3fefc,
-3ff67,
-3ffb4,
-3ffe1,
-0001b,
-0003a,
-00072,
-000c2,
-0012c,
-001ab,
-00235,
-002b9,
-00323,
-00356,
-0033a,
-002b4,
-001b6,
-0003b,
-3fe51,
-3fc18,
-3f9c5,
-3f79f,
-3f5f6,
-3f524,
-3f578,
-3f737,
-3fa88,
-3ff72,
-005d4,
-00d64,
-015b5,
-01e3c,
-0265c,
-02d7a,
-03305,
-0368a,
-037bf,
-0368a,
-03305,
-02d7a,
-0265c,
-01e3c,
-015b5,
-00d64,
-005d4,
-3ff72,
-3fa88,
-3f737,
-3f578,
-3f524,
-3f5f6,
-3f79f,
-3f9c5,
-3fc18,
-3fe51,
-0003b,
-001b6,
-002b4,
-0033a,
-00356,
-00323,
-002b9,
-00235,
-001ab,
-0012c,
-000c2,
-00072,
-0003a,
-0001b,
-0000a,
-3fffb,
-3ffeb,
-3ffce,
-3ff9e,
-3ff56,
-3fef3,
-3fe72,
-3fdd3,
-3fd19,
-3fc4c,
-3fb77,
-3faaa,
-3f9f9,
-3f97d,
-3f94f,
-3f98a,
-3fa45,
-3fb96,
-3fd89,
-00026,
-00369,
-00742,
-00b97,
-01044,
-0151c,
-019ec,
-01e7b,
-02293,
-02600,
-02895,
-02a30,
-02abb,
-02a30,
-02895,
-02600,
-02293,
-01e7b,
-019ec,
-0151c,
-01044,
-00b97,
-00742,
-00369,
-00026,
-3fd89,
-3fb96,
-3fa45,
-3f98a,
-3f94f,
-3f97d,
-3f9f9,
-3faaa,
-3fb77,
-3fc4c,
-3fd19,
-3fdd3,
-3fe72,
-3fef3,
-3ff56,
-3ff9e,
-3ffce,
-3ffeb,
-3fffb,
-0000a;
+MEMORY_INITIALIZATION_RADIX =10;
+MEMORY_INITIALIZATION_VECTOR =1854,
+6759,
+4998,
+-2562,
+-7592,
+-2,
+11387,
+6413,
+-15089,
+-20836,
+17723,
+80972,
+112397,
+80972,
+17723,
+-20836,
+-15089,
+6413,
+11387,
+-2,
+-7592,
+-2562,
+4998,
+6759,
+1854;

Rozdílová data souboru nebyla zobrazena, protože soubor je příliš velký
+ 250 - 4000
src/src/Sim/ImpResp.txt


Rozdílová data souboru nebyla zobrazena, protože soubor je příliš velký
+ 500 - 4000
src/src/Sim/InputSignal.txt


+ 25 - 0
src/src/Sim/R2.txt

@@ -0,0 +1,25 @@
+1854
+6759
+4998
+-2562
+-7592
+-2
+11387
+6413
+-15089
+-20836
+17723
+80972
+112397
+80972
+17723
+-20836
+-15089
+6413
+11387
+-2
+-7592
+-2562
+4998
+6759
+1854

+ 25 - 64
src/src/Sim/R2Test.fcf

@@ -1,67 +1,28 @@
- 0.00107574462890625                                                           
- 0.0037841796875                                                               
- 0.00572967529296875                                                           
- 0.002197265625                                                                
--0.00731658935546875                                                           
--0.014739990234375                                                             
--0.0111541748046875                                                            
- 0                                                                             
- 0.0045318603515625                                                            
--0.00325775146484375                                                           
--0.0103759765625                                                               
--0.0035552978515625                                                            
- 0.00838470458984375                                                           
- 0.005828857421875                                                             
--0.00910186767578125                                                           
--0.01177978515625                                                              
- 0.00559234619140625                                                           
- 0.016143798828125                                                             
--0.000823974609375                                                             
--0.0207061767578125                                                            
--0.00753021240234375                                                           
- 0.02294158935546875                                                           
- 0.01874542236328125                                                           
--0.02227783203125                                                              
--0.03399658203125                                                              
- 0.0161590576171875                                                            
- 0.05472564697265625                                                           
--0.0002899169921875                                                            
--0.08820343017578125                                                           
--0.0429840087890625                                                            
- 0.18334197998046875                                                           
- 0.40891265869140625                                                           
- 0.40891265869140625                                                           
- 0.18334197998046875                                                           
--0.0429840087890625                                                            
--0.08820343017578125                                                           
--0.0002899169921875                                                            
- 0.05472564697265625                                                           
- 0.0161590576171875                                                            
--0.03399658203125                                                              
--0.02227783203125                                                              
- 0.01874542236328125                                                           
- 0.02294158935546875                                                           
--0.00753021240234375                                                           
--0.0207061767578125                                                            
--0.000823974609375                                                             
- 0.016143798828125                                                             
- 0.00559234619140625                                                           
--0.01177978515625                                                              
--0.00910186767578125                                                           
- 0.005828857421875                                                             
- 0.00838470458984375                                                           
--0.0035552978515625                                                            
--0.0103759765625                                                               
--0.00325775146484375                                                           
- 0.0045318603515625                                                            
- 0                                                                             
--0.0111541748046875                                                            
--0.014739990234375                                                             
--0.00731658935546875                                                           
- 0.002197265625                                                                
- 0.00572967529296875                                                           
- 0.0037841796875                                                               
- 0.00107574462890625                                                           
+ 0.00707244873046875                                                           
+ 0.025783538818359375                                                          
+ 0.01906585693359375                                                           
+-0.00977325439453125                                                           
+-0.028961181640625                                                             
+-0.00000762939453125                                                           
+ 0.043437957763671875                                                          
+ 0.024463653564453125                                                          
+-0.057559967041015625                                                          
+-0.0794830322265625                                                            
+ 0.067607879638671875                                                          
+ 0.3088836669921875                                                            
+ 0.42876052856445313                                                           
+ 0.3088836669921875                                                            
+ 0.067607879638671875                                                          
+-0.0794830322265625                                                            
+-0.057559967041015625                                                          
+ 0.024463653564453125                                                          
+ 0.043437957763671875                                                          
+-0.00000762939453125                                                           
+-0.028961181640625                                                             
+-0.00977325439453125                                                           
+ 0.01906585693359375                                                           
+ 0.025783538818359375                                                          
+ 0.00707244873046875                                                           
 
                                                                               
 

+ 64 - 0
src/src/Sim/R4.txt

@@ -0,0 +1,64 @@
+-14
+54
+214
+531
+1022
+1643
+2265
+2693
+2710
+2159
+1030
+-483
+-1989
+-2990
+-3041
+-1936
+151
+2633
+4635
+5257
+3910
+616
+-3848
+-8044
+-10211
+-8784
+-2919
+7127
+19909
+33060
+43863
+49951
+49951
+43863
+33060
+19909
+7127
+-2919
+-8784
+-10211
+-8044
+-3848
+616
+3910
+5257
+4635
+2633
+151
+-1936
+-3041
+-2990
+-1989
+-483
+1030
+2159
+2710
+2693
+2265
+1643
+1022
+531
+214
+54
+-14

+ 67 - 0
src/src/Sim/R4Test.fcf

@@ -0,0 +1,67 @@
+-0.0000514984130859375                                                         
+ 0.00020599365234375                                                           
+ 0.00081634521484375                                                           
+ 0.002025604248046875                                                          
+ 0.0039005279541015625                                                         
+ 0.006267547607421875                                                          
+ 0.008640289306640625                                                          
+ 0.010272979736328125                                                          
+ 0.01033782958984375                                                           
+ 0.008235931396484375                                                          
+ 0.00392913818359375                                                           
+-0.0018405914306640625                                                         
+-0.0075855255126953125                                                         
+-0.0114040374755859375                                                         
+-0.0115985870361328125                                                         
+-0.0073833465576171875                                                         
+ 0.000576019287109375                                                          
+ 0.010044097900390625                                                          
+ 0.0176830291748046875                                                         
+ 0.0200557708740234375                                                         
+ 0.01491546630859375                                                           
+ 0.002349853515625                                                             
+-0.014678955078125                                                             
+-0.0306835174560546875                                                         
+-0.038951873779296875                                                          
+-0.03350830078125                                                              
+-0.0111331939697265625                                                         
+ 0.0271892547607421875                                                         
+ 0.075946807861328125                                                          
+ 0.1261157989501953125                                                         
+ 0.167324066162109375                                                          
+ 0.190547943115234375                                                          
+ 0.190547943115234375                                                          
+ 0.167324066162109375                                                          
+ 0.1261157989501953125                                                         
+ 0.075946807861328125                                                          
+ 0.0271892547607421875                                                         
+-0.0111331939697265625                                                         
+-0.03350830078125                                                              
+-0.038951873779296875                                                          
+-0.0306835174560546875                                                         
+-0.014678955078125                                                             
+ 0.002349853515625                                                             
+ 0.01491546630859375                                                           
+ 0.0200557708740234375                                                         
+ 0.0176830291748046875                                                         
+ 0.010044097900390625                                                          
+ 0.000576019287109375                                                          
+-0.0073833465576171875                                                         
+-0.0115985870361328125                                                         
+-0.0114040374755859375                                                         
+-0.0075855255126953125                                                         
+-0.0018405914306640625                                                         
+ 0.00392913818359375                                                           
+ 0.008235931396484375                                                          
+ 0.01033782958984375                                                           
+ 0.010272979736328125                                                          
+ 0.008640289306640625                                                          
+ 0.006267547607421875                                                          
+ 0.0039005279541015625                                                         
+ 0.002025604248046875                                                          
+ 0.00081634521484375                                                           
+ 0.00020599365234375                                                           
+-0.0000514984130859375                                                         
+
+                                                                              
+

+ 64 - 0
src/src/Sim/R6.txt

@@ -0,0 +1,64 @@
+57
+121
+232
+388
+587
+817
+1054
+1261
+1393
+1398
+1225
+834
+204
+-657
+-1705
+-2857
+-3991
+-4957
+-5585
+-5704
+-5165
+-3858
+-1735
+1180
+4782
+8885
+13240
+17548
+21494
+24772
+27119
+28344
+28344
+27119
+24772
+21494
+17548
+13240
+8885
+4782
+1180
+-1735
+-3858
+-5165
+-5704
+-5585
+-4957
+-3991
+-2857
+-1705
+-657
+204
+834
+1225
+1398
+1393
+1261
+1054
+817
+587
+388
+232
+121
+57

+ 67 - 0
src/src/Sim/R6Test.fcf

@@ -0,0 +1,67 @@
+ 0.0002193450927734375                                                         
+ 0.00046253204345703125                                                        
+ 0.000885009765625                                                             
+ 0.00148105621337890625                                                        
+ 0.0022411346435546875                                                         
+ 0.00311946868896484375                                                        
+ 0.0040225982666015625                                                         
+ 0.00481319427490234375                                                        
+ 0.0053157806396484375                                                         
+ 0.00533390045166015625                                                        
+ 0.00467395782470703125                                                        
+ 0.00318145751953125                                                           
+ 0.0007781982421875                                                            
+-0.00250530242919921875                                                        
+-0.0065021514892578125                                                         
+-0.01089572906494140625                                                        
+-0.01522350311279296875                                                        
+-0.01890850067138671875                                                        
+-0.0213031768798828125                                                         
+-0.02175807952880859375                                                        
+-0.01970195770263671875                                                        
+-0.01471710205078125                                                           
+-0.0066165924072265625                                                         
+ 0.00450420379638671875                                                        
+ 0.01824188232421875                                                           
+ 0.0338954925537109375                                                         
+ 0.05050754547119140625                                                        
+ 0.06694316864013671875                                                        
+ 0.0819950103759765625                                                         
+ 0.0944995880126953125                                                         
+ 0.10345363616943359375                                                        
+ 0.10812473297119140625                                                        
+ 0.10812473297119140625                                                        
+ 0.10345363616943359375                                                        
+ 0.0944995880126953125                                                         
+ 0.0819950103759765625                                                         
+ 0.06694316864013671875                                                        
+ 0.05050754547119140625                                                        
+ 0.0338954925537109375                                                         
+ 0.01824188232421875                                                           
+ 0.00450420379638671875                                                        
+-0.0066165924072265625                                                         
+-0.01471710205078125                                                           
+-0.01970195770263671875                                                        
+-0.02175807952880859375                                                        
+-0.0213031768798828125                                                         
+-0.01890850067138671875                                                        
+-0.01522350311279296875                                                        
+-0.01089572906494140625                                                        
+-0.0065021514892578125                                                         
+-0.00250530242919921875                                                        
+ 0.0007781982421875                                                            
+ 0.00318145751953125                                                           
+ 0.00467395782470703125                                                        
+ 0.00533390045166015625                                                        
+ 0.0053157806396484375                                                         
+ 0.00481319427490234375                                                        
+ 0.0040225982666015625                                                         
+ 0.00311946868896484375                                                        
+ 0.0022411346435546875                                                         
+ 0.00148105621337890625                                                        
+ 0.000885009765625                                                             
+ 0.00046253204345703125                                                        
+ 0.0002193450927734375                                                         
+
+                                                                              
+

+ 64 - 0
src/src/Sim/R7.txt

@@ -0,0 +1,64 @@
+25
+-3
+-31
+-88
+-184
+-330
+-536
+-808
+-1147
+-1545
+-1986
+-2446
+-2888
+-3265
+-3526
+-3611
+-3463
+-3029
+-2265
+-1142
+348
+2191
+4348
+6755
+9325
+11954
+14522
+16906
+18987
+20655
+21821
+22420
+22420
+21821
+20655
+18987
+16906
+14522
+11954
+9325
+6755
+4348
+2191
+348
+-1142
+-2265
+-3029
+-3463
+-3611
+-3526
+-3265
+-2888
+-2446
+-1986
+-1545
+-1147
+-808
+-536
+-330
+-184
+-88
+-31
+-3
+25

+ 67 - 0
src/src/Sim/R7Test.fcf

@@ -0,0 +1,67 @@
+ 0.00009632110595703125                                                        
+-0.000011444091796875                                                          
+-0.00011730194091796875                                                        
+-0.0003337860107421875                                                         
+-0.0006999969482421875                                                         
+-0.00125885009765625                                                           
+-0.002044677734375                                                             
+-0.003082275390625                                                             
+-0.00437259674072265625                                                        
+-0.00589084625244140625                                                        
+-0.00757598876953125                                                           
+-0.00932979583740234375                                                        
+-0.0110149383544921875                                                         
+-0.012454986572265625                                                          
+-0.01344776153564453125                                                        
+-0.0137729644775390625                                                         
+-0.01320934295654296875                                                        
+-0.0115528106689453125                                                         
+-0.0086383819580078125                                                         
+-0.00435543060302734375                                                        
+ 0.0013275146484375                                                            
+ 0.008358001708984375                                                          
+ 0.0165863037109375                                                            
+ 0.02576923370361328125                                                        
+ 0.03557491302490234375                                                        
+ 0.04560089111328125                                                           
+ 0.05539703369140625                                                           
+ 0.06449413299560546875                                                        
+ 0.0724315643310546875                                                         
+ 0.07879543304443359375                                                        
+ 0.08324146270751953125                                                        
+ 0.0855274200439453125                                                         
+ 0.0855274200439453125                                                         
+ 0.08324146270751953125                                                        
+ 0.07879543304443359375                                                        
+ 0.0724315643310546875                                                         
+ 0.06449413299560546875                                                        
+ 0.05539703369140625                                                           
+ 0.04560089111328125                                                           
+ 0.03557491302490234375                                                        
+ 0.02576923370361328125                                                        
+ 0.0165863037109375                                                            
+ 0.008358001708984375                                                          
+ 0.0013275146484375                                                            
+-0.00435543060302734375                                                        
+-0.0086383819580078125                                                         
+-0.0115528106689453125                                                         
+-0.01320934295654296875                                                        
+-0.0137729644775390625                                                         
+-0.01344776153564453125                                                        
+-0.012454986572265625                                                          
+-0.0110149383544921875                                                         
+-0.00932979583740234375                                                        
+-0.00757598876953125                                                           
+-0.00589084625244140625                                                        
+-0.00437259674072265625                                                        
+-0.003082275390625                                                             
+-0.002044677734375                                                             
+-0.00125885009765625                                                           
+-0.0006999969482421875                                                         
+-0.0003337860107421875                                                         
+-0.00011730194091796875                                                        
+-0.000011444091796875                                                          
+ 0.00009632110595703125                                                        
+
+                                                                              
+

+ 19 - 4
src/src/Sim/firFilter/systolicFilter.v

@@ -2,7 +2,7 @@ module systolicFilter
 #(	parameter	filteredDataWidth	=	35,
 	parameter	inOutDataWidth	=	18,
 	parameter	decimCntWidth	=	7,
-	parameter	CoeffCount		=	64
+	parameter	CoeffCount		=	25
 )
 (
 	input Clk_i,
@@ -22,7 +22,22 @@ module systolicFilter
 	wire	[17:0]	test2 = outData[35-:18];
 	
 	
-	systolicFilterBlockTest # (
+	// systolicFilterBlockTest # (
+		// .CoeffCount(CoeffCount)
+	// )
+	// systolicFilterBlockInst
+	// (
+		// .Clk_i(Clk_i),
+		// .Rst_i(Rst_i),
+		// .Data_i(Data_i),
+		// .DecimFactor_i(DecimFactor_i),
+		// .DataNd_i(DataNd_i),
+		// .DataNd_i(1'b1),
+		// .Data_o(outData),
+		// .DataValid_o(outDataValid)
+	// );
+	
+	systolicFilterBlock # (
 		.CoeffCount(CoeffCount)
 	)
 	systolicFilterBlockInst
@@ -30,9 +45,9 @@ module systolicFilter
 		.Clk_i(Clk_i),
 		.Rst_i(Rst_i),
 		.Data_i(Data_i),
-		.DecimFactor_i(DecimFactor_i),
+		.CoefData_i(CoefData_i),
+		.CoefDataVal_i(CoefDataVal_i),
 		.DataNd_i(DataNd_i),
-		// .DataNd_i(1'b1),
 		.Data_o(outData),
 		.DataValid_o(outDataValid)
 	);

+ 13 - 49
src/src/Sim/firFilter/systolicFilterBlock.v

@@ -13,17 +13,17 @@ module systolicFilterBlock # (
 );
 
 	reg signed [17:0] coeff[0:CoeffCount-1];
-
-
-
+	
 	wire signed [17:0] dataIn = Data_i;
-	reg [3:0] ndShReg;
+	reg [CoeffCount-1:0] ndShReg;
+	
+	wire comRst = (Rst_i|!(DataNd_i|DataValid_o));
 	
 	always @ (posedge Clk_i)
 		if (!Rst_i) begin
-			ndShReg <= {ndShReg[2:0], DataNd_i};
+			ndShReg <= {ndShReg[CoeffCount-2:0], DataNd_i};
 		end else begin
-			ndShReg <= 4'h0;
+			ndShReg <= 0;
 		end
 	
 	reg signed [17:0] inReg0[0:CoeffCount-1];
@@ -46,55 +46,19 @@ module systolicFilterBlock # (
 		end 
 	end
 	
-	always @(*) begin
+	always @(posedge Clk_i) begin
 		if (!Rst_i) begin
 			if (CoefDataVal_i) begin
-				coeff[addrCnt] = CoefData_i;
+				coeff[addrCnt] <= CoefData_i;
 			end
-		end else begin
-			coeff[0]  = 18'h002fd;
-			coeff[1]  = 18'h00f3e;
-			coeff[2]  = 18'h013ef;
-			coeff[3]  = 18'h006f0;
-			coeff[4]  = 18'h3f248;
-			coeff[5]  = 18'h3f30a;
-			coeff[6]  = 18'h00bcc;
-			coeff[7]  = 18'h01664;
-			coeff[8]  = 18'h3fa36;
-			coeff[9]  = 18'h3de4b;
-			coeff[10] = 18'h3f843;
-			coeff[11] = 18'h02d1e;
-			coeff[12] = 18'h021a2;
-			coeff[13] = 18'h3c919;
-			coeff[14] = 18'h3a7f7;
-			coeff[15] = 18'h03d7b;
-			coeff[16] = 18'h13ec9;
-			coeff[17] = 18'h1c034;
-			coeff[18] = 18'h13ec9;
-			coeff[19] = 18'h03d7b;
-			coeff[20] = 18'h3a7f7;
-			coeff[21] = 18'h3c919;
-			coeff[22] = 18'h021a2;
-			coeff[23] = 18'h02d1e;
-			coeff[24] = 18'h3f843;
-			coeff[25] = 18'h3de4b;
-			coeff[26] = 18'h3fa36;
-			coeff[27] = 18'h01664;
-			coeff[28] = 18'h00bcc;
-			coeff[29] = 18'h3f30a;
-			coeff[30] = 18'h3f248;
-			coeff[31] = 18'h006f0;
-			coeff[32] = 18'h013ef;
-			coeff[33] = 18'h00f3e;
-			coeff[34] = 18'h002fd;
-		end                 
+		end 
 	end
 	
 	genvar i;
 	generate
 		for (i = 0; i < CoeffCount; i = i + 1)begin 
 			always @ (posedge Clk_i) begin
-				if (!Rst_i) begin
+				if (!comRst) begin
 					if (DataNd_i) begin
 						if (i == 0) begin
 							inReg0[i] <= 0;
@@ -105,11 +69,11 @@ module systolicFilterBlock # (
 						end
 					end
 				
-					if (ndShReg[0]) begin
+					if (ndShReg[0]|ndShReg[CoeffCount-2]) begin
 						multResult[i] <= inReg1[i] * coeff[i];
 					end
 					
-					if (ndShReg[1]) begin
+					if (ndShReg[1]|ndShReg[CoeffCount-1]) begin
 						if (i == 0) begin
 							sumResult[i] <= multResult[i];
 						end else begin
@@ -127,6 +91,6 @@ module systolicFilterBlock # (
 	endgenerate
 
 	assign Data_o = sumResult[CoeffCount-1];
-	assign DataValid_o = ndShReg[2];
+	assign DataValid_o = ndShReg[CoeffCount-1];
 
 endmodule

+ 69 - 0
src/src/Sim/fir_filter7Test.coe

@@ -0,0 +1,69 @@
+; XILINX CORE Generator(tm)Distributed Arithmetic FIR filter coefficient (.COE) File
+; Generated by MATLAB(R) 9.13 and DSP System Toolbox 9.15.
+; Generated on: 29-Mar-2024 11:09:52
+Radix = 16; 
+Coefficient_Width = 18; 
+CoefData = 00065,
+3fff4,
+3ff85,
+3fea2,
+3fd22,
+3fad8,
+3f7a0,
+3f360,
+3ee17,
+3e7df,
+3e0f8,
+3d9c9,
+3d2e2,
+3ccfc,
+3c8eb,
+3c796,
+3c9e5,
+3d0ae,
+3dc9e,
+3ee29,
+00570,
+0223c,
+043f0,
+0698d,
+091b7,
+0bac8,
+0e2e8,
+1082b,
+128ae,
+142bf,
+154f5,
+15e52,
+15e52,
+154f5,
+142bf,
+128ae,
+1082b,
+0e2e8,
+0bac8,
+091b7,
+0698d,
+043f0,
+0223c,
+00570,
+3ee29,
+3dc9e,
+3d0ae,
+3c9e5,
+3c796,
+3c8eb,
+3ccfc,
+3d2e2,
+3d9c9,
+3e0f8,
+3e7df,
+3ee17,
+3f360,
+3f7a0,
+3fad8,
+3fd22,
+3fea2,
+3ff85,
+3fff4,
+00065;

+ 52 - 46
src/src/Top/S5243Top.v

@@ -535,10 +535,15 @@ module	S5243Top
 	assign	gainHighThresholdBus	[ChNum-2]	=	gainHighThreshR2;
 	assign	gainHighThresholdBus	[ChNum-1]	=	gainHighThreshT2;
 	
-	assign	AmpEn_o	[3]	=	~ampEnNewStates[3];	
-	assign	AmpEn_o	[2]	=	~ampEnNewStates[2];	
-	assign	AmpEn_o	[1]	=	~ampEnNewStates[0];	
-	assign	AmpEn_o	[0]	=	~ampEnNewStates[1];		
+	// assign	AmpEn_o	[3]	=	~ampEnNewStates[3];	
+	// assign	AmpEn_o	[2]	=	~ampEnNewStates[2];	
+	// assign	AmpEn_o	[1]	=	~ampEnNewStates[0];	
+	// assign	AmpEn_o	[0]	=	~ampEnNewStates[1];	
+	
+	assign	AmpEn_o	[3]	=	1'b1;	
+	assign	AmpEn_o	[2]	=	1'b1;	
+	assign	AmpEn_o	[1]	=	1'b1;	
+	assign	AmpEn_o	[0]	=	1'b1;		
 	
 	assign	Overload_o	=	overCtrlR;
 
@@ -774,7 +779,8 @@ InternalDsp
 	
 	.GatingPulse_i		(gatingPulse),
 	
-	.StartMeas_i		(measStart),
+	// .StartMeas_i		(measStart),
+	.StartMeas_i		(sampleStrobe),
 	.StartMeasDsp_i		(startMeasSync),
 	.OscDataRdFlag_i	(oscDataRdFlag),
 	
@@ -976,52 +982,52 @@ endgenerate
 //	Gain Control module	
 //--------------------------------------------------------------------------------	
 genvar g;
-generate
-	for	(g=0;	g<ChNum;	g=g+1)	begin	:GainControl
-	GainControlWrapper
-	#(	
-		.AdcDataWidth		(AdcDataWidth),
-		.ThresholdWidth		(ThresholdWidth),
-		.PhIncWidth			(PhIncWidth),
-		.IfNcoOutWidth		(NcoWidth),
-		.MeasPeriod			(MeasPeriod)
-	)	
-	GainControlModule
-	(
-		.Rst_i				(initRst),
-		.Clk_i				(gclk),	
-		.StartMeas_i		(sampleStrobe),
+// generate
+	// for	(g=0;	g<ChNum;	g=g+1)	begin	:GainControl
+	// GainControlWrapper
+	// #(	
+		// .AdcDataWidth		(AdcDataWidth),
+		// .ThresholdWidth		(ThresholdWidth),
+		// .PhIncWidth			(PhIncWidth),
+		// .IfNcoOutWidth		(NcoWidth),
+		// .MeasPeriod			(MeasPeriod)
+	// )	
+	// GainControlModule
+	// (
+		// .Rst_i				(initRst),
+		// .Clk_i				(gclk),	
+		// .StartMeas_i		(sampleStrobe),
 		
-		.NcoSin_i			(ncoSin),
-		.NcoCos_i			(ncoCos),
+		// .NcoSin_i			(ncoSin),
+		// .NcoCos_i			(ncoCos),
 		
-		.AdcData_i			(adcDataBus[g]),
+		// .AdcData_i			(adcDataBus[g]),
 		// .AdcData_i			(AdcData_i),
 		
-		.GainLowThreshold_i	(gainLowThresholdBus[g]),
-		.GainHighThreshold_i(gainHighThresholdBus[g]),
-		.GainAutoEn_i		(gainAutoEn[g]),
-		.GainManualState_i	(gainManual[g]),
+		// .GainLowThreshold_i	(gainLowThresholdBus[g]),
+		// .GainHighThreshold_i(gainHighThresholdBus[g]),
+		// .GainAutoEn_i		(gainAutoEn[g]),
+		// .GainManualState_i	(gainManual[g]),
 		
-		.AmpEnNewState_o	(ampEnNewStates[g]),
-		.SensEn_o			(sensEn[g]),
-		.MeasStart_o		(measStartBus[g])
-	);
-	end
-endgenerate
-
-StartAfterGainSel	
-#(	
-	.ChNum	(ChNum)
-)	
-StartAfterGainSelInst
-(
-	.Rst_i			(initRst),
-	.GainCtrl_i		(gainAutoEn),
-	.MeasStart_i	(measStartBus),
-	
-	.MeasStart_o	(measStart)
-);
+		// .AmpEnNewState_o	(ampEnNewStates[g]),
+		// .SensEn_o			(sensEn[g]),
+		// .MeasStart_o		(measStartBus[g])
+	// );
+	// end
+// endgenerate
+
+// StartAfterGainSel	
+// #(	
+	// .ChNum	(ChNum)
+// )	
+// StartAfterGainSelInst
+// (
+	// .Rst_i			(initRst),
+	// .GainCtrl_i		(gainAutoEn),
+	// .MeasStart_i	(measStartBus),
+	
+	// .MeasStart_o	(measStart)
+// );
 //--------------------------------------------------------------------------------
 //	Trig TO/FROM DSP	
 //--------------------------------------------------------------------------------