Search code examples
arraysvhdlconstants

Constant value of ROM array


I am trying to crate a 64 bit ROM type ROM is array (7 downto 0, 7 downto 0) of std_logic;

then I want create constant R :ROM :=.

Where R(0, 7 downto 0 ) would be value of "00010011",

R(0, ) R(1, ) is selected by an 3bit pointer value and then it output by formula :

for i in 0 to 7  loop
      Data_Out(i) <= R(conv_integer(AArray),i);
end loop;.

But which ever way I am trying define the constant value of ROM I get an error, could someone point me to right way of defining constant for this array.


Solution

  • For more complex initialization values, it is often helpful to make a function that returns the constant value to assign, like:

    type ROM is array (7 downto 0, 7 downto 0) of std_logic;
    
    function ROM_init return ROM is
      variable res_v : ROM;
    begin
      -- Write code that assigns initial value to res_v
      return res_v;
    end function;
    
    constant R : ROM := ROM_init;
    

    If an array of vectors is actually needed, you may consider instead doing:

    type ROM is array (7 downto 0) of std_logic_vector(7 downto 0);
    function ROM_init return ROM is
      variable res_v : ROM;
    begin
      res_v(0) := "00010011";  -- Value from question
      -- Write more code that assigns initial value to res_v;
      return res_v;
    end function;
    constant R : ROM := ROM_init;
    

    Note that the synthesis tool will probably not implement this as a ROM memory block, but simply as a simple logic network.