补充拉姆vhdl

时间:2017-03-14 00:01:46

标签: vhdl fpga ram

在写完Ram的每个地址然后读取Ram的每个地址之后,我将如何重新初始化Ram,以便当我第二次再次写入时,它开始时就好像它是第一次写入它或者换句话说,一个干净的石板。

故障:

1)写入RAM

2)读取Ram

3)将所有ram值设置回0?或者我可以继续提供地址= 0再次从0-23开始写作?

这是我的拉姆:

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use ieee.numeric_std.all;

entity Ram is
Port(   
    clk       : in  std_logic;                      
    address : in  std_logic_vector(4 downto 0);                         
    write_en  : in  std_logic;                      
    data_in   : in  std_logic_vector(15 downto 0);    
    data_out  : out std_logic_vector(15 downto 0)   
);

end Ram;

architecture Behavioral of Ram is

type ram_type is array(0 to 23) of std_logic_vector(15 downto 0);
signal Memory : ram_type;

begin
process(clk)
begin
     if(rising_edge(clk)) then
        if(write_en = '1') then
            Memory(to_integer(unsigned(address))) <= data_in;
        end if;
        data_out <= Memory(to_integer(unsigned(address)));
     end if;
  end process;
end behavioral;

1 个答案:

答案 0 :(得分:0)

如果您打算在设备中推断BRAM,则无法重置。重置BRAM作为设备配置的一部分完成。您可以随时写入零(或者当您的初始状态返回到内存以重新初始化时)

但是,如果您不关心它是否会被合成到BRAM中,我认为最干净的方法是在您的系统中添加一个重置端口并更改您的过程以将重置考虑在内。如果要重置内存,请在输入端口应用重置。

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use ieee.numeric_std.all;

entity Ram is
Port(   
    clk       : in  std_logic; 
    rstn      : in std_logic;                     
    address : in  std_logic_vector(4 downto 0);                         
    write_en  : in  std_logic;                      
    data_in   : in  std_logic_vector(15 downto 0);    
    data_out  : out std_logic_vector(15 downto 0)   
);

end Ram;

architecture Behavioral of Ram is

type ram_type is array(0 to 23) of std_logic_vector(15 downto 0);
signal Memory : ram_type;

begin

    process(clk)
    begin

         if(rising_edge(clk)) then
            if(rstn ='0') then
                Memory <= (OTHERS => (OTHERS => '0'));
            elsif(write_en = '1') then
                Memory(to_integer(unsigned(address))) <= data_in;
            end if;
            data_out <= Memory(to_integer(unsigned(address)));
         end if;
      end process;
end behavioral;

您的代码示例的另一个注释。如果您打算推断BRAM,您的代码是“先写后读”。根据WP231(https://www.xilinx.com/support/documentation/white_papers/wp231.pdf

,这将导致较慢的BRAM性能