source: sandbox/MultiChannelUSB/Paella.v@ 133

Last change on this file since 133 was 132, checked in by demin, 14 years ago

add 4th stage to the deconvolution module

File size: 10.0 KB
RevLine 
[107]1module Paella
2 (
3 input wire CLK_50MHz,
4 output wire LED,
5
6 inout wire [3:0] TRG,
7 inout wire I2C_SDA,
8 inout wire I2C_SCL,
9 inout wire [4:0] CON_A,
10 input wire [15:0] CON_B,
11 input wire [12:0] CON_C,
12 input wire [1:0] CON_BCLK,
13 input wire [1:0] CON_CCLK,
14
15 input wire ADC_DCO,
16 input wire ADC_FCO,
17 input wire [2:0] ADC_D,
18
19 output wire USB_SLRD,
20 output wire USB_SLWR,
21 input wire USB_IFCLK,
22 input wire USB_FLAGA, // EMPTY flag for EP6
23 input wire USB_FLAGB, // FULL flag for EP8
24 input wire USB_FLAGC,
25 inout wire USB_PA0,
26 inout wire USB_PA1,
27 output wire USB_PA2,
28 inout wire USB_PA3,
29 output wire USB_PA4,
30 output wire USB_PA5,
31 output wire USB_PA6,
32 inout wire USB_PA7,
33 inout wire [7:0] USB_PB,
34
35 output wire RAM_CLK,
36 output wire RAM_CE1,
37 output wire RAM_WE,
38 output wire [19:0] RAM_ADDR,
39 inout wire RAM_DQAP,
40 inout wire [7:0] RAM_DQA,
41 inout wire RAM_DQBP,
42 inout wire [7:0] RAM_DQB
43 );
44
45 localparam N = 3;
46
47 // Turn output ports off
48/*
49 assign RAM_CLK = 1'b0;
50 assign RAM_CE1 = 1'b0;
51 assign RAM_WE = 1'b0;
52 assign RAM_ADDR = 20'h00000;
53*/
54 assign RAM_CLK = sys_clock;
55 assign RAM_CE1 = 1'b0;
56
57 // Turn inout ports to tri-state
58 assign TRG = 4'bz;
59 assign CON_A = 5'bz;
60 assign USB_PA0 = 1'bz;
61 assign USB_PA1 = 1'bz;
62 assign USB_PA3 = 1'bz;
63 assign USB_PA7 = 1'bz;
64// assign RAM_DQAP = 1'bz;
65// assign RAM_DQA = 8'bz;
66// assign RAM_DQBP = 1'bz;
67// assign RAM_DQB = 8'bz;
68
69 assign USB_PA2 = ~usb_rden;
70 assign USB_PA4 = usb_addr[0];
71 assign USB_PA5 = usb_addr[1];
72 assign USB_PA6 = ~usb_pktend;
73
74 wire usb_wrreq, usb_rdreq, usb_rden, usb_pktend;
75 wire usb_tx_wrreq, usb_rx_rdreq;
76 wire usb_tx_full, usb_rx_empty;
77 wire [7:0] usb_tx_data, usb_rx_data;
78 wire [1:0] usb_addr;
79
80 assign USB_SLRD = ~usb_rdreq;
81 assign USB_SLWR = ~usb_wrreq;
82
83 usb_fifo usb_unit
84 (
85 .usb_clock(USB_IFCLK),
86 .usb_data(USB_PB),
87 .usb_full(~USB_FLAGB),
88 .usb_empty(~USB_FLAGA),
89 .usb_wrreq(usb_wrreq),
90 .usb_rdreq(usb_rdreq),
91 .usb_rden(usb_rden),
92 .usb_pktend(usb_pktend),
93 .usb_addr(usb_addr),
94
95 .clock(sys_clock),
96
97 .tx_full(usb_tx_full),
98 .tx_wrreq(usb_tx_wrreq),
99 .tx_data(usb_tx_data),
100
101 .rx_empty(usb_rx_empty),
102 .rx_rdreq(usb_rx_rdreq),
103 .rx_q(usb_rx_data)
104 );
105
106 wire [11:0] osc_mux_data [4:0];
107
108 wire [11:0] trg_mux_data;
109 wire trg_flag;
110
111 wire [2:0] coi_data;
112 wire coi_flag;
113
114 wire [7*12-1:0] int_mux_data [N-1:0];
115
116 wire ana_dead [N-1:0];
117 wire ana_good [N-1:0];
118 wire [11:0] ana_data [N-1:0];
119 wire [11:0] ana_base [N-1:0];
120
[123]121 wire amp_flag [N-1:0];
[107]122 wire [11:0] amp_data [N-1:0];
123
124 wire cnt_good [N-1:0];
125 wire [15:0] cnt_bits_wire;
126
127 wire sys_clock, sys_frame;
128
129 wire [11:0] adc_data [N-1:0];
130 wire [11:0] sys_data [N-1:0];
131 wire [11:0] tst_data;
132
133 wire [11:0] cmp_data;
134 wire [11:0] del_data;
135
[123]136 wire [15:0] uwt_data1 [N-1:0];
137 wire [18:0] uwt_data2 [N-1:0];
[107]138 wire [1:0] uwt_flag1 [N-1:0];
[123]139 wire [1:0] uwt_flag2 [N-1:0];
[63]140
[132]141 wire [20:0] cic_data [N-1:0];
[123]142
143 wire [11:0] dec_data [N-1:0];
[132]144 wire [11:0] tmp_data;
[123]145
146 wire [1:0] ext_flag [N-1:0];
147
[107]148 wire i2c_reset;
149
150 sys_pll sys_pll_unit(
151 .inclk0(CLK_50MHz),
152 .c0(sys_clock));
153
154 test test_unit(
155 .clock(ADC_FCO),
156 .data(tst_data));
157
158 adc_lvds #(
159 .size(3),
160 .width(12)) adc_lvds_unit (
161 .clock(sys_clock),
162 .lvds_dco(ADC_DCO),
163 .lvds_fco(ADC_FCO),
164 .lvds_d(ADC_D),
165 .test(tst_data),
166 .trig({CON_B[9:0], TRG[1:0]}),
167 .adc_frame(sys_frame),
168 .adc_data({cmp_data, adc_data[2], adc_data[1], adc_data[0]}));
169
170 wire [15:0] cfg_bits [31:0];
171 wire [511:0] int_cfg_bits;
172
173 wire [39:0] cfg_mux_selector;
174
175 wire cfg_reset;
176
177 wire [11:0] bus_ssel;
178 wire bus_wren;
179 wire [31:0] bus_addr;
180 wire [15:0] bus_mosi;
181 wire [15:0] bus_miso [10:0];
182 wire [11:0] bus_busy;
183
184 wire [15:0] mrg_bus_miso;
185 wire mrg_bus_busy;
186
187 wire [11*16-1:0] int_bus_miso;
188
189 genvar j;
190
191 generate
192 for (j = 0; j < 32; j = j + 1)
193 begin : CONFIGURATION_OUTPUT
194 assign cfg_bits[j] = int_cfg_bits[j*16+15:j*16];
195 end
196 endgenerate
197
198 configuration configuration_unit (
199 .clock(sys_clock),
200 .reset(cfg_reset),
201 .bus_ssel(bus_ssel[0]),
202 .bus_wren(bus_wren),
203 .bus_addr(bus_addr[4:0]),
204 .bus_mosi(bus_mosi),
205 .bus_miso(bus_miso[0]),
206 .bus_busy(bus_busy[0]),
207 .cfg_bits(int_cfg_bits));
208
209 generate
210 for (j = 0; j < 3; j = j + 1)
211 begin : MUX_DATA
212 assign int_mux_data[j] = {
[123]213// {4'd0, amp_flag[j], 7'd0},
214// dec_data[j][37:26],
215// dec_data[j][36:25],
216// dec_data[j][35:24],
217 dec_data[j][11:0],
218 dec_data[j][11:0],
219 amp_data[j][11:0],
220 {ext_flag[j][1], 11'd0},
221 {ext_flag[j][0], 11'd0},
[132]222 cic_data[j][19:8],
[107]223 sys_data[j]};
224 end
225 endgenerate
226
227 assign cfg_mux_selector = {cfg_bits[4][7:0], cfg_bits[3], cfg_bits[2]};
228
229 lpm_mux #(
230 .lpm_size(7*3),
231 .lpm_type("LPM_MUX"),
232 .lpm_width(12),
233 .lpm_widths(5)) trg_mux_unit (
234 .sel(cfg_bits[4][12:8]),
235 .data({int_mux_data[2], int_mux_data[1], int_mux_data[0]}),
236 .result(trg_mux_data));
237
238 generate
239 for (j = 0; j < 5; j = j + 1)
240 begin : OSC_CHAIN
241
242 lpm_mux #(
243 .lpm_size(7*3),
244 .lpm_type("LPM_MUX"),
245 .lpm_width(12),
246 .lpm_widths(5)) osc_mux_unit (
247 .sel(cfg_mux_selector[j*8+4:j*8]),
248 .data({int_mux_data[2], int_mux_data[1], int_mux_data[0]}),
249 .result(osc_mux_data[j]));
250 end
251 endgenerate
252
253 trigger trigger_unit (
254 .clock(sys_clock),
255 .frame(sys_frame),
256 .reset(cfg_bits[0][0]),
257 .cfg_data(cfg_bits[5][11:0]),
258 .trg_data(trg_mux_data),
259 .trg_flag(trg_flag));
260
261 oscilloscope oscilloscope_unit (
262 .clock(sys_clock),
263 .frame(sys_frame),
264 .reset(cfg_bits[0][1]),
265 .cfg_data(cfg_bits[5][12]),
266 .trg_flag(trg_flag),
267 .osc_data({cmp_data[3:0], osc_mux_data[4], osc_mux_data[3], osc_mux_data[2], osc_mux_data[1], osc_mux_data[0]}),
268 .ram_wren(RAM_WE),
269 .ram_addr(RAM_ADDR),
270 .ram_data({RAM_DQA, RAM_DQAP, RAM_DQB, RAM_DQBP}),
271 .bus_ssel(bus_ssel[1]),
272 .bus_wren(bus_wren),
273 .bus_addr(bus_addr[19:0]),
274 .bus_mosi(bus_mosi),
275 .bus_miso(bus_miso[1]),
276 .bus_busy(bus_busy[1]));
[54]277
[132]278 new_filter #(.size(3), .width(12)) filter_unit (
[107]279 .clock(sys_clock),
[90]280 .frame(sys_frame),
[107]281 .reset(1'b0),
[132]282 .inp_data({sys_data[2], sys_data[1], sys_data[0]}),
283 .out_data({cic_data[2], cic_data[1], cic_data[0]}));
[107]284
[132]285 deconv #(.size(1), .shift(22), .width(20), .widthr(12)) deconv_unit (
[123]286 .clock(sys_clock),
287 .frame(sys_frame),
288 .reset(1'b0),
[132]289 .del_data({6'd14, 6'd14, 6'd14, 6'd14}),
290 .amp_data({6'd17, 6'd17, 6'd17, 6'd17}),
291 .tau_data({16'd16660, 16'd16660, 16'd16660, 16'd16660}),
[123]292// .del_data({cfg_bits[16][5:0], cfg_bits[15][13:8], cfg_bits[15][5:0]}),
293// .amp_data({cfg_bits[18][7:0], cfg_bits[17][15:8], cfg_bits[17][7:0]}),
294// .tau_data({cfg_bits[21], cfg_bits[20], cfg_bits[19]}),
[132]295 .inp_data({cic_data[2][19:0], cic_data[1][19:0], cic_data[0][19:0], 20'd0}),
296 .out_data({dec_data[2], dec_data[1], dec_data[0], tmp_data}));
[123]297
298
[107]299 generate
300 for (j = 0; j < 3; j = j + 1)
301 begin : MCA_CHAIN
302
303 assign sys_data[j] = (cfg_bits[1][4*j]) ? (adc_data[j] ^ 12'hfff) : (adc_data[j]);
[132]304
[123]305 extrema #(.width(12)) extrema_unit (
306 .clock(sys_clock),
307 .frame(sys_frame),
308 .reset(1'b0),
309 .inp_data(dec_data[j]),
310 .out_flag(ext_flag[j]));
[107]311
312 analyser analyser_unit (
313 .clock(sys_clock),
314 .frame(sys_frame),
315 .reset(cfg_bits[0][2+j]),
316 .cfg_data({cfg_bits[7+2*j][12:0], cfg_bits[6+2*j][11:0]}),
317 .uwt_flag(uwt_flag2[j]),
[123]318 .uwt_data(uwt_data2[j][18:7]),
[107]319 .ana_dead(ana_dead[j]),
320 .ana_good(ana_good[j]),
321 .ana_data(ana_data[j]),
322 .ana_base(ana_base[j]));
323
[123]324 amplitude #(.width(12)) amplitude_unit (
[107]325 .clock(sys_clock),
326 .frame(sys_frame),
327 .reset(cfg_bits[0][2+j]),
[123]328// .cfg_data(cfg_bits[12][11:0]),
[132]329 .cfg_data(12'd5),
[123]330 .inp_data(dec_data[j]),
331 .out_flag(amp_flag[j]),
332 .out_data(amp_data[j]));
[107]333 end
334 endgenerate
335
336 histogram32 histogram32_unit (
337 .clock(sys_clock),
338 .frame(sys_frame),
339 .reset(cfg_bits[0][5]),
340 .hst_good((ana_good[0]) & (cnt_good[0]) & (cfg_bits[13][1])),
341 .hst_data(ana_data[0]),
342/*
[123]343 .hst_good((amp_flag[j]) & (cnt_good[j]) & (cfg_bits[13][1])),
[107]344 .hst_data(amp_data[j]),
345*/
346 .bus_ssel(bus_ssel[2]),
347 .bus_wren(bus_wren),
348 .bus_addr(bus_addr[12:0]),
349 .bus_mosi(bus_mosi),
350 .bus_miso(bus_miso[2]),
351 .bus_busy(bus_busy[2]));
352
353 counter hst_counter_unit (
354 .clock(sys_clock),
355 .frame((sys_frame) & (~ana_dead[0])),
356// .frame(sys_frame),
357 .reset(cfg_bits[0][8]),
358 .setup(cfg_bits[13][0]),
359 .count(cfg_bits[13][1]),
360 .bus_ssel(bus_ssel[5]),
361 .bus_wren(bus_wren),
362 .bus_addr(bus_addr[1:0]),
363 .bus_mosi(bus_mosi),
364 .bus_miso(bus_miso[5]),
365 .bus_busy(bus_busy[5]),
366 .cnt_good(cnt_good[0]));
367
368
369 i2c_fifo i2c_unit(
370 .clock(sys_clock),
371 .reset(i2c_reset),
372/*
373 normal connection
374 .i2c_sda(I2C_SDA),
375 .i2c_scl(I2C_SCL),
376
377 following is a cross wire connection for EPT
378*/
379 .i2c_sda(I2C_SCL),
380 .i2c_scl(I2C_SDA),
381
382 .bus_ssel(bus_ssel[11]),
383 .bus_wren(bus_wren),
384 .bus_mosi(bus_mosi),
385 .bus_busy(bus_busy[11]));
386
387 generate
388 for (j = 0; j < 11; j = j + 1)
389 begin : BUS_OUTPUT
390 assign int_bus_miso[j*16+15:j*16] = bus_miso[j];
391 end
392 endgenerate
393
394 lpm_mux #(
395 .lpm_size(11),
396 .lpm_type("LPM_MUX"),
397 .lpm_width(16),
398 .lpm_widths(4)) bus_miso_mux_unit (
399 .sel(bus_addr[31:28]),
400 .data(int_bus_miso),
401 .result(mrg_bus_miso));
402
403 lpm_mux #(
404 .lpm_size(12),
405 .lpm_type("LPM_MUX"),
406 .lpm_width(1),
407 .lpm_widths(4)) bus_busy_mux_unit (
408 .sel(bus_addr[31:28]),
409 .data(bus_busy),
410 .result(mrg_bus_busy));
411
412 lpm_decode #(
413 .lpm_decodes(12),
414 .lpm_type("LPM_DECODE"),
415 .lpm_width(4)) lpm_decode_unit (
416 .data(bus_addr[31:28]),
417 .eq(bus_ssel));
418
419
420 control control_unit (
421 .clock(sys_clock),
422 .rx_empty(usb_rx_empty),
423 .tx_full(usb_tx_full),
424 .rx_data(usb_rx_data),
425 .rx_rdreq(usb_rx_rdreq),
426 .tx_wrreq(usb_tx_wrreq),
427 .tx_data(usb_tx_data),
428 .bus_wren(bus_wren),
429 .bus_addr(bus_addr),
430 .bus_mosi(bus_mosi),
431 .bus_miso(mrg_bus_miso),
432 .bus_busy(mrg_bus_busy),
433 .led(LED));
434
435/*
436 altserial_flash_loader #(
437 .enable_shared_access("OFF"),
438 .enhanced_mode(1),
439 .intended_device_family("Cyclone III")) sfl_unit (
440 .noe(1'b0),
441 .asmi_access_granted(),
442 .asmi_access_request(),
443 .data0out(),
444 .dclkin(),
445 .scein(),
446 .sdoin());
447*/
448
449endmodule
Note: See TracBrowser for help on using the repository browser.