Initial import

git-svn-id: http://moon:8086/svn/vhdl/trunk@5 cc03376c-175c-47c8-b038-4cd826a8556b
This commit is contained in:
2008-08-23 08:20:30 +00:00
parent bfbeba5129
commit d3bd08bb52
160 changed files with 56260 additions and 0 deletions
+117
View File
@@ -0,0 +1,117 @@
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use ieee.numeric_std.all;
use IEEE.MATH_REAL.ALL;
use work.fixed_pkg.all;
-------------------------------------------------------------------------------
package nco_pkg is
constant tpd : time := 0 ns;
-- Global set arithmetic rounding mode
constant pi : real := 3.141592653589793e+000;
constant sqrt2 : real := 1.414213562373095e+000;
constant sqrt2_inv : real := 7.071067811865475e-001;
type real_array_t is array (natural range <>) of real;
type natural_array_t is array (natural range <>) of natural;
type phase_relation_t is (phase_90deg, phase_270deg);
type debug_out_t is record
lfsr : unsigned(31 downto 0);
i_ud : real;
q_ud : real;
i_d : real;
q_d : real;
end record;
constant lfsr_poly : natural_array_t(3 to 24) :=
(
12, -- 3
24, -- 4
58, -- 5
114, -- 6
210, -- 7
500, -- 8
1000, -- 9
1824, -- 10
3712, -- 11
7184, -- 12
14592, -- 13
28674, -- 14
59392, -- 15
106512, -- 16
245760, -- 17
466944, -- 18
933888, -- 19
1654784, -- 20
3735552, -- 21
7342080, -- 22
14745600, -- 23
14811138 -- 24
);
function sin_tbl(nsamples : integer; omega, phi_in : real) return real_array_t;
function cos_tbl(nsamples : integer; omega, phi_in : real) return real_array_t;
-------------------------------------------------------------
-- Constructor helpers
-- Use: variable v8u6 : ufixed_t(ufixed(8,6)'range);
function uproto (nbits : integer; nbits_frac : integer) return ufixed;
-- Use: variable v8s6 : sfixed_t(sfixed(8,6)'range);
function sproto (nbits : integer; nbits_frac : integer) return sfixed;
end; -- package nco_pkg;
-------------------------------------------------------------------------------
package body nco_pkg is
function sin_tbl(nsamples : integer; omega, phi_in : real) return real_array_t is
variable tbl : real_array_t (0 to nsamples-1);
variable phi : real := phi_in;
variable dphi : real := 2.0*pi*omega;
begin
for i in 0 to nsamples-1 loop
tbl(i) := sin(phi);
phi := phi + dphi;
end loop;
return tbl;
end sin_tbl;
-------------------------------------------------------------
function cos_tbl(nsamples : integer; omega, phi_in : real) return real_array_t is
variable tbl : real_array_t (0 to nsamples-1);
variable phi : real := phi_in;
variable dphi : real := 2.0*pi*omega;
begin
for i in 0 to nsamples-1 loop
tbl(i) := cos(phi);
phi := phi + dphi;
end loop;
return tbl;
end cos_tbl;
-------------------------------------------------------------
-- Constuctor helpers
function uproto (nbits : integer; nbits_frac : integer) return ufixed is
constant result : ufixed (nbits-nbits_frac-1 downto -nbits_frac) := (others => '0');
begin
return result(nbits-nbits_frac-1 downto -nbits_frac);
end uproto;
-------------------------------------------------------------
function sproto (nbits : integer; nbits_frac : integer) return sfixed is
constant result : sfixed (nbits-nbits_frac downto -nbits_frac+1) := (others => '0');
begin
return result(nbits-nbits_frac downto -nbits_frac+1);
end sproto;
-------------------------------------------------------------------------------
end; -- package nco_pkg;