【问题标题】:VHDL multiplexer testbench errorVHDL 多路复用器测试台错误
【发布时间】:2017-05-08 05:01:11
【问题描述】:

我是 vhdl 的新手,并试图用 5 条选择线为多路复用器制作测试台,但它给了我错误(代码很长,所以我只是复制了包含错误的部分)

代码:

    library ieee;
    use ieee.std_logic_1164.all;
    use IEEE.std_logic_unsigned.all;
    use ieee.numeric_std.all;
    entity Mux_4_to_1_tb is
    end Mux_4_to_1_tb;

    architecture tb of Mux_4_to_1_tb is

    component Mux_4_to_1 is
      port( clock : in std_logic;
        D0, D1, D2, D3 : in std_logic; -- the data lines D0=A0 D1=A1 D2=B0 D3=B1
            S0, S1, S2, S3, S4  : in std_logic; -- the selector switches
            F : out std_logic_vector(2 downto 0)
        );-- the output
    end component;
    constant clockperiod : time := 20 ns;
    signal D0, D1, D2, D3, S0, S1 , S2, S3, S4  , F : std_logic;
    signal selectors : std_logic_vector(4 downto 0);

    begin
    mapping: Mux_4_to_1 port map(D0, D1, D2, D3, S0, S1, S2, S3, S4, F );

    --Concurrent processes
    process
    begin   

      S0 <= '0'; S1 <= '0'; S2 <= '0'; S3 <= '0'; S4 <= '0';wait for clockperiod;
      S0 <= '0'; S1 <= '0'; S2 <= '0'; S3 <= '0'; S4 <= '1';wait for clockperiod;
      S0 <= '0'; S1 <= '0'; S2 <= '0'; S3 <= '1'; S4 <= '0';wait for clockperiod;
      S0 <= '0'; S1 <= '0'; S2 <= '0'; S3 <= '1'; S4 <= '1';wait for clockperiod;
      S0 <= '0'; S1 <= '0'; S2 <= '1'; S3 <= '0'; S4 <= '0';wait for clockperiod;
      S0 <= '0'; S1 <= '0'; S2 <= '1'; S3 <= '0'; S4 <= '1';wait for clockperiod;
      S0 <= '0'; S1 <= '0'; S2 <= '1'; S3 <= '1'; S4 <= '0';wait for clockperiod;
      S0 <= '0'; S1 <= '0'; S2 <= '1'; S3 <= '1'; S4 <= '1';wait for clockperiod;
      S0 <= '0'; S1 <= '1'; S2 <= '0'; S3 <= '0'; S4 <= '0';wait for clockperiod;
      S0 <= '0'; S1 <= '1'; S2 <= '0'; S3 <= '0'; S4 <= '1';wait for clockperiod;
      S0 <= '0'; S1 <= '1'; S2 <= '0'; S3 <= '1'; S4 <= '0';wait for clockperiod;
      S0 <= '0'; S1 <= '1'; S2 <= '0'; S3 <= '1'; S4 <= '1';wait for clockperiod;
      S0 <= '0'; S1 <= '1'; S2 <= '1'; S3 <= '0'; S4 <= '0';wait for clockperiod;
      S0 <= '0'; S1 <= '1'; S2 <= '1'; S3 <= '0'; S4 <= '1';wait for clockperiod;
      S0 <= '0'; S1 <= '1'; S2 <= '1'; S3 <= '1'; S4 <= '0';wait for clockperiod;
      S0 <= '0'; S1 <= '1'; S2 <= '1'; S3 <= '1'; S4 <= '1';wait for clockperiod;
      S0 <= '1'; S1 <= '0'; S2 <= '0'; S3 <= '0'; S4 <= '0';wait for clockperiod;
      end process;

      process(S4, S3, S2, S1, S0)
      begin
       selectors <= S0&S1&S2&S3&S4;
        end process;

       process
       begin

      --The "assert" keyword allows you to test certain 
      --conditions. In other words, the point of assertion is
      --to allow you to inspect what you expect.

      --Two test cases are presented here. Feel free 
      --to add your own cases.

       --TEST 1
         D0 <= '0';
        D1 <= '1';
        D2 <= '0';
        D3 <= '1';
        wait for clockperiod;
        case selectors is
         when "00000" =>
           assert(F => "000") report "Error 1: 00000" severity error;

