【发布时间】:2013-01-09 19:32:42
【问题描述】:
我有一个带有四个按钮的 FPGA——最左边的两个按钮应该在 16 个寄存器中上下循环,而最右边的两个按钮应该增加和减少存储在这个寄存器中的值。这是我尝试执行此操作的代码:
entity raminfr is --inferring the RAM here
port (
clk : in std_logic;
we : in std_logic;
a : in unsigned(3 downto 0);
di : in unsigned(7 downto 0);
do : out unsigned(7 downto 0)
);
end raminfr;
architecture rtl of raminfr is
type ram_type is array (0 to 15) of unsigned(7 downto 0);
signal RAM : ram_type;
signal read_a : unsigned(3 downto 0);
begin
U1: entity work.lab1 port map ( --ERROR ON THIS LINE
register_counter => a,
value_counter => di
);
process (clk)
begin
if rising_edge(clk) then
if we = '1' then
RAM(to_integer(a)) <= di;
end if;
read_a <= a;
end if;
end process;
do <= RAM(to_integer(read_a));
end rtl;
--lab1 starts here
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity lab1 is
port(
clock : in std_logic;
key : in std_logic_vector(3 downto 0);
value_counter : out unsigned(7 downto 0) ; --value to be written to register
register_counter : out unsigned(3 downto 0) --register to write value to
);
end lab1;
architecture up_and_down of lab1 is --actual button logic here
begin
process(clock)
begin
if rising_edge(clock) then
if (key(3)='0' and key(2)='0' and key(1)='1' and key(0)='0') then
value_counter <= value_counter + "1";
elsif (key(3)='0' and key(2)='0' and key(1)='0' and key(0)='1') then
value_counter <= value_counter - "1";
elsif (key(3)='1' and key(2)='0' and key(1)='0' and key(0)='0') then
register_counter<= register_counter + "1";
elsif (key(3)='0' and key(2)='1' and key(1)='0' and key(0)='0') then
register_counter<= register_counter - "1";
end if;
end if;
end process;
end architecture up_and_down;
我在上面指示的行上收到错误Error (10577): VHDL error at DE2_TOP.vhd(312): actual port "a" of mode "in" cannot be associated with formal port "register_counter" of mode "out"。很明显,这不是我做我想做的事的方式。有人可以对此有所了解吗?
【问题讨论】:
-
不清楚您要做什么。错误很容易看出:“a”是 ram_infr 的输入,因此 ram_infr 可以读取它但不能驱动它。然而,ram_infr 的一部分是驱动 reg_counter 的 lab1。因此将 reg_counter 连接到“a”是一个错误。如果您希望“a”成为 lab1 的“reg_counter”输出,请将“a”设为 ram_infr 中的信号,而不是输入端口!
-
谢谢 - 我现在有一个不同但可能相关的问题。你能看看吗? stackoverflow.com/questions/14532705/…
标签: vhdl cpu-registers