source: sandbox/MultiChannelUSB/uwt_bior31.v@ 168

Last change on this file since 168 was 124, checked in by demin, 14 years ago

add uwt bior31 module

File size: 2.7 KB
RevLine 
[124]1module uwt_bior31
2 #(
3 parameter level = 1, // transform level
4 parameter width = 12 // bit width of the input data (unsigned)
5
6 )
7 (
8 input wire clock, frame, reset,
9 input wire [width-1:0] inp_data,
10 output wire [widthr-1:0] out_data,
11 output wire [1:0] out_flag
12 );
13
14 localparam widthr = width + 3;
15
16 localparam index1 = 1 << (level - 1);
17 localparam index2 = 2 << (level - 1);
18 localparam index3 = 3 << (level - 1);
19
20 // Tapped delay line
21 reg [width-1:0] tap_data_reg [index3:0], tap_data_next [index3:0];
22
23 wire [1:0] int_comp_wire;
24 reg [1:0] int_comp_reg, int_comp_next;
25
26 reg [1:0] out_flag_reg, out_flag_next;
27
28 wire [widthr-1:0] add_data_wire [1:0];
29 reg [widthr-1:0] add_data_reg [1:0], add_data_next [1:0];
30
31 reg [widthr-1:0] out_data_reg, out_data_next;
32
33 integer i;
34
35 assign add_data_wire[0] = tap_data_reg[index3] + {tap_data_reg[index2][width-2:0], 1'b0} + tap_data_reg[index2];
36 assign add_data_wire[1] = {tap_data_reg[index1][width-2:0], 1'b0} + tap_data_reg[index1] + tap_data_reg[0];
37 assign int_comp_wire[0] = (add_data_reg[0] > add_data_reg[1]);
38 assign int_comp_wire[1] = (add_data_reg[0] < add_data_reg[1]);
39
40 always @(posedge clock)
41 begin
42 if (reset)
43 begin
44 add_data_reg[0] <= {(widthr){1'b0}};
45 add_data_reg[1] <= {(widthr){1'b0}};
46 out_data_reg <= {(widthr){1'b0}};
47 int_comp_reg <= 2'd0;
48 out_flag_reg <= 2'd0;
49
50 for(i = 0; i <= index3; i = i + 1)
51 begin
52 tap_data_reg[i] <= {(width){1'b0}};
53 end
54 end
55 else
56 begin
57 add_data_reg[0] <= add_data_next[0];
58 add_data_reg[1] <= add_data_next[1];
59 out_data_reg <= out_data_next;
60 int_comp_reg <= int_comp_next;
61 out_flag_reg <= out_flag_next;
62
63 for(i = 0; i <= index3; i = i + 1)
64 begin
65 tap_data_reg[i] <= tap_data_next[i];
66 end
67 end
68 end
69
70 always @*
71 begin
72 add_data_next[0] = add_data_reg[0];
73 add_data_next[1] = add_data_reg[1];
74 out_data_next = out_data_reg;
75 int_comp_next = int_comp_reg;
76 out_flag_next = out_flag_reg;
77
78 for(i = 0; i <= index3; i = i + 1)
79 begin
80 tap_data_next[i] = tap_data_reg[i];
81 end
82
83 if (frame)
84 begin
85 // Tapped delay line: shift one
86 for(i = 0; i < index3; i = i + 1)
87 begin
88 tap_data_next[i+1] = tap_data_reg[i];
89 end
90
91 // Input in register 0
92 tap_data_next[0] = inp_data;
93
94 add_data_next[0] = add_data_wire[0];
95 add_data_next[1] = add_data_wire[1];
96
97 out_data_next = add_data_next[0] + add_data_next[1];
98
99 int_comp_next = int_comp_wire;
100 out_flag_next[0] = (~int_comp_reg[0]) & (int_comp_wire[0]);
101 out_flag_next[1] = (~int_comp_reg[1]) & (int_comp_wire[1]);
102
103 end
104
105 end
106
107 // output logic
108 assign out_data = out_data_reg;
109 assign out_flag = out_flag_reg;
110
111endmodule
Note: See TracBrowser for help on using the repository browser.