Attention
This documentation is a work in progress. Expect to see errors and unfinished things.
cic_multichannel Source File
1`timescale 1ns / 1ns
2
3/** CIC Multichannel
4 Generic multichannel Cascaded-Integrator-Comb filter comprised of:
5 - Double Integrator (DI) per channel
6 - Multichannel Serializer sampling the output of all DIs into a shift-chain
7 at a rate defined by cic_base_per
8 - (Optional configurable delay chain)
9 - Cascaded Differentiator and post-filter (CC Filter) with barrel shifter
10 sampled at a rate defined by cc_samp_per
11 - CIC timing generator
12 - Shift-chain tap of the DI serialized stream
13
14 +-------------------------------------+
15 | +-----+ +---+ |
16 in[0]--->D INT+---> | +-------------> di_sr_out
17 | +-----+ | S | | |
18 | | E | | +------+ |
19 | +-----+ | R | | | | |
20 in[1]--->D INT+---> I +-[][][]--+-->CCFILT+---> cc_sr_out
21 | +-----+ | A | SHIFT | | |
22 | | L | +---^--+ |
23 | +-----+ | | | |
24 in[N]--->D INT+---> | | |
25 | +-----+ +-^-+ | |
26 | | | |
27 +-------------------------------------+
28 | |
29 cic_sample + + cc_sample
30*/
31
32module cic_multichannel #(
33 parameter n_chan=12,
34
35 // DI parameters
36 parameter di_dwi=16, // data width
37 parameter di_rwi=32, // result width
38 // Difference between above two widths should be N*log2 of the maximum number
39 // of samples per CIC sample, where N=2 is the order of the CIC filter
40 parameter di_noise_bits=4, // Number of noise bits to discard at the output of Double Integrator.
41 // This depends on the SNR of the inputs and the CIC sample rate
42
43 parameter shift_delay=0, // Optional shifter between Integrator and Comb. A value of 0 disables shifter
44
45 parameter cc_outw=20, // CCFilt output width; Must be 20 if using half-band filter
46 parameter cc_halfband=1,
47 parameter cc_use_delay=0, // Match pipeline length of filt_halfband=1
48 parameter cc_shift_base=0, // Bits to discard from previous acc step
49 parameter cc_shift_wi=4
50) (
51 // Incoming stream
52 input clk,
53 input reset,
54 input stb_in, // Strobe signal for input samples
55 input [n_chan*di_dwi-1:0] d_in, // Flattened array of unprocessed data streams. CH0 in LSBs
56 input cic_sample, // CIC base sampling signal
57
58 // CC Filter controls
59 input cc_sample, // CCFilt sampling signal
60 input [cc_shift_wi-1:0] cc_shift, // controls scaling of filter result
61
62 // Post-integrator conveyor belt tap
63 output di_stb_out,
64 output [di_rwi-1:0] di_sr_out,
65
66 // Post-CC filter conveyor belt out
67 output cc_stb_out,
68 output signed [cc_outw-1:0] cc_sr_out
69);
70 // Synchronize reset
71 reg [1:0] reset_r=0;
72
73 always @(posedge clk) begin
74 reset_r <= {reset_r[0],reset};
75 end
76
77 // ------
78 // Double Integrator per channel
79 // ------
80
81 wire [n_chan*di_rwi-1:0] di_out;
82
83 genvar ch_id;
84 generate for (ch_id=0; ch_id < n_chan; ch_id=ch_id+1) begin : g_d_int
85
86 double_inte_smp #(
87 .dwi (di_dwi),
88 .dwo (di_rwi))
89 i_double_inte (
90 .clk (clk),
91 .reset (reset_r[1]),
92 .stb_in (stb_in),
93 .in (d_in[(ch_id+1)*di_dwi-1:ch_id*di_dwi]),
94 .out (di_out[(ch_id+1)*di_rwi-1:ch_id*di_rwi])
95 );
96
97 end endgenerate
98
99 // ------
100 // Multichannel serializer/conveyor belt generator
101 // ------
102
103 wire [di_rwi-1:0] sr_out_l;
104 wire stb_out_l;
105
106 serializer_multichannel #(
107 .n_chan (n_chan),
108 .dw (di_rwi))
109 i_serializer_multich (
110 .clk (clk),
111 .sample_in (cic_sample),
112 .data_in (di_out),
113 .gate_out (stb_out_l),
114 .stream_out (sr_out_l)
115 );
116
117 // ------
118 // Optional shift-based delay
119 // ------
120 wire [di_rwi-1:0] sr_out_shift;
121 wire stb_out_shift, stb_out_shift_l;
122
123 reg_delay #(
124 .dw (di_rwi+1),
125 .len (shift_delay*n_chan))
126 i_shift_delay (
127 .clk (clk),
128 .reset (reset),
129 .gate (stb_out_l), // Shift at line-rate
130 .din ({sr_out_l, stb_out_l}),
131 .dout ({sr_out_shift, stb_out_shift_l})
132 );
133
134 assign stb_out_shift = stb_out_shift_l & stb_out_l;
135
136 // Pre-comb conveyor-belt tap
137 assign di_stb_out = stb_out_shift;
138 assign di_sr_out = sr_out_shift;
139
140 // ------
141 // Cascaded differentiator and post-filter
142 // ------
143`ifdef SIMULATE
144 // Enforces correct parameter settings
145 initial begin
146 if (cc_halfband && cc_outw != 20) begin
147 $display("ERROR: Output width of CC filt must be 20 when using the Half-Band filter");
148 $finish;
149 end
150 end
151`endif
152
153 ccfilt #(
154 .dw (di_rwi-di_noise_bits),
155 .outw (cc_outw),
156 .shift_wi (cc_shift_wi),
157 .shift_base (cc_shift_base),
158 .dsr_len (n_chan),
159 .use_hb (cc_halfband),
160 .use_delay (cc_use_delay))
161 i_ccfilt
162 (
163 .clk (clk),
164 .reset (reset),
165 .sr_in (sr_out_shift[di_rwi-1:(di_noise_bits)]), // Discard noisy LSBs
166 .sr_valid (stb_out_shift&cc_sample),
167 .shift (cc_shift),
168 .result (cc_sr_out), // signed filtered and scaled result
169 .strobe (cc_stb_out)
170 );
171
172endmodule