VHDL 中的 RAM 到 read/write

RAM to read/write in VHDL

我正在尝试使用 RAM read/write。我的地址是一个整数值,应该是整数的内存。这是我下面的代码,但我一直收到错误消息。

这是我的数据路径,其中地址选择来自整数寄存器。

代码:

    library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;

entity Mem is
generic(    width:  integer:=4;
        depth:  integer:=4;
        addr:   integer:=2);
port(   Clock:      in std_logic;   
    Enable:     in std_logic;
    Read:       in std_logic;
    Write:      in std_logic;
    Read_Addr:  in integer;
    Write_Addr:     in integer; 
    Data_in:    in integer;
    Data_out:   out integer
);
end Mem;

--------------------------------------------------------------

architecture behav of Mem is

type ram_type is array (0 to 31) of 
    integer;
signal tmp_ram: ram_type;

begin   

    -- Read Functional Section
    process(Clock, Read)
    begin
    if (Clock'event and Clock='1') then
        if Enable='1' then
        if Read='1' then
            -- buildin function conv_integer change the type
            -- from std_logic_vector to integer
            Data_out <= tmp_ram(conv_integer(Read_Addr)); 
        else
            Data_out <= (Data_out'range => 'Z');
        end if;
        end if;
    end if;
    end process;

    -- Write Functional Section
    process(Clock, Write)
    begin
    if (Clock'event and Clock='1') then
        if Enable='1' then
        if Write='1' then
            tmp_ram(conv_integer(Write_Addr)) <= Data_in;
        end if;
        end if;
    end if;
    end process;

end behav;
----------------------------------------------------------------

错误:

Error (10514): VHDL aggregate error at Mem.vhd(41): can't determine type of aggregate -- found 0 possible types

您的错误代码是:

if Read='1' then
    -- buildin function conv_integer change the type
    -- from std_logic_vector to integer
    Data_out <= tmp_ram(conv_integer(Read_Addr)); 
else
    Data_out <= (Data_out'range => 'Z'); -- Faulty line
end if;

Data_out 是整数,不是 std_logic_vector 或派生类型。因此,它没有范围(只有数组有,std_logic_vector 被定义为 std_logic 的数组)。此外,它不能取 'Z' 的值,因为它不是 std_logicintegers 只能赋整数值。

如果您需要 Data_outenable'1'read'0' 时变为高阻抗,如您所述,您将需要您的使用 std_logic_vectorsigned/unsigned.

的内存输出

此外,如果您的目标是合成,我建议您不要在没有范围的情况下使用 integers。按照 VHDL 标准,integers 是 32 位。综合工具 可能 优化网表并使用更少的位,但您不应该指望它。要么限制 integers (signal x: integer range -4 to 3) 的范围,要么使用 signed/unsigned.