VHDL,选择信号,连接



需要了解如何使用选定的信号分配,并包括一个4位的内部信号,称为WXYZ,通过连接W与X与Y与Z为以下布尔代数表达式F(W,X,Y,Z)=Y'Z'+W'X'+X'Y

ENTITY Part_2A IS 
PORT(
    W, X, Y, Z  : IN STD_LOGIC;
    G1          : OUT STD_LOGIC);       
END Part_2A;
ARCHITECTURE sig OF Part_2A IS
SIGNAL inputs : STD_LOGIC_VECTOR(3 downto 0);
SIGNAL outputs: STD_LOGIC;
BEGIN 
--Concatenate input ports into 4-bit signal
inputs <= W & X & Y & Z;
WITH inputs SELECT         
    outputs     <=  "1" when "0000",
                    "1" when "0001",
                    "1" when "0010",
                    "1" when "0011",
                    "1" when "0100",
                    "1" when "1000",
                    "1" when "1010",
                    "1" when "1011",
                    "1" when "1100",
                    "0" when others;
G1 <= outputs;
END sig;

没有比

更好的了

需要了解如何使用选定的信号分配,并包括一个4位的内部信号,称为WXYZ,通过连接W与X与Y与Z为以下布尔代数表达式F(W,X,Y,Z)=Y'Z'+W'X'+X'Y

我甚至没有看到一个问号。

通过添加引用IEEE标准库std_logic_1164的上下文子句,并将字符串字面值"1""0"转换为字符字面值'1 '和'0'(字符字面值是可接受的枚举字面值,std_ulogic std_logic的基本类型是枚举标量类型),我们得到如下内容:

library ieee;
use ieee.std_logic_1164.all;
entity part_2a is 
    port (
        w, x, y, z  : in std_logic;
        g1          : out std_logic
    );       
end entity part_2a;
architecture sig of part_2a is
    signal inputs : std_logic_vector(3 downto 0);
    signal outputs: std_logic;
begin 
--concatenate input ports into 4-bit signal
    inputs <= w & x & y & z;
    with inputs select         
        outputs <=  '1' when "0000",
                    '1' when "0001",
                    '1' when "0010",
                    '1' when "0011",
                    '1' when "0100",
                    '1' when "1000",
                    '1' when "1010",
                    '1' when "1011",
                    '1' when "1100",
                    '0' when others;
    g1 <= outputs;
end architecture sig;

分析无误

你可能被你的VHDL工具误导了。有一些VHDL实现特别抱怨类型不匹配。例如ghdl:

hdl -a part 2 .vhdl
part_2a。Vhdl:21:21:无法将字符串字面值"1"与类型枚举子类型"std_logic"匹配
part_2a。Vhdl:22:21:无法将字符串字面值"1"与类型枚举子类型"std_logic"匹配
part_2a。Vhdl:23:21:无法将字符串字面值"1"与类型枚举子类型"std_logic"匹配
part_2a。Vhdl:24:21:无法将字符串字面值"1"与类型枚举子类型"std_logic"匹配
part_2a。Vhdl:25:21:无法将字符串字面值"1"与类型枚举子类型"std_logic"匹配
part_2a。Vhdl:26:21:无法将字符串字面值"1"与类型枚举子类型"std_logic"匹配
part_2a。Vhdl:27:21:无法将字符串字面值"1"与类型枚举子类型"std_logic"匹配
part_2a。Vhdl:28:21:无法将字符串字面值"1"与类型枚举子类型"std_logic"匹配
part_2a。Vhdl:29:21:无法将字符串字面值"1"与类型枚举子类型"std_logic"匹配
part_2a。Vhdl:30:21:无法将字符串字面值"0"与类型枚举子类型"std_logic"匹配
编译错误

而有些在第一个错误时退出:

nvc -a part_2a.vhdl  
** Error: no one dimensional arrays of character type in context
       File part_2a.vhdl, Line 21  
       outputs     <=  "1" when "0000",  
                       ^^^

如果你有一个仅仅指向语句开头的

WITH inputs SELECT

如果没有有用的信息,您可能会认为这是一个连接问题(取决于实际错误消息的内容)。这就解释了为什么一个最小的、完整的和可验证的例子是有价值的。

错误消息往往是不同于特定的供应商,并告诉你试图做什么。

最新更新