Debian Codegraph @

hdl/fpga/ip/nuand/synthesis/tb/iq_correction_tb.vhd

raw
1 library ieee;
2 use ieee.std_logic_1164.all;
3 use ieee.numeric_std.all;
4 use ieee.math_real.all;
5
6 library std;
7 use std.env.all;
8
9 entity iq_correction_tb is
10 end entity;
11
12 architecture arch of iq_correction_tb is
13
14 signal clock : std_logic := '1';
15 signal reset : std_logic := '1';
16
17 procedure nop( signal clock : in std_logic; count : in natural) is
18 begin
19 for i in 1 to count loop
20 wait until rising_edge(clock);
21 end loop;
22 end procedure;
23
24 constant SIGNAL_LENGTH : natural := 1000;
25 constant F_SAMP : real := 1.0e7;
26 constant F_TONE : real := 100.0e3;
27 constant PHASE_STEP : real := MATH_2_PI*(F_TONE/F_SAMP);
28
29 constant Q_SCALE : positive := 12;
30 constant DC_WIDTH : positive := 16;
31
32 --error constants
33 constant PHASE_OFFSET : real := (10.0/180.0);
34 constant DC_OFFSET_REAL : real := 0.0;
35 constant DC_OFFSET_IMAG : real := 0.0;
36 constant GAIN_OFFSET : real := 1.0;
37
38 signal PHASE_OFFSET_SIGNED : signed(15 downto 0) := to_signed(integer(round(real(2**Q_SCALE) * PHASE_OFFSET)),DC_WIDTH);
39 constant DC_OFFSET_REAL_SIGNED : signed(15 downto 0) := to_signed(integer(round(real(2**Q_SCALE) * DC_OFFSET_REAL)),DC_WIDTH);
40 constant DC_OFFSET_IMAG_SIGNED : signed(15 downto 0) :=to_signed(integer(round(real(2**Q_SCALE) * DC_OFFSET_IMAG)),DC_WIDTH);
41 constant GAIN_OFFSET_SIGNED : signed(15 downto 0) := to_signed(integer(round(real(2**Q_SCALE) * GAIN_OFFSET)),DC_WIDTH);
42
43 signal signal_real : signed(15 downto 0);
44 signal signal_imag : signed(15 downto 0);
45 signal signal_valid : std_logic;
46
47 signal correction_valid : std_logic;
48
49
50 signal corrected_real : signed(15 downto 0);
51 signal corrected_imag : signed(15 downto 0);
52 signal corrected_valid : std_logic;
53
54
55 signal signal_ref_real : signed(15 downto 0);
56 signal signal_ref_imag : signed(15 downto 0);
57
58
59 signal error_real : signed(15 downto 0);
60 signal error_imag : signed(15 downto 0);
61
62 signal signal_real_float : real;
63 signal signal_imag_float : real;
64
65 begin
66
67 clock <= not clock after 1 ns;
68
69 U_iq_correction : entity work.iq_correction(tx)
70 generic map(
71 INPUT_WIDTH => 16
72 )
73 port map(
74 reset => reset,
75 clock => clock,
76
77 in_real => signal_real,
78 in_imag => signal_imag,
79 in_valid => signal_valid,
80
81 out_real => corrected_real,
82 out_imag => corrected_imag,
83 out_valid => corrected_valid,
84
85 dc_real => DC_OFFSET_REAL_SIGNED,
86 dc_imag => DC_OFFSET_IMAG_SIGNED,
87 gain => GAIN_OFFSET_SIGNED,
88 phase => PHASE_OFFSET_SIGNED,
89
90 correction_valid => correction_valid
91 );
92
93 tb : process
94 begin
95 reset <= '1';
96 signal_real <= (others => '0');
97 signal_imag<= (others => '0');
98
99 signal_real_float <= 0.0;
100 signal_imag_float <= 0.0;
101 correction_valid <= '0';
102 signal_valid <= '0';
103
104 nop(clock,10);
105 correction_valid <= '1';
106 reset <= '0';
107 nop(clock,10);
108
109 for i in 0 to SIGNAL_LENGTH loop
110 wait until rising_edge(clock);
111
112 signal_real <= to_signed(integer(round(real(3635)*(cos( PHASE_STEP*real(i) ) + DC_OFFSET_REAL))),signal_real'length);
113 signal_imag <= to_signed(integer(round(real(3635)*GAIN_OFFSET*(sin( PHASE_STEP*real(i) + PHASE_OFFSET*MATH_PI ) + DC_OFFSET_IMAG))),signal_imag'length);
114
115
116 signal_real_float <= cos( PHASE_STEP*real(i) ) + DC_OFFSET_REAL;
117 signal_imag_float <= GAIN_OFFSET*sin( PHASE_STEP*real(i) + PHASE_OFFSET*MATH_PI ) + DC_OFFSET_IMAG;
118
119 signal_valid <= '1';
120 wait until rising_edge(clock);
121 signal_valid <= '0';
122 end loop;
123
124
125 nop(clock, 100);
126 report "-- End of Simulation --";
127 stop(2) ;
128 end process;
129
130 compare : process(clock,reset)
131 variable i : integer;
132 begin
133 if reset = '1' then
134 --
135 i := 0;
136 signal_ref_real <= (others => '0');
137 signal_ref_imag <= (others => '0');
138 error_real <= (others => '0');
139 error_imag <= (others => '0');
140 elsif rising_edge(clock) then
141 signal_ref_real <= to_signed(integer(round(real(3592)*(cos( PHASE_STEP*real(i) + PHASE_OFFSET*MATH_PI/2.0 ) ))),signal_real'length);
142 signal_ref_imag <= to_signed(integer(round(real(3592)*(sin( PHASE_STEP*real(i) + PHASE_OFFSET*MATH_PI/2.0 ) ))),signal_imag'length);
143
144 if corrected_valid = '1' then
145 -- calc error
146 error_real <= signal_ref_real - corrected_real;
147 error_imag <= signal_ref_imag - corrected_imag;
148 i := i + 1;
149 end if;
150 end if;
151 end process;
152
153
154
155 end architecture;