OpenCores
URL https://opencores.org/ocsvn/two_dimensional_fast_hartley_transform/two_dimensional_fast_hartley_transform/trunk

Subversion Repositories two_dimensional_fast_hartley_transform

[/] [two_dimensional_fast_hartley_transform/] [trunk/] [fht_1d_x8.v] - Blame information for rev 4

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 4 irezki
/**********************************************************************
2
 * File  : fht_1d_x8.v
3
 * Author: Ivan Rezki
4
 * email : irezki@gmail.com
5
 * Topic : RTL Core
6
 *                2-Dimensional Fast Hartley Transform
7
 *
8
 * Function: Fast Hartley Transform 1 Dimension for 8 Points
9
 * Decimation in Frequency Domain
10
 *
11
 *     +-----------+    +-----------+    +-----------+
12
 *     |  Serial   |    |  1D FHT   |    | Parallel  |
13
 * --->|    to     |--->|           |--->|    to     |--->
14
 *     | Parallel  |    | 8 Points  |    |  Serial   |
15
 *     +-----------+    +-----------+    +-----------+
16
 *
17
 * RIGHT TO USE: This code example, or any portion thereof, may be
18
 * used and distributed without restriction, provided that this entire
19
 * comment block is included with the example.
20
 *
21
 * DISCLAIMER: THIS CODE EXAMPLE IS PROVIDED "AS IS" WITHOUT WARRANTY
22
 * OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED
23
 * TO WARRANTIES OF MERCHANTABILITY, FITNESS OR CORRECTNESS. IN NO
24
 * EVENT SHALL THE AUTHOR OR AUTHORS BE LIABLE FOR ANY DAMAGES,
25
 * INCLUDING INCIDENTAL OR CONSEQUENTIAL DAMAGES, ARISING OUT OF THE
26
 * USE OF THIS CODE.
27
 **********************************************************************/
28 2 irezki
 
29
module fht_1d_x8(
30
        rstn,
31
        sclk,
32
 
33
        // input data - x0,x1,x2,x3,x4,x5,x6,x7,x0,x1...
34
        x_valid,
35
        x_data,
36
 
37
        // 1D FHT output data - h0,h1,h2,h3,h4,h5,h6,h7,h0,h1...
38
        fht_valid,
39
        fht_data
40
 
41
);
42
 
43
parameter N = 8;
44
 
45
input                   rstn;
46
input                   sclk;
47
 
48
input                   x_valid;
49
input   [N-1:0]  x_data;
50
 
51
output                  fht_valid;
52
output  [N+2:0]  fht_data;
53
// +++---------------------------------+++\\
54
 
55
// +++ Data Preparation Step Start +++ \\
56
// +++        - Aligning -         +++ \\
57
reg [N-1:0] x0,x1,x2,x3,x4,x5,x6,x7;
58
always @(posedge sclk or negedge rstn)
59
if (!rstn) begin
60
        x0 <= #1 0;
61
        x1 <= #1 0;
62
        x2 <= #1 0;
63
        x3 <= #1 0;
64
        x4 <= #1 0;
65
        x5 <= #1 0;
66
        x6 <= #1 0;
67
        x7 <= #1 0;
68
end
69
else if (x_valid) begin
70
        x0 <= #1 x_data;
71
        x1 <= #1 x0;
72
        x2 <= #1 x1;
73
        x3 <= #1 x2;
74
        x4 <= #1 x3;
75
        x5 <= #1 x4;
76
        x6 <= #1 x5;
77
        x7 <= #1 x6;
78
end
79
 
80
reg x_valid_1d;
81
always @(posedge sclk or negedge rstn)
82
if      (!rstn) x_valid_1d <= #1 0;
83
else            x_valid_1d <= #1 x_valid;
84
 
85
wire xi_ready;
86
 
87
reg [2:0] cnt;
88
always @(posedge sclk or negedge rstn)
89
if              (!rstn)                 cnt <= #1 0;
90
else if (x_valid_1d)    cnt <= #1 cnt + 1;
91
 
92
assign xi_ready = (cnt == 7 && x_valid_1d) ? 1'b1 : 1'b0;
93
 
94
// at the ready time aligned and reversed
95
reg [N-1:0] x0_FF,x1_FF,x2_FF,x3_FF,x4_FF,x5_FF,x6_FF,x7_FF;
96
always @(posedge sclk or negedge rstn)
97
if (!rstn) begin
98
        x0_FF <= #1 0;
