2015-05-21 26 views
1

我试图使用RAM来读/写。我的地址是一个整数值,它应该是一个整数的内存。这是我的代码在下面,但我不断收到错误。RAM在VHDL中读写

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

代码:

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 

回答

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_vectorsigned/unsigned

另外,如果你的目标是综合,我应该劝你不要使用integers。按照VHDL标准,integers是32位。综合工具可能优化网表并使用较少的位,但你不应该指望它。要么限制您的integerssignal x: integer range -4 to 3)或使用signed/unsigned的范围。

+0

如果我想使用双打而不是整数?意味着64位。 –

+0

双重意味着浮点数,所以我假设您的意思是四字,64位整数?它们不是以VHDL中的整数存在,你必须使用'signed/unsigned'或'std_logic_vector'。例如,'signal x:signed(63 downto 0)'。 –

+0

所以信号x:signed(63 downto 0)意味着64位的整数?如双?是不是认为二进制不是int? –