VHDL 门基础知识

发布于 2024-10-24 08:32:23 字数 2917 浏览 1 评论 0原文

我正在学习VHDL,但我已经停下来了。我想用较小的门(这里是与非门)创建一个简单的门。这是代码:

library IEEE;
use IEEE.STD_LOGIC_1164.all;

entity ANDGATE2 is
     port(
         x,y  : in STD_LOGIC;
         z    : out STD_LOGIC
         );
end ANDGATE2;

architecture ANDGATE2 of ANDGATE2 is
begin

    z <= x AND y;

end ANDGATE2;

library IEEE;
use IEEE.STD_LOGIC_1164.all;

entity NOTGATE1 is
     port(
         x : in STD_LOGIC;
         z : out STD_LOGIC
         );
end NOTGATE1;

architecture NOTGATE1 of NOTGATE1 is
begin

    z <= NOT x;

end NOTGATE1;       

library  ieee;
use  ieee.std_logic_1164.all;

entity NANDGATE2 is
     port(
         x : in STD_LOGIC;
         y : in STD_LOGIC;
         z : out STD_LOGIC
         );
end NANDGATE2;

architecture NANDGATE2 of NANDGATE2 is   
signal c, d: std_logic;
    component NOTGATE1
         port(
             n_in : in STD_LOGIC;
             n_out : out STD_LOGIC
             );
    end component;  
    component ANDGATE2
        port(
             a_in1, a_in2 : in STD_LOGIC;
             a_out        : out STD_LOGIC
             );
    end component;
begin     
    N0: ANDGATE2
    port map(x, y, c);
    N1: NOTGATE1
    port map(c, d); 

    z <= d;

end NANDGATE2;

这是我一直用作模板的一些教程中的代码;它编译没有问题。

library  ieee;
use  ieee.std_logic_1164.all;

-- definition of a full adder

entity FULLADDER is
    port 
    (
        a, b, c: in std_logic;
        sum, carry: out std_logic
    );
end FULLADDER;     

architecture fulladder_behav of FULLADDER is
begin
sum <= (a xor b) xor c ;
carry <= (a and b) or (c and (a xor b));
     end fulladder_behav;

     -- 4-bit adder

library  ieee;
use  ieee.std_logic_1164.all;

entity FOURBITADD is
    port 
    (
        a, b: in std_logic_vector(3 downto 0);
        Cin : in std_logic;
        sum: out std_logic_vector (3 downto 0);
        Cout, V: out std_logic
    );
end FOURBITADD;

architecture fouradder_structure of FOURBITADD is
     signal c: std_logic_vector (4 downto 0);
component FULLADDER
    port
    (
        a, b, c: in std_logic;
        sum, carry: out std_logic
    );
end component;

begin
           FA0: FULLADDER
                port map (a(0), b(0), Cin, sum(0), c(1));
           FA1: FULLADDER
                port map (a(1), b(1), C(1), sum(1), c(2));
           FA2: FULLADDER
                port map (a(2), b(2), C(2), sum(2), c(3));
           FA3: FULLADDER
                port map (a(3), b(3), C(3), sum(3), c(4));
           V <= c(3) xor c(4);
           Cout <= c(4);
end fouradder_structure;

我的代码编译没有错误,但有两个警告:

# Warning: ELAB1_0026: p2.vhd : (85, 0): There is no default binding for component "andgate2".(Port "a_in1" is not on the entity).
# Warning: ELAB1_0026: p2.vhd : (87, 0): There is no default binding for component "notgate1".(Port "n_in" is not on the entity).

什么给出了?

I'm learning VHDL and I've come to a halt. I'd like to create a simple gate out of smaller gates (a NAND gate here). Here's the code:

library IEEE;
use IEEE.STD_LOGIC_1164.all;

entity ANDGATE2 is
     port(
         x,y  : in STD_LOGIC;
         z    : out STD_LOGIC
         );
end ANDGATE2;

architecture ANDGATE2 of ANDGATE2 is
begin

    z <= x AND y;

end ANDGATE2;

library IEEE;
use IEEE.STD_LOGIC_1164.all;

entity NOTGATE1 is
     port(
         x : in STD_LOGIC;
         z : out STD_LOGIC
         );
end NOTGATE1;

architecture NOTGATE1 of NOTGATE1 is
begin

    z <= NOT x;

end NOTGATE1;       

library  ieee;
use  ieee.std_logic_1164.all;

entity NANDGATE2 is
     port(
         x : in STD_LOGIC;
         y : in STD_LOGIC;
         z : out STD_LOGIC
         );
