用VHDL读取/写入的RAM

时间:2015-05-21 21:53:02

标签: vhdl

我正在尝试使用RAM来读/写。我的地址是一个整数值,它应该是一个整数的内存。这是我的代码,但我一直收到错误。

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

代码:

    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

1 个答案:

答案 0 :(得分:2)

您的错误代码是:

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 beeing被定义为std_logic的数组。此外,它不能取'Z'的值,因为它不是std_logic; integers只能分配整数值。

如果Data_out enable '1' read '0'std_logic_vector,如果您需要signed/unsigned成为高阻抗,则需要内存输出使用integersintegers

此外,如果您的目标是综合,我建议您不要使用integers而不使用范围。根据VHDL标准,signal x: integer range -4 to 3是32位。综合工具可能优化网表并使用更少的位,但您不应指望它。约束signed/unsignedsetMessage)的范围或使用builder.setMessage("Please help us to track the route, has this route arrived the stop? ");

相关问题