【问题标题】:VHDL array index out of boundVHDL 数组索引超出范围
【发布时间】:2018-05-15 11:48:42
【问题描述】:

我的 VHDL 程序(有限状态机)的综合有问题;错误是:

[Synth 8-97] 数组索引 'number' 超出范围

但我很确定我的索引永远不会达到那个“数字”(正好是 255)。此外,行为模拟也有效。

这是我的一些代码(发生错误的地方):

K := 0;
 while (K < var_col) loop --var_col is set to 24
   if (array_col(K) = '1') then  --the error is here
      tot_col := tot_col + 1 + num_zero;
      num_zero := 0;
   else
      tot_rows := tot_rows;
      if (tot_col > 0) then
         num_zero := num_zero + 1;
      else
         num_zero := 0;
      end if;
   end if;
   K := K + 1;
 end loop

我是这样声明数组的

architecture Behavioral of A is
   subtype my_array is std_logic;
   type my_array0 is array (0 to 254) of my_array;
--other signals declaration

begin
state_comb: process(sensitivity list)
    variable array_col : my_array0 := (others => '0');

我该如何解决我的问题?

我使用 Vivado 2017.3

【问题讨论】:

  • var_col 是如何分配的?
  • 合成while循环是......勇敢。如果您可以将其转换为具有恒定边界的 for 循环,则更多合成器工具可能会正确支持它。如需更多帮助,请将此示例设为minimal reproducible example,它至少会显示上述内容是否属于同步过程(可能正常)或其他(可能不正常)。
  • 你为什么不用for K in 0 to var_col loop
  • 最好不要使用变量。您应该改用信号。
  • @JHBonarius 这对综合没有帮助,但如果它发生在模拟中,它应该会捕获错误。这提醒了我:Xilinx ISE 模拟器(Vivado 之前的版本)在默认情况下关闭边界检查/溢出检查;你必须去“高级选项”才能打开它。疯狂但真实。是否值得检查他们是否有机会在 Vivado 中修复该问题?

标签: vhdl synthesis vivado


【解决方案1】:

首先,一般不推荐使用变量。如果可能的话,用于信号。

话虽如此,但在某些情况下变量是有意义的。例如,有些函数可以很容易地在多次迭代中计算出来,但你不能在一行中计算它们。在这种情况下也可以使用生成语句,但这变得不那么可读了。但是,我会将此类代码封装到函数中并在其他任何地方使用信号。

无论如何,在完成你的功能后,我得到了和你一样的错误信息。问题是综合工具显然无法确定var_col 的范围是有限的。解决方案很简单:通过在变量声明中添加例如range 0 to 24 来告诉综合工具范围是多少。以下是我的代码:

library IEEE;
  use IEEE.STD_LOGIC_1164.ALL;
  use IEEE.NUMERIC_STD.ALL;

entity A is
   port
   (
     ival  : in  std_logic_vector(254 downto 0);
     iters : in  std_logic_vector(4 downto 0);
     oval  : out std_logic_vector(9 downto 0)
   );
end A;

architecture Behavioral of A is
   subtype my_array is std_logic;
   type my_array0 is array (0 to 254) of my_array;

begin
  state_comb: process(ival)
    variable array_col: my_array0 := (others => '0');
    variable K:         integer;
    variable var_col:   integer range 0 to 24;
    variable tot_col:   integer;
    variable num_zero:  integer;
    variable tot_rows:  integer;
  begin
    for i in 0 to 254
    loop
      array_col(i) := ival(i);
    end loop;

    K := 0;
    var_col := to_integer(unsigned(iters));
    while (K < var_col) loop --var_col is set to 24
     if (array_col(K) = '1') then  --the error is here
        tot_col := tot_col + 1 + num_zero;
        num_zero := 0;
     else
        tot_rows := tot_rows;
        if (tot_col > 0) then
           num_zero := num_zero + 1;
        else
           num_zero := 0;
        end if;
     end if;
     K := K + 1;
   end loop;

   oval <= std_logic_vector(to_unsigned(tot_col, 10));
  end process;
end Behavioral;

顺便说一句,将tot_rows 分配给tot_rows 是没有意义的。

此外,您声称您的流程是同步的,但您称其为state_comb。除非comb 不是指组合,否则没有意义。

【讨论】:

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