【问题标题】:VHDL 10^x LUT With-SelectVHDL 10^x LUT 带选择
【发布时间】:2022-01-15 18:21:12
【问题描述】:

我必须编写一个 VHDL 代码来计算 10^x 函数,用于计算 x 介于零和九之间(包括零和九)的整数值。实体应有一个 4 位无符号整数 (std_logic_vector) 类型输入和一个 32 位无符号整数 (std_logic_vector) 类型输出。 32 位宽度足以满足 10^9 的需求。我必须为解决方案使用 LUT(查找表)逻辑。为此,我应该在架构块中使用信号分配和 with-select 结构,而不使用该过程。通过使用 with-select,我将通过固定分配确定 x 的每个值的输出 (LUT)。

开始合成时出错: 分配中的宽度不匹配;目标有 32 位,源有 1 位

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;

entity main is
Port ( 
    input : in std_logic_vector(3 downto 0);
    output: out std_logic_vector(31 downto 0)
     );
end main;

architecture Behavioral of main is

begin

with input select
   output <= "00000000000000000000000000000001" when "0000", --10^0
             "00000000000000000000000000001010" when "0001", --10^1
             "00000000000000000000000001100100" when "0010", --10^2
             "00000000000000000000001111101000" when "0011", --10^3
             "00000000000000000010011100010000" when "0100", --10^4
             "00000000000000011000011010100000" when "0101", --10^5
             "00000000000011110100001001000000" when "0110", --10^6
             "00000000100110001001011010000000" when "0111", --10^7
             "00000101111101011110000100000000" when "1000", --10^8
             "00111011100110101100101000000000" when "1001", --10^9
             "0" when others;
end Behavioral;

【问题讨论】:

  • 我的 VHDL 有点生疏,但值得尝试"00000000000000000000000000000000" when others; 吗? "0" 确实匹配错误消息...
  • 成功了,谢谢! “00000000000000000000000000000000”当其他人时;
  • 或者(更简单)(others =&gt; '0') when others;
  • IEEE Std 1076-2008 14.7.3.4 Signal update "如果 S 是复合信号(包括数组的切片),则 S 的有效值隐式转换为 S 的子类型。转换检查 S 的每个元素在有效值中是否存在匹配元素,反之亦然。如果此检查失败,则会发生错误。字符串文字“0”中只有一个元素。还有(output'range =&gt; '0') when others;,其中'range 也可以是'reverse_range 以及user_1818839 的(others =&gt; '0')。另请参阅 9.3.6 类型转换、9.3.3.3 数组聚合。

标签: vhdl fpga


【解决方案1】:

您了解问题所在,因此此答案只是为了向您展示如何避免对十个 32 位常量(使用 VHDL 2008)进行外部计算,这要归功于 ieee.numeric_std_unsigned 包和 32 的常量数组-bits 向量,由函数计算:

library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std_unsigned.all;

entity main is
...
end main;

architecture Behavioral of main is

  type w32_array is array(0 to 15) of std_ulogic_vector(31 downto 0);

  function powers_of_ten return w32_array is
    variable res: w32_array := (others => (others => '0'));
  begin
    for i in 0 to 9 loop
      res(i) := to_stdulogicvector(10**i, 32);
    end loop;
    return res;
  end function powers_of_ten;

  constant pw10: w32_array := powers_of_ten;

begin

  output <= pw10(to_integer(input));

end architecture Behavioral;

注意:是的,它应该是可合成的,因为在合成期间计算常数的是合成器,而不是合成的硬件。

【讨论】:

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