Vhdl:无约束数组和大小实例化
我试图将数组大小(integer ArraySize)从顶级文件传递到组件,但出现错误: [Synth 8-561]范围表达式无法解析为常量[/uncorray.vhd]:39] 我想知道是否有办法做到这一点。另外,如果一个无约束数组必须定义为常数,那么重点是什么 无约束测试Vhdl:无约束数组和大小实例化,vhdl,fpga,Vhdl,Fpga,我试图将数组大小(integer ArraySize)从顶级文件传递到组件,但出现错误: [Synth 8-561]范围表达式无法解析为常量[/uncorray.vhd]:39] 我想知道是否有办法做到这一点。另外,如果一个无约束数组必须定义为常数,那么重点是什么 无约束测试 library IEEE; use IEEE.STD_LOGIC_1164.ALL; entity UnconstrainedTest is Port ( clk : in std_logic;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity UnconstrainedTest is
Port ( clk : in std_logic;
reset: in std_logic;
LED0 : out std_logic := '0';
LED1 : out std_logic := '0'
);
end UnconstrainedTest;
architecture Behavioral of UnconstrainedTest is
component UnconArray is
port( clk_1 : in std_logic;
ArraySize : in integer;
LED_0 : out std_logic
);
end component;
begin
A1: UnconArray port map (
clk_1 => clk,
ArraySize => 12,
LED_0 => LED0
);
A2: UnconArray port map (
clk_1 => clk,
ArraySize => 8,
LED_0 => LED1
);
end Behavioral;
组件名为array.vhd
begin
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity UnconArray is
-- generic (depth : integer := 2);
Port ( clk_1 : in std_logic;
ArraySize : in integer;
LED_0 : out std_logic
);
end UnconArray;
architecture Behavioral of UnconArray is
type Array_type is array (integer range <>) of integer;
signal MyUnconArray : Array_type (0 to ArraySize);
-- type Array_type is array (0 to ArraySize) of integer;
-- signal MyUnconArray : Array_type;
begin
MyUnconArray <= (1, 2, 3);
process (clk_1)
begin
if rising_edge(clk_1) then
if ( MyUnconArray(0) = 1 )then
LED_0 <= '1';
else
LED_0 <= '0';
end if;
end if;
end process;
end Behavioral;
开始
图书馆IEEE;
使用IEEE.STD_LOGIC_1164.ALL;
实体数组是
--通用(深度:整数:=2);
端口(clk_1:标准逻辑中;
数组化:整数形式;
LED_0:输出标准_逻辑
);
末端阵列;
阵列的体系结构是
类型数组\类型是整数的数组(整数范围);
信号数组:数组类型(0表示数组化);
--类型Array\u type是整数的数组(0表示数组化);
--信号阵列:阵列\ U型;
开始
MyArray在用VHDL编写实际硬件模型时,必须为阵列使用恒定的大小。信号就像电路板上的一根导线,不能动态添加或删除它们
如果要使用此代码,则必须使用泛型(这是一个局部常量)来声明向量的大小。实际上,您已经在代码中注释掉了这一点,但它应该如下所示:
entity UnconArray is
generic (
depth : integer := 2
);
port (
clk_1 : in std_logic;
LED_0 : out std_logic
);
end UnconArray;
architecture Behavioral of UnconArray is
type Array_type is array (integer range <>) of integer;
signal MyUnconArray : Array_type (0 to depth);
...
但是,如果不将“深度常规”设置为3,则仍会出现错误,因为在分配数据时将其视为固定大小。您也只使用元素0,因此在合成最小化过程中,将删除数组的其余部分
无约束数组的意义在于,您可以在声明信号时设置它们的大小,这可能会减少需要声明的类型数量
例如,假设您希望在代码中使用两个不同的整数数组,其中包含不同数量的元素。您可以声明两个大小不同的受约束数组类型,也可以声明一个无约束数组。您的错误消息表示合成工具的限制。您的代码实际上遇到了MyU的边界检查错误nconArray没有无约束数组的原因是它们不反映硬件。在FPGA中实现后,您无法决定数组(此处)中有多少个整数(注意Vivado错误消息编号)。需要知道数组的边界。您的“设计”也会受到最小化的影响,其中(如果是正确的VHDL)唯一幸存的元素是0
。在本例中,您几乎不需要数组。我没有意识到您必须将变量作为通用映射从顶层传递到组件。工作非常出色。非常感谢。谢谢您对无约束数组的解释。
A1: UnconArray
generic map (
depth => 2
)
port map (
clk_1 => clk,
LED_0 => LED0
);