VHDL结构

VHDL Structural

嗨,谁能帮我解决一个 VHDL 问题。我正在尝试一些实用的结构编程,想从一个简单的半加器开始。这是我的代码

LIBRARY IEEE;
USE IEEE.std_logic_1164.all;

--异或描述

entity xor_2 is
    port (a, b : in std_logic;
        f : out std_logic );
end xor_2;

Architecture func of xor_2 is
begin
    f <= a xor b;
end func;

--和描述

entity and_2 is
    port (a, b : in std_logic;
            f : out std_logic);
end and_2;

architecture func of and_2 is
begin
    f1 <= a and b;
end func;

--半加器说明

entity struct_1 is
    port ( a, b : in std_logic;
            s, c : out std_logic);
end struct_1;

architecture struct_1 of struct_1 is

component xor_2 is
    port( a, b : in std_logic;
            f : out std_logic);
end component;

component and_2 is
    port( a, b : in std_logic;
            f : out std_logic);
end component;

begin
    g1 : xor_2 port map (a, b, s);
    g2 : and_2 port map (a, b, c);

end struct_1;

我正在使用 Quartus II 设计软件,在 运行 测试时我不断收到以下警告:

Error (10482): VHDL error at Struct_1.vhd(15): object "std_logic" is used but
not declared

我查看了各种网站和论文以了解我在做什么,但我访问过的每个地方提供的细节都略有不同,我还没有找到一个真正有效的比较。我可以让它与数据流方法一起工作,但没有结构。 请小伙子们和女士们在这里帮助一个人

问题是 std_logic 类型不可见。它需要通过 library/use 子句使其可见:

library ieee;
use ieee.std_logic_1164.all;

当然我看到你已经有这样的条款了。它的范围没有你想象的那么大。在 VHDL 中,library/use 子句仅适用于以下实体、体系结构、包或包体。架构会自动从其实体继承 library/use 子句,但反之则不然。包主体自动从其包中继承 library/use 子句,反之则不然。

我猜你把所有东西都放在同一个文件里了Struct_1.vhd?在那种情况下,只有 xor_2 entity/architecture 可以看到 ieee.std_logic_1164 的 library/use 子句。您需要将它添加到每个实体之上。另外一个好的编码习惯是每个文件只有一对 entity/architecture。