寻求有关 vhdl 错误的帮助

asking help for vhdl error

我正在尝试在 vhdl 上为 RAM 16*4 编写代码,代码是:

entity RAM_16_4 is
Port ( clk : in  STD_LOGIC;
       WR : in  STD_LOGIC;
       add : in  STD_LOGIC_VECTOR (3 downto 0);
       Di : in  STD_LOGIC_VECTOR (3 downto 0);
       Do : out  STD_LOGIC_VECTOR (3 downto 0));
end RAM_16_4;

architecture Behavioral of RAM_16_4 is

type RAM is array (15 downto 0) of std_logic_vector (3 downto 0);
 signal int : STD_LOGIC_VECTOR (3 downto 0);
 signal x : STD_LOGIC_VECTOR (3 downto 0);
begin

process (clk,WR)
begin

if ( clk'event and clk='1') then
if ( WR='1') then
int<= conv_integer (add);
int<= Di;
end if;
x<=add;
end if;
end process;

x<= conv_integer (add);
Do<= x;

end Behavioral;

这是即将发生的错误: int 类型与 conv_integer.

类型不兼容

我怎样才能摆脱这个错误?

conv_integerstd_logic_vector 转换为 integer。您不能将 integer 分配给 std_logic_vector。如果要将 add 分配给 intx,为什么还要使用 conv_integer?他们都是同一类型...

更重要的是:请注意 conv_integer 非标准化 std_logic_arithstd_logic_unsigned 的一部分,您不应该这样做采用。相反,您应该在此处使用标准化包 numeric_std 中的 to_integer(unsigned(...))

为 FPGA 实现 RAM 时,应参考 FPGA 制造商手册。例如来自 Xilinx Synthesis User Guide

-- Single-Port RAM with Asynchronous Read (Distributed RAM)
-- File: rams_dist.vhd
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;

entity rams_dist is
    port(
        clk : in std_logic;
        we : in std_logic;
        a : in std_logic_vector(5 downto 0);
        di : in std_logic_vector(15 downto 0);
        do : out std_logic_vector(15 downto 0)
    );
end rams_dist;

architecture syn of rams_dist is
    type ram_type is array (63 downto 0) of std_logic_vector(15 downto 0);
    signal RAM : ram_type;
begin
    process(clk)
    begin
        if (clk'event and clk = '1') then
            if (we = '1') then
                RAM(conv_integer(a)) <= di;
            end if;
        end if;
    end process;
    do <= RAM(conv_integer(a));
end syn;

...好吧,废话.... Xilinx 也用错了转换函数。让我们将其重写为标准化代码:

-- Single-Port RAM with Asynchronous Read (Distributed RAM)
-- File: rams_dist.vhd
library ieee;
use ieee.std_logic_1164.all;

entity rams_dist is
    port(
        clk : in std_logic;
        we : in std_logic;
        a : in std_logic_vector(5 downto 0);
        di : in std_logic_vector(15 downto 0);
        do : out std_logic_vector(15 downto 0)
    );
end rams_dist;

architecture syn of rams_dist is
    use ieee.numeric_std.all;
    type ram_type is array (2**a'length-1 downto 0) of std_logic_vector(di'length-1 downto 0);
    signal RAM : ram_type := (others => (others => '0')); -- let's initialize it at zeros
begin
    ram_proc: process(clk)
    begin
        if rising_edge(clk) then
            if we = '1' then
                RAM(to_integer(unsigned(a))) <= di;
            end if;
        end if;
    end process;
    do <= RAM(to_integer(unsigned(a)));
end syn;