source: trunk/3DEES/Paella.v@ 178

Last change on this file since 178 was 178, checked in by demin, 11 years ago

adapt to 6ch

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