VHDL数组索引超出范围
我的VHDL程序(有限状态机)的合成有问题;错误是: [Synth 8-97]数组索引“编号”超出范围 但我很确定我的索引永远不会达到那个“数字”(精确到255)。此外,行为模拟工作 以下是我的一些代码(发生错误的地方): 我怎样才能解决我的问题VHDL数组索引超出范围,vhdl,synthesis,vivado,Vhdl,Synthesis,Vivado,我的VHDL程序(有限状态机)的合成有问题;错误是: [Synth 8-97]数组索引“编号”超出范围 但我很确定我的索引永远不会达到那个“数字”(精确到255)。此外,行为模拟工作 以下是我的一些代码(发生错误的地方): 我怎样才能解决我的问题 我使用Vivado 2017.3首先,通常不建议使用变量。如有可能,使用信号 话虽如此,在某些情况下,变量是有意义的。例如,有些函数可以在多次迭代中轻松计算,但不能在一行中计算。在这种情况下,还可以使用generate语句,但可读性会降低。但是,我会将
我使用Vivado 2017.3首先,通常不建议使用变量。如有可能,使用信号 话虽如此,在某些情况下,变量是有意义的。例如,有些函数可以在多次迭代中轻松计算,但不能在一行中计算。在这种情况下,还可以使用generate语句,但可读性会降低。但是,我会将这些代码封装到函数中,并在其他任何地方使用信号 无论如何,在完成您的函数后,我得到了与您相同的错误消息。问题在于,合成工具显然无法确定
var\u col
的范围是有限的。解决方案很简单:通过在变量声明中添加范围0到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;
IEEE库;
使用IEEE.STD_LOGIC_1164.ALL;
使用IEEE.NUMERIC_STD.ALL;
实体A是
港口
(
IVL:标准逻辑向量(254到0);
iters:标准逻辑向量(4到0);
椭圆:输出标准逻辑向量(9到0)
);
结束A;
is的行为体系结构
子类型my_数组是std_逻辑;
键入my_数组0是my_数组的数组(0到254);
开始
状态梳:过程(ival)
变量数组_col:my_array0:=(其他=>'0');
变量K:整数;
变量var_col:0到24的整数范围;
变量tot_col:整数;
变量num_zero:整数;
变量tot_行:整数;
开始
对于0到254中的i
环
数组_col(i):=ival(i);
端环;
K:=0;
var_col:=to_整数(无符号(iters));
而(K0),则
num_zero:=num_zero+1;
其他的
num_zero:=0;
如果结束;
如果结束;
K:=K+1;
端环;
椭圆形var\u col
是如何分配的?循环时进行合成。。。勇敢。如果您可以将其转换为具有常量边界的for循环,那么可能会有更多的synth工具正确地支持它。要获得更多帮助,请将此示例设为一个示例,该示例至少可以揭示上述内容是否属于同步过程的一部分(可能是正常的)或其他部分(可能不是正常的)。为什么不使用表示K in 0 to var_col loop
?最好不要使用变量。您应该使用一个信号来代替它。@JHBonarius,这对合成没有帮助,但如果在模拟中发生错误,它应该捕获错误。这提醒了我:Xilinx ISE模拟器(pre Vivado)运行时默认关闭边界检查/溢出检查;您必须转到“高级选项”才能打开它。疯狂但真实。值得检查一下他们是否有时间在Vivado解决这个问题?
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');
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;