source: trunk/MultiChannelUSB/Paella.v@ 180

Last change on this file since 180 was 172, checked in by demin, 12 years ago

remove overflow bins

File size: 13.4 KB
Line 
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 [16:0] CON_B,
11 input wire [12:0] CON_C,
12 input wire 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_PA5 = 1'b1;
71 assign USB_PA6 = ~usb_pktend;
72
73 wire usb_wrreq, usb_rdreq, usb_rden, usb_pktend;
74 wire usb_tx_wrreq, usb_rx_rdreq;
75 wire usb_tx_full, usb_rx_empty;
76 wire [7:0] usb_tx_data, usb_rx_data;
77
78 assign USB_SLRD = ~usb_rdreq;
79 assign USB_SLWR = ~usb_wrreq;
80
81 usb_fifo usb_unit
82 (
83 .usb_clock(USB_IFCLK),
84 .usb_data(USB_PB),
85 .usb_full(~USB_FLAGB),
86 .usb_empty(~USB_FLAGA),
87 .usb_wrreq(usb_wrreq),
88 .usb_rdreq(usb_rdreq),
89 .usb_rden(usb_rden),
90 .usb_pktend(usb_pktend),
91 .usb_addr(USB_PA4),
92
93 .clock(sys_clock),
94
95 .tx_full(usb_tx_full),
96 .tx_wrreq(usb_tx_wrreq),
97 .tx_data(usb_tx_data),
98
99 .rx_empty(usb_rx_empty),
100 .rx_rdreq(usb_rx_rdreq),
101 .rx_q(usb_rx_data)
102 );
103/*
104 reg [31:0] led_counter;
105 always @(posedge CLK_50MHz)
106 begin
107 led_counter = led_counter + 32'd1;
108 end
109 assign LED = led_counter[28];
110*/
111 wire [11:0] osc_mux_data [4:0];
112
113 wire [11:0] trg_mux_data;
114 wire trg_flag;
115
116 wire [4*12-1:0] int_mux_data [N-1:0];
117
118 wire [1:0] amp_flag [3*N-1:0];
119 wire [12:0] amp_data [3*N-1:0];
120
121 wire [1:0] amp_mux_flag [2:0];
122 wire [11:0] amp_mux_data [2:0];
123
124 wire cnt_good [3: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 [1:0] cmp_data;
134 wire [1:0] del_data;
135
136 wire [19:0] cic_data [N-1:0];
137
138 wire [11:0] dec_data [N-1:0];
139 wire [12:0] clp_data [N-1:0];
140 wire [11:0] tmp_data;
141
142
143 wire i2c_reset;
144
145 sys_pll sys_pll_unit(
146 .inclk0(CLK_50MHz),
147 .c0(sys_clock));
148
149 test test_unit(
150 .clk(ADC_FCO),
151 .data(tst_data));
152
153 adc_lvds #(
154 .size(3),
155 .width(12)) adc_lvds_unit (
156 .clock(sys_clock),
157 .lvds_dco(ADC_DCO),
158 .lvds_fco(ADC_FCO),
159 .lvds_d(ADC_D),
160 .trig(TRG[1:0]),
161 .adc_frame(sys_frame),
162 .adc_data({cmp_data, adc_data[2], adc_data[1], adc_data[0]}));
163
164 wire [15:0] cfg_bits [63:0];
165 wire [1023:0] int_cfg_bits;
166
167 wire [39:0] cfg_mux_selector;
168
169 wire cfg_reset;
170
171 wire [11:0] bus_ssel;
172 wire bus_wren;
173 wire [31:0] bus_addr;
174 wire [15:0] bus_mosi;
175 wire [15:0] bus_miso [10:0];
176 wire [11:0] bus_busy;
177
178 wire [15:0] mrg_bus_miso;
179 wire mrg_bus_busy;
180
181 wire [11*16-1:0] int_bus_miso;
182
183 genvar j;
184
185 generate
186 for (j = 0; j < 64; j = j + 1)
187 begin : CONFIGURATION_OUTPUT
188 assign cfg_bits[j] = int_cfg_bits[j*16+15:j*16];
189 end
190 endgenerate
191
192 configuration configuration_unit (
193 .clock(sys_clock),
194 .reset(cfg_reset),
195 .bus_ssel(bus_ssel[0]),
196 .bus_wren(bus_wren),
197 .bus_addr(bus_addr[4:0]),
198 .bus_mosi(bus_mosi),
199 .bus_miso(bus_miso[0]),
200 .bus_busy(bus_busy[0]),
201 .cfg_bits(int_cfg_bits));
202
203 generate
204 for (j = 0; j < 3; j = j + 1)
205 begin : MUX_DATA
206 assign int_mux_data[j] = {
207 {4'd0, amp_flag[0+j][0], 7'd0},
208 amp_data[0+j][11:0],
209 clp_data[j][11:0],
210 sys_data[j]};
211 end
212 endgenerate
213
214 assign cfg_mux_selector = {cfg_bits[4][7:0], cfg_bits[3], cfg_bits[2]};
215
216 lpm_mux #(
217 .lpm_size(4*3),
218 .lpm_type("LPM_MUX"),
219 .lpm_width(12),
220 .lpm_widths(4)) trg_mux_unit (
221 .sel(cfg_bits[4][11:8]),
222 .data({int_mux_data[2], int_mux_data[1], int_mux_data[0]}),
223 .result(trg_mux_data));
224
225 lpm_mux #(
226 .lpm_size(3),
227 .lpm_type("LPM_MUX"),
228 .lpm_width(14),
229 .lpm_widths(2)) amp_mux_unit_1 (
230 .sel(cfg_bits[6][1:0]),
231 .data({
232 {amp_flag[2], amp_data[2][11:0]},
233 {amp_flag[1], amp_data[1][11:0]},
234 {amp_flag[0], amp_data[0][11:0]}}),
235 .result({amp_mux_flag[0], amp_mux_data[0]}));
236
237 lpm_mux #(
238 .lpm_size(3),
239 .lpm_type("LPM_MUX"),
240 .lpm_width(14),
241 .lpm_widths(2)) amp_mux_unit_2 (
242 .sel(cfg_bits[6][5:4]),
243 .data({
244 {amp_flag[5], amp_data[5][11:0]},
245 {amp_flag[4], amp_data[4][11:0]},
246 {amp_flag[3], amp_data[3][11:0]}}),
247 .result({amp_mux_flag[1], amp_mux_data[1]}));
248
249 lpm_mux #(
250 .lpm_size(3),
251 .lpm_type("LPM_MUX"),
252 .lpm_width(14),
253 .lpm_widths(2)) amp_mux_unit_3 (
254 .sel(cfg_bits[6][9:8]),
255 .data({
256 {amp_flag[8], amp_data[8][11:0]},
257 {amp_flag[7], amp_data[7][11:0]},
258 {amp_flag[6], amp_data[6][11:0]}}),
259 .result({amp_mux_flag[2], amp_mux_data[2]}));
260
261 generate
262 for (j = 0; j < 5; j = j + 1)
263 begin : OSC_CHAIN
264
265 lpm_mux #(
266 .lpm_size(4*3),
267 .lpm_type("LPM_MUX"),
268 .lpm_width(12),
269 .lpm_widths(4)) osc_mux_unit (
270 .sel(cfg_mux_selector[j*8+3:j*8]),
271 .data({int_mux_data[2], int_mux_data[1], int_mux_data[0]}),
272 .result(osc_mux_data[j]));
273
274 end
275 endgenerate
276
277 trigger trigger_unit (
278 .clock(sys_clock),
279 .frame(sys_frame),
280 .reset(cfg_bits[0][0]),
281 .cfg_data(cfg_bits[5][11:0]),
282 .trg_data(trg_mux_data),
283 .trg_flag(trg_flag));
284
285 oscilloscope oscilloscope_unit (
286 .clock(sys_clock),
287 .frame(sys_frame),
288 .reset(cfg_bits[0][1]),
289 .cfg_data(cfg_bits[5][12]),
290 .trg_flag(trg_flag),
291 .osc_data({2'd0, cmp_data, osc_mux_data[4], osc_mux_data[3], osc_mux_data[2], osc_mux_data[1], osc_mux_data[0]}),
292 .ram_wren(RAM_WE),
293 .ram_addr(RAM_ADDR),
294 .ram_data({RAM_DQA, RAM_DQAP, RAM_DQB, RAM_DQBP}),
295 .bus_ssel(bus_ssel[1]),
296 .bus_wren(bus_wren),
297 .bus_addr(bus_addr[19:0]),
298 .bus_mosi(bus_mosi),
299 .bus_miso(bus_miso[1]),
300 .bus_busy(bus_busy[1]));
301
302 filter #(.size(3), .width(12)) filter_unit (
303 .clock(sys_clock),
304 .frame(sys_frame),
305 .reset(1'b0),
306 .inp_data({sys_data[2], sys_data[1], sys_data[0]}),
307 .out_data({cic_data[2], cic_data[1], cic_data[0]}));
308
309
310/*
311 clip #(.shift(19), .width(19), .widthr(12)) clip_unit (
312 .clock(sys_clock),
313 .frame(sys_frame),
314 .reset(1'b0),
315 .del_data({cfg_bits[39][5:0], cfg_bits[37][5:0], cfg_bits[35+8][5:0], cfg_bits[33][5:0]}),
316 .amp_data({6'd6, 6'd6, 6'd6, 6'd6}),
317 .tau_data({cfg_bits[38], cfg_bits[36], cfg_bits[34], cfg_bits[32]}),
318 .inp_data({
319 19'd0, cic_data[2][18:0],
320 cic_data[1][18:0], cic_data[0][18:0]}),
321 .out_data({
322 tmp_data, clp_data[2],
323 clp_data[1], clp_data[0]}));
324*/
325 generate
326 for (j = 0; j < 3; j = j + 1)
327 begin : MCA_CHAIN
328
329 shift #(.shift(11), .width(19), .widthr(13)) shift_unit (
330 .clock(sys_clock),
331 .frame(sys_frame),
332 .reset(1'b0),
333 .amp_data(6'd21),
334 .inp_data(cic_data[j][18:0]),
335 .out_data(clp_data[j]));
336
337 assign sys_data[j] = (cfg_bits[1][4*j]) ? (adc_data[j] ^ 12'hfff) : (adc_data[j]);
338
339 amplitude #(.width(13)) amplitude_unit_1 (
340 .clock(sys_clock),
341 .frame(sys_frame),
342 .reset(1'b0),
343 .min_data({1'b0, cfg_bits[7][11:0]}),
344 .max_data(13'd4095),
345// .cfg_data(cfg_bits[6+2*j][11:0]),
346 .inp_data(clp_data[j]),
347 .out_flag(amp_flag[0+j]),
348 .out_data(amp_data[0+j]));
349
350 amplitude #(.width(13)) amplitude_unit_2 (
351 .clock(sys_clock),
352 .frame(sys_frame),
353 .reset(1'b0),
354 .min_data({1'b0, cfg_bits[8][11:0]}),
355 .max_data(13'd4095),
356// .cfg_data(cfg_bits[7+2*j][11:0]),
357 .inp_data(clp_data[j]),
358 .out_flag(amp_flag[3+j]),
359 .out_data(amp_data[3+j]));
360
361 amplitude #(.width(13)) amplitude_unit_3 (
362 .clock(sys_clock),
363 .frame(sys_frame),
364 .reset(1'b0),
365 .min_data({1'b0, cfg_bits[9][11:0]}),
366 .max_data(13'd4095),
367// .cfg_data(cfg_bits[7+2*j][11:0]),
368 .inp_data(clp_data[j]),
369 .out_flag(amp_flag[6+j]),
370 .out_data(amp_data[6+j]));
371
372 end
373 endgenerate
374
375 histogram32 histogram32_unit_1 (
376 .clock(sys_clock),
377 .frame(sys_frame),
378 .reset(cfg_bits[0][5]),
379 .hst_good((amp_mux_flag[0][0]) & (cnt_good[0]) & (cfg_bits[13][1])),
380 .hst_data(amp_mux_data[0]),
381 .bus_ssel(bus_ssel[2]),
382 .bus_wren(bus_wren),
383 .bus_addr(bus_addr[12:0]),
384 .bus_mosi(bus_mosi),
385 .bus_miso(bus_miso[2]),
386 .bus_busy(bus_busy[2]));
387
388 counter hst_counter_unit_1 (
389 .clock(sys_clock),
390 .frame((sys_frame) & (~amp_mux_flag[0][1])),
391// .frame(sys_frame),
392 .reset(cfg_bits[0][8]),
393 .setup(cfg_bits[13][0]),
394 .count(cfg_bits[13][1]),
395 .bus_ssel(bus_ssel[5]),
396 .bus_wren(bus_wren),
397 .bus_addr(bus_addr[1:0]),
398 .bus_mosi(bus_mosi),
399 .bus_miso(bus_miso[5]),
400 .bus_busy(bus_busy[5]),
401 .cnt_good(cnt_good[0]));
402
403 histogram32 histogram32_unit_2 (
404 .clock(sys_clock),
405 .frame(sys_frame),
406 .reset(cfg_bits[0][6]),
407 .hst_good((amp_mux_flag[1][0]) & (cnt_good[1]) & (cfg_bits[14][1])),
408 .hst_data(amp_mux_data[1]),
409 .bus_ssel(bus_ssel[3]),
410 .bus_wren(bus_wren),
411 .bus_addr(bus_addr[12:0]),
412 .bus_mosi(bus_mosi),
413 .bus_miso(bus_miso[3]),
414 .bus_busy(bus_busy[3]));
415
416 counter hst_counter_unit_2 (
417 .clock(sys_clock),
418 .frame((sys_frame) & (~amp_mux_flag[1][1])),
419// .frame(sys_frame),
420 .reset(cfg_bits[0][8]),
421 .setup(cfg_bits[14][0]),
422 .count(cfg_bits[14][1]),
423 .bus_ssel(bus_ssel[6]),
424 .bus_wren(bus_wren),
425 .bus_addr(bus_addr[1:0]),
426 .bus_mosi(bus_mosi),
427 .bus_miso(bus_miso[6]),
428 .bus_busy(bus_busy[6]),
429 .cnt_good(cnt_good[1]));
430
431 histogram16 histogram16_unit (
432 .clock(sys_clock),
433 .frame(sys_frame),
434 .reset(cfg_bits[0][11]),
435 .hst_good((cnt_good[3]) & (~cnt_good[2])),
436 .hst_data(cnt_bits_wire < 16'd9999 ? cnt_bits_wire[13:0] : 14'd9999),
437 .bus_ssel(bus_ssel[8]),
438 .bus_wren(bus_wren),
439 .bus_addr(bus_addr[13:0]),
440 .bus_mosi(bus_mosi),
441 .bus_miso(bus_miso[8]),
442 .bus_busy(bus_busy[8]));
443
444 counter rmt_counter_1 (
445 .clock(sys_clock),
446 .frame((sys_frame) & (~amp_mux_flag[2][1])),
447// .frame(sys_frame),
448 .reset(cfg_bits[0][12]),
449 .setup((sys_frame) & (~cnt_good[2])),
450 .count((cnt_good[3]) & (cfg_bits[16][1])),
451 .bus_ssel(bus_ssel[9]),
452 .bus_wren(bus_wren),
453 .bus_addr(bus_addr[1:0]),
454 .bus_mosi(bus_mosi),
455 .bus_miso(bus_miso[9]),
456 .bus_busy(bus_busy[9]),
457 .cnt_good(cnt_good[2]));
458
459 counter rmt_counter_2 (
460 .clock(sys_clock),
461 .frame((sys_frame) & (~cnt_good[2])),
462 .reset(cfg_bits[0][13]),
463 .setup(cfg_bits[16][0]),
464 .count(cfg_bits[16][1]),
465 .bus_ssel(bus_ssel[10]),
466 .bus_wren(bus_wren),
467 .bus_addr(bus_addr[1:0]),
468 .bus_mosi(bus_mosi),
469 .bus_miso(bus_miso[10]),
470 .bus_busy(bus_busy[10]),
471 .cnt_good(cnt_good[3]));
472
473 lpm_counter #(
474 .lpm_direction("UP"),
475 .lpm_port_updown("PORT_UNUSED"),
476 .lpm_type("LPM_COUNTER"),
477 .lpm_width(16)) lpm_counter_component (
478 .sclr(((sys_frame) & (cnt_good[3]) & (~cnt_good[2])) | (cfg_bits[0][11])),
479 .clock(sys_clock),
480 .cnt_en((sys_frame) & (amp_mux_flag[2][0]) & (cnt_good[2]) & (cnt_good[3]) & (cfg_bits[16][1])),
481 .q(cnt_bits_wire));
482
483 i2c_fifo i2c_unit(
484 .clock(sys_clock),
485 .reset(i2c_reset),
486/*
487 normal connection
488 .i2c_sda(I2C_SDA),
489 .i2c_scl(I2C_SCL),
490
491 following is a cross wire connection for EPT
492*/
493 .i2c_sda(I2C_SCL),
494 .i2c_scl(I2C_SDA),
495
496 .bus_ssel(bus_ssel[11]),
497 .bus_wren(bus_wren),
498 .bus_mosi(bus_mosi),
499 .bus_busy(bus_busy[11]));
500
501 generate
502 for (j = 0; j < 11; j = j + 1)
503 begin : BUS_OUTPUT
504 assign int_bus_miso[j*16+15:j*16] = bus_miso[j];
505 end
506 endgenerate
507
508 lpm_mux #(
509 .lpm_size(11),
510 .lpm_type("LPM_MUX"),
511 .lpm_width(16),
512 .lpm_widths(4)) bus_miso_mux_unit (
513 .sel(bus_addr[31:28]),
514 .data(int_bus_miso),
515 .result(mrg_bus_miso));
516
517 lpm_mux #(
518 .lpm_size(12),
519 .lpm_type("LPM_MUX"),
520 .lpm_width(1),
521 .lpm_widths(4)) bus_busy_mux_unit (
522 .sel(bus_addr[31:28]),
523 .data(bus_busy),
524 .result(mrg_bus_busy));
525
526 lpm_decode #(
527 .lpm_decodes(12),
528 .lpm_type("LPM_DECODE"),
529 .lpm_width(4)) lpm_decode_unit (
530 .data(bus_addr[31:28]),
531 .eq(bus_ssel));
532
533
534 control control_unit (
535 .clock(sys_clock),
536 .rx_empty(usb_rx_empty),
537 .tx_full(usb_tx_full),
538 .rx_data(usb_rx_data),
539 .rx_rdreq(usb_rx_rdreq),
540 .tx_wrreq(usb_tx_wrreq),
541 .tx_data(usb_tx_data),
542 .bus_wren(bus_wren),
543 .bus_addr(bus_addr),
544 .bus_mosi(bus_mosi),
545 .bus_miso(mrg_bus_miso),
546 .bus_busy(mrg_bus_busy),
547 .led(LED));
548
549/*
550 altserial_flash_loader #(
551 .enable_shared_access("OFF"),
552 .enhanced_mode(1),
553 .intended_device_family("Cyclone III")) sfl_unit (
554 .noe(1'b0),
555 .asmi_access_granted(),
556 .asmi_access_request(),
557 .data0out(),
558 .dclkin(),
559 .scein(),
560 .sdoin());
561*/
562
563endmodule
Note: See TracBrowser for help on using the repository browser.