-----------------------------------------------------
---------------16位精度锯齿波VHDL实现----------------
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
package sim is
component ncoaw
port( reset :in std_logic;
clk :in std_logic;
sync:in std_logic;
freq:in std_logic_vector(15 downto 0);
saw_out: out std_logic_vector(7 downto 0)
);
end component;
end sim;
-----------------------------------------------------
-----------------------------------------------------
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
library work;
use work.sim.all;
entity ncosaw is
port( reset :in std_logic;
clk :in std_logic;
sync:in std_logic;--同步信号,当sync为1时,相位累加器清0
freq:in std_logic_vector(15 downto 0);--输入频率值
saw_out: out std_logic_vector(7 downto 0)
);
end ncosaw;
architecture arch_ncosaw of ncosaw is
signal phase:std_logic_vector(15 downto 0);--相位累计器的存储器,将每次累加的结果保存起来
constant max_phase:std_logic_vector(13 downto 0):=(others=>'1');
constant output_zeros:std_logic_vector(7 downto 0):=(others=>'0');
signal sin_index:std_logic_vector(7 downto 0);
signal sin_table:std_logic_vector(7 downto 0);
signal phase_d1:std_logic_vector(1 downto 0);
signal phase_d2:std_logic_vector(1 downto 0);
signal cos_index:std_logic_vector(13 downto 0);
signal cos_table:std_logic_vector(7 downto 0);
begin
process(reset,clk)
begin
if reset='1' then
phase<=(others=>'0');
elsif clk'event and clk='1' then
if sync='1' then
phase<=(others=>'0');
else
phase<=phase+freq;
end if;
end if;
end process;
saw_out<=phase(15 downto 8);
end arch_ncosaw;
编译通过!!