Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
12 years ago

2D Array VHDL

Hi!!

I'm using the parallel_add megafunction from altera and the data port is define as:

----------------

data : in altera_mf_logic_2D(size - 1 downto 0, width- 1 downto 0);

with

type altera_mf_logic_2D is array (NATURAL RANGE <>, NATURAL RANGE <>) of STD_LOGIC;

----------------

in my code this port look like

data : in altera_mf_logic_2D(23 downto 0, 31 downto 0);

and I want to connect my_data to it, but my data is defined using subtype and type

-----------

signal my_data : t_32bit_data_array(23 downto 0);

with

subtype t_32bit_data is std_logic_vector ( 31 downto 0);

type t_32bit_data_array is array ( natural range <>) of t_32bit_data;

-----------

Ideas????

I tried :

--for first 32bit value for ex.

data(0 , 31 downto 0) <= my_data(0);

doesnt work (Error (10486): VHDL error at beamforming_t.vhd(247): slice of object cannot be specified for object that has an array type of more than one dimension)

tkxs!

3 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    This is the problem of defining new arrays of std_logic, especially 2D arrays of std_logic. (Thanks altera!). Just to note, your data type is NOT a 2D array, its a 1D array of a 1D array type.

    Like the error says, you cannot part slice into 2d arrays. You can only access individual elements or the entire array.

    There is only one way for you to work around this error: assign each bit individually.

    The hand coded way will be long an tedious:

    data(0,0) <= my_data(0)(0);

    data(0,1) <= my_data(0)(1);

    --etc

    --zzzzzzzzzz

    but to make your life simpler, why not simply write a conversion function?

    
    function convert_normal_to_stupid_type(s : t_32bit_data_array) return altera_mf_logic_2D is
      variable ret : altera_mf_logic_2D(s'range, 31 downto 0);
    begin
      for i in s'range loop
        for j in 31 downto 0 loop
          ret(,i,j) <= s(i)(j);
        end loop;
      end loop;
      return ret;
    end function;
    ....
    data <= convert_normal_to_stupid_type(my_data);
    
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Thank u Tricky!!

    It works!!

    or!

    --Stupid process :D

    process (my_data)

    begin

    for i in 0 to 23 loop

    for j in 0 to 31 loop

    data(i,j) <= my_data(i)(j);

    end loop;

    end loop;

    end process;

    bye! THKS!

    PS: change ret(,i,j) to ret(i,j)
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    The process is just fine. But using a function means you can use it on any signal of your type, of any size.