0

我正在尝试使用 2 位加法器作为组件创建一个 16 位加法器(它们本身使用 1 位加法器作为组件)。但是,我的代码不能在 Quartus II 中编译。有人能帮助我吗?非常感谢!

我的项目由 3 个文件组成:bit_adder.vhd、add2.vhd 和 add16.vhd。错误发生在 add16.vhd 中:

--- bit_adder.vhd
-- description of 1 bit adder
LIBRARY IEEE;
use IEEE.STD_LOGIC_1164.ALL;

entity BIT_ADDER is
        port( a, b, cin         : in  STD_LOGIC;
              sum, cout         : out STD_LOGIC );
end BIT_ADDER;

architecture BHV of BIT_ADDER is
begin

        sum <=  (not a and not b and cin) or
                        (not a and b and not cin) or
                        (a and not b and not cin) or
                        (a and b and cin);

        cout <= (not a and b and cin) or
                        (a and not b and cin) or
                        (a and b and not cin) or
                        (a and b and cin);
end BHV;

-- 下面是 add2.vhd,一个 2 位加法器。使用两个 1 位加法器将两个 2 位数字相加

LIBRARY IEEE;
use IEEE.STD_LOGIC_1164.ALL;


entity add2 is
    port( a, b      : in    STD_LOGIC_VECTOR(1 downto 0);
          ans       : out   STD_LOGIC_VECTOR(1 downto 0);
          cout      : out   STD_LOGIC       );
end add2;

architecture STRUCTURE of add2 is

-- Component: two 1-bit adders

component BIT_ADDER
    port( a, b, cin     : in  STD_LOGIC;
          sum, cout     : out STD_LOGIC );
end component;

signal c0, c1 : STD_LOGIC;
begin

c0 <= '0';
b_adder0: BIT_ADDER port map (a(0), b(0), c0, ans(0), c1);
b_adder1: BIT_ADDER port map (a(1), b(1), c1, ans(1), cout);

END STRUCTURE;

-- add16.vhd -- 设置为顶级实体

LIBRARY IEEE;
use IEEE.STD_LOGIC_1164.ALL;

entity add16 is
    port (a, b : in std_logic_vector(15 downto 0);
            sum1 : out std_logic_vector(15 downto 0);
            cout : out std_logic_VECTOR(1 downto 0)); --_vector);
end add16;

architecture arch16 of add16 is
    component BIT_ADDER 
        port( a, b, cin         : in  STD_LOGIC;
              sum, cout         : out STD_LOGIC );
    end component;

    component add2
        port (a, b      : in    STD_LOGIC_VECTOR(1 downto 0);
          ans       : out   STD_LOGIC_VECTOR(1 downto 0);
          cout      : out   STD_LOGIC       );
    end component;

    signal c0, c1, c2, c3, c4, c5, c6, c7  : std_LOGIC_VECTOR(1 downto 0);
    begin
    c0 <='00'; --Error (10500): VHDL syntax error at add16.vhd(26) near text "'";  expecting "(", or an identifier, or  unary operator

    D_adder0: add2 port map (a(0), b(0), c0, sum1(0), c1);
    D_adder1: add2 port map (a(1), b(1), c0, sum1(1), c2);
    D_adder2: add2 port map (a(2), b(2), c0, sum1(2), c3);
    D_adder3: add2 port map (a(3), b(3), c0, sum1(3), c4);
    D_adder4: add2 port map (a(4), b(4), c0, sum1(4), c5);
    D_adder5: add2 port map (a(5), b(5), c0, sum1(5), c6);
    D_adder6: add2 port map (a(6), b(6), c0, sum1(6), c7);
    D_adder7: add2 port map (a(7), b(7), c0, sum1(7), cout);
    end arch16;
4

2 回答 2

0

1)模块必须有一个端口add2,你为什么不把它添加到你的设计中?如果你想得到正确的结果,所有的模块都必须有“carry in”。您使用的技术是,然后在每个块(实例)中必须有一个从前一个块提供的端口。add16cinCarry Ripple Adderadd16cin

2) 在模块add16中,为什么信号c1, c2, ... 是 2 位?每个块需要一个cin1 位的端口。你也不需要信号c0,因为在模块add16中,c0是一样的cin

