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

Subversion Repositories cordic_atan_iq

[/] [cordic_atan_iq/] [cordic_atan_abs_tb.sv] - Blame information for rev 8

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 8 Papayaved
timeunit 1ns;
2
timeprecision 1ns;
3
 
4
`include "AuxFunc.sv"
5
`include "AuxClasses.sv"
6
 
7
module cordic_atan_abs_tb;
8
        import AuxFuncPkg::*;
9
        import AuxClassesPkg::*;
10
 
11
        bit clk = 0;
12
        bit signed [29:0] IS, QS;
13
        wire signed [31:0] angle;
14
        wire [30:0] abs;
15
 
16
        int ang_delta_max = 0, ang_delta_min = 0;
17
        int abs_delta_max = 0, abs_delta_min = 0;
18
        real pct;
19
        int i, j;
20
 
21
        always #10ns clk++;
22
 
23
        initial begin
24
                repeat(10) @(posedge clk);
25
 
26
                //Test(20_000_000, 4_000_000);
27
                //Test(0, V_MAX);
28
                //Test(V_MIN, 0);
29
//              Test(V_MIN, V_MIN);
30
//              Test(32'he0000008, 32'h1fffffff);
31
                //Test(0, V_MIN);
32
                Test2();
33
 
34
                $stop(2);
35
        end
36
 
37
        cordic_atan_abs dut(.*);
38
 
39
        //
40
        task Test(bit signed [29:0] I, Q);
41
                int atan_ref, ang_delta, abs_ref, abs_res, abs_delta;
42
 
43
                IS = I;
44
                QS = Q;
45
                repeat(100) @(posedge clk);
46
 
47
                atan_ref = atan_iq_int(int'(IS), int'(QS));
48
                ang_delta = delta(atan_ref, angle);
49
                pct = rel_pct(atan_ref, angle);
50
 
51
                $display("%d {%08h, %08h}. Ref %g deg (%d), RTL A = %g deg (%d), delta %d (%g pct)", i, int'(IS), int'(QS), int_to_deg(atan_ref), atan_ref, int_to_deg(angle), angle, ang_delta, pct);
52
 
53
                abs_ref = imag(I, Q);
54
                abs_res = 32'(abs);
55
                abs_delta = delta(abs_ref, abs_res);
56
                $display("\tAbs: Ref %d, RTL %d, delta %d", abs_ref, abs_res, abs_delta);
57
 
58
                assert (iabs(ang_delta) <= 16 && iabs(abs_delta) <= 16) else $display("ERROR!");
59
        endtask
60
 
61
        task Test2(int POINTS = 8192);
62
                int atan_ref, ang_delta, abs_ref, abs_res, abs_delta;
63
                int I, Q;
64
                automatic bit error = 0;
65
 
66
//              automatic IQArrayList v = GenIQ(POINTS/8);
67
                automatic IQArrayList v = GenIQ(1024);
68
 
69
                fork
70
                        begin
71
                                for (int i = 0; i < v.size(); i++) begin
72
                                        IS = v.data[i].I;
73
                                        QS = v.data[i].Q;
74
                                        @(posedge clk);
75
                                end
76
                        end
77
                        begin
78
                                repeat(32+2) @(posedge clk);
79
 
80
                                for (int i = 0; i < v.size(); i++) begin
81
                                        I = v.data[i].I;
82
                                        Q = v.data[i].Q;
83
 
84
                                        atan_ref = atan_iq_int(I, Q);
85
 
86
                                        ang_delta = delta(atan_ref, angle);
87
                                        if (ang_delta > ang_delta_max) ang_delta_max = ang_delta;
88
                                        if (ang_delta < ang_delta_min) ang_delta_min = ang_delta;
89
 
90
                                        pct = rel_pct(atan_ref, angle);
91
 
92
                                        $display("%d {%08h, %08h}: Ref %g deg (%d), RTL %g deg (%d), delta %d (%g pct)", i, I, Q, int_to_deg(atan_ref), atan_ref, int_to_deg(angle), angle, ang_delta, pct);
93
 
94
                                        abs_ref = imag(I, Q);
95
                                        abs_res = 32'(abs);
96
                                        abs_delta = delta(abs_ref, abs_res);
97
                                        if (abs_delta > abs_delta_max) abs_delta_max = abs_delta;
98
                                        if (abs_delta < abs_delta_min) abs_delta_min = abs_delta;
99
 
100
                                        $display("\tAbs: Ref %d, RTL %d, delta %d", abs_ref, abs_res, abs_delta);
101
 
102
                                        assert (iabs(ang_delta) <= 16 && iabs(abs_delta) <= 16)
103
                                        else
104
                                                begin
105
                                                        error = 1;
106
                                                        $display("ERROR!");
107
                                                end
108
 
109
                                        @(posedge clk);
110
                                end
111
 
112
                                if (error)
113
                                        $display("Result: ERROR!");
114
                                else
115
                                        $display("Result: OK");
116
                        end
117
                join
118
 
119
                $display("Calculation precision: [%d, %d] ([%g, %g] sec)", ang_delta_min, ang_delta_max, int_to_deg(ang_delta_min) * 60**2, int_to_deg(ang_delta_max) * 60**2);
120
                $display("\tAbs: [%d, %d])", abs_delta_min, abs_delta_max);
121
 
122
                repeat(100) @(posedge clk);
123
                $stop(2);
124
        endtask
125
 
126
        //
127
        wire [31:0][31:0] x;
128
        wire [30:0][31:0] y;
129
        wire [31:1][31:0] a;
130
 
131
        genvar k;
132
        generate for (k = 0; k < 32; k++)
133
                begin :gen_x
134
                        assign x[k] = dut.cordic_inst.x[k];
135
                end
136
        endgenerate
137
 
138
        genvar n;
139
        generate for (n = 0; n < 31; n++)
140
                begin :gen_y
141
                        assign y[n] = dut.cordic_inst.y[n];
142
                end
143
        endgenerate
144
 
145
        genvar m;
146
        generate for (m = 1; m < 32; m++)
147
                begin :gen_a
148
                        assign a[m] = dut.cordic_inst.a[m];
149
                end
150
        endgenerate
151
 
152
endmodule :cordic_atan_abs_tb

powered by: WebSVN 2.1.0

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