首页 文章

非法类型转换VHDL

提问于
浏览
0

我试图通过vhdl中的类型转换返回类型std_logic_vector . 这是我的代码:

function mul(num1,num2 : in std_logic_vector(7 DOWNTO 0)) return std_logic_vector is
    variable v_TEST_VARIABLE1 : integer;
    variable v_TEST_VARIABLE2 : integer;
    variable n_times: integer:=1;
    variable product: integer:=0;
    begin 
      for n_times in 1 to v_TEST_VARIABLE2 loop
        product:=product + v_TEST_VARIABLE1;
      end loop;
    return std_logic_vector(product);
  end mul;

它在编译时给出 "Illegal type conversion from std.standard.integer to ieee.std_logic_1164.std_logic_vector (numeric to array)." . 如何在这样的代码中返回std_logic_vector?

2 回答

  • 1

    您必须先将其转换为无符号 . 我希望你使用的是numeric_std?如果是这样,您的代码看起来像这样 . 请注意,要使用to_unsigned,您必须知道输出std_logic_vector的长度 . 所以这需要是你的函数的输入,或者你可以绑定返回向量:

    return std_logic_vector(to_unsigned(product, length));
    

    有关如何convert std_logic_vector to integer的更多信息 .

  • 0

    先看看罗素的帖子 . 如果您使用VHDL-2008,numeric_std_unsigned包,那么您只能使用一次转换:

    use ieee.numeric_std_unsigned.all ; 
    ...
    return to_std_logic_vector(product, length) ;  -- long form
    
    -- alternate short form
    return to_slv(product, length) ;
    

    Usage warning: 对于综合,我认为VHDL-2008项目处于支持的最前沿 . 因此,虽然我经常在我的测试平台中使用VHDL-2008,但我尝试将其在RTL代码中的使用限制为使用其他方法无法完成的操作 . 但是,如果你想使用这样的代码,那么在你的综合工具中尝试它是很重要的,并且如果它不起作用就提交bug报告 - 这是改变发生的唯一方法 .

相关问题