3)在模块add16中为什么每个实例的端口(a, b, sum1)是 1 位。它必须是 2 位。

4)在模块中add16你不需要组件BIT_ADDER。你可以删除它。

我用上述更改编辑了您的代码。我对其进行了模拟,并且可以在 Modelsim 中得到正确的结果。(我没有更改模块BIT_ADDER):

------------------------------- add2 ---------------------------------
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;


ENTITY add2 IS
    PORT( a, b  : IN  STD_LOGIC_VECTOR(1 DOWNTO 0);
          cin   : IN  STD_LOGIC;
          ans   : OUT STD_LOGIC_VECTOR(1 DOWNTO 0);
          cout  : OUT STD_LOGIC
    );
END add2;

ARCHITECTURE STRUCTURE OF add2 IS

    COMPONENT BIT_ADDER
        PORT( a, b, cin  : IN  STD_LOGIC;
                sum, cout  : OUT STD_LOGIC
        );
    END COMPONENT;

    SIGNAL c1 : STD_LOGIC;

BEGIN

    b_adder0: BIT_ADDER PORT MAP (a(0), b(0), cin, ans(0), c1);
    b_adder1: BIT_ADDER PORT MAP (a(1), b(1), c1, ans(1), cout);

END STRUCTURE;



------------------------------- add16 ---------------------------------
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;

ENTITY add16 is
    PORT (  a, b : IN  std_logic_vector(15 DOWNTO 0);
            cin  : IN  STD_LOGIC;
            sum1 : OUT std_logic_vector(15 DOWNTO 0);
            cout : OUT std_logic);
END add16;

ARCHITECTURE arch16 OF add16 IS

    COMPONENT add2
        PORT(  a, b      : IN    STD_LOGIC_VECTOR(1 DOWNTO 0);
               cin       : IN    STD_LOGIC;
               ans       : OUT   STD_LOGIC_VECTOR(1 DOWNTO 0);
               cout      : OUT   STD_LOGIC);
    END COMPONENT;

    SIGNAL c1, c2, c3, c4, c5, c6, c7  : std_LOGIC;

BEGIN

    D_adder0: add2 PORT MAP ( a(1  DOWNTO 0)  , b(1 DOWNTO 0)  , cin, sum1(1 DOWNTO 0)   , c1  );
    D_adder1: add2 PORT MAP ( a(3  DOWNTO 2)  , b(3 DOWNTO 2)  , c1 , sum1(3 DOWNTO 2)   , c2  );
    D_adder2: add2 PORT MAP ( a(5  DOWNTO 4)  , b(5 DOWNTO 4)  , c2 , sum1(5 DOWNTO 4)   , c3  );
    D_adder3: add2 PORT MAP ( a(7  DOWNTO 6)  , b(7 DOWNTO 6)  , c3 , sum1(7 DOWNTO 6)   , c4  );
    D_adder4: add2 PORT MAP ( a(9  DOWNTO 8)  , b(9 DOWNTO 8)  , c4 , sum1(9 DOWNTO 8)   , c5  );
    D_adder5: add2 PORT MAP ( a(11 DOWNTO 10) , b(11 DOWNTO 10), c5 , sum1(11 DOWNTO 10) , c6  );
    D_adder6: add2 PORT MAP ( a(13 DOWNTO 12) , b(13 DOWNTO 12), c6 , sum1(13 DOWNTO 12) , c7  );
    D_adder7: add2 PORT MAP ( a(15 DOWNTO 14) , b(15 DOWNTO 14), c7 , sum1(15 DOWNTO 14) , cout);

END arch16;
于 2015-03-06T22:17:07.743 回答
0

VHDL 中的向量文字放在双引号中,即"00",不是'00'

Update:在port map您将单位信号分配给双位输入的部分中:

 D_adder0: add2 port map (a(0), b(0), c0, sum1(0), c1);

例如,这里a(0)是 的最低位a。但是您的add2组件期望宽度为 2 的信号:

 component add2
        port (a, b : in    STD_LOGIC_VECTOR(1 downto 0); -- <-- 2bits wide
        ans       : out   STD_LOGIC_VECTOR(1 downto 0);
        cout      : out   STD_LOGIC       );
    end component;
于 2015-03-06T21:04:59.453 回答