end NANDGATE2;

architecture NANDGATE2 of NANDGATE2 is   
signal c, d: std_logic;
    component NOTGATE1
         port(
             n_in : in STD_LOGIC;
             n_out : out STD_LOGIC
             );
    end component;  
    component ANDGATE2
        port(
             a_in1, a_in2 : in STD_LOGIC;
             a_out        : out STD_LOGIC
             );
    end component;
begin     
    N0: ANDGATE2
    port map(x, y, c);
    N1: NOTGATE1
    port map(c, d); 

    z <= d;

end NANDGATE2;

Here's the code from some tutorial I've been using as a template; it compiles with no problems.

library  ieee;
use  ieee.std_logic_1164.all;

-- definition of a full adder

entity FULLADDER is
    port 
    (
        a, b, c: in std_logic;
        sum, carry: out std_logic
    );
end FULLADDER;     

architecture fulladder_behav of FULLADDER is
begin
sum <= (a xor b) xor c ;
carry <= (a and b) or (c and (a xor b));
     end fulladder_behav;

     -- 4-bit adder

library  ieee;
use  ieee.std_logic_1164.all;

entity FOURBITADD is
    port 
    (
        a, b: in std_logic_vector(3 downto 0);
        Cin : in std_logic;
        sum: out std_logic_vector (3 downto 0);
        Cout, V: out std_logic
    );
end FOURBITADD;

architecture fouradder_structure of FOURBITADD is
     signal c: std_logic_vector (4 downto 0);
component FULLADDER
    port
    (
        a, b, c: in std_logic;
        sum, carry: out std_logic
    );
end component;

begin
           FA0: FULLADDER
                port map (a(0), b(0), Cin, sum(0), c(1));
           FA1: FULLADDER
                port map (a(1), b(1), C(1), sum(1), c(2));
           FA2: FULLADDER
                port map (a(2), b(2), C(2), sum(2), c(3));
           FA3: FULLADDER
                port map (a(3), b(3), C(3), sum(3), c(4));
           V <= c(3) xor c(4);
           Cout <= c(4);
end fouradder_structure;

My code compiles with no errors, but with two warnings:

# Warning: ELAB1_0026: p2.vhd : (85, 0): There is no default binding for component "andgate2".(Port "a_in1" is not on the entity).
# Warning: ELAB1_0026: p2.vhd : (87, 0): There is no default binding for component "notgate1".(Port "n_in" is not on the entity).

What gives?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

白日梦 2024-10-31 08:32:23

您需要在组件和实体声明中使用相同的端口名称。

现在,例如在您的 NOTGATE1 实体声明中,您有输入端口 x 和输出端口 z,但在 NANDGATE2< /code> 架构中,您声明 NOTGATE1 组件具有端口 n_inn_out

这不会在编译期间引起问题,因为编译一次查看一个单元,并且不会看到实际的实体。在细化阶段,您的工具将尝试将实体与组件进行匹配,但这将会失败,因为端口不匹配。

You need to use the same port names on your component and entity declarations.

Right now, for example in your NOTGATE1 entity declaration, you have input port x and output port z, but in the NANDGATE2 architecture, you declare the NOTGATE1 component to have ports n_in and n_out.

This won't cause problems during compilation, since compilation looks at a single unit at a time, and won't see the actual entities. In the elaboration phase, your tools will try to match up the entities to components, but this will fail since the ports don't match.

素手挽清风 2024-10-31 08:32:23

不是 100% 确定,但我认为 component 声明中的引脚需要与 entity 块中的引脚匹配:

component NOTGATE1
     port(
         x : in STD_LOGIC;
         z : out STD_LOGIC
         );
end component;  
component ANDGATE2
    port(
         x,y : in STD_LOGIC;
         z   : out STD_LOGIC
         );

Not 100% sure, but I think the pins in your component declarations need to match up to the ones in your entity blocks:

component NOTGATE1
     port(
         x : in STD_LOGIC;
         z : out STD_LOGIC
         );
end component;  
component ANDGATE2
    port(
         x,y : in STD_LOGIC;
         z   : out STD_LOGIC
         );
怼怹恏 2024-10-31 08:32:23

始终在端口映射中使用显式端口绑定,这样

port map(a_in1 => x, 
         a_in2 => y, 
         a_out => c);

您的代码也会更加清晰。在大型项目中,这是第一条经验法则。

Always use explicit port bindings in your port maps, like

port map(a_in1 => x, 
         a_in2 => y, 
         a_out => c);

It will make your code also more clear. In big projects it is the first rule of thumb.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文