| 1 |
-- Copyright (c) 2013 Nuand LLC |
| 2 |
-- |
| 3 |
-- Permission is hereby granted, free of charge, to any person obtaining a copy |
| 4 |
-- of this software and associated documentation files (the "Software"), to deal |
| 5 |
-- in the Software without restriction, including without limitation the rights |
| 6 |
-- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 7 |
-- copies of the Software, and to permit persons to whom the Software is |
| 8 |
-- furnished to do so, subject to the following conditions: |
| 9 |
-- |
| 10 |
-- The above copyright notice and this permission notice shall be included in |
| 11 |
-- all copies or substantial portions of the Software. |
| 12 |
-- |
| 13 |
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 14 |
-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 15 |
-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 16 |
-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 17 |
-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 18 |
-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 19 |
-- THE SOFTWARE. |
| 20 |
|
| 21 |
library ieee ; |
| 22 |
use ieee.std_logic_1164.all ; |
| 23 |
use ieee.numeric_std.all ; |
| 24 |
use ieee.math_real.all ; |
| 25 |
|
| 26 |
library work ; |
| 27 |
use work.cordic_p.all ; |
| 28 |
|
| 29 |
entity cordic_tb is |
| 30 |
end entity ; -- cordic_tb |
| 31 |
|
| 32 |
architecture arch of cordic_tb is |
| 33 |
|
| 34 |
signal clock : std_logic := '1' ; |
| 35 |
signal reset : std_logic := '1' ; |
| 36 |
signal inputs : cordic_xyz_t := ( x => (others =>'0'), y => (others =>'0'), z => (others =>'0'), valid => '0' ); |
| 37 |
signal outputs : cordic_xyz_t ; |
| 38 |
signal outputs2 : cordic_xyz_t ; |
| 39 |
|
| 40 |
procedure nop( signal clock : in std_logic ; count : in natural ) is |
| 41 |
begin |
| 42 |
for i in 1 to count loop |
| 43 |
wait until rising_edge( clock ) ; |
| 44 |
end loop ; |
| 45 |
end procedure ; -- nop |
| 46 |
|
| 47 |
begin |
| 48 |
|
| 49 |
-- Generate clock |
| 50 |
clock <= not clock after 1 ns ; |
| 51 |
|
| 52 |
-- Magnitude/phase to cos+isin |
| 53 |
U_cordic : entity work.cordic |
| 54 |
port map ( |
| 55 |
clock => clock, |
| 56 |
reset => reset, |
| 57 |
mode => CORDIC_ROTATION, |
| 58 |
inputs => inputs, |
| 59 |
outputs => outputs |
| 60 |
) ; |
| 61 |
|
| 62 |
-- cos+isin to magnitude/phase |
| 63 |
U_cordic2 : entity work.cordic |
| 64 |
port map ( |
| 65 |
clock => clock, |
| 66 |
reset => reset, |
| 67 |
mode => CORDIC_VECTORING, |
| 68 |
inputs => outputs, |
| 69 |
outputs => outputs2 |
| 70 |
) ; |
| 71 |
|
| 72 |
tb : process |
| 73 |
variable ang : integer := 0 ; |
| 74 |
variable dang : integer := integer(round(0.01*4096.0)) ; |
| 75 |
begin |
| 76 |
reset <= '1' ; |
| 77 |
nop( clock, 10 ) ; |
| 78 |
|
| 79 |
reset <= '0' ; |
| 80 |
nop( clock, 10 ) ; |
| 81 |
|
| 82 |
ang := 0 ; |
| 83 |
inputs.x <= to_signed( integer(round(4096.0/1.66)), inputs.x'length ) ; |
| 84 |
inputs.y <= to_signed( 0, inputs.y'length ) ; |
| 85 |
for i in 0 to 10000 loop |
| 86 |
inputs.z <= to_signed( ang, inputs.z'length ) ; |
| 87 |
inputs.valid <= '1' ; |
| 88 |
wait until rising_edge( clock ) ; |
| 89 |
inputs.valid <= '0' ; |
| 90 |
nop( clock, 20 ) ; |
| 91 |
ang := ang + dang ; |
| 92 |
if( ang > 4096 ) then |
| 93 |
ang := ang - 8192 ; |
| 94 |
elsif( ang < -4096 ) then |
| 95 |
ang := ang + 8192 ; |
| 96 |
end if ; |
| 97 |
|
| 98 |
end loop ; |
| 99 |
|
| 100 |
report "-- End of Simulation --" severity failure ; |
| 101 |
|
| 102 |
end process ; |
| 103 |
|
| 104 |
end architecture ; -- arch |