Statistics
| Branch: | Tag: | Revision:

root / usrp2 / sdr_lib / ddc_chain.v @ 6d45600a

History | View | Annotate | Download (6.71 KB)

1
//
2
// Copyright 2011-2012 Ettus Research LLC
3
//
4
// This program is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
8
//
9
// This program is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
// GNU General Public License for more details.
13
//
14
// You should have received a copy of the GNU General Public License
15
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
//
17

    
18
//! The USRP digital down-conversion chain
19

    
20
module ddc_chain
21
  #(
22
    parameter BASE = 0,
23
    parameter DSPNO = 0,
24
    parameter WIDTH = 24
25
  )
26
  (input clk, input rst, input clr,
27
   input set_stb, input [7:0] set_addr, input [31:0] set_data,
28
   input set_stb_user, input [7:0] set_addr_user, input [31:0] set_data_user,
29

    
30
   // From RX frontend
31
   input [WIDTH-1:0] rx_fe_i,
32
   input [WIDTH-1:0] rx_fe_q,
33

    
34
   // To RX control
35
   output [31:0] sample,
36
   input run,
37
   output strobe,
38
   output [31:0] debug
39
   );
40

    
41
   localparam  cwidth = 25;
42
   localparam  zwidth = 24;
43

    
44
   wire ddc_enb;
45
   wire [31:0] phase_inc;
46
   reg [31:0]  phase;
47

    
48
   wire [17:0] scale_factor;
49
   wire [cwidth-1:0] i_cordic, q_cordic;
50
   wire [WIDTH-1:0] i_cordic_clip, q_cordic_clip;
51
   wire [WIDTH-1:0] i_cic, q_cic;
52
   wire [WIDTH-1:0] i_hb1, q_hb1;
53
   wire [WIDTH-1:0] i_hb2, q_hb2;
54
   
55
   wire        strobe_cic, strobe_hb1, strobe_hb2;
56
   wire        enable_hb1, enable_hb2;
57
   wire [7:0]  cic_decim_rate;
58

    
59
   reg [WIDTH-1:0]  rx_fe_i_mux, rx_fe_q_mux;
60
   wire        realmode;
61
   wire        swap_iq;
62
   
63
   setting_reg #(.my_addr(BASE+0)) sr_0
64
     (.clk(clk),.rst(rst),.strobe(set_stb),.addr(set_addr),
65
      .in(set_data),.out(phase_inc),.changed());
66

    
67
   setting_reg #(.my_addr(BASE+1), .width(18)) sr_1
68
     (.clk(clk),.rst(rst),.strobe(set_stb),.addr(set_addr),
69
      .in(set_data),.out(scale_factor),.changed());
70

    
71
   setting_reg #(.my_addr(BASE+2), .width(10)) sr_2
72
     (.clk(clk),.rst(rst),.strobe(set_stb),.addr(set_addr),
73
      .in(set_data),.out({enable_hb1, enable_hb2, cic_decim_rate}),.changed());
74

    
75
   setting_reg #(.my_addr(BASE+3), .width(2)) sr_3
76
     (.clk(clk),.rst(rst),.strobe(set_stb),.addr(set_addr),
77
      .in(set_data),.out({realmode,swap_iq}),.changed());
78

    
79
   // MUX so we can do realmode signals on either input
80
   
81
   always @(posedge clk)
82
     if(swap_iq)
83
       begin
84
	  rx_fe_i_mux <= rx_fe_q;
85
	  rx_fe_q_mux <= realmode ? 0 : rx_fe_i;
86
       end
87
     else
88
       begin
89
	  rx_fe_i_mux <= rx_fe_i;
90
	  rx_fe_q_mux <= realmode ? 0 : rx_fe_q;
91
       end
92

    
93
   // NCO
94
   always @(posedge clk)
95
     if(rst)
96
       phase <= 0;
97
     else if(~ddc_enb)
98
       phase <= 0;
99
     else
100
       phase <= phase + phase_inc;
101

    
102
   //sign extension of cordic input
103
   wire [WIDTH-1:0] to_ddc_chain_i, to_ddc_chain_q;
104
   wire [cwidth-1:0] to_cordic_i, to_cordic_q;
105
   sign_extend #(.bits_in(WIDTH), .bits_out(cwidth)) sign_extend_cordic_i (.in(to_ddc_chain_i), .out(to_cordic_i));
106
   sign_extend #(.bits_in(WIDTH), .bits_out(cwidth)) sign_extend_cordic_q (.in(to_ddc_chain_q), .out(to_cordic_q));
107

    
108
   // CORDIC  24-bit I/O
109
   cordic_z24 #(.bitwidth(cwidth))
110
     cordic(.clock(clk), .reset(rst), .enable(ddc_enb),
111
	    .xi(to_cordic_i),. yi(to_cordic_q), .zi(phase[31:32-zwidth]),
112
	    .xo(i_cordic),.yo(q_cordic),.zo() );
113

    
114
   clip_reg #(.bits_in(cwidth), .bits_out(WIDTH)) clip_i
