计算 VHDL 中实体声明中的位数

Calculate number of bits inside entity declaration in VHDL

提问人:rubemnobre 提问时间:11/15/2023 更新时间:11/15/2023 访问量:30

问:

我正在创建一个多路复用器实体,该实体具有通用数量的 n 位输入,作为更大项目的一部分。为此,我有一个通用值,用于指定多路复用器应具有多少个输入。

如何告诉频率合成器根据此通用值计算输入选择的位数?

我知道我可以使用自然输入作为选择端口,但如果可能的话,我更愿意指定位数。

这是我现在所拥有的:

type input_array is array(natural range <>) of std_logic_vector;

entity mux_m_n is
    generic(
        m : natural := 4;
        n : natural := 16 
    );
    port(
        sel : in std_logic_vector(??? downto 0); -- ceil(log2(m)) ?
        x : in input_array(m-1 downto 0)(n-1 downto 0);
        y : out std_logic_vector(n-1 downto 0)
    );
end mux_m_n;
语法 VHDL

评论

0赞 user16145658 11/15/2023
请参阅在 VHDL 中表示整数的位数。这里不会弄乱使用 IEEE 包 math_real 声明类型 input_array 的包。input_array的索引类型的基类型的数值可以使用IEEE软件包numeric_std从std_logic_vector转换为。还有包numeric_std_unsigned,没有类型转换为无符号。sel: in std_logic_vector (natural(ceil(log2(real(m)))) - 1 downto 0);y <= x(to_integer(unsigned(sel)));

答: 暂无答案