Presentation is loading. Please wait.

Presentation is loading. Please wait.

Implementation in Verilog Kirk Weedman KD7IRS

Similar presentations


Presentation on theme: "Implementation in Verilog Kirk Weedman KD7IRS"— Presentation transcript:

1 Implementation in Verilog Kirk Weedman KD7IRS
Mercury Receiver Implementation in Verilog Kirk Weedman KD7IRS

2 Stages ADC Data VARCIC CIC FIR rate CORDIC I I CIC FIR VARCIC Q Q
Decimation: 80/160/320 Stages: 11 Decimation: 4 Decimation: 2 VARCIC CIC FIR rate 2 Out_strobe In_strobe CORDIC 1 In_strobe Out_strobe In_strobe I I ADC Data 22 23 24 24 CIC FIR VARCIC Q Q 22 23 24 24 32 Out_strobe In_strobe Frequency 1 In_strobe Out_strobe In_strobe MHz clock

3 //------------------------------------------------------------------------------
// Copyright (c) 2008 Alex Shovkoplyas, VE3NEA module receiver( input clock, // MHz input [1:0] rate, //00=48, 01=96, 10=192 kHz input [31:0] frequency, output out_strobe, input signed [15:0] in_data, output [23:0] out_data_I, output [23:0] out_data_Q ); wire signed [21:0] cordic_outdata_I; wire signed [21:0] cordic_outdata_Q; // cordic cordic cordic_inst( .clock(clock), .in_data(in_data), //16 bit .frequency(frequency), //32 bit .out_data_I(cordic_outdata_I), //22 bit .out_data_Q(cordic_outdata_Q) receiver.v

4 //------------------------------------------------------------------------------
// CIC decimator #1, decimation factor 80/160/320 //I channel wire cic_outstrobe_1; wire signed [22:0] cic_outdata_I1; wire signed [22:0] cic_outdata_Q1; varcic #(.STAGES(5), .DECIMATION(80), .IN_WIDTH(22), .ACC_WIDTH(64), .OUT_WIDTH(23)) varcic_inst_I1( .clock(clock), .in_strobe(1'b1), .extra_decimation(rate), .out_strobe(cic_outstrobe_1), .in_data(cordic_outdata_I), .out_data(cic_outdata_I1) ); //Q channel varcic_inst_Q1( .out_strobe(), .in_data(cordic_outdata_Q), .out_data(cic_outdata_Q1) receiver.v

5 //------------------------------------------------------------------------------
// CIC decimator #2, decimation factor 4 //I channel wire cic_outstrobe_2; wire signed [23:0] cic_outdata_I2; wire signed [23:0] cic_outdata_Q2; cic #(.STAGES(11), .DECIMATION(4), .IN_WIDTH(23), .ACC_WIDTH(45), .OUT_WIDTH(24)) cic_inst_I2( .clock(clock), .in_strobe(cic_outstrobe_1), .out_strobe(cic_outstrobe_2), .in_data(cic_outdata_I1), .out_data(cic_outdata_I2) ); //Q channel cic_inst_Q2( .out_strobe(), .in_data(cic_outdata_Q1), .out_data(cic_outdata_Q2) receiver.v

6 //------------------------------------------------------------------------------
// FIR coefficients and sequencing wire signed [23:0] fir_coeff; fir_coeffs fir_coeffs_inst( .clock(clock), .start(cic_outstrobe_2), .coeff(fir_coeff) ); // FIR decimator fir #(.OUT_WIDTH(24)) fir_inst_I( .coeff(fir_coeff), .in_data(cic_outdata_I2), .out_data(out_data_I), .out_strobe(out_strobe) fir_inst_Q( .in_data(cic_outdata_Q2), .out_data(out_data_Q), .out_strobe() endmodule receiver.v

7 Stages ADC Data VARCIC CIC FIR rate CORDIC I I CIC FIR VARCIC Q Q
Decimation: 80/160/320 Stages: 11 Decimation: 4 Decimation: 2 VARCIC CIC FIR rate 2 Out_strobe In_strobe CORDIC 1 In_strobe Out_strobe In_strobe I I ADC Data 22 23 24 24 CIC FIR VARCIC Q Q 22 23 24 24 32 Out_strobe In_strobe Frequency 1 In_strobe Out_strobe In_strobe MHz clock

