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

Subversion Repositories pipelined_fft_128

[/] [pipelined_fft_128/] [trunk/] [TB/] [FFT128_TB.v] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 unicore
/////////////////////////////////////////////////////////////////////
2
////                                                             ////
3
////  FFT/IFFT 128 points transform                              ////
4
////                                                             ////
5
////  Authors: Anatoliy Sergienko, Volodya Lepeha                ////
6
////  Company: Unicore Systems http://unicore.co.ua              ////
7
////                                                             ////
8
////  Downloaded from: http://www.opencores.org                  ////
9
////                                                             ////
10
/////////////////////////////////////////////////////////////////////
11
////                                                             ////
12
//// Copyright (C) 2006-2010 Unicore Systems LTD                 ////
13
//// www.unicore.co.ua                                           ////
14
//// o.uzenkov@unicore.co.ua                                     ////
15
////                                                             ////
16
//// This source file may be used and distributed without        ////
17
//// restriction provided that this copyright statement is not   ////
18
//// removed from the file and that any derivative work contains ////
19
//// the original copyright notice and the associated disclaimer.////
20
////                                                             ////
21
//// THIS SOFTWARE IS PROVIDED "AS IS"                           ////
22
//// AND ANY EXPRESSED OR IMPLIED WARRANTIES,                    ////
23
//// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED                  ////
24
//// WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT              ////
25
//// AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.        ////
26
//// IN NO EVENT SHALL THE UNICORE SYSTEMS OR ITS                ////
27
//// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,            ////
28
//// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL            ////
29
//// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT         ////
30
//// OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,               ////
31
//// DATA, OR PROFITS; OR BUSINESS INTERRUPTION)                 ////
32
//// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,              ////
33
//// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT              ////
34
//// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING                 ////
35
//// IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,                 ////
36
//// EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.          ////
37
////                                                             ////
38
/////////////////////////////////////////////////////////////////////
39
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~           
40
// DESCRIPTION  :        Testbench for the FFT128_core - FFT 128 processor
41
// FUNCTION:              a set of 4 sine waves is inputted to the FFT processor,
42
//                         the results are compared with the expected waves,
43
//                        the square root mean error is calculated (without a root)
44
// FILES:                        FFT128_TB.v - this file, contains
45
//                                              FFT128.v - unit under test
46
//                    Wave_ROM128.v - rom with the test waveform, generating by 
47
//                    sinerom128_gen.pl            script
48
//  PROPERTIES: 1) the calculated error after ca. 6us modeling 
49
//                                                                      is outputted to the console      as the note:
50
//                                                      rms error is           1 lsb
51
//                                                      2)if the error is 0,1,2 then the test is OK
52
//                                                      3) the customer can exchange the test selecting the 
53
//                                                              different frequencies and generating the wave ROM by
54
//                            the script  sinerom128_gen.pl                     
55
//                                                 4) the proper operation can be checked by investigation
56
//                         of the core output waveforms
57
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
58
`include "FFT128_CONFIG.inc"
59
 
60
`timescale 1ns / 1 ps
61
module FFT128_tb;
62
        //Parameters declaration: 
63
        `FFT128paramnb
64
 
65
        //Internal signals declarations:
66
        reg CLK;
67
        reg RST;
68
        reg ED;
69
        reg START;
70
        reg [3:0]SHIFT;
71
        wire [nb-1:0]DR;
72
        wire [nb-1:0]DI;
73
        wire RDY;
74
        wire OVF1;
75
        wire OVF2;
76
        wire [6:0]ADDR;
77
        wire signed [nb+3:0]DOR;
78
        wire signed [nb+3:0]DOI;
79
 
80
        initial
81
                begin
82
                        CLK = 1'b0;
83
                        forever #5 CLK = ~CLK;
84
                end
85
 
86
        initial
87
                begin
88
                        SHIFT = 4'b0000;
89
                        ED = 1'b1;
90
                        RST = 1'b0;
91
                        START = 1'b0;
92
                        #13 RST =1'b1;
93
                        #43 RST =1'b0;
94
                        #53 START =1'b1;
95
                        #12 START =1'b0;
96
                end
97
 
98
        //initial                                                               //ED testing
99
//              begin
100
//                      #1 ED = 1'b0;
101
//                      forever #10 ED = ~ED;
102
//              end             
103
 
104
        reg [6:0] ct128;
105
        always @(posedge CLK or posedge START)
106
                if (ED) begin
107
                        if (START) ct128 = 7'b000_0000;
108
                        else ct128 = ct128+ 'd1;
109
                end
110
 
111
        wire [15:0] D_R,D_I,DATA_0;
112
        Wave_ROM128 UG( .ADDR(ct128) ,
113
                .DATA_RE(D_R), .DATA_IM(D_I), .DATA_REF(DATA_0) );// 
114
 
115
        assign DR=(D_R[15]&&(nb!=16))? (D_R[15:15-nb+1]+1) : D_R[15:15-nb+1];
116
        assign DI=(D_I[15]&&(nb!=16))? (D_I[15:15-nb+1]+1) : D_I[15:15-nb+1];
117
 
118
        // Unit Under Test 
119
        FFT128 UUT (
120
                .CLK(CLK),
121
                .RST(RST),
122
                .ED(ED),
123
                .START(START),
124
                .SHIFT(SHIFT),
125
                .DR(DR),
126
                .DI(DI),
127
                .RDY(RDY),
128
                .OVF1(OVF1),
129
                .OVF2(OVF2),
130
                .ADDR(ADDR),
131
                .DOR(DOR),
132
                .DOI(DOI));
133
 
134
                wire [7:0] addrr;
135
        `ifdef FFT128paramifft
136
                assign addrr= (128-ADDR);  //the result order if IFFT 
137
        `else
138
                assign addrr= ADDR;
139
        `endif
140
 
141
 
142
                wire signed [15:0] DATA_R0,DATA_I0,DATA_REF;
143
        Wave_ROM128 UR( .ADDR(addrr) ,
144
                .DATA_RE(DATA_R0), .DATA_IM(DATA_I0), .DATA_REF(DATA_REF) );// 
145
 
146
        wire signed [18:15-nb+1] DREF=2*DATA_REF[15:15-nb+1];
147
 
148
        integer sqra;
149
        integer ctres;
150
        reg f;
151
        initial f=0;
152
        always@(posedge CLK) begin        //SQR calculator 
153
                if(ED) begin
154
                if (f)
155
                        ctres=ctres+1;
156
                        if (RST || RDY)  begin
157
                                if (RDY) f=1;
158
                                sqra=0;
159
                                ctres=0; end
160
                        else if (ctres<128) begin
161
                                //considered that input phase is 45 deg. ie. DOI=DOR
162
                                        #2 sqra = sqra +(DREF-DOR)*(DREF-DOR);
163
                                #2 sqra = sqra +(DREF-DOI)*(DREF-DOI); end
164
                        else if (ctres==128)
165
                                $display("rms error is ", (sqra/256), " lsb");
166
                end      end
167
 
168
 
169
endmodule

powered by: WebSVN 2.1.0

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