在 VHDL return 中添加两个 bit_vector 错误“(vcom-1581) No feasible entries for infix operator '+'.”

Adding two bit_vector in VHDL return error "(vcom-1581) No feasible entries for infix operator '+'."

这是我在 VHDL 中将二进制转换为 BCD 的代码

library ieee;
use ieee.numeric_bit.all;

entity bin2bcd is
    port (bin : in bit_vector(3 downto 0) := "0000";
        clk : in bit;
        bcdout : out bit_vector(4 downto 0) := "00000");
end bin2bcd;

architecture bin2bcdarch of bin2bcd is
begin
    process(clk)
    variable gt9 : bit;
    variable temp : bit_vector(3 downto 0) := "0110";
    variable bcdout_temp : bit_vector(4 downto 0);
    begin 
        if clk'event and clk = '1' then
            gt9 := bin(3) and(bin(2) or bin(1));
            if gt9 = '1' then
                bcdout_temp := ('0' & bin) + ('0' & temp);
            else
                bcdout_temp := ('0' & bin);
            end if;
        end if;
    bcdout <= bcdout_temp;
    end process;
end bin2bcdarch;

问题是当我试图在行

中添加两个 bit_vector

bcdout_temp := ('0' & bin) + ('0' & temp);

使用“+”运算符,出现错误

(vcom-1581) No feasible entries for infix operator '+'.

现在,我在网上看了看,大多数解决方案都是在我使用 std_logic_vector 时使用的。

如果我使用 std_logic_vector,代码工作正常,但当我使用 bit_vector.

时,代码工作正常

对于我收到错误的原因,是否有任何解决方案?

如果使用 VHDL-2008 的一部分 ieee.numeric_bit_unsigned.all,则可以添加位向量。您使用的 numeric_std 包没有为位向量定义加法。

如果您发现旧的 CAD 实验室软件不支持 numeric_bit_unsigned,您可以使用类型转换,numeric_bit 包含有符号和无符号类型的声明:

library ieee;
use ieee.numeric_bit.all;

entity bin2bcd is
    port (bin : in bit_vector(3 downto 0) := "0000";
        clk : in bit;
        bcdout : out bit_vector(4 downto 0) := "00000");
end bin2bcd;

architecture bin2bcdarch of bin2bcd is
begin
    process(clk)
    variable gt9 : bit;
    variable temp : unsigned(3 downto 0) := "0110";  -- was bit_vector
    variable bcdout_temp : unsigned(4 downto 0);     -- was bit vector
    begin 
        if clk'event and clk = '1' then
            gt9 := bin(3) and(bin(2) or bin(1));
            if gt9 = '1' then
                bcdout_temp := '0' & unsigned(bin) + ('0' & temp);  -- type conversion
            else
                bcdout_temp := '0' & unsigned(bin); -- type conversion
            end if;
        end if;
    bcdout <= bit_vector(bcdout_temp);  -- type conversion
    end process;
end bin2bcdarch;

注意 temp 也可以是 class 常量而不是变量,除了初始值外,它不会被赋值。

根据您使用 WARP2 进行综合(大概是 CPLD)的评论,我记得它最初是为使用 AHDL 作为输入描述而开发的,而对 VHDL 和 Verilog 的支持是事后才想到的。

您可能会看到基于哪些 VHDL 构造映射到支持合成的 AHDL 构造的限制。

处理此类限制的方法可能是将设计中的麻烦部分描述为数据流描述:

entity bin2bcd is
    port (
        bin:    in  bit_vector(3 downto 0);
        clk:    in  bit;
        bcdout: out bit_vector(4 downto 0)
    );
end entity bin2bcd;

architecture dataflow of bin2bcd is
    signal bcdout_temp:     bit_vector(4 downto 0);
begin

    bcdout_temp(4) <=  bin(3) and ( bin(2) or bin(1) ); -- gt9

    bcdout_temp(3) <=  not bcdout_temp(4) and bin(3);   --  zero if gt9 

    bcdout_temp(2) <=  (    bin(3) and bin(2) and bin(1)) or
                       (not bin(3) and bin(2));

    bcdout_temp(1) <= (    bcdout_temp(4) and not bin(1)) or -- gt9 XOR bin(1)
                      (not bcdout_temp(4) and     bin(1));

    bcdout_temp(0) <= bin(0);                           -- doesn't change

REG5:
    process (clk)
    begin
        if clk'event and clk = '1' then
            bcdout <= bcdout_temp;
        end if;
    end process;
end architecture;

虽然不能保证这会更好地工作(尽管可能),但它也可以模拟为带有测试台的 VHDL:

library ieee;
use ieee.numeric_bit.all;

entity bin2bcd_tb is
end entity;

architecture foo of bin2bcd_tb is
    signal bin:         bit_vector(3 downto 0);
    signal clk:         bit;
    signal bcdout:      bit_vector(4 downto 0);
begin

DUT:
    entity work. bin2bcd (dataflow)
        port map (
            bin => bin,
            clk => clk,
            bcdout => bcdout
        );

CLOCK:
    process
    begin
        wait for 5 ns;
        clk <= not clk;
        if now > 160 ns then
            wait;
        end if;
    end process;

STIMULI:
    process
    begin
        for i in 0 to 2 ** bin'length - 1 loop
            bin <= bit_vector(to_unsigned(i, bin'length));
            wait for 10 ns;
        end loop;
        wait;
    end process;
end architecture;

并显示它给出了正确的结果:

bin以十进制显示,bcdout以十六进制显示。