错误:

** 错误:E:\OneDrive\Engineering\Digital Circuit Design\TestBench.vhd(70): (vcom-1581) 中缀运算符“=”没有可行的条目。
** 错误:E:\ OneDrive\Engineering\Digital Circuit Design\TestBench.vhd(70):类型错误将中缀表达式“=”解析为类型 std.STANDARD.BOOLEAN。

错误将我指向带有断言字的行。

我在代码末尾也收到此错误

代码:

 when others =>
     assert true;
  end case;
end process;
end tb;

错误:

** 错误:E:\OneDrive\Engineering\Digital Circuit Design\TestBench.vhd(229):VHDL 编译器退出

错误将我指向此处的最后一行。

【问题讨论】:

  • 你为什么有assert true?它没用,它永远不会显示。也许是编译器错误的原因?
  • assert(F =&gt; "000") 是一个错误,F 是一个 std_logic 对象,没有 =&gt; 运算符将其与字符串 "000" 作为兼容数组类型的值进行比较。删除多余的括号,您可能会收到更有意义的错误消息。修复似乎是针对“0”的关系测试(相等),注意到多路复用器的F 输出端口 std_logic_vector 与其 std_logic 输入端口不一致。那么它真的是多路复用器吗?您没有提供Minimal, Complete and Verifiable example。信号F的声明可能有误。
  • 存在涉及F 的语义错误。它被声明为 std_logic 对象,不能与“000”进行比较。如果没有看到Mux_4_to_1 的代码,读者无法判断F 应该是什么,在它的组件端口声明中它是一个std_logic_vector。将信号F 声明更改为signal F: std_logic_vector (2 downto 0); 表明mapping 的参数存在问题,它缺少clock 正式关联,缺少输出(F)不是错误。使用命名关联。添加时钟关联。修复断言条件(例如&gt;= 不是=&gt; )。

标签: vhdl


【解决方案1】:

在不透露Mux_4_to_1 的内容的情况下,您无法提供有关此测试平台应该如何运行的任何见解。

断言语句条件有两点错误:

assert(F => "000")

F 被声明为 std_logic 类型,它不是数组类型,不能与字符串值进行比较(它的数组类型可以由上下文确定)。此外,关系运算符应该是&gt;= 而不是=&gt;,读作“大于或等于”。 =&gt; 是用于关联的分隔符。

更改关系运算符并更改F 的声明:

signal D0, D1, D2, D3, S0, S1 , S2, S3, S4 :  std_logic; --  , F : std_logic;
signal F:   std_logic_vector (2 downto 0);

产生一个错误告诉我们F can't be associated with S4,告诉我们你有一个参数列表错误。你没有足够的参数。不为输出提供关联并不是错误,这就是为什么以前没有注意到它,尽管读者可能会认为您更改了 F 的声明以预先消除该错误。

为时钟添加信号声明:

constant clockperiod : time := 20 ns;
signal clock:   std_logic;

并添加关联:

begin
-- mapping: Mux_4_to_1 port map(D0, D1, D2, D3, S0, S1, S2, S3, S4, F );
mapping: 
    Mux_4_to_1 
        port map (
            clock => clock,
            D0 => D0,
            D1 => D1,
            D2 => D2,
            D3 => D3, 
            S0 => S0,
            S1 => S1,
            S2 => S2,
            S3 => S3,
            S4 => S4, 
            F => F
        );

允许您的代码进行分析(通过将找到的代码与其他选项连接到 VHDL 代码的末尾,您无需提供Minimal, Complete and Verifiable example)。

注意事项:

  1. clock 未在更改描述中显示驱动,如果您的测试需要,应由测试台驱动。
  2. Mux_4_to_1 实例化的端口映射中显示正式关联,它允许您查看缺少或错误的正式与实际端口关联。
  3. 条件周围的多余括号可能会掩盖错误。只有当它们包含的表达式在没有它们的情况下是合法的时,它们才是合法的。它可以更改您看到的错误消息。缺少适当的关系运算符会导致语法错误。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-01-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多