8 CIC Filters A CIC decimator has N cascaded integrator stages clocked at fs, followed by a rate change factor of R, followed by N cascaded comb stages running at fs/R I I I R C C C Three Stage Decimating CIC Filter (N = 3)

9 CIC Filters Bit Gain For CIC decimators, the gain G at the output of the final comb section is: Gain = (RM) R = decimation rate M = design parameter and is called the differential delay M can be any positive integer, but it is usually limited to 1 or 2 N = Number of Integrator /Comb stages Assuming two's complement arithmetic, we can use this result to calculate the number of bits required for the last comb due to bit growth. If Bin is the number of input bits, then the number of output bits, Bout, is Bout = N log (RM) + Bin It also turn out that Bout bits are needed for each integrator and comb stage. The input needs to be sign extended to Bout bits, but LSB's can either be truncated or rounded at later stages. N 2

10 CIC Filters Bit Gain For CIC decimators, the gain G at the output of the final comb section is: Gain = (RM) For the Mercury receiver: R = decimation rate = 320 (when running at 48Khz) for varcic.v and 4 for cic.v M = 1 N = 5 stages for varcic.v and 11 for cic.v Bout = N log (RM) + Bin Bout1 = 5 * = = Why is ACC_WIDTH = 64 in the code? Bout2 = 11 * = = 45. See ACC_WIDTH in cic.v instantiation N 2

11 ( ) ( ) CIC Filters Filter Gain 2 2 RM RM
For a CIC decimator, the normalized gain at the output of the last comb is given by G = This lies in the interval (1/2 : 1]. Note that when R is a power of two, the gain is unity. This gain can be used to calculate a scale factor, S, to apply to the final shifted output. S = which lies in the interval [1; 2). By doing this, the CIC decimation filter can have unity DC gain. ( ) N RM 2 log RM 2 ( ) log RM N 2 2 RM

12 ( ) ( ) ( ) ( ) ( ) ( ) CIC Filters Filter Gain 2 2 2 2 RM 320 320 320
For Mercury, the first VARCIC has N = 5 stages, M = 1, and R = 80/160/320 G = = = = This lies in the interval (1/2 : 1]. Note that when R is a power of two, the gain is unity. This gain can be used to calculate a scale factor, S, to apply to the final shifted output. S = = = 10.49 which lies in the interval [1; 2). By doing this, the CIC decimation filter can have unity DC gain. ( ) ( ) ( ) ( ) N 5 5 5 RM 320 320 320 2 log RM 2 log 320 2 9 512 2 2 ( ) ( ) log RM N 5 2 512 2 RM 320

13 module varcic( extra_decimation, clock, in_strobe, out_strobe, in_data, out_data );
//design parameters parameter STAGES = 5; parameter DECIMATION = 320; parameter IN_WIDTH = 22; //computed parameters //ACC_WIDTH = IN_WIDTH + Ceil(STAGES * Log2(decimation factor)) //OUT_WIDTH = IN_WIDTH + Ceil(Log2(decimation factor) / 2) parameter ACC_WIDTH = 64; parameter OUT_WIDTH = 27; //00 = DECIMATION*4, 01 = DECIMATION*2, 10 = DECIMATION input [1:0] extra_decimation; input clock; input in_strobe; output reg out_strobe; input signed [IN_WIDTH-1:0] in_data; output reg signed [OUT_WIDTH-1:0] out_data; varcic.v

14 varcic.v DECIMATION = 80 extra_decimation sample_no 2’b00 320-1
// // control reg [15:0] sample_no; initial sample_no = 16'd0; clock) if (in_strobe) begin if (sample_no == ((DECIMATION << (2-extra_decimation))-1)) sample_no <= 0; out_strobe <= 1; end else sample_no <= sample_no + 8'd1; out_strobe <= 0; varcic.v DECIMATION = 80 extra_decimation sample_no 2’b 2’b 2’b

15 //------------------------------------------------------------------------------
// stages wire signed [ACC_WIDTH-1:0] integrator_data [0:STAGES]; wire signed [ACC_WIDTH-1:0] comb_data [0:STAGES]; assign integrator_data[0] = in_data; assign comb_data[0] = integrator_data[STAGES]; genvar i; generate for (i=0; i<STAGES; i=i+1) begin : cic_stages cic_integrator #(ACC_WIDTH) cic_integrator_inst( .clock(clock), .strobe(in_strobe), .in_data(integrator_data[i]), .out_data(integrator_data[i+1]) ); cic_comb #(ACC_WIDTH) cic_comb_inst( .strobe(out_strobe), .in_data(comb_data[i]), .out_data(comb_data[i+1]) end endgenerate varcic.v Stages = 5 I R C

