vhdl 将块的输出反馈到它的输入

vhdl feedback the output of a block to its input

我有一个加法器块,我需要将输出 (std_logic_vector) 反馈到加法器的一个输入端口以与另一个数字相加(这将在加法器所在的另一个实体中完成用来。)。我试图通过 processsensitivity list 来做到这一点,但它没有用。有办法吗? 注意:没有使用时钟。

这是我的代码:

library IEEE;
use IEEE.std_logic_1164.all;

entity example is
port ( 
    X: IN std_logic_vector(15 downto 0);
    Y: IN std_logic_vector(15 downto 0);
    Z: OUT std_logic_vector(15 downto 0)
    );
end example;

architecture arch_example of example is
    component adder is
    port(a: in std_logic_vector(15 downto 0);
        b: in std_logic_vector(15 downto 0);
        cin: in std_logic;
        s: out std_logic_vector(15 downto 0);
        overflow: out std_logic);
    end component;
    signal s, ain, bin: std_logic_vector(15 downto 0);
    signal cin, overflow, useless: std_logic;
begin
    process(x, y) is
    begin
        ain <= x;
        bin <= y;
        cin <= '0';
    end process;
    process(s, overflow) is
    begin
        ain <= s;
        bin <= "1111111110000001";
        cin <= overflow;
    end process;
    U1: adder port map (ain, bin, cin, s, overflow);
    z <= s;
end arch_example;

在您的代码中,信号 ainbincin 有多个驱动程序,因为两个进程同时驱动这些信号。你可以把它想象成驱动同一条电线的两个门。

要在完全组合设计中将另一个数字添加到中间结果,您将需要第二个加法器。第一个加法器无法重复使用,因为您无法轻易判断何时使用多路复用器切换到新输入。 (异步逻辑的概念是可能的,但这要复杂得多。)

一个简单的解决方案是实例化您的加法器组件两次:

architecture arch_example of example is
    component adder is
    port(a: in std_logic_vector(15 downto 0);
        b: in std_logic_vector(15 downto 0);
        cin: in std_logic;
        s: out std_logic_vector(15 downto 0);
        overflow: out std_logic);
    end component;
    signal s : std_logic_vector(15 downto 0);
    signal overflow : std_logic;
begin
    U1: adder port map (x, y, '0', s, overflow);
    U2: adder port map (s, "1111111110000001", overflow, z, open);
end arch_example;

上面的代码片段使用了组件端口的位置分配。应该避免这种情况,因为很容易混淆端口的顺序。我建议改用命名赋值。在这里可以清楚地看到哪个端口(=>左边)分配给哪个信号(右边):

architecture arch_example of example is
    component adder is
    port(a: in std_logic_vector(15 downto 0);
        b: in std_logic_vector(15 downto 0);
        cin: in std_logic;
        s: out std_logic_vector(15 downto 0);
        overflow: out std_logic);
    end component;
    signal s : std_logic_vector(15 downto 0);
    signal overflow : std_logic;
begin
    U1: adder port map (
      a => x,
      b => y,
      cin => '0',
      s => s,
      overflow => overflow);

    U2: adder port map (
      a => s,
      b => "1111111110000001",
      cin => overflow,
      s => z,
      overflow => open);
end arch_example;