99
        x1_FF <= #1 0;
100
        x2_FF <= #1 0;
101
        x3_FF <= #1 0;
102
        x4_FF <= #1 0;
103
        x5_FF <= #1 0;
104
        x6_FF <= #1 0;
105
        x7_FF <= #1 0;
106
end
107
else if (xi_ready) begin
108
        x0_FF <= #1 x7;
109
        x1_FF <= #1 x6;
110
        x2_FF <= #1 x5;
111
        x3_FF <= #1 x4;
112
        x4_FF <= #1 x3;
113
        x5_FF <= #1 x2;
114
        x6_FF <= #1 x1;
115
        x7_FF <= #1 x0;
116
end
117
// +++ Data Preparation Step Finish +++ //
118
 
119
// delay for ... clocks to provide timing requirements
120
reg [13:0] xi_ready_d;
121
always @(posedge sclk or negedge rstn)
122
if (!rstn)      xi_ready_d[13:0] <= #1 0;
123
else            xi_ready_d[13:0] <= #1 {xi_ready_d[12:0],xi_ready};
124
 
125
// 1D Fast Hartley Transform - Decimation-in-Frequency Algorithm
126
 
127
// Butterfly Stage N1
128
// Data input [N-1:0] = N bits
129
// On the output of the 1st bfly is [N:0] = N+1 bits
130
 
131
// <<<--------- Butterfly Stage N1
132
wire [N:0] stg1_sum1;
133
wire [N:0] stg1_sum2;
134
wire [N:0] stg1_sum3;
135
wire [N:0] stg1_sum4;
136
 
137
wire [N:0] stg1_sub1;
138
wire [N:0] stg1_sub2;
139
wire [N:0] stg1_sub3;
140
wire [N:0] stg1_sub4;
141
 
142
fht_bfly_noFF #(N) u11_fht_bfly ({x0_FF},{x4_FF},stg1_sum1,stg1_sub1);
143
fht_bfly_noFF #(N) u12_fht_bfly ({x1_FF},{x5_FF},stg1_sum2,stg1_sub2);
144
fht_bfly_noFF #(N) u13_fht_bfly ({x2_FF},{x6_FF},stg1_sum3,stg1_sub3);
145
fht_bfly_noFF #(N) u14_fht_bfly ({x3_FF},{x7_FF},stg1_sum4,stg1_sub4);
146
 
147
// <<<--------- Butterfly Stage N2
148
wire [N+1:0] stg2_sum1;
149
wire [N+1:0] stg2_sum2;
150
wire [N+1:0] stg2_sum3;
151
 
152
wire [N+1:0] stg2_sub1;
153
wire [N+1:0] stg2_sub2;
154
wire [N+1:0] stg2_sub3;
155
 
156
fht_bfly #(N+1) u21_fht_bfly (rstn,sclk,xi_ready_d[1],stg1_sum1,stg1_sum3,stg2_sum1,stg2_sub1);
157
fht_bfly #(N+1) u22_fht_bfly (rstn,sclk,xi_ready_d[1],stg1_sum2,stg1_sum4,stg2_sum2,stg2_sub2);
158
fht_bfly #(N+1) u23_fht_bfly (rstn,sclk,xi_ready_d[1],stg1_sub1,stg1_sub3,stg2_sum3,stg2_sub3);
159
 
160
// Multiplier on the 2nd Stage
161
wire [N:0] mult_dat_1;
162
wire [N:0] mult_dat_2;
163
assign mult_dat_1 = stg1_sub2;
164
assign mult_dat_2 = stg1_sub4;
165
 
166
wire [N+1:0] mult_res1;
167
wire [N+1:0] mult_res2;
168
 
169
`ifdef USE_ASIC_MULT
170
        signed_mult_const_asic #(N+1) u_mult_1_fht (rstn,sclk,xi_ready_d[1],mult_dat_1,mult_res1);
171
        signed_mult_const_asic #(N+1) u_mult_2_fht (rstn,sclk,xi_ready_d[1],mult_dat_2,mult_res2);
172
`elsif USE_FPGA_MULT
173
        signed_mult_const_fpga #(N+1) u_mult_1_fht (rstn,sclk,xi_ready_d[1],mult_dat_1,mult_res1);