16 //------------------------------------------------------------------------------
// output rounding localparam MSB0 = ACC_WIDTH - 1; //63 localparam LSB0 = ACC_WIDTH - OUT_WIDTH; //41 localparam MSB1 = MSB0 - STAGES; //58 localparam LSB1 = LSB0 - STAGES; //36 localparam MSB2 = MSB1 - STAGES; //53 localparam LSB2 = LSB1 - STAGES; //31 clock) case (extra_decimation) 0: out_data <= comb_data[STAGES][MSB0:LSB0] + comb_data[STAGES][LSB0-1]; 1: out_data <= comb_data[STAGES][MSB1:LSB1] + comb_data[STAGES][LSB1-1]; 2: out_data <= comb_data[STAGES][MSB2:LSB2] + comb_data[STAGES][LSB2-1]; endcase endmodule @ 48Khz R = 320, N log2(320) = 5*9 Bout = = 67 –3 (-3 is to increase gain by 8) OUT_WIDTH = 23 @ 96Khz R = 160, N log2(160) = 5*8 Bout = = 62 –3 @ 192Khz R = 80, N log2(80) = 5*7 Bout = = 57 –3 varcic.v

17 cic_comb.v - + module cic_comb( clock, strobe, in_data, out_data );
parameter WIDTH = 64; input clock; input strobe; input signed [WIDTH-1:0] in_data; output reg signed [WIDTH-1:0] out_data; reg signed [WIDTH-1:0] prev_data; initial prev_data = 0; clock) if (strobe) begin out_data <= in_data - prev_data; prev_data <= in_data; end endmodule cic_comb.v strobe WIDTH EN in_data prev_data WIDTH - + EN WIDTH out_data WIDTH clock

18 module cic_integrator( clock, strobe, in_data, out_data );
parameter WIDTH = 64; input clock; input strobe; input signed [WIDTH-1:0] in_data; output reg signed [WIDTH-1:0] out_data; initial out_data = 0; clock) if (strobe) out_data <= out_data + in_data; endmodule cic_integrator.v strobe WIDTH + + EN WIDTH WIDTH out_data in_data WIDTH clock

19 FIR Filters A FIR filter is described by the function
y(n) = x(n-i) h(i) Or a transfer function Where N = filter Order N-1 i= 0 N 1 2 -1 -2 -N H(z) = a + a z + a z + …. a z Low Pass

20 + FIR Filters y(n) = x(n-i) h(i) N-1 Example: N = 8 i = 0 x(n) x(n-7)
Filter coefficients y(n)

21 FIR Filters ) ( ) ( ) ( H(z) = a + a z + a z + …. a z a = w(i)
N 1 2 -1 -2 -N H(z) = a + a z + a z + …. a z Low Pass Do how do we calculate the coefficients? For a FIR low pass filter they could be calculated as follows: sin(n w ) c . . . w = 2 p c F c F = cutoff frequency a = w(i) . c i c (n w ) . i: 0, 1, …. N n = i – N/2 Where w(i) is a window function. Two well known window functions are the Hamming and Blackman Hamming: Blackman: ) . 2 p n N ( w(i) = cos ) . 2 p n N ( . ) ( 4 p n N w(i) = cos + .08cos

22 FIR Filters ) ( ) ( ) ( H(z) = a + a z + a z + …. a z a = w(i)
5th order N = 4 N 1 2 -1 -2 -N H(z) = a + a z + a z + …. a z Low Pass Do how do we calculate the coefficients? For a FIR low pass filter they could be calculated as follows: sin(n w ) c . . . w = 2 p c F c F = cutoff frequency a = w(i) . c i c (n w ) . i: 0, 1, …. N n = i – N/2 i: 0, 1, 2, 3, 4 n: -2, -1, 0, 1, 2 Where w(i) is a window function. Two well known window functions are the Hamming and Blackman Hamming: Blackman: ) . 2 p n N ( w(i) = cos Notice symmetry: w(0) and w(4) values are identical ) . 2 p n N ( . ) ( 4 p n N w(i) = cos + .08cos


Download ppt "Implementation in Verilog Kirk Weedman KD7IRS"

Similar presentations


Ads by Google