|
|
@@ -6,13 +6,15 @@ module DecimFilterWrapperTb ();
|
|
|
// PARAMETERS
|
|
|
//================================================================================
|
|
|
|
|
|
-parameter N = 6; // Order of the filter
|
|
|
-parameter M = 8;// Delay in CIC filter
|
|
|
+parameter N = 4; // Order of the filter
|
|
|
+parameter M = 4;// Delay in CIC filter
|
|
|
parameter InDataWidth = 14;
|
|
|
+parameter integer DECIM_WIDTH = $ceil($clog2(2*M)) + 4; // Decimation factor width
|
|
|
|
|
|
parameter K = N*20*($log10(M));
|
|
|
parameter BitGworth = $ceil(2**(K/20));
|
|
|
-parameter integer MaxWidth = InDataWidth+BitGworth + 15;
|
|
|
+parameter integer BitGrowth = $ceil($clog2(((M/2*M)**N)/(M/2)));
|
|
|
+parameter integer MaxWidth = InDataWidth+BitGrowth+5;
|
|
|
|
|
|
// parameter [31:0] Nco1PhaseInc = 32'h40000000;//12.5 MHz
|
|
|
parameter [31:0] Nco1PhaseInc = 32'h23d70a3d;//7 MHz
|
|
|
@@ -28,11 +30,11 @@ parameter [31:0] Nco2PhaseInc = 32'h0f5c28f6;// 3 MHz
|
|
|
reg Clk50;
|
|
|
reg Rst;
|
|
|
|
|
|
-reg [2:0] decimFactor;
|
|
|
+reg [DECIM_WIDTH-1:0] decimFactor;
|
|
|
|
|
|
reg [31:0] tbCnt;
|
|
|
|
|
|
-wire oscWind = (tbCnt>=100&tbCnt<=299)? 1'b1:1'b0;
|
|
|
+wire oscWind = (tbCnt>=100&tbCnt<=(1123 + 1024*1))?1'b1:1'b0;
|
|
|
|
|
|
wire resultVal;
|
|
|
wire impResponseVal;
|
|
|
@@ -43,7 +45,10 @@ wire signed [InDataWidth-1:0] ncoSin2;
|
|
|
wire signed [InDataWidth-1:0] ncoSin3;
|
|
|
|
|
|
wire signed [MaxWidth-1:0] filteredDataOut;
|
|
|
+logic signed [MaxWidth-1:0] firDataOut;
|
|
|
wire signed [MaxWidth-1:0] impResponse;
|
|
|
+wire signed [31:0] impResp32;
|
|
|
+assign impResp32 = impResponse[53:53-32]; // Cut to 32 bits
|
|
|
|
|
|
wire signed [InDataWidth*2-1:0] adcDataMixed = (ncoSin1*ncoSin2);
|
|
|
wire signed [InDataWidth-1:0] adcDataMixedCut = adcDataMixed[26-:14];
|
|
|
@@ -54,7 +59,34 @@ wire signed [InDataWidth-1:0] sinMult = sinMultFull[(2*InDataWidth-1)-:InDataWid
|
|
|
|
|
|
wire signed [InDataWidth-1:0] singlePulse = (tbCnt==100)? 14'h1fff:14'h0;
|
|
|
|
|
|
-integer inSignal,filteredData, impResp;
|
|
|
+// wire signed [(MaxWidth < 32 ? MaxWidth : InDataWidth+18)-1:0] impRespCut;
|
|
|
+// assign impRespCut = MaxWidth < 32 ? impResponse :
|
|
|
+// impResponse[MaxWidth-1:MaxWidth-(InDataWidth+18)];
|
|
|
+wire signed [InDataWidth -1 : 0] impRespCut = impResponse [MaxWidth-1:MaxWidth-InDataWidth];
|
|
|
+
|
|
|
+longint inSignal,filteredData, impResp, afterFir;
|
|
|
+
|
|
|
+/* 2nd CIC */
|
|
|
+wire signed [2*MaxWidth-1:0] impResponse2nd;
|
|
|
+
|
|
|
+// wire signed [(MaxWidth < 32 ? MaxWidth : InDataWidth+18)-1:0] impResp2ndCut;
|
|
|
+// assign impResp2ndCut = MaxWidth < 32 ? impResponse2nd :
|
|
|
+// impResponse2nd[MaxWidth-1:MaxWidth-(InDataWidth+18)];
|
|
|
+wire signed [31:0] impResp2ndCut = impResponse2nd [39:39-32]; // 32 bits for 2nd stage
|
|
|
+// wire signed [InDataWidth -1 : 0] impResp2ndCut = impResponse2nd [MaxWidth-1:MaxWidth-InDataWidth];
|
|
|
+wire impResp2ndVal;
|
|
|
+
|
|
|
+/* 3rd CIC */
|
|
|
+wire signed [MaxWidth-1:0] impResponse3rd;
|
|
|
+
|
|
|
+wire signed [(MaxWidth < 32 ? MaxWidth : InDataWidth+18)-1:0] impResp3rdCut;
|
|
|
+assign impResp3rdCut = MaxWidth < 32 ? impResponse3rd :
|
|
|
+ impResponse3rd[MaxWidth-1:MaxWidth-(InDataWidth+18)];
|
|
|
+wire impResp3rdVal;
|
|
|
+
|
|
|
+/* FIR Filt */
|
|
|
+wire signed [31:0] firFiltTestData;
|
|
|
+wire firFiltVal;
|
|
|
|
|
|
//================================================================================
|
|
|
// CLK GEN
|
|
|
@@ -84,7 +116,7 @@ end
|
|
|
always @(posedge Clk50) begin
|
|
|
if (!Rst) begin
|
|
|
if (tbCnt == 100) begin
|
|
|
- decimFactor <= 4;
|
|
|
+ decimFactor <= M/1;
|
|
|
end
|
|
|
// end else if (tbCnt == 5400) begin
|
|
|
// decimFactor <= 1;
|
|
|
@@ -102,7 +134,7 @@ always @(posedge Clk50) begin
|
|
|
// decimFactor <= 7;
|
|
|
// end
|
|
|
end else begin
|
|
|
- decimFactor <= 4;
|
|
|
+ decimFactor <= M/1; //
|
|
|
end
|
|
|
end
|
|
|
|
|
|
@@ -153,7 +185,8 @@ CicFilterNewWrapperNoIntDiff
|
|
|
.InDataWidth (InDataWidth),
|
|
|
.N (N),
|
|
|
.M (M),
|
|
|
- .OutDataWidth (MaxWidth)
|
|
|
+ .DECIM_WIDTH (DECIM_WIDTH),
|
|
|
+ .OutDataWidth (MaxWidth+20)
|
|
|
)
|
|
|
DecimFilter
|
|
|
(
|
|
|
@@ -173,6 +206,7 @@ CicFilterNewWrapperNoIntDiff
|
|
|
.InDataWidth (InDataWidth),
|
|
|
.N (N),
|
|
|
.M (M),
|
|
|
+ .DECIM_WIDTH (DECIM_WIDTH),
|
|
|
.OutDataWidth (MaxWidth)
|
|
|
)
|
|
|
ImpulseResponseFilter
|
|
|
@@ -188,6 +222,65 @@ ImpulseResponseFilter
|
|
|
.DataVal_o (impResponseVal)
|
|
|
);
|
|
|
|
|
|
+CicFilterNewWrapperNoIntDiff
|
|
|
+#(
|
|
|
+ .InDataWidth (MaxWidth),
|
|
|
+ .N (N),
|
|
|
+ .M (M),
|
|
|
+ .DECIM_WIDTH (DECIM_WIDTH),
|
|
|
+ .OutDataWidth (2*MaxWidth)
|
|
|
+)
|
|
|
+ImpulseResponseFilter2ndStage
|
|
|
+(
|
|
|
+ .Clk_i (Clk50),
|
|
|
+ .DecimFactor_i (decimFactor),
|
|
|
+ .Rst_i (Rst),
|
|
|
+ .DataVal_i (impResponseVal),
|
|
|
+
|
|
|
+ .Data_i (impResponse),
|
|
|
+
|
|
|
+ .Data_o (impResponse2nd),
|
|
|
+ .DataVal_o (impResp2ndVal)
|
|
|
+);
|
|
|
+
|
|
|
+// CicFilterNewWrapperNoIntDiff
|
|
|
+// #(
|
|
|
+// .InDataWidth (InDataWidth),
|
|
|
+// .N (N),
|
|
|
+// .M (M),
|
|
|
+// .DECIM_WIDTH (DECIM_WIDTH),
|
|
|
+// .OutDataWidth (MaxWidth)
|
|
|
+// )
|
|
|
+// ImpulseResponseFilter3rdStage
|
|
|
+// (
|
|
|
+// .Clk_i (Clk50),
|
|
|
+// .DecimFactor_i (decimFactor),
|
|
|
+// .Rst_i (Rst),
|
|
|
+// .DataVal_i (impResp2ndVal),
|
|
|
+
|
|
|
+// .Data_i (impResp2ndCut),
|
|
|
+
|
|
|
+// .Data_o (impResponse3rd),
|
|
|
+// .DataVal_o (impResp3rdVal)
|
|
|
+// );
|
|
|
+
|
|
|
+FirFilter #(
|
|
|
+ .DATA_WIDTH (16),
|
|
|
+ .COEFF_WIDTH (16),
|
|
|
+ .NUM_TAPS (32)
|
|
|
+)
|
|
|
+FirFiltTest
|
|
|
+(
|
|
|
+ .Clk_i (Clk50),
|
|
|
+ .Rst_i (Rst),
|
|
|
+ .DecimFactor_i (decimFactor),
|
|
|
+ .Data_i (impResponse[MaxWidth-1:MaxWidth-16]), // 16 bits for FIR filter
|
|
|
+ .Val_i (impResponseVal),
|
|
|
+
|
|
|
+ .Data_o (firFiltTestData),
|
|
|
+ .Val_o (firFiltVal)
|
|
|
+);
|
|
|
+
|
|
|
CicFilterNewWrapperNoIntDiff
|
|
|
#(
|
|
|
.InDataWidth (InDataWidth),
|
|
|
@@ -205,6 +298,18 @@ CicFilterInst
|
|
|
.Data_o (),
|
|
|
.DataVal_o ()
|
|
|
);
|
|
|
+
|
|
|
+always_ff @(posedge Clk50) begin
|
|
|
+ if (Rst) begin
|
|
|
+ firDataOut <= '0;
|
|
|
+ end
|
|
|
+ else begin
|
|
|
+ if (firFiltVal) begin
|
|
|
+ firDataOut <= firFiltTestData;
|
|
|
+ end
|
|
|
+ end
|
|
|
+end
|
|
|
+
|
|
|
|
|
|
always @(posedge Clk50) begin
|
|
|
if (tbCnt==32'd1) begin
|
|
|
@@ -240,13 +345,26 @@ always @(posedge Clk50) begin
|
|
|
$fwrite(impResp,"%d\n", impResponse);
|
|
|
end
|
|
|
end
|
|
|
-end
|
|
|
+end
|
|
|
+
|
|
|
+always @(posedge Clk50) begin
|
|
|
+ if (tbCnt == 32'd1) begin
|
|
|
+ afterFir <= $fopen("C:/S5243_FFT_REPO/src/src/Sim/AfterFir.txt","w");
|
|
|
+ end
|
|
|
+ else begin
|
|
|
+ if (firFiltVal) begin
|
|
|
+ $fwrite(afterFir,"%d\n", firFiltTestData);
|
|
|
+ end
|
|
|
+ end
|
|
|
+end
|
|
|
+
|
|
|
|
|
|
always @(posedge Clk50) begin
|
|
|
- if (tbCnt == 32'd1000) begin
|
|
|
+ if (tbCnt == 32'd1500 + (1024*1)) begin
|
|
|
$fclose(inSignal);
|
|
|
$fclose(filteredData);
|
|
|
$fclose(impResp);
|
|
|
+ $fclose(afterFir);
|
|
|
$finish;
|
|
|
end
|
|
|
end
|