【问题标题】:VHDL: Concise formulation of conditional signal assignmentVHDL:条件信号分配的简明表述
【发布时间】:2017-04-02 19:30:53
【问题描述】:

以下代码是一个 4:1 多路复用器。如果dis 信号为“1”,则所有输出引脚上的输出都应为 0。有没有一种简洁的方式来说明如果dis为高,那么输出应该是0,不管sel,没有 必须通过sel 的每个组合进行置换?

我知道,在某些情况下,如果条件赋值不明确,则可能会产生意外的锁存器以及其他不良副作用。

architecture dataflow of mux8_4 is
begin
    q <=d0 when sel = "00" and dis = '0' else
        d1 when sel = "01" and dis = '0' else
        d2 when sel = "10" and dis = '0' else
        d3 when sel = "11" and dis = '0' else
        "00000000" when sel = "00" and dis = '1' else
        "00000000" when sel = "01" and dis = '1' else
        "00000000" when sel = "10" and dis = '1' else
        "00000000" when sel = "11" and dis = '1';
end architecture dataflow;

我的尝试(我理解省略所有可能的陈述是不好的 但是练习)

architecture dataflow of mux8_4 is
begin
    q <=    "00000000" when dis = '1' else
        d0 when sel = "00" and dis = '0' else
        d1 when sel = "01" and dis = '0' else
        d2 when sel = "10" and dis = '0' else
        d3 when sel = "11" and dis = '0';
end architecture dataflow;

【问题讨论】:

    标签: syntax vhdl


    【解决方案1】:

    还有选定的信号分配:

    architecture foo of mux8_4 is
        subtype choice_type is std_logic_vector (2 downto 0);
    begin
        with choice_type'(dis & sel) select
            q <= d0          when "000",
                 d1          when "001",
                 d2          when "010",
                 d3          when "011",
                 "00000000"  when others;
    end architecture;
    

    case 表达式可能是一个带有类型标记的限定表达式,该类型标记具有本地静态子类型。

    参见 IEEE Std 1076-1993 9.5.2 Selected signal assignments, 8.8 Case statement 或 IEEE Std 1076-2008 11.6 Concurrent signal assignment statements, 10.5.4 Selected signal assignment statements, 10.9 Case statement。

    此(和您的)并发信号分配语句具有等效的过程,其中包含等效的顺序信号分配语句。在 -2008 中,条件和选定的信号分配语句都允许作为顺序语句。对于选定的信号分配,有一个等效的 case 语句。

    只为 dis 和 select 提供二进制值可以用于合成,其中弱值“H”和“L”分别映射到强值“1”和“0”。对于模拟,您可以使用转换函数来确保 dis 和 sel 表示二进制值(如果它们可以具有弱值)。

    如果您的四个多路复用器数据输入可以表示为一个数组值,您可以更简洁地描述一个多路复用器:

    architecture fum of mux8_4 is
        type mux4 is array (0 to 3) of std_logic_vector(7 downto 0);
        use ieee.numeric_std.all;
        signal mux:      mux4;
    begin
        mux <= (d0, d1, d2, d3);
        q <= mux(to_integer(unsigned(sel))) when dis = '0' else (others => '0');
    
    end architecture;
    

    索引名称需要具有本地静态名称的数组对象,因此在声明分配了 mux4 类型聚合值的数组对象 (mux) 时使用类型声明。

    之后,我们可以使用从 sel 转换为自然的索引作为条件信号分配中 dis = '0' 时的索引,else 值全为 '0'。

    这两种架构都会进行分析。如果您提供了带有实体声明和测试平台的Minimal, Complete and Veriable example,那么它们可以被详细说明和模拟,展示功能。 (他们都通过添加的实体声明进行分析)。

    如果您的 sel 信号是受约束的整数子类型,则索引名称索引将更加紧凑和可读。包 numeric_std 中的 to_integer 转换函数将表示二进制值的弱级别映射到强级别,并在 sel 包含元值元素值(将映射到“0”)时生成警告。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多