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

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

reorder channels

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