1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
|
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
use ieee.math_real.all;
library std;
use std.env.all;
entity cos_table_tb is
end entity;
architecture arch of cos_table_tb is
signal clock : std_logic := '1';
signal reset : std_logic := '1';
constant Q_SCALE : positive := 12;
constant SIGNAL_LENGTH : positive := 16;
constant PHASE_STEPS_90 : positive := 1024;
constant PHASE_STEPS : positive := PHASE_STEPS_90*4;
signal phase_request : unsigned(SIGNAL_LENGTH-1 downto 0);
signal phase_request_valid : std_logic := '1';
signal cos_value : signed(SIGNAL_LENGTH-1 downto 0);
signal cos_value_valid : std_logic;
signal cos_ieee : signed(SIGNAL_LENGTH-1 downto 0);
signal cos_error : signed(SIGNAL_LENGTH-1 downto 0);
procedure nop( signal clock : in std_logic ; count : in natural ) is
begin
for i in 1 to count loop
wait until rising_edge( clock ) ;
end loop ;
end procedure ;
begin
clock <= not clock after 1 ns;
--
U_cos_table : entity work.cos_table
generic map(
Q => Q_SCALE,
DPHASE_STEPS_90 => PHASE_STEPS_90
)
port map(
reset => reset,
clock => clock,
phase => phase_request,
phase_valid => phase_request_valid,
y => cos_value,
y_valid => cos_value_valid
);
tb : process
--
begin
reset <= '1';
nop(clock, 10);
phase_request <= (others => '0');
phase_request_valid <= '0';
reset <= '0';
nop(clock, 10);
for i in 0 to PHASE_STEPS-1 loop
wait until rising_edge(clock);
phase_request <= to_unsigned(i, phase_request'length);
if phase_request_valid = '1' then
cos_ieee <= to_signed(integer(round(real(2**Q_SCALE)*cos( (MATH_PI*2.0) * (real(i-1)/real(PHASE_STEPS))) )),cos_ieee'length);
end if;
phase_request_valid <= '1';
end loop;
phase_request_valid <= '0';
nop(clock, 1000);
report "-- End of Simulation --";
stop(2) ;
end process;
error_check : process
begin
wait until rising_edge(clock);
cos_error <= cos_ieee - cos_value;
end process;
end architecture;
|