source: trunk/MultiChannelUSB/Paella.v@ 44

Last change on this file since 44 was 44, checked in by demin, 15 years ago

add baseline subtraction

File size: 10.7 KB
Line 
1module Paella
2 (
3 input wire CLK_50MHz,
4 output wire LED,
5
6 inout wire [3:0] TRG,
7 inout wire [6:0] CON_A,
8 inout wire [15:0] CON_B,
9 inout wire [12:0] CON_C,
10 input wire [1:0] CON_BCLK,
11 input wire [1:0] CON_CCLK,
12
13 input wire ADC_DCO,
14 input wire ADC_FCO,
15 input wire [2:0] ADC_D,
16
17 output wire USB_SLRD,
18 output wire USB_SLWR,
19 input wire USB_IFCLK,
20 input wire USB_FLAGA, // EMPTY flag for EP6
21 input wire USB_FLAGB, // FULL flag for EP8
22 input wire USB_FLAGC,
23 inout wire USB_PA0,
24 inout wire USB_PA1,
25 output wire USB_PA2,
26 inout wire USB_PA3,
27 output wire USB_PA4,
28 output wire USB_PA5,
29 output wire USB_PA6,
30 inout wire USB_PA7,
31 inout wire [7:0] USB_PB,
32
33 output wire RAM_CLK,
34 output wire RAM_CE1,
35 output wire RAM_WE,
36 output wire [19:0] RAM_ADDR,
37 inout wire RAM_DQAP,
38 inout wire [7:0] RAM_DQA,
39 inout wire RAM_DQBP,
40 inout wire [7:0] RAM_DQB
41 );
42
43 // Turn output ports off
44 assign RAM_CLK = 1'b0;
45 assign RAM_CE1 = 1'b0;
46 assign RAM_WE = 1'b0;
47 assign RAM_ADDR = 20'h00000;
48
49 // Turn inout ports to tri-state
50 assign TRG = 4'bz;
51 assign CON_A = 7'bz;
52 assign CON_B = 16'bz;
53 assign CON_C = 13'bz;
54 assign USB_PA0 = 1'bz;
55 assign USB_PA1 = 1'bz;
56 assign USB_PA3 = 1'bz;
57 assign USB_PA7 = 1'bz;
58 assign RAM_DQAP = 1'bz;
59 assign RAM_DQA = 8'bz;
60 assign RAM_DQBP = 1'bz;
61 assign RAM_DQB = 8'bz;
62
63
64 assign USB_PA2 = ~usb_rden;
65 assign USB_PA4 = usb_addr[0];
66 assign USB_PA5 = usb_addr[1];
67 assign USB_PA6 = ~usb_pktend;
68
69 reg [31:0] counter;
70 reg led_reg;
71// assign LED = counter[24];
72 assign LED = led_reg;
73
74 wire usb_wrreq, usb_rdreq, usb_rden, usb_pktend;
75 wire usb_fifo_aclr;
76 reg usb_fifo_tx_wrreq;
77 reg usb_fifo_rx_rdreq;
78 wire usb_fifo_tx_full, usb_fifo_rx_empty;
79 reg [7:0] usb_fifo_tx_data;
80 wire [7:0] usb_fifo_rx_data;
81 wire [1:0] usb_addr;
82
83 assign USB_SLRD = ~usb_rdreq;
84 assign USB_SLWR = ~usb_wrreq;
85
86 usb_fifo usb_fifo_unit
87 (
88 .usb_clk(USB_IFCLK),
89 .usb_data(USB_PB),
90 .usb_full(~USB_FLAGB),
91 .usb_empty(~USB_FLAGA),
92 .usb_wrreq(usb_wrreq),
93 .usb_rdreq(usb_rdreq),
94 .usb_rden(usb_rden),
95 .usb_pktend(usb_pktend),
96 .usb_addr(usb_addr),
97
98 .clk(CLK_50MHz),
99 .aclr(usb_fifo_aclr),
100
101 .tx_full(usb_fifo_tx_full),
102 .tx_wrreq((~usb_fifo_tx_full) & usb_fifo_tx_wrreq),
103 .tx_data(usb_fifo_tx_data),
104
105 .rx_empty(usb_fifo_rx_empty),
106 .rx_rdreq((~usb_fifo_rx_empty) & usb_fifo_rx_rdreq),
107 .rx_q(usb_fifo_rx_data)
108 );
109
110 reg [23:0] rx_counter;
111 reg [10:0] tst_counter;
112
113 reg ana_reset [2:0];
114 wire ana_peak_ready [2:0];
115 wire [11:0] ana_peak [2:0];
116
117 reg [9:0] osc_counter;
118 reg osc_byte_num;
119
120 reg osc_reset_mux, osc_reset [2:0];
121 wire [9:0] osc_start_addr [2:0];
122 reg [9:0] osc_start_addr_mux, osc_addr_mux, osc_addr [2:0];
123 wire [15:0] osc_q [2:0];
124 reg [15:0] osc_q_mux;
125
126 reg [1:0] hst_byte_num;
127
128 reg hst_reset_mux, hst_reset [2:0];
129 reg [11:0] hst_addr_mux, hst_addr [2:0];
130 wire [31:0] hst_q [2:0];
131 reg [31:0] hst_q_mux;
132
133 reg [3:0] select, state1, state2;
134 reg adc_fifo_aclr;
135
136 wire adc_clk;
137
138 reg [11:0] adc_data;
139
140 wire adc_data_ready [2:0];
141 wire [11:0] adc_lvds_data [2:0];
142
143 wire [11:0] raw_data [2:0];
144 wire [11:0] uwt_data [2:0];
145 wire [1:0] uwt_flag [2:0];
146
147 pll pll_unit(
148 .inclk0(CLK_50MHz),
149 .c0(adc_clk));
150/*
151 altserial_flash_loader #(
152 .enable_shared_access("OFF"),
153 .enhanced_mode(1),
154 .intended_device_family("Cyclone III")) sfl_unit (
155 .noe(1'b0),
156 .asmi_access_granted(),
157 .asmi_access_request(),
158 .data0out(),
159 .dclkin(),
160 .scein(),
161 .sdoin());
162*/
163 adc_lvds adc_lvds_unit (
164 .lvds_dco(ADC_DCO),
165 .lvds_fco(ADC_FCO),
166 .lvds_d(ADC_D),
167 .adc_db(adc_lvds_data[0]),
168 .adc_dc(adc_lvds_data[1]),
169 .adc_dd(adc_lvds_data[2]));
170
171 genvar i;
172 generate
173 for (i = 0; i < 3; i = i + 1)
174 begin : MCA_CHAIN
175 adc_fifo adc_fifo_unit (
176 .adc_clk(ADC_FCO),
177 .adc_data(adc_lvds_data[i]),
178 .aclr(adc_fifo_aclr),
179 .rdclk(CLK_50MHz),
180 .ready(adc_data_ready[i]),
181 .raw_data(raw_data[i]),
182 .uwt_data({uwt_flag[i], uwt_data[i]}));
183
184 analyser analyser_unit (
185 .clk(CLK_50MHz),
186 .reset(ana_reset[i]),
187 .data_ready(adc_data_ready[i]),
188 .uwt_flag(uwt_flag[i]),
189 .uwt_data(uwt_data[i]),
190 .peak_ready(ana_peak_ready[i]),
191 .peak(ana_peak[i]));
192/*
193 histogram histogram_unit (
194 .clk(CLK_50MHz),
195 .reset(hst_reset[i]),
196 .data_ready(adc_data_ready[i]),
197 .data(raw_data[i]),
198 .address(hst_addr[i]),
199 .q(hst_q[i]));
200*/
201 histogram histogram_unit (
202 .clk(CLK_50MHz),
203 .reset(hst_reset[i]),
204 .data_ready(ana_peak_ready[i]),
205 .data(ana_peak[i]),
206 .address(hst_addr[i]),
207 .q(hst_q[i]));
208
209 oscilloscope oscilloscope_unit (
210 .clk(CLK_50MHz),
211 .reset(osc_reset[i]),
212 .data_ready(adc_data_ready[i]),
213 .raw_data(raw_data[i]),
214 .uwt_data(uwt_data[i]),
215 .threshold(16'd100),
216 .address(osc_addr[i]),
217 .start_address(osc_start_addr[i]),
218 .q(osc_q[i]));
219 end
220 endgenerate
221
222/*
223 always @ (posedge adc_clk)
224 begin
225 counter <= counter + 32'd1;
226 end
227*/
228
229 always @*
230 begin
231 case(select)
232 4'h0:
233 begin
234 osc_reset[0] = osc_reset_mux;
235 osc_addr[0] = osc_addr_mux;
236 osc_q_mux = osc_q[0];
237 osc_start_addr_mux = osc_start_addr[0];
238
239 hst_reset[0] = hst_reset_mux;
240 hst_addr[0] = hst_addr_mux;
241 hst_q_mux = hst_q[0];
242 end
243 4'h1:
244 begin
245 osc_reset[1] = osc_reset_mux;
246 osc_addr[1] = osc_addr_mux;
247 osc_q_mux = osc_q[1];
248 osc_start_addr_mux = osc_start_addr[1];
249
250 hst_reset[1] = hst_reset_mux;
251 hst_addr[1] = hst_addr_mux;
252 hst_q_mux = hst_q[1];
253 end
254 4'h2:
255 begin
256 osc_reset[2] = osc_reset_mux;
257 osc_addr[2] = osc_addr_mux;
258 osc_q_mux = osc_q[2];
259 osc_start_addr_mux = osc_start_addr[2];
260
261 hst_reset[2] = hst_reset_mux;
262 hst_addr[2] = hst_addr_mux;
263 hst_q_mux = hst_q[2];
264 end
265 default:
266 begin
267 osc_reset[0] = osc_reset_mux;
268 osc_addr[0] = osc_addr_mux;
269 osc_q_mux = osc_q[0];
270 osc_start_addr_mux = osc_start_addr[0];
271
272 hst_reset[0] = hst_reset_mux;
273 hst_addr[0] = hst_addr_mux;
274 hst_q_mux = hst_q[0];
275 end
276 endcase
277 end
278
279 always @(posedge CLK_50MHz)
280 begin
281 if (~usb_fifo_rx_empty)
282 begin
283 led_reg <= 1'b0;
284 rx_counter <= 24'd0;
285 end
286 else
287 begin
288 if (&rx_counter)
289 begin
290 led_reg <= 1'b1;
291 end
292 else
293 begin
294 rx_counter <= rx_counter + 24'd1;
295 end
296 end
297
298 case(state1)
299 1:
300 begin
301 usb_fifo_rx_rdreq <= 1'b1;
302 usb_fifo_tx_wrreq <= 1'b0;
303 hst_reset_mux <= 1'b0;
304 osc_reset_mux <= 1'b0;
305 state1 <= 4'd2;
306 end
307
308 2:
309 begin
310 if (~usb_fifo_rx_empty)
311 begin
312 case (usb_fifo_rx_data)
313 8'h40, 8'h41, 8'h42:
314 begin
315 usb_fifo_rx_rdreq <= 1'b0;
316 hst_reset_mux <= 1'b1;
317 select <= usb_fifo_rx_data[3:0];
318 state1 <= 4'd1;
319 end
320 8'h50, 8'h51, 8'h52:
321 begin
322 usb_fifo_rx_rdreq <= 1'b0;
323 hst_addr_mux <= 12'd0;
324 hst_byte_num <= 2'd0;
325 select <= usb_fifo_rx_data[3:0];
326 state1 <= 4'd3;
327 end
328 8'h60, 8'h61, 8'h62:
329 begin
330 usb_fifo_rx_rdreq <= 1'b0;
331 osc_reset_mux <= 1'b1;
332 select <= usb_fifo_rx_data[3:0];
333 state1 <= 4'd1;
334 end
335 8'h70, 8'h71, 8'h72:
336 begin
337 usb_fifo_rx_rdreq <= 1'b0;
338 osc_addr_mux <= osc_start_addr_mux;
339 osc_counter <= 10'd0;
340 osc_byte_num <= 1'd0;
341 select <= usb_fifo_rx_data[3:0];
342 state1 <= 4'd6;
343 end
344 8'h30:
345 begin
346 usb_fifo_rx_rdreq <= 1'b0;
347 state1 <= 4'd1;
348 end
349 8'h31:
350 begin
351 usb_fifo_rx_rdreq <= 1'b0;
352 tst_counter <= 11'd0;
353 state1 <= 4'd9;
354 end
355 endcase
356 end
357 end
358
359 // hst transfer
360 3:
361 begin
362 usb_fifo_tx_data <= hst_q_mux[7:0];
363 usb_fifo_tx_wrreq <= 1'b1;
364 hst_byte_num <= 2'd1;
365 state1 <= 4'd4;
366 end
367 4:
368 begin
369 if (~usb_fifo_tx_full)
370 begin
371 case (hst_byte_num)
372 2'd0: usb_fifo_tx_data <= hst_q_mux[7:0];
373 2'd1: usb_fifo_tx_data <= hst_q_mux[15:8];
374 2'd2: usb_fifo_tx_data <= hst_q_mux[23:16];
375 2'd3: usb_fifo_tx_data <= hst_q_mux[31:24];
376 endcase
377 if ((&hst_byte_num) & (&hst_addr_mux))
378 begin
379 state1 <= 4'd5;
380 end
381 else
382 begin
383 if (&hst_byte_num)
384 begin
385 hst_addr_mux <= hst_addr_mux + 12'd1;
386 end
387 hst_byte_num <= hst_byte_num + 2'd1;
388 end
389 end
390 end
391 5:
392 begin
393 if (~usb_fifo_tx_full)
394 begin
395 usb_fifo_tx_wrreq <= 1'b0;
396 state1 <= 4'd1;
397 end
398 end
399
400 // osc transfer
401 6:
402 begin
403 usb_fifo_tx_data <= osc_q_mux[7:0];
404 usb_fifo_tx_wrreq <= 1'b1;
405 osc_byte_num <= 1'd1;
406 state1 <= 4'd7;
407 end
408 7:
409 begin
410 if (~usb_fifo_tx_full)
411 begin
412 case (osc_byte_num)
413 1'd0: usb_fifo_tx_data <= osc_q_mux[7:0];
414 1'd1: usb_fifo_tx_data <= osc_q_mux[15:8];
415 endcase
416 if ((&osc_byte_num) & (&osc_counter))
417 begin
418 state1 <= 4'd8;
419 end
420 else
421 begin
422 if (&osc_byte_num)
423 begin
424 osc_addr_mux <= osc_addr_mux + 10'd1;
425 osc_counter <= osc_counter + 10'd1;
426 end
427 osc_byte_num <= osc_byte_num + 1'd1;
428 end
429 end
430 end
431 8:
432 begin
433 if (~usb_fifo_tx_full)
434 begin
435 usb_fifo_tx_wrreq <= 1'b0;
436 state1 <= 4'd1;
437 end
438 end
439 // tst transfer
440 9:
441 begin
442 usb_fifo_tx_data <= tst_counter;
443 usb_fifo_tx_wrreq <= 1'b1;
444 tst_counter <= tst_counter + 11'd1;
445 state1 <= 4'd10;
446 end
447 10:
448 begin
449 if (~usb_fifo_tx_full)
450 begin
451 usb_fifo_tx_data <= tst_counter;
452 if (tst_counter == 11'd0) //(&osc_counter)
453 begin
454 state1 <= 4'd11;
455 end
456 else
457 begin
458 tst_counter <= tst_counter + 11'd1;
459 end
460 end
461 end
462 11:
463 begin
464 if (~usb_fifo_tx_full)
465 begin
466 usb_fifo_tx_wrreq <= 1'b0;
467 state1 <= 4'd1;
468 end
469 end
470
471 default:
472 begin
473 state1 <= 4'd1;
474 end
475 endcase
476 end
477
478 always @ (posedge adc_clk)
479 begin
480 case (state2)
481 1:
482 begin
483 adc_data <= 12'd0;
484 state2 <= 4'd2;
485 end
486
487 2:
488 begin
489 adc_data <= 12'd1024;
490 state2 <= 4'd3;
491 end
492
493 3:
494 begin
495 adc_data <= 12'd2048;
496 state2 <= 4'd4;
497 end
498
499 4:
500 begin
501 adc_data <= 12'd3072;
502 state2 <= 4'd5;
503 end
504
505 5:
506 begin
507 adc_data <= 12'd4095;
508 state2 <= 4'd1;
509 end
510
511 default:
512 begin
513 state2 <= 4'd1;
514 end
515 endcase
516 end
517
518endmodule
Note: See TracBrowser for help on using the repository browser.