如何使用FPGA中的组件

问题描述 投票:0回答:1

我想在 if 情况下(在 and gateway 情况下)使用端口映射,但我无法使用它。问题是什么?我对 FPGA 编码非常陌生。你能帮我解决代码方面的问题吗?因为当我在 if 情况之前使用它时,它可以工作,但是当我想在 if 情况内部使用它时。有问题,看不懂

and_Gate.vhd

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;

--Proje Amacı A ve B girislerini butonlara göre and,or,nor gibi kapılarla lojik islemlere sokmak...
entity and_Gate is
    Port ( 
           A_and        : in STD_LOGIC_VECTOR(15 downto 0);
           B_and        : in STD_LOGIC_VECTOR(15 downto 0);
           C_and        : out STD_LOGIC_VECTOR(15 downto 0)     
         );
end and_Gate;
architecture Behavioral of and_Gate is
begin
      C_and     <= A_and and B_and;
end Behavioral;

算术逻辑单元.vhd

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.NUMERIC_STD.ALL;

entity arithmetic_logic_unit is
    generic ( 
        N : integer := 16
    );
    Port ( 
        A : in  STD_LOGIC_VECTOR(N-1 downto 0);
        B : in  STD_LOGIC_VECTOR(N-1 downto 0);
        C : out     STD_LOGIC_VECTOR(N-1 downto 0) 
    );
end arithmetic_logic_unit;

architecture Behavioral of arithmetic_logic_unit is
    signal operation_type : STD_LOGIC_VECTOR(3 downto 0) := "0000";
    signal C_out_and :      STD_LOGIC_VECTOR(15 downto 0);
    
component and_Gate is
    Port ( 
        A_and   : in STD_LOGIC_VECTOR(15 downto 0);
        B_and   : in STD_LOGIC_VECTOR(15 downto 0);
        C_and   : out STD_LOGIC_VECTOR(15 downto 0)        
    );
end component and_Gate;

begin
    process (A, B, operation_type)
    begin

        if (operation_type = "0101") then -- AND GATE
            and_gate1 : and_Gate port map (
                 A_and          => A,
                 B_and          => B,
                 C_and          => C_out_and
            );
                            C <= C_out_and;

        end if;
    end process;
end Behavioral;
vhdl fpga software-design
1个回答
0
投票

您的评论(我将其翻译成英文)指出:

--项目目的:根据按钮将A、B输入进行与、或、或非等门的逻辑运算...

...您应该改进您的问题,以更好地反映预期结果和意图...就像评论所说,您应该记住您正在用 VHDL 描述硬件。有时,如果不是复杂的设计,绘制图表可能会有所帮助。阅读语言参考手册 (LRM) 对您没有多大帮助,因为您似乎仍在学习 VHDL 的基本概念。


所以你想根据操作类型(来自按钮或开关)使用不同的组件对信号 A 和 B 执行不同的逻辑运算(与/或/非等...),然后将结果输出到信号 C .

因为您正在设计硬件,所以您无法根据信号的值使组件消失/出现。它是硬件,因此组件必须在那里 - 这就是为什么 VHDL 语言不允许您做您正在尝试的事情。

相反,您可能想要实例化所有必要的组件(AND / OR / NOT /等...),然后根据信号的值选择顶层设计的输出。所以如下图所示:

    ┌─────────────────────────────┐
    │    arithmetic logic unit    │
    │                             │
 A  │     ┌────────┐              │
────┼───┬─►        │ c_out_and    │
    │   │ │ and_   ├─┐            │
    │ ┌─┼─► gate   │ │  ┌───────┐ │
    │ │ │ └────────┘ └──► Multi-│ │ C
    │ │ │               │ plexer├─┼─►
    │ │ │ ┌────────┐ ┌──►       │ │
    │ │ └─► or_    │ │  └────▲──┘ │
 B  │ │   │ gate   ├─┘       │    │
────┼─┴───►        │c_out_or │    │
    │     └────────┘         │    │
    │                        │    │
    │              operation_type │
    └─────────────────────────────┘

对于 VHDL,它看起来像这样:您将在进程外部进行组件实例化(端口映射)(因为它不是顺序语句,而是 VHDL 中的并发语句),然后在进程中选择输出,例如:

architecture Behavioral of arithmetic_logic_unit is
--- ...signals, component declations... omitted
begin
   and_gate1 : and_Gate port map (
        A_and          => A,
        B_and          => B,
        C_and          => C_out_and
   );
   -- Imaginary OR gate port map
   and_gate1 : or_Gate port map (
    A_or          => A,
    B_or          => B,
    C_or          => C_out_or
   );
    process (operation_type)
    begin
        if (operation_type = "0101") then -- AND GATE
            C <= C_out_and;
        else -- OR GATE
            C <= C_out_or;
        end if;
    end process;
end architecture Behavioral;
© www.soinside.com 2019 - 2024. All rights reserved.