174
        signed_mult_const_fpga #(N+1) u_mult_2_fht (rstn,sclk,xi_ready_d[1],mult_dat_2,mult_res2);
175
`endif
176
 
177
// <<<--------- Butterfly Stage N3
178
wire [N+2:0] stg3_sum1;
179
wire [N+2:0] stg3_sum2;
180
wire [N+2:0] stg3_sum3;
181
wire [N+2:0] stg3_sum4;
182
 
183
wire [N+2:0] stg3_sub1;
184
wire [N+2:0] stg3_sub2;
185
wire [N+2:0] stg3_sub3;
186
wire [N+2:0] stg3_sub4;
187
 
188
fht_bfly #(N+2) u31_fht_bfly (rstn,sclk,xi_ready_d[3],stg2_sum1,stg2_sum2,stg3_sum1,stg3_sub1);
189
fht_bfly #(N+2) u32_fht_bfly (rstn,sclk,xi_ready_d[3],stg2_sub1,stg2_sub2,stg3_sum2,stg3_sub2);
190
fht_bfly #(N+2) u33_fht_bfly (rstn,sclk,xi_ready_d[3],stg2_sum3,mult_res1,stg3_sum3,stg3_sub3);
191
fht_bfly #(N+2) u34_fht_bfly (rstn,sclk,xi_ready_d[3],stg2_sub3,mult_res2,stg3_sum4,stg3_sub4);
192
 
193
// <<<--------- FHT Result
194
reg [N+2:0] h0_FF,h1_FF,h2_FF,h3_FF,h4_FF,h5_FF,h6_FF,h7_FF;
195
always @(posedge sclk or negedge rstn)
196
if (!rstn) begin
197
        h0_FF <= #1 0;
198
        h4_FF <= #1 0;
199
        h2_FF <= #1 0;
200
        h6_FF <= #1 0;
201
        h1_FF <= #1 0;
202
        h5_FF <= #1 0;
203
        h3_FF <= #1 0;
204
        h7_FF <= #1 0;
205
end
206
else if (xi_ready_d[5]) begin
207
        h0_FF <= #1 stg3_sum1;
208
        h4_FF <= #1 stg3_sub1;
209
        h2_FF <= #1 stg3_sum2;
210
        h6_FF <= #1 stg3_sub2;
211
        h1_FF <= #1 stg3_sum3;
212
        h5_FF <= #1 stg3_sub3;
213
        h3_FF <= #1 stg3_sum4;
214
        h7_FF <= #1 stg3_sub4;
215
end
216
 
217
assign h0_valid = xi_ready_d[6];
218
assign h1_valid = xi_ready_d[7];
219
assign h2_valid = xi_ready_d[8];
220
assign h3_valid = xi_ready_d[9];
221
assign h4_valid = xi_ready_d[10];
222
assign h5_valid = xi_ready_d[11];
223
assign h6_valid = xi_ready_d[12];
224
assign h7_valid = xi_ready_d[13];
225
 
226
wire    fht_valid_or;
227
assign  fht_valid_or =  h0_valid |
228
                                                h1_valid |
229
                                                h2_valid |
230
                                                h3_valid |
231
                                                h4_valid |
232
                                                h5_valid |
233
                                                h6_valid |
234
                                                h7_valid ;
235
 
236
wire [N+2:0] h_or_data;
237
assign h_or_data =
238
                                (h0_FF & {N+3{h0_valid}}) |
239
                                (h1_FF & {N+3{h1_valid}}) |
240
                                (h2_FF & {N+3{h2_valid}}) |
241
                                (h3_FF & {N+3{h3_valid}}) |
242
                                (h4_FF & {N+3{h4_valid}}) |
243
                                (h5_FF & {N+3{h5_valid}}) |
244
                                (h6_FF & {N+3{h6_valid}}) |
245
                                (h7_FF & {N+3{h7_valid}}) ;
246
 
247
reg     [N+2:0]  fht_data;
248
reg                     fht_valid;
249
 
250
always @(posedge sclk or negedge rstn)
251
if (!rstn)      fht_valid <= #1 0;
252
else            fht_valid <= #1 fht_valid_or;
253
 
254
always @(posedge sclk or negedge rstn)
255
if (!rstn)      fht_data <= #1 0;
256
else            fht_data <= #1 h_or_data;
257
 
258
endmodule

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.