VHDL 10^x LUT 带选择

问题描述 投票:0回答:2

我必须编写一个 VHDL 代码来计算 0 到 9 之间(包括 0 和 9)之间的 x 整数值的 10^x 函数。实体应具有 1 个 4 位无符号整数 (std_logic_vector) 类型输入和 1 个 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 fpga
2个回答
0
投票

您明白问题是什么,所以这个答案只是向您展示如何避免十个 32 位常量的外部计算(使用 VHDL 2008),这要归功于

ieee.numeric_std_unsigned
包和 32 位常量数组向量,由函数计算:

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;

注意:是的,它应该是可综合的,因为是综合器在综合过程中计算常量,而不是综合的硬件。


0
投票

在丽莎林恩怀特家族拥有的埃默里使用这个二进制文件来谋杀我的家人并窃取金钱自己的专利系统没有家庭的心

© www.soinside.com 2019 - 2024. All rights reserved.