Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vhdl 使用2位加法器作为组件的16位加法器_Vhdl_Quartus - Fatal编程技术网

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

Vhdl 使用2位加法器作为组件的16位加法器,vhdl,quartus,Vhdl,Quartus,我试图创建一个16位加法器,使用2位加法器作为组件(它本身使用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 i

我试图创建一个16位加法器,使用2位加法器作为组件(它本身使用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;
——位加法器.vhd
--1位加法器的描述
图书馆IEEE;
使用IEEE.STD_LOGIC_1164.ALL;
实体位加法器为
端口(a、b、cin:STD_逻辑中;
求和,cout:out标准逻辑);
端位加法器;
位加法器的结构BHV是
开始

sumVHDL中的矢量文字被放在双引号中,即
“00”
,而不是
'00'


更新:在
端口映射
部分,您将单位信号分配给双位输入:

 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;
组件添加2
端口(a,b:在STD_LOGIC_VECTOR(1到0);--1)模块
add2
add16
必须具有
cin
端口,为什么不将其添加到设计中?如果您想得到正确的结果,所有模块必须具有“进位”。您使用的技术是进位涟波加法器
,然后在
add16
中,每个块(实例)必须具有前一块提供的
cin
端口

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

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

4) 在模块
add16
中,您不需要组件
位加法器
。您可以删除它

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


谢谢@eugene sh,但是add16.vhd中还有3个错误。这一个在端口映射部分:Error(10381):add16处的VHDL类型不匹配错误。vhd(28):indexed name返回一个类型与目标表达式类型“std_logic_vector”不匹配的值
 D_adder0: add2 port map (a(0), b(0), c0, sum1(0), c1);
 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;
------------------------------- 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;