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

Subversion Repositories iqcorrection

[/] [iqcorrection/] [branches/] [implemented with real variables/] [IQGainPhaseCorrection_testbench_read.vhd] - Blame information for rev 26

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 26 Abraxas3d
library ieee;
2
use ieee.std_logic_1164.all;
3
use ieee.math_real.all;
4
use ieee.numeric_std.all;
5
use std.textio.all;
6
use ieee.std_logic_textio.all;
7
 
8
entity IQGainPhaseCorrection_testbench is
9
end entity;
10
 
11
 
12
--The read architecture reads I and Q samples from a text file.
13
--The values were created by the MATLAB reference model for the design.
14
 
15
architecture IQGainPhaseCorrection_testbench_read of IQGainPhaseCorrection_testbench is
16
 
17
--declare the DUT as a component.
18
component IQGainPhaseCorrection is
19
        generic(width :natural);
20
        port(
21
        clk                             :in std_logic;
22
        x1                              :in signed(width-1 downto 0);
23
        y1                              :in signed(width-1 downto 0);
24
        gain_error              :out signed(width-1 downto 0);
25
        gain_lock               :out bit;
26
        phase_error             :out signed(width-1 downto 0);
27
        phase_lock              :out bit;
28
        corrected_x1    :out signed(width-1 downto 0);
29
        corrected_y1    :out signed(width-1 downto 0)
30
        );
31
end component;
32
 
33
 
34
--provide signals to run the DUT.
35
signal clk_tb                   : std_logic := '0';
36
signal clk_tb_delayed   : std_logic     := '0';
37
signal x1_tb                    : signed(31 downto 0);
38
signal y1_tb                    : signed(31 downto 0);
39
signal gain_error_tb    : signed(31 downto 0);
40
signal gain_lock_tb             : bit;
41
signal phase_error_tb   : signed(31 downto 0);
42
signal phase_lock_tb    : bit;
43
signal corrected_x1_tb  : signed(31 downto 0);
44
signal corrected_y1_tb  : signed(31 downto 0);
45
 
46
 
47
 
48
begin
49
 
50
        --connect the testbench signal to the component
51
        DUT:IQGainPhaseCorrection
52
        generic map(
53
        width => 32
54
        )
55
        port map(
56
        clk => clk_tb_delayed,
57
        x1 => x1_tb,
58
        y1 => y1_tb,
59
        gain_error => gain_error_tb,
60
        gain_lock => gain_lock_tb,
61
        phase_error => phase_error_tb,
62
        phase_lock => phase_lock_tb,
63
        corrected_x1 => corrected_x1_tb,
64
        corrected_y1 => corrected_y1_tb
65
        );
66
 
67
 
68
--Read I and Q from a text file created by MATLAB.
69
READ_I_Q_SAMPLES: process (clk_tb) is
70
 
71
--read input data into process using the readline technique
72
file I_data : text open READ_MODE is "I_data_octave";
73
file Q_data : text open READ_MODE is "Q_data_octave";
74
variable incoming : line;
75
 
76
 
77
variable local_x1 : real;
78
variable local_y1 : real;
79
variable int_x1 : integer;
80
variable returned_x1 : signed(31 downto 0);  --need to parameterize this 
81
variable int_y1 : integer;
82
variable returned_y1 : signed(31 downto 0);  --need to parameterize this
83
 
84
begin
85
 
86
        if (clk_tb'event and clk_tb = '1') then
87
 
88
                if (not endfile(I_data) and not endfile(Q_data)) then
89
 
90
                        readline(I_data, incoming);  --read in the first line.
91
                        read(incoming, local_x1);  --get the real value from the first line
92
                        report "Reading " & real'image(local_x1) & " from I_data.";
93
                        local_x1 := local_x1/(1.11); --model AGC
94
                        report "AGC applied. Result: " & real'image(local_x1) & ".";
95
                        int_x1 := integer(trunc(local_x1*((2.0**31.0)-1.0)));  --scaled
96
                        report "Converted real I_data to the integer " & integer'image(int_x1) & ".";
97
                        returned_x1 := (to_signed(int_x1, 32));
98
                        x1_tb <= returned_x1;
99
 
100
                        readline(Q_data, incoming);  --read in the first line.
101
                        read(incoming, local_y1);  --get the real value from the first line
102
                        report "Reading " & real'image(local_y1) & " from Q_data.";
103
                        local_y1 := local_y1/(1.11); --model AGC
104
                        report "AGC applied. Result: " & real'image(local_y1) & ".";
105
                        int_y1 := integer(trunc(local_y1*((2.0**31.0)-1.0)));  --scaled
106
                        report "Converted real Q_data to the integer " & integer'image(int_y1) & ".";
107
                        returned_y1 := (to_signed(int_y1, 32));
108
                        y1_tb <= returned_y1;
109
 
110
                else
111
                        file_close(I_data);
112
                        file_close(Q_data);
113
                end if;
114
        end if;
115
end process READ_I_Q_SAMPLES;
116
 
117
 
118
 
119
 
120
 
121
 
122
 
123
COMPARE_RESULTS : process (clk_tb) is
124
 
125
--compare process output with data file using the readline technique
126
file phase_error : text open READ_MODE is "phase_error_estimate_octave";
127
file gain_error : text open READ_MODE is "gain_error_estimate_octave";
128
variable incoming : line;
129
variable filter_delay : natural := 0;
130
 
131
variable real_phase_error : real;
132
variable int_phase_error : integer;
133
variable octave_phase_error : signed(31 downto 0);
134
variable real_gain_error : real;
135
variable int_gain_error : integer;
136
variable octave_gain_error : signed(31 downto 0);
137
 
138
begin
139
        if (clk_tb'event and clk_tb = '1') then
140
                        if (not endfile(phase_error) and not endfile(phase_error)) then
141
                                --read in a result and compare with testbench result
142
                                readline(phase_error, incoming);  --read in the first line.
143
                                read(incoming, real_phase_error);  --get the real value from the first line
144
                                report "Phase error from model: " & real'image(real_phase_error) & ".";
145
                                int_phase_error := integer(trunc(real_phase_error*((2.0**31.0)-1.0)));  --scaled
146
                                report "Converted real phase_error to the integer " & integer'image(int_phase_error) & ".";
147
                                octave_phase_error := (to_signed(int_phase_error, 32));
148
                                --does the phase error from the block match octave_phase_error?
149
 
150
                                readline(gain_error, incoming);  --read in the first line.
151
                                read(incoming, real_gain_error);  --get the real value from the first line
152
                                report "Gain error from model: " & real'image(real_gain_error) & ".";
153
                                int_gain_error := integer(trunc(real_gain_error*((2.0**31.0)-1.0)));  --scaled
154
                                report "Converted real gain_error to the integer " & integer'image(int_gain_error) & ".";
155
                                octave_gain_error := (to_signed(int_gain_error, 32));
156
                                --does the gain error from the block match octave_gain_error?
157
 
158
 
159
 
160
                        else
161
                                file_close(phase_error);
162
                                file_close(gain_error);
163
                        end if;
164
        end if;
165
end process COMPARE_RESULTS;
166
 
167
 
168
 
169
 
170
 
171
 
172
DRIVE_CLOCK:process
173
begin
174
        wait for 50 ns;
175
        clk_tb <= not clk_tb;
176
        clk_tb_delayed <= not clk_tb_delayed after 1 ns;
177
end process;
178
 
179
end IQGainPhaseCorrection_testbench_read;

powered by: WebSVN 2.1.0

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