| 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 |
|
| 25 |
package nco_p is |
| 26 |
|
| 27 |
type nco_input_t is record |
| 28 |
dphase : signed(15 downto 0) ; |
| 29 |
valid : std_logic ; |
| 30 |
end record ; |
| 31 |
|
| 32 |
type nco_output_t is record |
| 33 |
re : signed(15 downto 0) ; |
| 34 |
im : signed(15 downto 0) ; |
| 35 |
valid : std_logic ; |
| 36 |
end record ; |
| 37 |
|
| 38 |
end package ; -- nco_p |
| 39 |
|
| 40 |
library ieee ; |
| 41 |
use ieee.std_logic_1164.all ; |
| 42 |
use ieee.numeric_std.all ; |
| 43 |
|
| 44 |
library work ; |
| 45 |
use work.cordic_p.all ; |
| 46 |
use work.nco_p.all ; |
| 47 |
|
| 48 |
entity nco is |
| 49 |
port ( |
| 50 |
clock : in std_logic ; |
| 51 |
reset : in std_logic ; |
| 52 |
inputs : in nco_input_t ; |
| 53 |
outputs : out nco_output_t |
| 54 |
) ; |
| 55 |
end entity ; -- nco |
| 56 |
|
| 57 |
architecture arch of nco is |
| 58 |
|
| 59 |
signal phase : signed(15 downto 0) ; |
| 60 |
|
| 61 |
signal cordic_inputs : cordic_xyz_t ; |
| 62 |
signal cordic_outputs : cordic_xyz_t ; |
| 63 |
|
| 64 |
begin |
| 65 |
|
| 66 |
accumulate_phase : process(clock, reset) |
| 67 |
variable temp : signed(15 downto 0) ; |
| 68 |
begin |
| 69 |
if( reset = '1' ) then |
| 70 |
phase <= (others =>'0') ; |
| 71 |
elsif( rising_edge( clock ) ) then |
| 72 |
if( inputs.valid = '1' ) then |
| 73 |
temp := phase + inputs.dphase ; |
| 74 |
if( temp > 4096 ) then |
| 75 |
temp := temp - 8192 ; |
| 76 |
elsif( temp < -4096 ) then |
| 77 |
temp := temp + 8192 ; |
| 78 |
end if ; |
| 79 |
phase <= temp ; |
| 80 |
end if ; |
| 81 |
end if ; |
| 82 |
end process ; |
| 83 |
|
| 84 |
cordic_inputs <= ( x => to_signed(1234,16), y => (others =>'0'), z => phase, valid => inputs.valid ) ; |
| 85 |
|
| 86 |
U_cordic : entity work.cordic |
| 87 |
port map ( |
| 88 |
clock => clock, |
| 89 |
reset => reset, |
| 90 |
mode => CORDIC_ROTATION, |
| 91 |
inputs => cordic_inputs, |
| 92 |
outputs => cordic_outputs |
| 93 |
) ; |
| 94 |
|
| 95 |
outputs.re <= cordic_outputs.x ; |
| 96 |
outputs.im <= cordic_outputs.y ; |
| 97 |
outputs.valid <= cordic_outputs.valid ; |
| 98 |
|
| 99 |
end architecture ; -- arch |