多个VHDL组件实例化

时间:2015-12-15 14:56:28

标签: components vhdl instantiation

以下一般性问题:

如何使用三个子模块(SubX,SubY,SubZ)设置以下系统(主):

Main
  |______ SubX
  |         |_______SubZ
  |
  |______ SubZ

这里是代码:

entity System is
    port (
        clk_clk                                : in  std_logic;     
        pwm    : OUT std_logic 
    );
end entity System_Misc;

architecture rtl of System is
    component SubX
        port(clk       : IN  STD_LOGIC;
             pwmSubX   : OUT STD_LOGIC;
    end component SubX;

    component SubZ
        port(clk       : IN  STD_LOGIC;
             pwmSubZ   : OUT STD_LOGIC;
    end component SubZ;


begin
    component SubX
        port map(
            clk      => clk_clk,
            pwmSubX  => pwm
        );

    component SubZ
        port map(
            clk      => clk_clk,
            pwmSubZ  => pwm
        );


end architecture rtl;

此方法是否正确,因为 SubZ Main 以及 SubX 中实例化(此处未显示)。如果我这样做,则会收到错误,我无法将 pwmSubX pwmSubZ 连接到相同的输出 pwm (Main)。 解决此问题的正确方法是什么和/或如何实现?

谢谢!

2 个答案:

答案 0 :(得分:1)

您有多个端口pwm的驱动程序。

您需要为每个组件使用不同的信号,并指定SubXSubZ的输出将如何生成pwm输出。

SubXSubZ在其他地方实例化的情况下,没有任何区别。

architecture rtl of System is
    component SubX
        port(clk       : IN  STD_LOGIC;
             pwmSubX   : OUT STD_LOGIC;
    end component SubX;

    component SubZ
        port(clk       : IN  STD_LOGIC;
             pwmSubZ   : OUT STD_LOGIC;
    end component SubZ;


    signal pwmSubX : std_logic;
    signal pwmSubZ : std_logic;


begin
    component SubX
        port map(
            clk      => clk_clk,
            pwmSubX  => pwmSubX
        );

    component SubZ
        port map(
            clk      => clk_clk,
            pwmSubZ  => pwmSubZ
        );

    -- Do what you need with both pwmSubX and pwmSubZ in order to assign
    -- the pwm port
    pwm <= pwmSubX or pwmSubZ;


end architecture rtl;

答案 1 :(得分:1)

每个组件实例化都被详细说明为两个嵌套的块语句和零个或多个进程语句以及更多的块语句。

每个流程都有一个驱动程序,用于在该流程中分配的每个信号;

类型std_logic是已解析的std_ulogic。分辨率表示将一个或多个驱动程序值解析为信号的有效值。

充实(并纠正)你的榜样:

library ieee;                           -- added subx entity/architecture
use ieee.std_logic_1164.all;

entity subx is
    port (
        clk:        in  std_logic;
        pwmsubx:    out std_logic
    );
end entity;

architecture foo of subx is
    signal pwm:     std_logic;
    component subz is
        port (
            clk:        in  std_logic;
            pwmsubz:    out std_logic
        );
    end component;
    signal pwmsubz: std_logic;

begin
SUB_Z:
    subz 
        port map (
            clk => clk,
            pwmsubz => pwmsubz
        );
    pwm <= pwmsubz after 2 us; 
    pwmsubx <= pwm;   
end architecture;

library ieee;                             -- added subz entity/architecture
use ieee.std_logic_1164.all;

entity subz is
    port (
        clk:        in  std_logic;
        pwmsubz:    out std_logic
    );
end entity;

architecture foo of subz is
    signal pwm:     std_logic;
begin
    pwm <= clk after 1 us;
    pwmsubz <= pwm;
end architecture;

library ieee;                -- added context clause
use ieee.std_logic_1164.all;

entity system is
    port (
        clk_clk:         in  std_logic;     
        pwm:             out std_logic 
    );
end entity; --  system_misc;

architecture rtl of system is
    component subx
        port(clk:        in  std_logic;
             pwmsubx:    out std_logic -- ;
        );             -- added
    end component subx;

    component subz
        port(clk:        in  std_logic;
             pwmsubz:    out std_logic -- ;
        );              -- added
    end component subz;

begin

U0:  -- added label
    component subx
        port map (
            clk      => clk_clk,
            pwmsubx  => pwm
        );
U1:   -- added label
    component subz
        port map (
            clk      => clk_clk,
            pwmsubz  => pwm
        );

end architecture rtl;

library ieee;
use ieee.std_logic_1164.all;

entity system_tb is
end entity;

architecture foo of system_tb is
    signal clk:     std_logic := '0';
    signal pwm:     std_logic;
begin
DUT:
    entity work.system
    port map (
        clk_clk => clk,
        pwm => pwm
    );
STIMULUS:
    process
    begin
        wait for 3 us;
        clk <= not clk;
        if now > 15 us then
            wait;
        end if;
    end process;
end architecture;

注意两个组件subx和subz在分配给与系统中的pwm相关的输出之前有内部信号。

这为我们提供了一些我们可以在波形上看到的东西,以展示分辨率的效果:

system_tb_showing_X.png

如果两个司机发生冲突,我们会得到'X'(红色)。

合成软件通常采用将两个驱动器短接在一起的模糊视图,通常不允许在内部使用线OR或线AND。您获得的任何错误都可能来自您的综合工具,而不是VHDL投诉(您可以看到它模拟得很好)。

如何解决同一信号的两个驱动程序的问题取决于信号的含义,这在您的示例中并不明显。正如AndréSouto所说,你可以将两个输出与逻辑设备连接起来。