Vhdl 如何实例化一个组件以并行生成多个组件?
我尝试使用泛型映射生成多个组件,但我不知道我的代码VHDL是否正确? 在这里,程序生成5个并行组件组件,用于形成基本组件Vhdl 如何实例化一个组件以并行生成多个组件?,vhdl,fpga,Vhdl,Fpga,我尝试使用泛型映射生成多个组件,但我不知道我的代码VHDL是否正确? 在这里,程序生成5个并行组件组件,用于形成基本组件 entity bascule is Port ( X1,X2,X3,X4,X5: in STD_LOGIC; Y1,Y2, Y3,Y4,Y5 : in STD_LOGIC; Z1,Z2,Z3,Z4,Z5 : in STD_LOGIC;
entity bascule is
Port ( X1,X2,X3,X4,X5: in STD_LOGIC;
Y1,Y2, Y3,Y4,Y5 : in STD_LOGIC;
Z1,Z2,Z3,Z4,Z5 : in STD_LOGIC;
S1,S2,S3,S4,S5 : out STD_LOGIC);
end bascule;
architecture Behavioral of bascule is
component comp
Generic( N: integer :=1);
Port ( X : in STD_LOGIC;
Y : in STD_LOGIC;
Z: in STD_LOGIC;
S : out STD_LOGIC);
end component;
begin
m1 : comp generic map (5)
port map ( X1,Y1,Z1, S1);
m2 : comp generic map (5)
port map ( X2,Y2,Z2, S2);
m3 : comp generic map (5)
port map ( X3,Y3,Z3, S3);
m4 : comp generic map (5)
port map ( X4,Y4,Z4, S4);
m5 : comp generic map (5)
port map ( X5,Y5,Z5, S5);
end Behavioral;
我想知道如何生成任意数量的组件
我的问候
library ieee;
use ieee.std_logic_1164.all;
-- dummy comp this analyzes and elaborates
entity comp is
Generic( N: integer :=1);
Port (
X: in STD_LOGIC;
Y: in STD_LOGIC;
Z: in STD_LOGIC;
S: out STD_LOGIC
);
end entity;
architecture behave of comp is
begin
S <= X and Y and Z;
end architecture;
library ieee;
use ieee.std_logic_1164.all;
entity bascule is
Port (
-- X1,X2,X3,X4,X5: in STD_LOGIC;
-- Y1,Y2, Y3,Y4,Y5: in STD_LOGIC;
-- Z1,Z2,Z3,Z4,Z5: in STD_LOGIC;
-- S1,S2,S3,S4,S5: out STD_LOGIC
-并在生成迭代方案中使用与上述相同的泛型:
for i in 1 to 5 generate
M:
comp generic map (5)
port map (
X(i), Y(i), Z(i), S(i)
);
end generate;
-- m1 : comp generic map (5)
-- port map ( X1,Y1,Z1, S1);
-- m2 : comp generic map (5)
-- port map ( X2,Y2,Z2, S2);
-- m3 : comp generic map (5)
-- port map ( X3,Y3,Z3, S3);
-- m4 : comp generic map (5)
-- port map ( X4,Y4,Z4, S4);
-- m5 : comp generic map (5)
-- port map ( X5,Y5,Z5, S5);
end Behavioral;
使用泛型控制实例化comp的generate语句交互
由于您似乎对如何使用泛型控制组件数量感到困惑,我将演示:
library ieee;
use ieee.std_logic_1164.all;
-- dummy comp
entity comp is
Port (
X: in STD_LOGIC;
Y: in STD_LOGIC;
Z: in STD_LOGIC;
S: out STD_LOGIC
);
end entity;
architecture behave of comp is
begin
S <= X and Y and Z;
end architecture;
library ieee;
use ieee.std_logic_1164.all;
entity bascule is
generic (MSIZE: natural := 1);
Port (
X: in std_logic_vector (1 to MSIZE);
Y: in std_logic_vector (1 to MSIZE);
Z: in std_logic_vector (1 to MSIZE);
S: out std_logic_vector (1 to MSIZE)
);
end bascule;
architecture Behavioral of bascule is
component comp
Port (
X: in STD_LOGIC;
Y: in STD_LOGIC;
Z: in STD_LOGIC;
S: out STD_LOGIC
);
end component;
begin
Mgen:
for i in 1 to MSIZE generate
M:
comp
port map (
X(i), Y(i), Z(i), S(i)
);
end generate;
end Behavioral;
library ieee;
use ieee.std_logic_1164.all;
entity bascule_tb is
end entity;
architecture foo of bascule_tb is
constant MSIZE: natural :=5;
signal X: std_logic_vector (1 to MSIZE);
signal Y: std_logic_vector (1 to MSIZE);
signal Z: std_logic_vector (1 to MSIZE);
signal S: std_logic_vector (1 to MSIZE);
begin
DUT: entity work.bascule
generic map (MSIZE)
port map (
X => X,
Y => Y,
Z => Z,
S => S
);
end architecture;
我们根据通用MSIZE获得comp组件的MSIZE数量,该MSIZE通过常量MSIZE,其中bascule在测试台bascule_tb中实例化。虽然它实际上什么都没做,但它还是进行了分析、阐述和运行
-并在生成迭代方案中使用与上述相同的泛型:
for i in 1 to 5 generate
M:
comp generic map (5)
port map (
X(i), Y(i), Z(i), S(i)
);
end generate;
-- m1 : comp generic map (5)
-- port map ( X1,Y1,Z1, S1);
-- m2 : comp generic map (5)
-- port map ( X2,Y2,Z2, S2);
-- m3 : comp generic map (5)
-- port map ( X3,Y3,Z3, S3);
-- m4 : comp generic map (5)
-- port map ( X4,Y4,Z4, S4);
-- m5 : comp generic map (5)
-- port map ( X5,Y5,Z5, S5);
end Behavioral;
使用泛型控制实例化comp的generate语句交互
由于您似乎对如何使用泛型控制组件数量感到困惑,我将演示:
library ieee;
use ieee.std_logic_1164.all;
-- dummy comp
entity comp is
Port (
X: in STD_LOGIC;
Y: in STD_LOGIC;
Z: in STD_LOGIC;
S: out STD_LOGIC
);
end entity;
architecture behave of comp is
begin
S <= X and Y and Z;
end architecture;
library ieee;
use ieee.std_logic_1164.all;
entity bascule is
generic (MSIZE: natural := 1);
Port (
X: in std_logic_vector (1 to MSIZE);
Y: in std_logic_vector (1 to MSIZE);
Z: in std_logic_vector (1 to MSIZE);
S: out std_logic_vector (1 to MSIZE)
);
end bascule;
architecture Behavioral of bascule is
component comp
Port (
X: in STD_LOGIC;
Y: in STD_LOGIC;
Z: in STD_LOGIC;
S: out STD_LOGIC
);
end component;
begin
Mgen:
for i in 1 to MSIZE generate
M:
comp
port map (
X(i), Y(i), Z(i), S(i)
);
end generate;
end Behavioral;
library ieee;
use ieee.std_logic_1164.all;
entity bascule_tb is
end entity;
architecture foo of bascule_tb is
constant MSIZE: natural :=5;
signal X: std_logic_vector (1 to MSIZE);
signal Y: std_logic_vector (1 to MSIZE);
signal Z: std_logic_vector (1 to MSIZE);
signal S: std_logic_vector (1 to MSIZE);
begin
DUT: entity work.bascule
generic map (MSIZE)
port map (
X => X,
Y => Y,
Z => Z,
S => S
);
end architecture;
我们根据通用MSIZE获得comp组件的MSIZE数量,该MSIZE通过常量MSIZE,其中bascule在测试台bascule_tb中实例化。虽然它实际上什么都没做,但它还是进行了分析、阐述和运行
我想知道如何生成任意数量的组件
关键是单词生成
您可以使用for..generate循环。为此,需要使用与预期组件数量相同的向量输入数量来表示顶级实体:
entity bascule is
generic ( number_of_comps : positive)
port ( X,Y,Z: in STD_LOGIC_VECTOR(number_of_comps downto 1);
S : out STD_LOGIC_VECTOR(number_of_comps downto 1));
end bascule;
然后在体系结构中,您可以像这样连接组件:
for i in 1 to number_of_comps generate
inst : entity work.comp
generic map (5)
port map ( X(i),Y(i),Z(i), S(i));
end generate;
我想你可能还是有点困惑,因为你的低级别comp上有一个通用的5,但在我看来,通用应该只在顶层实体中,以指定你想要多少comp,除非你在comp实体中也这样做
我想知道如何生成任意数量的组件
关键是单词生成
您可以使用for..generate循环。为此,需要使用与预期组件数量相同的向量输入数量来表示顶级实体:
entity bascule is
generic ( number_of_comps : positive)
port ( X,Y,Z: in STD_LOGIC_VECTOR(number_of_comps downto 1);
S : out STD_LOGIC_VECTOR(number_of_comps downto 1));
end bascule;
然后在体系结构中,您可以像这样连接组件:
for i in 1 to number_of_comps generate
inst : entity work.comp
generic map (5)
port map ( X(i),Y(i),Z(i), S(i));
end generate;
我想你可能还是有点困惑,因为你的较低级别的comp的generic是5,但在我看来,generic应该只在顶层实体中,以指定你想要多少comp,除非你在comp实体中也这样做?谢谢你的回答我编译了程序,它工作正常,我还有另一个问题,为什么我们使用泛型N:integer:=1?而不是泛型N:integer:=5?我的最佳评论1.1.1.1泛型IEEE Std 1076-1993注-泛型可用于控制块的结构、数据流或行为特征,或仅用作文档。特别是,可以使用泛型来指定端口的大小;块内的子组件数;块的定时特性;或者甚至是设计的物理特性,如温度、电容、位置等。没有看到comp的设计说明,我无法评论。谢谢你的回答谢谢你的回答我编译了程序,它工作正常,我还有其他问题,为什么我们使用通用N:整数:=1?而不是泛型N:integer:=5?我的最佳评论1.1.1.1泛型IEEE Std 1076-1993注-泛型可用于控制块的结构、数据流或行为特征,或仅用作文档。特别是,可以使用泛型来指定端口的大小;块内的子组件数;块的定时特性;甚至是设计的物理特性,如温度、电容、位置等。如果没有看到comp的设计说明,我无法发表评论。感谢您的回答是的,我现在理解了,它在较低级别中不使用泛型5,只在顶部实体中指定comp的数量。对于comp实体,我只使用结构描述,Thanks@user3212448字体很高兴你发现它对你有帮助-请投票选出所有对你有帮助的答案。另外,在等待其他答案后,考虑把其中一个作为答案:马丁·汤普森:现在我选择答案,我等待得到15的声誉来支持这个答案。D@pushpen.paul收获季节到了,我现在明白了,它在较低级别中不使用泛型5,只在顶层实体中指定comp的数量。对于comp实体,我只使用结构描述,Thanks@user3212448字体很高兴你发现它对你有帮助-请投票选出所有对你有帮助的答案。此外,在等待其他答案后,考虑把其中一个答案作为答案。
w我选择答案,我等待获得15个声誉才能投票决定答案,@user3212448现在你获得了17个声誉:D@pushpen.paul现在是收获季节:D