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