2012-03-10 33 views
2

最近我使用VHDL编写一个16-RAM的RAM。我的代码是:VHDL设置RAM中的常量数据

library IEEE; 
use IEEE.STD_LOGIC_1164.ALL; 
use IEEE.STD_LOGIC_ARITH.ALL; 
use IEEE.STD_LOGIC_UNSIGNED.ALL; 
use IEEE.Numeric_Std.all; 

entity RAM is 
port(
PC_in: in std_logic_vector (5 downto 0); 
EN_WR_in: in std_logic_vector (1 downto 0); 
RAM_in : in std_logic_vector(15 downto 0); 
RAM_out : out std_logic_vector(15 downto 0); 
test : out integer 
); 


end RAM; 

architecture Behavioral of RAM is 
type ram_t is array (63 downto 0) of std_logic_vector(15 downto 0); 
signal ram : ram_t; 
begin 
PROCESS (EN_WR_in) 
BEGIN 
     if (EN_WR_in(1)='1') then 

     IF (EN_WR_in(0) = '1') THEN 
      ram(conv_integer(unsigned(PC_in))) <= RAM_in; 
      else 
     RAM_out <= ram(conv_integer(unsigned(PC_in))); 
     end if; 

     else 

     RAM_out <="ZZZZZZZZZZZZZZZZ"; 

     end if; 

END PROCESS; 
    ram(20) <= "0000100010010000"; 
end Behavioral; 

,我与面临的问题是我需要设置在RAM中的一些常量数据就像

ram(20) <= "0000100010010000"; 

但恒定的数据模拟过程中并不存在。有什么办法解决它?

谢谢。

回答

5

在声明它可以初始化RAM:

signal ram : ram_t := ("0000100010010000", x"1234", ...); 

或许

signal ram : ram_t := (20 => "0000100010010000", others => (others=>'0')); 
+1

你甚至可以使用一个函数来初始化您的RAM块: '信号RAM:ram_t:= load_from_file (filename);' – trondd 2012-09-28 10:30:47

+0

如果你想使用一个函数,[stackoverflow]上的[this](http://stackoverflow.com/questions/10555729/bram-init-in-vhdl)问题/答案应该有所帮助。 – jrast 2013-04-26 16:13:43