首页 文章

vhdl中index(9)和index(9 downto 9)之间有什么区别?

提问于
浏览
2
logic index : unsigned(9 downto 0) ;  
type fft_data  is array (3 downto 0) of unsigned(16 downto 0);  
signal tmp,signal fmax_data :fft_data;  
tmp = fmax_data(to_integer(index(9)));

上面的部分代码给出了以下编译错误; “子程序调用或运算符参数类型不匹配87”

如果我做以下修改,它的工作原理 .

logic index : unsigned(9 downto 0) ;  
type fft_data  is array (3 downto 0) of unsigned(16 downto 0);  
signal tmp,signal fmax_data :fft_data;;  
tmp = fmax_data(to_integer(index(**9 downto 9**)));

谁能解释一下上面两个实现有什么区别?我正在使用vhdl-93 std和ncvhdl . 谢谢

1 回答

  • 4

    numeric_std 中, to_integer 函数仅为 unsignedsigned 类型定义 .

    无符号派生自 std_logic as type UNSIGNED is array ( NATURAL range <> ) of STD_LOGIC;

    当您使用 to_integer(index(9)) 时,您传递 index(9) ,其类型为 std_logic .

    当您使用 to_integer(index(9 downto 9)) 时,您传递的范围为 index ,大小为1,但是,它是 unsigned 类型 .

    您也可以根据需要创建自定义功能 . 要将 std_logic 转换为 integer .

    function to_integer (ARG : std_logic)
      return integer is
    begin
      if ARG = '1' OR ARG = 'H' then
        return 1;
      else
        return 0;
      end if;
    end function to_integer;`
    

    或环绕 to_integer

    function to_integer (ARG : std_logic)
        return integer is
        variable t : unsigned(0 downto 0) := "0";
    begin
        t(0) := ARG;
        return to_integer(t);
    end function to_integer;
    

相关问题