1 | module shift
|
---|
2 | #(
|
---|
3 | parameter shift = 24, // right shift of the result
|
---|
4 | parameter width = 27, // bit width of the input data
|
---|
5 | parameter widthr = 12 // bit width of the output data
|
---|
6 | )
|
---|
7 | (
|
---|
8 | input wire clock, frame, reset,
|
---|
9 | input wire [5:0] amp_data,
|
---|
10 | input wire [width-1:0] inp_data,
|
---|
11 | output wire [widthr-1:0] out_data
|
---|
12 | );
|
---|
13 |
|
---|
14 | localparam widthp = width + 6;
|
---|
15 |
|
---|
16 | reg [5:0] amp_data_reg;
|
---|
17 | reg [width-1:0] inp_data_reg;
|
---|
18 | reg [widthr-1:0] out_data_reg;
|
---|
19 | wire [widthr-1:0] out_data_wire;
|
---|
20 | wire [widthp-1:0] mul_data_wire;
|
---|
21 |
|
---|
22 | assign out_data_wire = mul_data_wire[shift+widthr-1:shift]
|
---|
23 | + {{(widthr-1){mul_data_wire[widthp-1]}}, mul_data_wire[shift-1]};
|
---|
24 |
|
---|
25 | lpm_mult #(
|
---|
26 | .lpm_hint("MAXIMIZE_SPEED=9"),
|
---|
27 | .lpm_representation("UNSIGNED"),
|
---|
28 | .lpm_type("LPM_MULT"),
|
---|
29 | .lpm_pipeline(3),
|
---|
30 | .lpm_widtha(width),
|
---|
31 | .lpm_widthb(6),
|
---|
32 | .lpm_widthp(widthp)) mult_unit (
|
---|
33 | .clock(clock),
|
---|
34 | .clken(1'b1),
|
---|
35 | .dataa(inp_data_reg),
|
---|
36 | .datab(amp_data_reg),
|
---|
37 | .result(mul_data_wire));
|
---|
38 |
|
---|
39 | always @(posedge clock)
|
---|
40 | begin
|
---|
41 | if (reset)
|
---|
42 | begin
|
---|
43 | amp_data_reg <= 6'b0;
|
---|
44 | inp_data_reg <= {(width){1'b0}};
|
---|
45 | out_data_reg <= {(widthr){1'b0}};
|
---|
46 | end
|
---|
47 | else if (frame)
|
---|
48 | begin
|
---|
49 | amp_data_reg <= amp_data;
|
---|
50 | inp_data_reg <= inp_data;
|
---|
51 | out_data_reg <= out_data_wire;
|
---|
52 | end
|
---|
53 | end
|
---|
54 |
|
---|
55 |
|
---|
56 | assign out_data = out_data_reg;
|
---|
57 |
|
---|
58 | endmodule
|
---|