115
     (.clk(clk), .in(i_cordic), .strobe_in(1'b1), .out(i_cordic_clip));
116
   clip_reg #(.bits_in(cwidth), .bits_out(WIDTH)) clip_q
117
     (.clk(clk), .in(q_cordic), .strobe_in(1'b1), .out(q_cordic_clip));
118

    
119
   // CIC decimator  24 bit I/O
120
   cic_strober cic_strober(.clock(clk),.reset(rst),.enable(ddc_enb),.rate(cic_decim_rate),
121
			   .strobe_fast(1),.strobe_slow(strobe_cic) );
122

    
123
   cic_decim #(.bw(WIDTH))
124
     decim_i (.clock(clk),.reset(rst),.enable(ddc_enb),
125
	      .rate(cic_decim_rate),.strobe_in(1'b1),.strobe_out(strobe_cic),
126
	      .signal_in(i_cordic_clip),.signal_out(i_cic));
127
   
128
   cic_decim #(.bw(WIDTH))
129
     decim_q (.clock(clk),.reset(rst),.enable(ddc_enb),
130
	      .rate(cic_decim_rate),.strobe_in(1'b1),.strobe_out(strobe_cic),
131
	      .signal_in(q_cordic_clip),.signal_out(q_cic));
132

    
133
   // First (small) halfband  24 bit I/O
134
   small_hb_dec #(.WIDTH(WIDTH)) small_hb_i
135
     (.clk(clk),.rst(rst),.bypass(~enable_hb1),.run(ddc_enb),
136
      .stb_in(strobe_cic),.data_in(i_cic),.stb_out(strobe_hb1),.data_out(i_hb1));
137
   
138
   small_hb_dec #(.WIDTH(WIDTH)) small_hb_q
139
     (.clk(clk),.rst(rst),.bypass(~enable_hb1),.run(ddc_enb),
140
      .stb_in(strobe_cic),.data_in(q_cic),.stb_out(),.data_out(q_hb1));
141

    
142
   // Second (large) halfband  24 bit I/O
143
   wire [8:0]  cpi_hb = enable_hb1 ? {cic_decim_rate,1'b0} : {1'b0,cic_decim_rate};
144
   hb_dec #(.WIDTH(WIDTH)) hb_i
145
     (.clk(clk),.rst(rst),.bypass(~enable_hb2),.run(ddc_enb),.cpi(cpi_hb),
146
      .stb_in(strobe_hb1),.data_in(i_hb1),.stb_out(strobe_hb2),.data_out(i_hb2));
147

    
148
   hb_dec #(.WIDTH(WIDTH)) hb_q
149
     (.clk(clk),.rst(rst),.bypass(~enable_hb2),.run(ddc_enb),.cpi(cpi_hb),
150
      .stb_in(strobe_hb1),.data_in(q_hb1),.stb_out(),.data_out(q_hb2));
151

    
152
   //scalar operation (gain of 6 bits)
153
   wire [35:0] prod_i, prod_q;
154

    
155
   MULT18X18S mult_i
156
     (.P(prod_i), .A(i_hb2[WIDTH-1:WIDTH-18]), .B(scale_factor), .C(clk), .CE(strobe_hb2), .R(rst) );
157
   MULT18X18S mult_q
158
     (.P(prod_q), .A(q_hb2[WIDTH-1:WIDTH-18]), .B(scale_factor), .C(clk), .CE(strobe_hb2), .R(rst) );
159

    
160
   //pipeline for the multiplier (gain of 10 bits)
161
   reg [WIDTH-1:0] prod_reg_i, prod_reg_q;
162
   reg strobe_mult;
163

    
164
   always @(posedge clk) begin
165
       strobe_mult <= strobe_hb2;
166
       prod_reg_i <= prod_i[33:34-WIDTH];
167
       prod_reg_q <= prod_q[33:34-WIDTH];
168
   end
169

    
170
   // Round final answer to 16 bits
171
   wire [31:0] ddc_chain_out;
172
   wire ddc_chain_stb;
173

    
174
   round_sd #(.WIDTH_IN(WIDTH),.WIDTH_OUT(16)) round_i
175
     (.clk(clk),.reset(rst), .in(prod_reg_i),.strobe_in(strobe_mult), .out(ddc_chain_out[31:16]), .strobe_out(ddc_chain_stb));
176

    
177
   round_sd #(.WIDTH_IN(WIDTH),.WIDTH_OUT(16)) round_q
178
     (.clk(clk),.reset(rst), .in(prod_reg_q),.strobe_in(strobe_mult), .out(ddc_chain_out[15:0]), .strobe_out());
179

    
180
   dsp_rx_glue #(.DSPNO(DSPNO), .WIDTH(WIDTH)) custom(
181
    .clock(clk), .reset(rst), .clear(clr), .enable(run),
182
    .set_stb(set_stb_user), .set_addr(set_addr_user), .set_data(set_data_user),
183
    .frontend_i(rx_fe_i_mux), .frontend_q(rx_fe_q_mux),
184
    .ddc_in_i(to_ddc_chain_i), .ddc_in_q(to_ddc_chain_q),
185
    .ddc_out_sample(ddc_chain_out), .ddc_out_strobe(ddc_chain_stb), .ddc_out_enable(ddc_enb),
186
    .bb_sample(sample), .bb_strobe(strobe));
187

    
188
   assign      debug = {enable_hb1, enable_hb2, run, strobe, strobe_cic, strobe_hb1, strobe_hb2};
189
   
190
endmodule // ddc_chain