【问题标题】:Passing Variables to procedure in VHDL将变量传递给 VHDL 中的过程
【发布时间】:2011-02-02 12:17:18
【问题描述】:

我有以下简单的过程添加两个数字:

  procedure add_elements
  (
    x : in  std_logic_vector(31 downto 0);
    y : in  std_logic_vector(31 downto 0);   
    r : out std_logic_vector(31 downto 0)
  )
  is

  begin

   r := a + b;

  end;

我想在一个看起来如下的过程中使用这个过程:

  test: process (....)
    variable inp1 : std_logic_vector(31 downto 0);
    variable inp2 : std_logic_vector(31 downto 0);
    variable res : std_logic_vector(31 downto 0);
  begin

    ...
    inp1  := some_value_a;
    inp2  := some_value_b;
    add_elements(inp1, inp2, res);
    ...
  end

但是,在尝试编译时,Modelsim 告诉我 子程序“add_elements”没有可行的条目

任何人都知道这里出了什么问题,是签名有问题 add_elements 过程?

非常感谢!

【问题讨论】:

    标签: vhdl hdl


    【解决方案1】:

    我想你会想要这样的设置(我注意到一些错别字)。

    library ieee;
    use ieee.std_logic_1164.all;
    use ieee.std_logic_unsigned.all;
    

    我将在此处添加强制性说明,您可能希望避免使用 std_logic_unsigned 并转而使用 numeric_std... 继续... 这里没什么有趣的:

    entity top is
        port (
        clk : in std_logic;
        x : in std_logic_vector(31 downto 0);
        y : in std_logic_vector(31 downto 0)
        );
    end top;
    

    在架构中,我们声明了过程。我想你有一个错字。 (x 和 y 与 a 和 b)。

    architecture top_arch of top is
     procedure add_elements
      (
        x : in  std_logic_vector(31 downto 0);
        y : in  std_logic_vector(31 downto 0);   
        r : out std_logic_vector(31 downto 0)
      )
      is
      begin
       r := x + y;
      end;
    
    begin
    

    现在实际过程:

      test: process (clk)
        variable inp1 : std_logic_vector(31 downto 0);
        variable inp2 : std_logic_vector(31 downto 0);
        variable res : std_logic_vector(31 downto 0);
      begin
        inp1  := x;
        inp2  := y;
        add_elements(inp1, inp2, res);
      end process;
    end architecture top_arch;
    

    就是这样。我认为你真的很亲密,只是可能错过了一个图书馆和/或有一些错别字。

    编辑:我还应该提到,如果您想要重复使用,您可以(并且可能应该)将该过程放在一个单独的包中。然后你需要使用“use”语句来包含这个包。

    【讨论】:

    • 绝对推荐使用 ieee.numeric_std.all
    • 建议使用非标准包,即使有警告说明,也不是很好的建议。帮助我们保存 VHDL :-)
    • 我当然认识到使用 std_logic_unsigned 是“不正确的”,但为了最直接地回答手头的问题,我决定不使用 OP 没有询问的主题来搅浑水。手头的问题是关于程序的使用。
    • 问题似乎与程序有关,但问题实际上与类型有关,从您的回答中可以看出。
    • 另一种想法:不要使用只有一个输出参数的过程,自然的解决方案是使用函数。
    【解决方案2】:

    为什么需要一个程序来添加两个数字?为什么不立即添加它们?

    --请注意,我假设 std_logic_vectors 代表数字。--

    我建议先将 std_logic_vectors 转换为无符号或有符号 (use ieee.numeric_std.all) 并使用“+”运算符。你永远不应该use ieee.std_logic_unsigned.all,它只会给你带来麻烦。

    【讨论】:

      【解决方案3】:

      其实问题出在“+”的签名上。在标准 VHDL 中,std_logic_vector 没有定义算术。

      正如其他人几乎建议的那样,请考虑改用IEEE.numeric_std 中的unsignedsigned

      为了完整起见,VHDL-2008 似乎添加了标准包来对 std_logic_vector 进行算术运算。但是,与非标准包一样,数字解释(有符号或无符号)取决于使用的包。我不喜欢那样。

      【讨论】:

        猜你喜欢
        • 2016-07-14
        • 2021-12-08
        • 2011-09-15
        • 2023-04-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-10-08
        相关资源
        最近更新 更多