source: sandbox/MultiChannelUSB/deconv.v@ 142

Last change on this file since 142 was 134, checked in by demin, 14 years ago

fix output assignment

File size: 12.1 KB
RevLine 
[113]1module deconv
2 #(
3 parameter size = 1, // number of channels
[123]4 parameter shift = 24, // right shift of the result
5 parameter width = 27, // bit width of the input data
[129]6 parameter widthr = 12 // bit width of the output data
[113]7 )
8 (
9 input wire clock, frame, reset,
[130]10 input wire [4*size*6-1:0] del_data,
11 input wire [4*size*6-1:0] amp_data,
12 input wire [4*size*16-1:0] tau_data,
13 input wire [4*size*width-1:0] inp_data,
14 output wire [4*size*widthr-1:0] out_data
[113]15 );
16
[114]17 localparam width1 = width + 1;
18 localparam width2 = width + 6 + 1;
[123]19 localparam width3 = width + 16 + 3;
[113]20
21 reg int_wren_reg, int_wren_next;
[130]22 reg int_flag_reg, int_flag_next;
[113]23 reg [1:0] int_chan_reg, int_chan_next;
24 reg [2:0] int_case_reg, int_case_next;
25 reg [7:0] int_addr_reg, int_addr_next;
26
[114]27 reg [5:0] del_addr_reg, del_addr_next;
28 wire [5:0] del_addr_wire;
[113]29 wire [7:0] int_addr_wire;
30
[130]31 reg [size*widthr-1:0] out_data_reg [4:0], out_data_next [4:0];
[114]32 wire [size*widthr-1:0] out_data_wire;
[113]33
[123]34 wire [size*width3-1:0] add_data_wire;
[120]35
[123]36 wire [size*width3-1:0] mul_data_wire [1:0];
[113]37
[130]38 reg [size*width2-1:0] acc_data_reg [4:0], acc_data_next [4:0];
[114]39 wire [size*width2-1:0] acc_data_wire;
[113]40
[114]41 wire [size*width1-1:0] sub_data_wire;
42
[130]43 reg [size*width-1:0] inp_data_reg [3:0], inp_data_next [3:0];
44 wire [size*width-1:0] inp_data_wire [4:0];
[114]45
[129]46 reg [size*6-1:0] amp_data_reg, amp_data_next;
[130]47 wire [size*6-1:0] amp_data_wire [3:0];
[114]48
49 reg [size*16-1:0] tau_data_reg, tau_data_next;
[130]50 wire [size*16-1:0] tau_data_wire [3:0];
[114]51
[113]52 integer i;
53 genvar j;
54
55 generate
56 for (j = 0; j < size; j = j + 1)
57 begin : INT_DATA
[130]58 assign inp_data_wire[0][j*width+width-1:j*width] = inp_data[(4*j+0)*width+width-1:(4*j+0)*width];
59 assign inp_data_wire[1][j*width+width-1:j*width] = inp_data[(4*j+1)*width+width-1:(4*j+1)*width];
60 assign inp_data_wire[2][j*width+width-1:j*width] = inp_data[(4*j+2)*width+width-1:(4*j+2)*width];
61 assign inp_data_wire[3][j*width+width-1:j*width] = inp_data[(4*j+3)*width+width-1:(4*j+3)*width];
62 assign amp_data_wire[0][j*6+6-1:j*6] = amp_data[(4*j+0)*6+6-1:(4*j+0)*6];
63 assign amp_data_wire[1][j*6+6-1:j*6] = amp_data[(4*j+1)*6+6-1:(4*j+1)*6];
64 assign amp_data_wire[2][j*6+6-1:j*6] = amp_data[(4*j+2)*6+6-1:(4*j+2)*6];
65 assign amp_data_wire[3][j*6+6-1:j*6] = amp_data[(4*j+3)*6+6-1:(4*j+3)*6];
66 assign tau_data_wire[0][j*16+16-1:j*16] = tau_data[(4*j+0)*16+16-1:(4*j+0)*16];
67 assign tau_data_wire[1][j*16+16-1:j*16] = tau_data[(4*j+1)*16+16-1:(4*j+1)*16];
68 assign tau_data_wire[2][j*16+16-1:j*16] = tau_data[(4*j+2)*16+16-1:(4*j+2)*16];
69 assign tau_data_wire[3][j*16+16-1:j*16] = tau_data[(4*j+3)*16+16-1:(4*j+3)*16];
[113]70
[114]71 lpm_mux #(
[130]72 .lpm_size(4),
[114]73 .lpm_type("LPM_MUX"),
74 .lpm_width(8),
75 .lpm_widths(2)) mux_unit_1 (
76 .sel(int_chan_next),
77 .data({
[130]78 2'd3, del_data[(4*j+3)*6+6-1:(4*j+3)*6],
79 2'd2, del_data[(4*j+2)*6+6-1:(4*j+2)*6],
80 2'd1, del_data[(4*j+1)*6+6-1:(4*j+1)*6],
81 2'd0, del_data[(4*j+0)*6+6-1:(4*j+0)*6]}),
[114]82 .result(int_addr_wire));
83
[113]84 lpm_add_sub #(
[114]85 .lpm_direction("SUB"),
[113]86 .lpm_hint("ONE_INPUT_IS_CONSTANT=NO,CIN_USED=NO"),
87 .lpm_representation("UNSIGNED"),
88 .lpm_type("LPM_ADD_SUB"),
89 .lpm_width(6)) add_unit_1 (
[114]90 .dataa(del_addr_reg),
[113]91 .datab(int_addr_wire[5:0]),
92 .result(del_addr_wire));
93
94 lpm_add_sub #(
95 .lpm_direction("SUB"),
96 .lpm_hint("ONE_INPUT_IS_CONSTANT=NO,CIN_USED=NO"),
97 .lpm_representation("SIGNED"),
98 .lpm_type("LPM_ADD_SUB"),
[114]99 .lpm_width(width1)) sub_unit_1 (
100 .dataa({{(width1-width){1'b0}}, inp_data_reg[0][j*width+width-1:j*width]}),
[130]101 .datab({{(width1-width){1'b0}}, inp_data_wire[4][j*width+width-1:j*width]}),
[114]102 .result(sub_data_wire[j*width1+width1-1:j*width1]));
[113]103
104 lpm_add_sub #(
105 .lpm_direction("ADD"),
106 .lpm_hint("ONE_INPUT_IS_CONSTANT=NO,CIN_USED=NO"),
107 .lpm_representation("SIGNED"),
108 .lpm_type("LPM_ADD_SUB"),
[114]109 .lpm_width(width2)) acc_unit_1 (
[118]110 .dataa({{(width2-width1+1){sub_data_wire[j*width1+width1-1]}}, sub_data_wire[j*width1+width1-2:j*width1]}),
[114]111 .datab(acc_data_reg[0][j*width2+width2-1:j*width2]),
112 .result(acc_data_wire[j*width2+width2-1:j*width2]));
[113]113
114 lpm_mult #(
115 .lpm_hint("MAXIMIZE_SPEED=9"),
116 .lpm_representation("SIGNED"),
117 .lpm_type("LPM_MULT"),
[133]118 .lpm_pipeline(3),
[114]119 .lpm_widtha(width1),
120 .lpm_widthb(17),
[123]121 .lpm_widthp(width3)) mult_unit_1 (
[113]122 .clock(clock),
123 .clken(int_wren_reg),
[117]124 .dataa(sub_data_wire[j*width1+width1-1:j*width1]),
[114]125 .datab({1'b0, tau_data_reg[j*16+16-1:j*16]}),
[123]126 .result(mul_data_wire[0][j*width3+width3-1:j*width3]));
[113]127
128 lpm_mult #(
129 .lpm_hint("MAXIMIZE_SPEED=9"),
[114]130 .lpm_representation("UNSIGNED"),
[113]131 .lpm_type("LPM_MULT"),
[133]132 .lpm_pipeline(3),
[114]133 .lpm_widtha(width2),
[129]134 .lpm_widthb(6),
[123]135 .lpm_widthp(width3)) mult_unit_2 (
[113]136 .clock(clock),
137 .clken(int_wren_reg),
[114]138 .dataa(acc_data_reg[0][j*width2+width2-1:j*width2]),
[129]139 .datab(amp_data_reg[j*6+6-1:j*6]),
[123]140 .result(mul_data_wire[1][j*width3+width3-1:j*width3]));
[113]141
142 lpm_add_sub #(
143 .lpm_direction("ADD"),
144 .lpm_hint("ONE_INPUT_IS_CONSTANT=NO,CIN_USED=NO"),
145 .lpm_representation("SIGNED"),
146 .lpm_type("LPM_ADD_SUB"),
[123]147 .lpm_width(width3)) add_unit_2 (
148 .dataa(mul_data_wire[0][j*width3+width3-1:j*width3]),
149 .datab(mul_data_wire[1][j*width3+width3-1:j*width3]),
150 .result(add_data_wire[j*width3+width3-1:j*width3]));
[113]151
[120]152
[123]153 lpm_add_sub #(
154 .lpm_direction("ADD"),
155 .lpm_hint("ONE_INPUT_IS_CONSTANT=NO,CIN_USED=NO"),
156 .lpm_representation("UNSIGNED"),
157 .lpm_type("LPM_ADD_SUB"),
158 .lpm_width(widthr)) add_unit_3 (
159 .dataa(add_data_wire[j*width3+shift+widthr-1:j*width3+shift]),
160 .datab({{(widthr-1){1'b0}}, add_data_wire[j*width3+shift-1]}),
[120]161 .result(out_data_wire[j*widthr+widthr-1:j*widthr]));
162
[113]163 end
164 endgenerate
165
166
167 altsyncram #(
168 .address_aclr_b("NONE"),
169 .address_reg_b("CLOCK0"),
170 .clock_enable_input_a("BYPASS"),
171 .clock_enable_input_b("BYPASS"),
172 .clock_enable_output_b("BYPASS"),
173 .intended_device_family("Cyclone III"),
174 .lpm_type("altsyncram"),
175 .numwords_a(256),
176 .numwords_b(256),
177 .operation_mode("DUAL_PORT"),
178 .outdata_aclr_b("NONE"),
179 .outdata_reg_b("CLOCK0"),
180 .power_up_uninitialized("FALSE"),
181 .read_during_write_mode_mixed_ports("DONT_CARE"),
182 .widthad_a(8),
183 .widthad_b(8),
[114]184 .width_a(size*width),
185 .width_b(size*width),
[113]186 .width_byteena_a(1)) ram_unit_1 (
187 .wren_a(int_wren_reg),
188 .clock0(clock),
189 .address_a(int_addr_reg),
190 .address_b({int_addr_wire[7:6], del_addr_wire}),
[114]191 .data_a(inp_data_reg[0]),
[130]192 .q_b(inp_data_wire[4]),
[113]193 .aclr0(1'b0),
194 .aclr1(1'b0),
195 .addressstall_a(1'b0),
196 .addressstall_b(1'b0),
197 .byteena_a(1'b1),
198 .byteena_b(1'b1),
199 .clock1(1'b1),
200 .clocken0(1'b1),
201 .clocken1(1'b1),
202 .clocken2(1'b1),
203 .clocken3(1'b1),
[114]204 .data_b({(size*width){1'b1}}),
[113]205 .eccstatus(),
206 .q_a(),
207 .rden_a(1'b1),
208 .rden_b(1'b1),
209 .wren_b(1'b0));
210
211 always @(posedge clock)
212 begin
213 if (reset)
214 begin
215 int_wren_reg <= 1'b1;
[130]216 int_flag_reg <= 1'b0;
[113]217 int_chan_reg <= 2'd0;
218 int_case_reg <= 3'd0;
[114]219 del_addr_reg <= 6'd0;
[113]220 int_addr_reg <= 8'd0;
[129]221 amp_data_reg <= 6'd0;
[114]222 tau_data_reg <= 16'd0;
[130]223 for(i = 0; i <= 3; i = i + 1)
[113]224 begin
[114]225 inp_data_reg[i] <= {(size*width){1'b0}};
[113]226 end
[130]227 for(i = 0; i <= 4; i = i + 1)
[113]228 begin
[114]229 acc_data_reg[i] <= {(size*width2){1'b0}};
[130]230 out_data_reg[i] <= {(size*widthr){1'b0}};
[113]231 end
232 end
233 else
234 begin
235 int_wren_reg <= int_wren_next;
[130]236 int_flag_reg <= int_flag_next;
[113]237 int_chan_reg <= int_chan_next;
238 int_case_reg <= int_case_next;
[114]239 del_addr_reg <= del_addr_next;
[113]240 int_addr_reg <= int_addr_next;
[114]241 amp_data_reg <= amp_data_next;
242 tau_data_reg <= tau_data_next;
[130]243 for(i = 0; i <= 3; i = i + 1)
[113]244 begin
[114]245 inp_data_reg[i] <= inp_data_next[i];
246 end
[130]247 for(i = 0; i <= 4; i = i + 1)
[114]248 begin
[113]249 acc_data_reg[i] <= acc_data_next[i];
[130]250 out_data_reg[i] <= out_data_next[i];
[114]251 end
[113]252 end
253 end
254
255 always @*
256 begin
257 int_wren_next = int_wren_reg;
[130]258 int_flag_next = int_flag_reg;
[113]259 int_chan_next = int_chan_reg;
260 int_case_next = int_case_reg;
[114]261 del_addr_next = del_addr_reg;
[113]262 int_addr_next = int_addr_reg;
[114]263 amp_data_next = amp_data_reg;
264 tau_data_next = tau_data_reg;
[130]265 for(i = 0; i <= 3; i = i + 1)
[113]266 begin
[114]267 inp_data_next[i] = inp_data_reg[i];
268 end
[130]269 for(i = 0; i <= 4; i = i + 1)
[114]270 begin
[113]271 acc_data_next[i] = acc_data_reg[i];
[130]272 out_data_next[i] = out_data_reg[i];
[114]273 end
[113]274
275 case (int_case_reg)
276 0:
277 begin
278 // write zeros
279 int_wren_next = 1'b1;
[114]280 del_addr_next = 6'd0;
[113]281 int_addr_next = 8'd0;
[129]282 amp_data_next = 6'd0;
[114]283 tau_data_next = 16'd0;
[130]284 for(i = 0; i <= 3; i = i + 1)
[113]285 begin
[114]286 inp_data_next[i] = {(size*width){1'b0}};
287 end
[130]288 for(i = 0; i <= 4; i = i + 1)
[113]289 begin
[114]290 acc_data_next[i] = {(size*width2){1'b0}};
[130]291 out_data_next[i] = {(size*widthr){1'b0}};
[114]292 end
293
[113]294 int_case_next = 3'd1;
295 end
296 1:
297 begin
298 // write zeros
299 int_addr_next = int_addr_reg + 8'd1;
300 if (&int_addr_reg)
301 begin
302 int_wren_next = 1'b0;
[130]303 int_flag_next = 1'b0;
[113]304 int_chan_next = 2'd0;
305 int_case_next = 3'd2;
306 end
307 end
308 2: // frame
309 begin
[130]310 int_flag_next = 1'b0;
311 int_wren_next = frame;
[113]312 if (frame)
313 begin
314 int_addr_next[7:6] = 2'd0;
315
316 // set read addr for 2nd pipeline
317 int_chan_next = 2'd1;
318
[130]319 // register input data for 2nd, 3rd and 4th sums
[114]320 inp_data_next[1] = inp_data_wire[1];
321 inp_data_next[2] = inp_data_wire[2];
[130]322 inp_data_next[3] = inp_data_wire[3];
[113]323
324 // prepare registers for 1st sum
[114]325 inp_data_next[0] = inp_data_wire[0];
326 acc_data_next[0] = acc_data_reg[1];
327
328 tau_data_next = tau_data_wire[0];
329 amp_data_next = amp_data_wire[0];
330
[113]331 int_case_next = 3'd3;
332 end
[130]333 if (int_flag_reg) // register 4th sum
334 begin
335 int_addr_next[5:0] = del_addr_reg;
[134]336 // register 4th sum and 1st product
[130]337 acc_data_next[4] = acc_data_wire;
[133]338 out_data_next[0] = out_data_wire;
[130]339 end
[113]340 end
341 3: // 1st sum
342 begin
343 int_addr_next[7:6] = 2'd1;
344
345 // set read addr for 3rd pipeline
346 int_chan_next = 2'd2;
347
348 // prepare registers for 2nd sum
[114]349 inp_data_next[0] = inp_data_reg[1];
350 acc_data_next[0] = acc_data_reg[2];
351
352 tau_data_next = tau_data_wire[1];
353 amp_data_next = amp_data_wire[1];
354
[134]355 // register 1st sum and 2nd product
[114]356 acc_data_next[1] = acc_data_wire;
[133]357 out_data_next[1] = out_data_wire;
[113]358
359 int_case_next = 3'd4;
360 end
361 4: // 2nd sum
362 begin
363 int_addr_next[7:6] = 2'd2;
364
[130]365 // set read addr for 4th pipeline
366 int_chan_next = 2'd3;
367
[113]368 // prepare registers for 3rd sum
[114]369 inp_data_next[0] = inp_data_reg[2];
370 acc_data_next[0] = acc_data_reg[3];
371
372 tau_data_next = tau_data_wire[2];
373 amp_data_next = amp_data_wire[2];
[113]374
[134]375 // register 2nd sum and 3rd product
[114]376 acc_data_next[2] = acc_data_wire;
[133]377 out_data_next[2] = out_data_wire;
[113]378
[114]379 del_addr_next = del_addr_reg + 6'd1;
380
[113]381 int_case_next = 3'd5;
382 end
383 5: // 3rd sum
384 begin
[130]385 int_flag_next = 1'b1;
[113]386
[130]387 int_addr_next[7:6] = 2'd3;
388
[113]389 // set read addr for 1st pipeline
390 int_chan_next = 2'd0;
391
[130]392 // prepare registers for 4th sum
393 inp_data_next[0] = inp_data_reg[3];
394 acc_data_next[0] = acc_data_reg[4];
395
396 tau_data_next = tau_data_wire[3];
397 amp_data_next = amp_data_wire[3];
398
[134]399 // register 3rd sum and 4th product
[114]400 acc_data_next[3] = acc_data_wire;
[133]401 out_data_next[3] = out_data_wire;
[113]402
[130]403 // register 4th output
[134]404 out_data_next[4] = out_data_reg[0];
[113]405
406 int_case_next = 3'd2;
407 end
408 default:
409 begin
410 int_case_next = 3'd0;
411 end
412 endcase
413 end
414
[134]415 assign out_data = {out_data_reg[3], out_data_reg[2], out_data_reg[1], out_data_reg[4]};
[113]416
417endmodule
Note: See TracBrowser for help on using the repository browser.