|
|
@@ -2,77 +2,66 @@
|
|
|
|
|
|
module DecimFilterWrapperTb ();
|
|
|
|
|
|
+//================================================================================
|
|
|
+// PARAMETERS
|
|
|
+//================================================================================
|
|
|
+
|
|
|
+parameter N = 4;
|
|
|
+parameter M = 3;
|
|
|
+parameter InDataWidth = 14;
|
|
|
+
|
|
|
+parameter K = N*20*($log10(M));
|
|
|
+parameter BitGworth = $ceil(2**(K/20));
|
|
|
+parameter MaxWidth = InDataWidth+BitGworth+1;
|
|
|
+
|
|
|
+parameter [31:0] Nco1PhaseInc = 32'h40000000;
|
|
|
+parameter [31:0] Nco2PhaseInc = 32'h0F5C28F6;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+//================================================================================
|
|
|
+// REG/WIRE
|
|
|
+//================================================================================
|
|
|
+
|
|
|
+
|
|
|
reg Clk50;
|
|
|
reg Rst;
|
|
|
|
|
|
reg [2:0] decimFactor;
|
|
|
|
|
|
-parameter MaxWidth = 32;
|
|
|
-
|
|
|
-reg [13:0] adcData;
|
|
|
-real pi = 3.14159265358;
|
|
|
-real phase = 0;
|
|
|
-real phaseInc = 0.001;
|
|
|
-real signal;
|
|
|
-
|
|
|
reg [31:0] tbCnt;
|
|
|
|
|
|
-wire [31:0] startValue = 32'd10;
|
|
|
-wire [31:0] pNum = 1000;
|
|
|
-wire [31:0] stopValue = startValue+pNum-1;
|
|
|
+wire oscWind = (tbCnt>=100&tbCnt<=199)? 1'b1:1'b0;
|
|
|
|
|
|
-// wire oscWind = (tbCnt>=10&tbCnt<=509)? 1'b1:1'b0;
|
|
|
-wire oscWind = (tbCnt>=startValue & tbCnt<=stopValue)? 1'b1:1'b0;
|
|
|
+wire resultVal;
|
|
|
+wire respVal;
|
|
|
|
|
|
-wire signed [13:0] ncoSin1;
|
|
|
-wire signed [13:0] ncoSin2;
|
|
|
-wire signed [13:0] ncoSin3;
|
|
|
+wire signed [InDataWidth-1:0] ncoSin1;
|
|
|
+wire signed [InDataWidth-1:0] ncoSin2;
|
|
|
+wire signed [InDataWidth-1:0] ncoSin3;
|
|
|
|
|
|
wire signed [MaxWidth-1:0] filteredDataOut;
|
|
|
wire signed [MaxWidth-1:0] impResponse;
|
|
|
-wire signed [MaxWidth-1:0] impResponseTest;
|
|
|
|
|
|
-wire resultVal;
|
|
|
-wire impRespVal;
|
|
|
-wire impRespValTest;
|
|
|
+wire signed [InDataWidth*2-1:0] adcDataMixed = (ncoSin1*ncoSin2);
|
|
|
+wire signed [InDataWidth-1:0] adcDataMixedCut = adcDataMixed[26-:14];
|
|
|
|
|
|
+wire signed [InDataWidth-1:0] sinAdd = (ncoSin1>>>1)+(ncoSin2>>>1);
|
|
|
|
|
|
-// wire signed [27:0] adcDataMixed = oscWind?(ncoSin1*ncoSin2):28'd0;
|
|
|
-wire signed [27:0] adcDataMixed = (ncoSin1*ncoSin2);
|
|
|
-wire signed [13:0] adcDataMixedCut = adcDataMixed[26-:14];
|
|
|
+wire signed [InDataWidth-1:0] singlePulse = (tbCnt==100)? 14'h1fff:14'h0;
|
|
|
|
|
|
-// wire signed [13:0] sinAdd = (ncoSin1>>>2)+(ncoSin2>>>2)+(ncoSin3>>>2);
|
|
|
-wire signed [13:0] sinAdd = (ncoSin1>>>1)+(ncoSin2>>>1);
|
|
|
-// wire signed [13:0] sinAdd = ncoSin1;
|
|
|
+integer inSignal,filteredData, impResp;
|
|
|
|
|
|
+//================================================================================
|
|
|
+// CLK GEN
|
|
|
+//================================================================================
|
|
|
|
|
|
-// wire signed [13:0] singlePulse = (tbCnt==10)? 14'h1fff:14'h0;
|
|
|
-// wire signed [15:0] singlePulse = (tbCnt==10)? 16'h1fff:14'h0;
|
|
|
-// wire signed [15:0] singlePulse = (tbCnt==10)? 16'h1:14'h0;
|
|
|
-wire signed [15:0] singlePulse = (tbCnt>=10&tbCnt<=11)? 14'h1fff:14'h0;
|
|
|
-//==========================================================================================
|
|
|
-//clocks gen
|
|
|
always #10 Clk50 = ~Clk50;
|
|
|
|
|
|
-//==========================================================================================
|
|
|
-parameter N = 1;
|
|
|
-parameter M = 1;
|
|
|
-
|
|
|
-always @(posedge Clk50) begin
|
|
|
- if (!Rst) begin
|
|
|
- decimFactor <= 0;
|
|
|
- end else begin
|
|
|
- decimFactor <= 0;
|
|
|
- end
|
|
|
-end
|
|
|
-
|
|
|
-parameter LsbForR1 = 10'd16;
|
|
|
-parameter LsbForR2 = 10'd18;
|
|
|
-parameter LsbForR4 = 10'd18;
|
|
|
+//================================================================================
|
|
|
+// CODING
|
|
|
+//================================================================================
|
|
|
|
|
|
-parameter [31:0] Nco1PhaseInc = 32'h051eb851;
|
|
|
-parameter [31:0] Nco2PhaseInc = 32'h33333333;
|
|
|
-
|
|
|
initial begin
|
|
|
Clk50 = 1'b1;
|
|
|
Rst = 1'b1;
|
|
|
@@ -87,31 +76,31 @@ always @(posedge Clk50) begin
|
|
|
tbCnt <= 32'd0;
|
|
|
end
|
|
|
end
|
|
|
-
|
|
|
-reg [20:0] oscWindDelay;
|
|
|
-
|
|
|
+
|
|
|
always @(posedge Clk50) begin
|
|
|
if (!Rst) begin
|
|
|
- oscWindDelay <= {oscWindDelay[20:0],oscWind};
|
|
|
- end else begin
|
|
|
- oscWindDelay <= 22'd0;
|
|
|
- end
|
|
|
-end
|
|
|
-
|
|
|
-always @ (posedge Clk50) begin
|
|
|
- if (oscWind) begin
|
|
|
- phase = phase + phaseInc;
|
|
|
- phaseInc <= phaseInc + 0.003;
|
|
|
- signal = $sin(2*pi*phase);
|
|
|
- adcData = 2**12 * signal;
|
|
|
- end else begin
|
|
|
- adcData = 0;
|
|
|
- phase = 0;
|
|
|
- phaseInc = 0.001;
|
|
|
- end
|
|
|
+ if (tbCnt == 100) begin
|
|
|
+ decimFactor <= 2;
|
|
|
+ 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
|
|
|
end
|
|
|
-
|
|
|
-
|
|
|
|
|
|
CordicNco
|
|
|
#(
|
|
|
@@ -157,15 +146,10 @@ ncoInst2
|
|
|
|
|
|
DecimFilterWrapperTest
|
|
|
#(
|
|
|
- .AdcDataWidth (14),
|
|
|
+ .InDataWidth (InDataWidth),
|
|
|
.N (N),
|
|
|
.M (M),
|
|
|
- .FilteredDataWidth (MaxWidth),
|
|
|
- .FirOutDataWidth (48),
|
|
|
- .FirOutCutBit (42),
|
|
|
- .LsbForR1 (LsbForR1),
|
|
|
- .LsbForR2 (LsbForR2),
|
|
|
- .LsbForR4 (LsbForR4)
|
|
|
+ .OutDataWidth (MaxWidth)
|
|
|
)
|
|
|
DecimFilter
|
|
|
(
|
|
|
@@ -175,9 +159,6 @@ DecimFilter
|
|
|
.DataVal_i (oscWind),
|
|
|
|
|
|
.Data_i (sinAdd),
|
|
|
- // .Data_i (adcDataMixedCut),
|
|
|
- // .Data_i (adcData),
|
|
|
- // .Data_i (ncoSin2),
|
|
|
|
|
|
.Data_o (filteredDataOut),
|
|
|
.DataVal_o (resultVal)
|
|
|
@@ -185,15 +166,10 @@ DecimFilter
|
|
|
|
|
|
DecimFilterWrapperTest
|
|
|
#(
|
|
|
- .AdcDataWidth (16),
|
|
|
+ .InDataWidth (InDataWidth),
|
|
|
.N (N),
|
|
|
.M (M),
|
|
|
- .FilteredDataWidth (MaxWidth),
|
|
|
- .FirOutDataWidth (48),
|
|
|
- .FirOutCutBit (42),
|
|
|
- .LsbForR1 (LsbForR1),
|
|
|
- .LsbForR2 (LsbForR2),
|
|
|
- .LsbForR4 (LsbForR4)
|
|
|
+ .OutDataWidth (MaxWidth)
|
|
|
)
|
|
|
ImpulseResponseFilter
|
|
|
(
|
|
|
@@ -205,13 +181,9 @@ ImpulseResponseFilter
|
|
|
.Data_i (singlePulse),
|
|
|
|
|
|
.Data_o (impResponse),
|
|
|
- .DataVal_o (impRespVal)
|
|
|
+ .DataVal_o ()
|
|
|
);
|
|
|
-
|
|
|
-integer inSignal,filteredData, impResp;
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
always @(posedge Clk50) begin
|
|
|
if (tbCnt==32'd1) begin
|
|
|
inSignal = $fopen("C:/S5243_FFT_REPO/src/src/Sim/InputSignal.txt","w");
|
|
|
@@ -225,28 +197,13 @@ always @(posedge Clk50) begin
|
|
|
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-2]);
|
|
|
-wire writeEn = (tbCnt>= (startValue+(N*2)) & tbCnt <= (stopValue+(N*2)));
|
|
|
-
|
|
|
-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 (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
|
|
|
@@ -256,8 +213,8 @@ 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 (writeEn) begin
|
|
|
- if (impRespVal) begin
|
|
|
+ if (resultVal) begin
|
|
|
+ // $fwrite(impResp,"%d\n", firRespout);
|
|
|
$fwrite(impResp,"%d\n", impResponse);
|
|
|
end
|
|
|
end
|