【问题标题】:Use a generic to determine (de)mux size in VHDL?使用泛型来确定 VHDL 中的(去)复用器大小?
【发布时间】:2011-05-05 01:27:11
【问题描述】:

我想使用通用的“p”来定义解复用器将有多少输出。输入和所有输出均为 1 位。输出、控制和输入可以很简单,例如:

 signal control : std_logic_vector(log 2 p downto 0); -- I can use a generic for the log2..
 signal input : std_logic;
 signal outputs : std_logic_vector(p-1 downto 0);

但是多路复用器的实现代码是什么?有没有可能?

【问题讨论】:

    标签: vhdl


    【解决方案1】:

    不需要泛型:

    library ieee;
    use ieee.std_logic_1164.all;
    use ieee.numeric_std.all;
    entity demux is
        port(
            control : in unsigned;
            input   : in std_logic;
            outputs : out std_logic_vector
            );
    end entity demux;
    
    architecture rtl of demux is
        -- Check size of input vectors
        assert 2**control'length = outputs'length 
               report "outputs length must be 2**control length" 
               severity failure;
        -- actually do the demuxing - this will cause feedback latches to be inferred
        outputs(to_integer(unsigned(control)) <= input;
    
    end architecture;
    

    (未经测试,只是在我脑海中输入...)

    这会推断出闩锁 - 这就是你想要的吗?

    【讨论】:

      【解决方案2】:

      您需要将log_p 作为通用输入并在进行时计算p

      library ieee;
      use ieee.std_logic_1164.all;
      entity demux is
          generic (
              log_p: integer);
          port(
              control : in std_logic_vector(log_p downto 0);
              input :in std_logic;
              outputs : out std_logic_vector(2**log_p - 1 downto 0)
              );
      end entity demux;
      

      【讨论】:

        【解决方案3】:

        您需要将输出的数量和控件数组的大小作为泛型传递,除非您总是使用 2 的幂。

        在您的 (de)mux 模块之外(即:当您实例化时),您可以使用代码来计算控制总线的位数。我在一个通用包中有一个函数,用于初始化各种配置常量和泛型,这些配置常量和泛型传递给类似于您的 (de)mux 应用程序的代码:

        -- Calculate the number of bits required to represent a given value
        function NumBits(val : integer) return integer is
            variable result : integer;
        begin
            if val=0 then
                result := 0;
            else
                result  := natural(ceil(log2(real(val))));
            end if;
            return result;
        end;
        

        ...它允许您执行以下操作:

        constant NumOut : integer := 17;
        signal CtrlBus  : std_logic_vector(NumBits(NumOut)-1 downto 0);
        
        my_mux : demux
        generic map (
            NumOut  => NumOut,
            NumCtrl => NumBits(NumOut) )
        port map (
            control => CtrlBus,
        ...
        ...
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2012-09-26
          • 2019-08-26
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2013-03-01
          • 1970-01-01
          • 2011-09-15
          相关资源
          最近更新 更多