| 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 |
library work ; |
| 26 |
use work.cordic_p.all ; |
| 27 |
|
| 28 |
entity fsk_demodulator is |
| 29 |
port ( |
| 30 |
clock : in std_logic ; |
| 31 |
reset : in std_logic ; |
| 32 |
|
| 33 |
in_real : in signed(15 downto 0) ; |
| 34 |
in_imag : in signed(15 downto 0) ; |
| 35 |
in_valid : in std_logic ; |
| 36 |
|
| 37 |
out_ssd : buffer signed(15 downto 0) ; |
| 38 |
out_valid : out std_logic |
| 39 |
) ; |
| 40 |
end entity ; -- fsk_demodulator |
| 41 |
|
| 42 |
architecture arch of fsk_demodulator is |
| 43 |
|
| 44 |
signal cordic_inputs : cordic_xyz_t ; |
| 45 |
signal cordic_outputs : cordic_xyz_t ; |
| 46 |
|
| 47 |
signal prev_z : signed(15 downto 0) ; |
| 48 |
signal delta_z : signed(15 downto 0) ; |
| 49 |
signal delta_z_valid : std_logic ; |
| 50 |
signal unwrapped_z : signed(15 downto 0) ; |
| 51 |
signal unwrapped_valid : std_logic ; |
| 52 |
|
| 53 |
begin |
| 54 |
|
| 55 |
cordic_inputs <= ( x => in_real, y => in_imag, z => (others =>'0'), valid => in_valid ) ; |
| 56 |
|
| 57 |
U_cordic : entity work.cordic |
| 58 |
port map ( |
| 59 |
clock => clock, |
| 60 |
reset => reset, |
| 61 |
mode => CORDIC_VECTORING, |
| 62 |
inputs => cordic_inputs, |
| 63 |
outputs => cordic_outputs |
| 64 |
) ; |
| 65 |
|
| 66 |
find_derivative : process(clock, reset) |
| 67 |
begin |
| 68 |
if( reset = '1' ) then |
| 69 |
prev_z <= (others =>'0') ; |
| 70 |
delta_z <= (others =>'0') ; |
| 71 |
delta_z_valid <= '0' ; |
| 72 |
elsif( rising_edge( clock ) ) then |
| 73 |
delta_z_valid <= cordic_outputs.valid ; |
| 74 |
if( cordic_outputs.valid = '1' ) then |
| 75 |
prev_z <= cordic_outputs.z ; |
| 76 |
delta_z <= cordic_outputs.z - prev_z ; |
| 77 |
end if ; |
| 78 |
end if ; |
| 79 |
end process ; |
| 80 |
|
| 81 |
unwrap : process(clock, reset) |
| 82 |
begin |
| 83 |
if( reset = '1' ) then |
| 84 |
unwrapped_z <= (others =>'0') ; |
| 85 |
unwrapped_valid <= '0' ; |
| 86 |
elsif( rising_edge( clock ) ) then |
| 87 |
unwrapped_valid <= delta_z_valid ; |
| 88 |
if( delta_z > 4096 ) then |
| 89 |
unwrapped_z <= delta_z - 8192 ; |
| 90 |
elsif( delta_z < -4096 ) then |
| 91 |
unwrapped_z <= delta_z + 8192 ; |
| 92 |
else |
| 93 |
unwrapped_z <= delta_z ; |
| 94 |
end if ; |
| 95 |
end if ; |
| 96 |
end process ; |
| 97 |
|
| 98 |
out_ssd <= out_ssd - shift_right(out_ssd,4) + unwrapped_z when rising_edge(clock) and unwrapped_valid = '1' ; |
| 99 |
out_valid <= unwrapped_valid when rising_edge(clock); |
| 100 |
|
| 101 |
end architecture ; -- arch |