使用2位加法器作为组件的16位加法器

时间:2015-03-06 21:01:48

标签: vhdl quartus

我正在尝试使用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;

2 个答案:

答案 0 :(得分:0)

VHDL中的矢量文字用双引号括起来,即"00",而不是'00'

更新:在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;

答案 1 :(得分:0)

1)模块add2add16必须有cin端口,为什么不将它添加到您的设计中?如果您想获得正确的结果,所有模块必须具有&#34;携带&#34;。您使用的技术是Carry Ripple Adder,然后在add16中,每个块(实例)必须具有从前一个块提供的cin端口。

2)在模块add16中,为什么信号c1c2,...是2位?每个块需要一个1位的cin端口。此外,您不需要信号c0,因为在模块add16中,c0cin相同。

3)在模块add16中,为什么每个实例(absum1)的端口都是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;
相关问题