|
@@ -0,0 +1,272 @@
|
|
|
|
|
+`timescale 1ns / 1ps
|
|
|
|
|
+
|
|
|
|
|
+module DecimFilterWrapperTb ();
|
|
|
|
|
+
|
|
|
|
|
+reg Clk50;
|
|
|
|
|
+reg Rst;
|
|
|
|
|
+
|
|
|
|
|
+reg [2:0] decimFactor;
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+reg [13:0] adcData;
|
|
|
|
|
+real pi = 3.14159265358;
|
|
|
|
|
+real phase = 0;
|
|
|
|
|
+real phaseInc = 0.001;
|
|
|
|
|
+real signal;
|
|
|
|
|
+
|
|
|
|
|
+reg [31:0] tbCnt;
|
|
|
|
|
+reg [31:0] pNumCnt;
|
|
|
|
|
+// wire oscWind = (tbCnt>=4500&tbCnt<=5499)? 1'b1:1'b0;
|
|
|
|
|
+wire oscWind = (tbCnt>=4500&tbCnt<=4999)? 1'b1:1'b0;
|
|
|
|
|
+
|
|
|
|
|
+wire signed [13:0] ncoSin1;
|
|
|
|
|
+wire signed [13:0] ncoCos1;
|
|
|
|
|
+wire signed [13:0] ncoSin2;
|
|
|
|
|
+wire signed [13:0] ncoCos2;
|
|
|
|
|
+
|
|
|
|
|
+wire signed [15:0] resultI;
|
|
|
|
|
+wire signed [15:0] resultQ;
|
|
|
|
|
+wire resultVal;
|
|
|
|
|
+
|
|
|
|
|
+wire signed [13:0] resultICut = resultI[0+:14];
|
|
|
|
|
+wire signed [13:0] resultQCut = resultQ[0+:14];
|
|
|
|
|
+
|
|
|
|
|
+// wire signed [27:0] adcDataMixed = oscWind?(ncoSin1*ncoSin2):28'd0;
|
|
|
|
|
+wire signed [27:0] adcDataMixed = (ncoSin1*ncoSin2);
|
|
|
|
|
+wire signed [13:0] adcDataMixedCut = adcDataMixed[27-:14];
|
|
|
|
|
+
|
|
|
|
|
+wire signed [13:0] sinAdd = (ncoSin1>>>1)+(ncoSin2>>>1);
|
|
|
|
|
+
|
|
|
|
|
+wire signed [17:0] wind;
|
|
|
|
|
+
|
|
|
|
|
+// wire signed [13:0] singlePulse = (tbCnt>=4505&tbCnt<=4510)? 14'h1fff:14'h0;
|
|
|
|
|
+wire signed [13:0] singlePulse = (tbCnt==4505)? 14'h1fff:14'h0;
|
|
|
|
|
+//==========================================================================================
|
|
|
|
|
+//clocks gen
|
|
|
|
|
+always #10 Clk50 = ~Clk50;
|
|
|
|
|
+
|
|
|
|
|
+//==========================================================================================
|
|
|
|
|
+
|
|
|
|
|
+parameter N = 4;
|
|
|
|
|
+parameter M = 1;
|
|
|
|
|
+
|
|
|
|
|
+initial begin
|
|
|
|
|
+ Clk50 = 1'b1;
|
|
|
|
|
+ Rst = 1'b1;
|
|
|
|
|
+ decimFactor = 3'd4;
|
|
|
|
|
+#100;
|
|
|
|
|
+ Rst = 1'b0;
|
|
|
|
|
+end
|
|
|
|
|
+
|
|
|
|
|
+always @(posedge Clk50) begin
|
|
|
|
|
+ if (!Rst) begin
|
|
|
|
|
+ tbCnt <= tbCnt+32'd1;
|
|
|
|
|
+ end else begin
|
|
|
|
|
+ tbCnt <= 32'd0;
|
|
|
|
|
+ end
|
|
|
|
|
+end
|
|
|
|
|
+
|
|
|
|
|
+always @(posedge Clk50) begin
|
|
|
|
|
+ if (!Rst) begin
|
|
|
|
|
+ if (oscWind) begin
|
|
|
|
|
+ pNumCnt <= pNumCnt+32'd1;
|
|
|
|
|
+ end else begin
|
|
|
|
|
+ pNumCnt <= 32'd0;
|
|
|
|
|
+ end
|
|
|
|
|
+ end else begin
|
|
|
|
|
+ pNumCnt <= 32'd0;
|
|
|
|
|
+ end
|
|
|
|
|
+end
|
|
|
|
|
+
|
|
|
|
|
+always @ (posedge Clk50) begin
|
|
|
|
|
+ if (tbCnt >= 4505) begin
|
|
|
|
|
+ phase = phase + phaseInc;
|
|
|
|
|
+ phaseInc <= phaseInc + 0.0005;
|
|
|
|
|
+ signal = $sin(2*pi*phase);
|
|
|
|
|
+ adcData = 2**12 * signal;
|
|
|
|
|
+ end else begin
|
|
|
|
|
+ adcData = 0;
|
|
|
|
|
+ end
|
|
|
|
|
+end
|
|
|
|
|
+
|
|
|
|
|
+CordicNco
|
|
|
|
|
+#(
|
|
|
|
|
+ .ODatWidth (14),
|
|
|
|
|
+ .PhIncWidth (32),
|
|
|
|
|
+ .IterNum (10),
|
|
|
|
|
+ .EnSinN (1)
|
|
|
|
|
+)
|
|
|
|
|
+ncoInst1
|
|
|
|
|
+(
|
|
|
|
|
+ .Clk_i (Clk50),
|
|
|
|
|
+ .Rst_i (Rst),
|
|
|
|
|
+ .Val_i (1'b1),
|
|
|
|
|
+ .PhaseInc_i (32'h51eb851),
|
|
|
|
|
+ .WindVal_i (1'b1),
|
|
|
|
|
+ .WinType_i (),
|
|
|
|
|
+ .Wind_o (),
|
|
|
|
|
+ .Sin_o (ncoSin1),
|
|
|
|
|
+ .Cos_o (ncoCos1),
|
|
|
|
|
+ .Val_o ()
|
|
|
|
|
+);
|
|
|
|
|
+
|
|
|
|
|
+CordicNco
|
|
|
|
|
+#(
|
|
|
|
|
+ .ODatWidth (14),
|
|
|
|
|
+ .PhIncWidth (32),
|
|
|
|
|
+ .IterNum (10),
|
|
|
|
|
+ .EnSinN (1)
|
|
|
|
|
+)
|
|
|
|
|
+ncoInst2
|
|
|
|
|
+(
|
|
|
|
|
+ .Clk_i (Clk50),
|
|
|
|
|
+ .Rst_i (Rst),
|
|
|
|
|
+ .Val_i (1'b1),
|
|
|
|
|
+ .PhaseInc_i (32'h33333333),
|
|
|
|
|
+ .WindVal_i (1'b1),
|
|
|
|
|
+ .WinType_i (),
|
|
|
|
|
+ .Wind_o (),
|
|
|
|
|
+ .Sin_o (ncoSin2),
|
|
|
|
|
+ .Cos_o (ncoCos2),
|
|
|
|
|
+ .Val_o ()
|
|
|
|
|
+);
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+DecimFilterWrapper
|
|
|
|
|
+#(
|
|
|
|
|
+ .AdcDataWidth (14),
|
|
|
|
|
+ .N (N),
|
|
|
|
|
+ .M (M),
|
|
|
|
|
+ .FilteredDataWidth (30),
|
|
|
|
|
+ .FirOutDataWidth (48),
|
|
|
|
|
+ .FirOutCutBit (42)
|
|
|
|
|
+)
|
|
|
|
|
+DecimFilter
|
|
|
|
|
+(
|
|
|
|
|
+ .Clk_i (Clk50),
|
|
|
|
|
+ .DecimFactor_i (decimFactor),
|
|
|
|
|
+ .Rst_i (Rst),
|
|
|
|
|
+ .OscWind_i (oscWind),
|
|
|
|
|
+
|
|
|
|
|
+ .IfFtwL_i (24'h51eb85),
|
|
|
|
|
+ .IfFtwH_i (24'h23),
|
|
|
|
|
+
|
|
|
|
|
+ .AdcData_i (singlePulse),
|
|
|
|
|
+ // .AdcData_i (sinAdd),
|
|
|
|
|
+ // .AdcData_i (adcDataMixedCut),
|
|
|
|
|
+
|
|
|
|
|
+ .FilteredAdcDataI_o (resultI),
|
|
|
|
|
+ .FilteredAdcDataQ_o (resultQ),
|
|
|
|
|
+ .FilteredDataVal_o (resultVal)
|
|
|
|
|
+);
|
|
|
|
|
+
|
|
|
|
|
+reg [32-1:0] windArg;
|
|
|
|
|
+wire [31:0] WindPhInc = 32'h418937<<<decimFactor-2;
|
|
|
|
|
+
|
|
|
|
|
+always @(posedge Clk50) begin
|
|
|
|
|
+ if (!Rst) begin
|
|
|
|
|
+ if (resultVal) begin
|
|
|
|
|
+ windArg <= windArg+WindPhInc;
|
|
|
|
|
+ end
|
|
|
|
|
+ end else begin
|
|
|
|
|
+ windArg <= WindPhInc>>1;
|
|
|
|
|
+ end
|
|
|
|
|
+end
|
|
|
|
|
+
|
|
|
|
|
+reg [1:0] valReg;
|
|
|
|
|
+always @(posedge Clk50) begin
|
|
|
|
|
+ if (!Rst) begin
|
|
|
|
|
+ valReg[0] <= resultVal;
|
|
|
|
|
+ valReg[1] <= valReg[0];
|
|
|
|
|
+ end else begin
|
|
|
|
|
+ valReg <= 2'b0;
|
|
|
|
|
+ end
|
|
|
|
|
+end
|
|
|
|
|
+
|
|
|
|
|
+reg signed [33:0] windResult;
|
|
|
|
|
+reg windResultVal;
|
|
|
|
|
+
|
|
|
|
|
+always @(posedge Clk50) begin
|
|
|
|
|
+ if (!Rst) begin
|
|
|
|
|
+ if (valReg[1]) begin
|
|
|
|
|
+ windResult <= wind*resultI;
|
|
|
|
|
+ windResultVal <= 1'b1;
|
|
|
|
|
+ end else begin
|
|
|
|
|
+ windResultVal <= 1'b0;
|
|
|
|
|
+ end
|
|
|
|
|
+ end else begin
|
|
|
|
|
+ windResult <= 0;
|
|
|
|
|
+ windResultVal <= 0;
|
|
|
|
|
+ end
|
|
|
|
|
+end
|
|
|
|
|
+
|
|
|
|
|
+wire signed [15:0] windResultCut = windResult[32-:16];
|
|
|
|
|
+
|
|
|
|
|
+Win_calc WinCalcInst
|
|
|
|
|
+(
|
|
|
|
|
+ .clk_i (Clk50),
|
|
|
|
|
+ .filterCmd_i (8'h60),
|
|
|
|
|
+ .reset_i (Rst),
|
|
|
|
|
+ .WinCtrl_i (1'b0),
|
|
|
|
|
+ .TukeyCtrl_i (2'b0),
|
|
|
|
|
+ .MeasWind_i (resultVal),
|
|
|
|
|
+ .win_value_i (windArg),
|
|
|
|
|
+ .win_type_i (3'b0),
|
|
|
|
|
+ .win_o (wind)
|
|
|
|
|
+);
|
|
|
|
|
+
|
|
|
|
|
+integer inSignal,filteredData;
|
|
|
|
|
+parameter PNum = 5000;
|
|
|
|
|
+
|
|
|
|
|
+always @(posedge Clk50) begin
|
|
|
|
|
+ if (Rst) begin
|
|
|
|
|
+ inSignal = $fopen("C:/Users/Stepan/Desktop/4portCompact/S5443Current/S5443_M/S5443.srcs/sources_1/new/InputSignal.txt","w");
|
|
|
|
|
+ end else begin
|
|
|
|
|
+ if (oscWind) begin
|
|
|
|
|
+ // $display("AdcData is %d", sinAdd);
|
|
|
|
|
+ // $fwrite(inSignal,"%d\n", sinAdd);
|
|
|
|
|
+ $fwrite(inSignal,"%d\n", singlePulse);
|
|
|
|
|
+ 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 (resultVal) begin
|
|
|
|
|
+ $fwrite(filteredData,"%d\n", resultI);
|
|
|
|
|
+ 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
|
|
|
|
|
+
|
|
|
|
|
+endmodule
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|