我想创建使用具有以下特点VHDL相位累加器。
输入:
输出:
源代码:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity Phase_accu is
port (
D : in std_logic_vector(3 downto 0);
CE : in std_logic;
CLK : in std_logic;
RESET : in std_logic;
Q : out std_logic_vector(15 downto 0)
);
end Phase_accu;
architecture Behavioral of Phase_accu is
begin
process(D, CE, CLK, RESET)
begin
if RESET = '1' then
Q <= "0000000000000000";
elsif rising_edge(CLK) then
if CE = '1' then
Q <= ("000000000000" & D) + Q;
end if;
end if;
end process;
end Behavioral;
我得到一个错误与行试图将两个信号合并在一起反馈...
Q <= ("000000000000" & D) + Q;
无法读取输出“Q”。
你可以不前VHDL-2008阅读VHDL修订的out
的价值。通常的方法来解决这个问题是让你的输出的内部副本中,当你需要得到它的价值使用该内部副本:
[...]
Q : out std_logic_vector(15 downto 0);
[...]
signal Q_reg : std_logic_vector(15 downto 0);
process(D, CE, CLK, RES)
begin
if RES = '1' then
Q_reg <= "0000000000000000";
elsif rising_edge(CLK) then
if CE = '1' then
Q_reg <= ("000000000000" & D) + Q_reg;
end if;
end if;
end process;
Q <= Q_reg;
我建议使用numeric_std库,而不是STD_LOGIC_ARITH和STD_LOGIC_UNSIGNED。我也建议作出关于矢量大小规格一些细微的优化。
另外,敏感列表有两种许多条目。你必须删除d和CE描述与异步复位有效时钟的过程。详情请参见您的合成工具手册。
这使得上述的代码
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity Phase_accu is
port (
D : in std_logic_vector(3 downto 0);
CE : in std_logic;
CLK : in std_logic;
RESET : in std_logic;
Q : out std_logic_vector(15 downto 0)
);
end Phase_accu;
architecture Behavioral of Phase_accu is
signal Q_reg : unsigned(Q'range);
begin
process(CLK, RES)
begin
if RES = '1' then
Q_reg <= (others => '0');
elsif rising_edge(CLK) then
if CE = '1' then
Q_reg <= resize(unsigned(D), Q_reg'length) + Q_reg;
end if;
end if;
end process;
Q <= std_logic_vector(Q_reg);
end Behavioral;