【问题标题】:vhdl structural statement inside a sequential architecture顺序架构中的 vhdl 结构语句
【发布时间】:2013-11-23 17:37:00
【问题描述】:

我正在使用两个组件在 Modelsim VHDL 上设计一个项目。根据控制输入,我将选择要使用的组件:

  • 如果 control=0 则输入将被移植到第一个组件。
  • 如果 control=1 输入将被移植到第二个组件。

但是,当我在 if 语句中写“U1: port map...”时出现编译错误 (不能将结构语句放入顺序架构中)。

任何想法如何解决我的问题?

【问题讨论】:

    标签: vhdl


    【解决方案1】:

    您的问题有两种可能的解释:

    • 情况#1:您的设计一次只使用两个可能的组件之一。使用哪个组件的决定是在编译时完成的,也就是说,它是在您的代码中编写的,并且在电路合成后无法更改。
    • 情况 #2:您的设计同时使用这两个组件,并且您使用信号动态选择可能的输出之一。

    每种情况都有不同的解决方案。

    情况 #1 的解决方案: 在您的实体中使用 generic,并在您的架构主体中使用 if-generate 语句。这是一个例子:

    entity component_selection_at_compile_time is
            generic (
            -- change this value to choose which component gets instantiated:
            COMPONENT_SELECT: in integer range 1 to 2 := 1
        );
        port (
            input: in integer;
            output: out integer
        );
    end;
    
    architecture rtl of component_selection_at_compile_time is
        component comp1 is port(input: in integer; output: out integer); end component;
        component comp2 is port(input: in integer; output: out integer); end component;
    
        signal comp1_output, comp2_output: integer;
    begin
        c1: if COMPONENT_SELECT = 1 generate
            u1: comp1 port map (input, output);
        end generate;
    
        c2: if COMPONENT_SELECT = 2 generate
            u2: comp2 port map (input, output);
        end generate;
    end;
    

    情况 #2 的解决方案: 创建第三个组件。该组件将是一个包装器,并将实例化您的两个原始组件。在某些情况下,您甚至可以将相同的输入分配给两个组件。然后使用一个选择信号来选择将哪个输出转发到包装器之外。

    entity wrapper is
        port (
            wrapper_input: in integer;
            wrapper_output: out integer;
            component_select: in integer range 1 to 2
        );
    end;
    
    architecture rtl of wrapper is
        component comp1 is port(input: in integer; output: out integer); end component;
        component comp2 is port(input: in integer; output: out integer); end component;
    
        signal comp1_output, comp2_output: integer;
    begin
        u1: comp1 port map (wrapper_input, comp1_output);
        u2: comp2 port map (wrapper_input, comp2_output);
    
        wrapper_output <= comp1_output when component_select = 1 else comp2_output;
    end;
    

    【讨论】:

      【解决方案2】:

      这个问题的答案取决于控制输入的性质。如果控制输入是在编译时配置设计的一种方式,则可以使用泛型和生成语句来实现所需的功能。 否则....

      根据您提出问题的方式,我假设情况并非如此。我会假设您的设计必须在不同的时间同时支持这两种设计,并使用相同的编译设计。在这种情况下,您必须实例化这两个组件,并将数据路由到这两个组件,并以某种方式向这些组件指示数据何时有效且必须进行处理。例如:

      en1 <= not control;
      en2 <= control;
      
      U1 : entity work.design1
      port map (
         data => data,
         en => en1
      );
      
      U2 : entity work.design2
      port map ( 
         data => data,
         en => en2
      );
      

      在此示例中,我们创建了 2 个新信号,en1en2,它们是“1”,以便在适当的时间启用每个组件。在每个实例化的实体中,您需要查看en 输入以确定输入数据何时有效。

      注意:您的设计可能已经有类似于en1en2 的信号。例如,您可能有一个具有有效信号的通用“总线”,指示总线上的数据何时有效。在这种情况下,您可以添加类似这样的内容,使用bus_valid 选通启用信号:

      en1 <= not control and bus_valid;
      en2 <= control and bus_valid;
      

      【讨论】:

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