|
@@ -6,16 +6,17 @@ module DecimFilterWrapperTb ();
|
|
|
// PARAMETERS
|
|
// PARAMETERS
|
|
|
//================================================================================
|
|
//================================================================================
|
|
|
|
|
|
|
|
-parameter N = 8;
|
|
|
|
|
-parameter M = 4;
|
|
|
|
|
|
|
+parameter N = 6; // Order of the filter
|
|
|
|
|
+parameter M = 8;// Delay in CIC filter
|
|
|
parameter InDataWidth = 14;
|
|
parameter InDataWidth = 14;
|
|
|
|
|
|
|
|
parameter K = N*20*($log10(M));
|
|
parameter K = N*20*($log10(M));
|
|
|
parameter BitGworth = $ceil(2**(K/20));
|
|
parameter BitGworth = $ceil(2**(K/20));
|
|
|
-parameter integer MaxWidth = InDataWidth+BitGworth;
|
|
|
|
|
|
|
+parameter integer MaxWidth = InDataWidth+BitGworth + 15;
|
|
|
|
|
|
|
|
-parameter [31:0] Nco1PhaseInc = 32'h40000000;
|
|
|
|
|
-parameter [31:0] Nco2PhaseInc = 32'h0F5C28F6;
|
|
|
|
|
|
|
+// parameter [31:0] Nco1PhaseInc = 32'h40000000;//12.5 MHz
|
|
|
|
|
+parameter [31:0] Nco1PhaseInc = 32'h23d70a3d;//7 MHz
|
|
|
|
|
+parameter [31:0] Nco2PhaseInc = 32'h0f5c28f6;// 3 MHz
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -31,7 +32,7 @@ reg [2:0] decimFactor;
|
|
|
|
|
|
|
|
reg [31:0] tbCnt;
|
|
reg [31:0] tbCnt;
|
|
|
|
|
|
|
|
-wire oscWind = (tbCnt>=100&tbCnt<=199)? 1'b1:1'b0;
|
|
|
|
|
|
|
+wire oscWind = (tbCnt>=100&tbCnt<=299)? 1'b1:1'b0;
|
|
|
|
|
|
|
|
wire resultVal;
|
|
wire resultVal;
|
|
|
wire impResponseVal;
|
|
wire impResponseVal;
|
|
@@ -41,13 +42,15 @@ wire signed [InDataWidth-1:0] ncoSin1;
|
|
|
wire signed [InDataWidth-1:0] ncoSin2;
|
|
wire signed [InDataWidth-1:0] ncoSin2;
|
|
|
wire signed [InDataWidth-1:0] ncoSin3;
|
|
wire signed [InDataWidth-1:0] ncoSin3;
|
|
|
|
|
|
|
|
-wire signed [InDataWidth-1:0] filteredDataOut;
|
|
|
|
|
-wire signed [InDataWidth-1:0] impResponse;
|
|
|
|
|
|
|
+wire signed [MaxWidth-1:0] filteredDataOut;
|
|
|
|
|
+wire signed [MaxWidth-1:0] impResponse;
|
|
|
|
|
|
|
|
wire signed [InDataWidth*2-1:0] adcDataMixed = (ncoSin1*ncoSin2);
|
|
wire signed [InDataWidth*2-1:0] adcDataMixed = (ncoSin1*ncoSin2);
|
|
|
wire signed [InDataWidth-1:0] adcDataMixedCut = adcDataMixed[26-:14];
|
|
wire signed [InDataWidth-1:0] adcDataMixedCut = adcDataMixed[26-:14];
|
|
|
|
|
|
|
|
-wire signed [InDataWidth-1:0] sinAdd = (ncoSin1>>>1)+(ncoSin2>>>1);
|
|
|
|
|
|
|
+// wire signed [InDataWidth-1:0] sinAdd = (ncoSin1>>>1)+(ncoSin2>>>1);
|
|
|
|
|
+wire signed [2*InDataWidth-1:0] sinMultFull = (ncoSin2*ncoSin1);
|
|
|
|
|
+wire signed [InDataWidth-1:0] sinMult = sinMultFull[(2*InDataWidth-1)-:InDataWidth];
|
|
|
|
|
|
|
|
wire signed [InDataWidth-1:0] singlePulse = (tbCnt==100)? 14'h1fff:14'h0;
|
|
wire signed [InDataWidth-1:0] singlePulse = (tbCnt==100)? 14'h1fff:14'h0;
|
|
|
|
|
|
|
@@ -81,7 +84,7 @@ end
|
|
|
always @(posedge Clk50) begin
|
|
always @(posedge Clk50) begin
|
|
|
if (!Rst) begin
|
|
if (!Rst) begin
|
|
|
if (tbCnt == 100) begin
|
|
if (tbCnt == 100) begin
|
|
|
- decimFactor <= 2;
|
|
|
|
|
|
|
+ decimFactor <= 4;
|
|
|
end
|
|
end
|
|
|
// end else if (tbCnt == 5400) begin
|
|
// end else if (tbCnt == 5400) begin
|
|
|
// decimFactor <= 1;
|
|
// decimFactor <= 1;
|
|
@@ -99,7 +102,7 @@ always @(posedge Clk50) begin
|
|
|
// decimFactor <= 7;
|
|
// decimFactor <= 7;
|
|
|
// end
|
|
// end
|
|
|
end else begin
|
|
end else begin
|
|
|
- decimFactor <= 2;
|
|
|
|
|
|
|
+ decimFactor <= 4;
|
|
|
end
|
|
end
|
|
|
end
|
|
end
|
|
|
|
|
|
|
@@ -145,7 +148,7 @@ ncoInst2
|
|
|
.Val_o ()
|
|
.Val_o ()
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
-DecimFilterWrapperTest
|
|
|
|
|
|
|
+CicFilterNewWrapperNoIntDiff
|
|
|
#(
|
|
#(
|
|
|
.InDataWidth (InDataWidth),
|
|
.InDataWidth (InDataWidth),
|
|
|
.N (N),
|
|
.N (N),
|
|
@@ -159,13 +162,13 @@ DecimFilter
|
|
|
.Rst_i (Rst),
|
|
.Rst_i (Rst),
|
|
|
.DataVal_i (oscWind),
|
|
.DataVal_i (oscWind),
|
|
|
|
|
|
|
|
- .Data_i (sinAdd),
|
|
|
|
|
|
|
+ .Data_i (sinMult),
|
|
|
|
|
|
|
|
.Data_o (filteredDataOut),
|
|
.Data_o (filteredDataOut),
|
|
|
.DataVal_o (resultVal)
|
|
.DataVal_o (resultVal)
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
-DecimFilterWrapperTest
|
|
|
|
|
|
|
+CicFilterNewWrapperNoIntDiff
|
|
|
#(
|
|
#(
|
|
|
.InDataWidth (InDataWidth),
|
|
.InDataWidth (InDataWidth),
|
|
|
.N (N),
|
|
.N (N),
|
|
@@ -175,14 +178,32 @@ DecimFilterWrapperTest
|
|
|
ImpulseResponseFilter
|
|
ImpulseResponseFilter
|
|
|
(
|
|
(
|
|
|
.Clk_i (Clk50),
|
|
.Clk_i (Clk50),
|
|
|
- .DecimFactor_i (1),
|
|
|
|
|
|
|
+ .DecimFactor_i (decimFactor),
|
|
|
.Rst_i (Rst),
|
|
.Rst_i (Rst),
|
|
|
.DataVal_i (oscWind),
|
|
.DataVal_i (oscWind),
|
|
|
|
|
|
|
|
- .Data_i (singlePulse),
|
|
|
|
|
|
|
+ .Data_i (singlePulse),
|
|
|
|
|
|
|
|
- .Data_o (impResponse),
|
|
|
|
|
- .DataVal_o (impResponseVal)
|
|
|
|
|
|
|
+ .Data_o (impResponse),
|
|
|
|
|
+ .DataVal_o (impResponseVal)
|
|
|
|
|
+);
|
|
|
|
|
+
|
|
|
|
|
+CicFilterNewWrapperNoIntDiff
|
|
|
|
|
+#(
|
|
|
|
|
+ .InDataWidth (InDataWidth),
|
|
|
|
|
+ .N (N),
|
|
|
|
|
+ .M (M),
|
|
|
|
|
+ .OutDataWidth (MaxWidth)
|
|
|
|
|
+)
|
|
|
|
|
+CicFilterInst
|
|
|
|
|
+(
|
|
|
|
|
+ .Clk_i (Clk50),
|
|
|
|
|
+ .DecimFactor_i (decimFactor),
|
|
|
|
|
+ .Rst_i (Rst),
|
|
|
|
|
+ .DataVal_i (oscWind),
|
|
|
|
|
+ .Data_i (sinMult),
|
|
|
|
|
+ .Data_o (),
|
|
|
|
|
+ .DataVal_o ()
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
always @(posedge Clk50) begin
|
|
always @(posedge Clk50) begin
|
|
@@ -193,7 +214,7 @@ always @(posedge Clk50) begin
|
|
|
// $display("AdcData is %d", sinAdd);
|
|
// $display("AdcData is %d", sinAdd);
|
|
|
// $fwrite(inSignal,"%d\n", sinAddExt18);
|
|
// $fwrite(inSignal,"%d\n", sinAddExt18);
|
|
|
// $fwrite(inSignal,"%d\n", adcDataMixedCut);
|
|
// $fwrite(inSignal,"%d\n", adcDataMixedCut);
|
|
|
- $fwrite(inSignal,"%d\n", sinAdd);
|
|
|
|
|
|
|
+ $fwrite(inSignal,"%d\n", sinMult);
|
|
|
end
|
|
end
|
|
|
end
|
|
end
|
|
|
end
|
|
end
|
|
@@ -221,6 +242,15 @@ always @(posedge Clk50) begin
|
|
|
end
|
|
end
|
|
|
end
|
|
end
|
|
|
|
|
|
|
|
|
|
+always @(posedge Clk50) begin
|
|
|
|
|
+ if (tbCnt == 32'd1000) begin
|
|
|
|
|
+ $fclose(inSignal);
|
|
|
|
|
+ $fclose(filteredData);
|
|
|
|
|
+ $fclose(impResp);
|
|
|
|
|
+ $finish;
|
|
|
|
|
+ end
|
|
|
|
|
+end
|
|
|
|
|
+
|
|
|
endmodule
|
|
endmodule
|
|
|
|
|
|
|
|
|
|
|