Generate with 2-Dimensional array

Discussion in 'VHDL' started by Ved, Sep 25, 2006.

  1. Ved

    Ved Guest

    Hi all,
    I have problem in assigning 2 dimensional array column to an array in
    generate statement.
    I have to take out columns(array of 8 elements) from 8x16 matrix (i.e.
    2-D array) and give it to a component which is to be generated 16
    times.
    I am confused in assigning a column array of 2D array to a 1D
    array(simple array) inside a GENERATE statement.
    I hope explanation is clear ?
    I have tried to do something (please see codes below).
    How to use a for loop inside generate.
    Textbooks and internet resources are not very clear about.
    Please correct me.
    Thanks
    Regards
    Ved

    ------Data types---------
    MatrixInt ---> array (0 to 7 , 0 to 15) of integer range 0 to 8;
    ---I am calling this Matrix

    comp_caseSel --> array (0 to 7) of integer range 0 to 8;
    ---- I am calling this 1D array

    countArray ---> array (0 to 15) of integer range 0 to 8 ;

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

    entity is
    Matrix2D : in MatrixInt;
    WordIndexCase: out countArray;
    end entity

    architecture......

    component Comp_Metric is
    port(
    IndexCOL : in comp_caseSel;
    WordIndexCase_c: out integer range 0 to 8
    );
    end component;
    begin

    gen: for i in 0 to 15 generate ---Generate 16 times
    for j in 0 to M-1 loop
    compx: Comp_Metric
    port map(
    IndexCOL => Matrix2D(j,i), ---What to do here ??
    ----1D array <=
    clolumn of 2D
    WordIndexCase_c => WordIndexCase(i)
    );
    end loop;
    end generate;
     
    Ved, Sep 25, 2006
    #1
    1. Advertising

  2. Ved

    David Ashley Guest

    Ved wrote:
    > Hi all,
    > I have problem in assigning 2 dimensional array column to an array in
    > generate statement.
    > I have to take out columns(array of 8 elements) from 8x16 matrix (i.e.
    > 2-D array) and give it to a component which is to be generated 16
    > times.
    > I am confused in assigning a column array of 2D array to a 1D
    > array(simple array) inside a GENERATE statement.
    > I hope explanation is clear ?
    > I have tried to do something (please see codes below).
    > How to use a for loop inside generate.
    > Textbooks and internet resources are not very clear about.
    > Please correct me.
    > Thanks
    > Regards
    > Ved
    >
    > ------Data types---------
    > MatrixInt ---> array (0 to 7 , 0 to 15) of integer range 0 to 8;
    > ---I am calling this Matrix
    >
    > comp_caseSel --> array (0 to 7) of integer range 0 to 8;
    > ---- I am calling this 1D array
    >
    > countArray ---> array (0 to 15) of integer range 0 to 8 ;
    >
    > -------------------------------
    >
    > entity is
    > Matrix2D : in MatrixInt;
    > WordIndexCase: out countArray;
    > end entity
    >
    > architecture......
    >
    > component Comp_Metric is
    > port(
    > IndexCOL : in comp_caseSel;
    > WordIndexCase_c: out integer range 0 to 8
    > );
    > end component;
    > begin
    >
    > gen: for i in 0 to 15 generate ---Generate 16 times
    > for j in 0 to M-1 loop
    > compx: Comp_Metric
    > port map(
    > IndexCOL => Matrix2D(j,i), ---What to do here ??
    > ----1D array <=
    > clolumn of 2D
    > WordIndexCase_c => WordIndexCase(i)
    > );
    > end loop;
    > end generate;
    >


    Ved,

    I've not used generate or loop myself yet, but it seems to me
    the loop should also be a generate.

    -Dave

    --
    David Ashley http://www.xdr.com/dash
    Embedded linux, device drivers, system architecture
     
    David Ashley, Sep 25, 2006
    #2
    1. Advertising

  3. David Ashley a écrit :
    > Ved wrote:
    >> Hi all,
    >> I have problem in assigning 2 dimensional array column to an array in
    >> generate statement.
    >> I have to take out columns(array of 8 elements) from 8x16 matrix (i.e.
    >> 2-D array) and give it to a component which is to be generated 16
    >> times.
    >> I am confused in assigning a column array of 2D array to a 1D
    >> array(simple array) inside a GENERATE statement.
    >> I hope explanation is clear ?
    >> I have tried to do something (please see codes below).
    >> How to use a for loop inside generate.
    >> Textbooks and internet resources are not very clear about.
    >> Please correct me.
    >> Thanks
    >> Regards
    >> Ved
    >>
    >> ------Data types---------
    >> MatrixInt ---> array (0 to 7 , 0 to 15) of integer range 0 to 8;
    >> ---I am calling this Matrix
    >>
    >> comp_caseSel --> array (0 to 7) of integer range 0 to 8;
    >> ---- I am calling this 1D array
    >>
    >> countArray ---> array (0 to 15) of integer range 0 to 8 ;
    >>
    >> -------------------------------
    >>
    >> entity is
    >> Matrix2D : in MatrixInt;
    >> WordIndexCase: out countArray;
    >> end entity
    >>
    >> architecture......
    >>
    >> component Comp_Metric is
    >> port(
    >> IndexCOL : in comp_caseSel;
    >> WordIndexCase_c: out integer range 0 to 8
    >> );
    >> end component;
    >> begin
    >>
    >> gen: for i in 0 to 15 generate ---Generate 16 times
    >> for j in 0 to M-1 loop
    >> compx: Comp_Metric
    >> port map(
    >> IndexCOL => Matrix2D(j,i), ---What to do here ??
    >> ----1D array <=
    >> clolumn of 2D
    >> WordIndexCase_c => WordIndexCase(i)
    >> );
    >> end loop;
    >> end generate;
    >>

    >
    > Ved,
    >
    > I've not used generate or loop myself yet, but it seems to me
    > the loop should also be a generate.


    Indeed.
    You can't have a loop outside of a process.

    Nicolas
     
    Nicolas Matringe, Sep 25, 2006
    #3
  4. Ved

    Andy Guest

    In addition to fixing the generate vs loop issue, try an array of
    arrays, instead of a two dimensional array. Two dimensional arrays are
    not usually synthesizable, but arrays of arrays of... are. That way an
    element of the outer array is an array itself, and can be assigned
    to/from a single array. The only thing you cannot do is slice it the
    other way (i.e. automatically create/reference an array consisting of
    the nth element of all arrays).

    Hope this helps.

    Andy


    Nicolas Matringe wrote:
    > David Ashley a écrit :
    > > Ved wrote:
    > >> Hi all,
    > >> I have problem in assigning 2 dimensional array column to an array in
    > >> generate statement.
    > >> I have to take out columns(array of 8 elements) from 8x16 matrix (i.e.
    > >> 2-D array) and give it to a component which is to be generated 16
    > >> times.
    > >> I am confused in assigning a column array of 2D array to a 1D
    > >> array(simple array) inside a GENERATE statement.
    > >> I hope explanation is clear ?
    > >> I have tried to do something (please see codes below).
    > >> How to use a for loop inside generate.
    > >> Textbooks and internet resources are not very clear about.
    > >> Please correct me.
    > >> Thanks
    > >> Regards
    > >> Ved
    > >>
    > >> ------Data types---------
    > >> MatrixInt ---> array (0 to 7 , 0 to 15) of integer range 0 to 8;
    > >> ---I am calling this Matrix
    > >>
    > >> comp_caseSel --> array (0 to 7) of integer range 0 to 8;
    > >> ---- I am calling this 1D array
    > >>
    > >> countArray ---> array (0 to 15) of integer range 0 to 8 ;
    > >>
    > >> -------------------------------
    > >>
    > >> entity is
    > >> Matrix2D : in MatrixInt;
    > >> WordIndexCase: out countArray;
    > >> end entity
    > >>
    > >> architecture......
    > >>
    > >> component Comp_Metric is
    > >> port(
    > >> IndexCOL : in comp_caseSel;
    > >> WordIndexCase_c: out integer range 0 to 8
    > >> );
    > >> end component;
    > >> begin
    > >>
    > >> gen: for i in 0 to 15 generate ---Generate 16 times
    > >> for j in 0 to M-1 loop
    > >> compx: Comp_Metric
    > >> port map(
    > >> IndexCOL => Matrix2D(j,i), ---What to do here ??
    > >> ----1D array <=
    > >> clolumn of 2D
    > >> WordIndexCase_c => WordIndexCase(i)
    > >> );
    > >> end loop;
    > >> end generate;
    > >>

    > >
    > > Ved,
    > >
    > > I've not used generate or loop myself yet, but it seems to me
    > > the loop should also be a generate.

    >
    > Indeed.
    > You can't have a loop outside of a process.
    >
    > Nicolas
     
    Andy, Sep 25, 2006
    #4
  5. Andy wrote:
    > In addition to fixing the generate vs loop issue, try an array of
    > arrays, instead of a two dimensional array. Two dimensional arrays are
    > not usually synthesizable, but arrays of arrays of... are. That way an
    > element of the outer array is an array itself, and can be assigned
    > to/from a single array. The only thing you cannot do is slice it the
    > other way (i.e. automatically create/reference an array consisting of
    > the nth element of all arrays).


    But you can easily write a function that does that :)
    >
    > Hope this helps.
    >
    > Andy
    >
    >
    > Nicolas Matringe wrote:
    >> David Ashley a écrit :
    >>> Ved wrote:
    >>>> Hi all,
    >>>> I have problem in assigning 2 dimensional array column to an array in
    >>>> generate statement.
    >>>> I have to take out columns(array of 8 elements) from 8x16 matrix (i.e.
    >>>> 2-D array) and give it to a component which is to be generated 16
    >>>> times.
    >>>> I am confused in assigning a column array of 2D array to a 1D
    >>>> array(simple array) inside a GENERATE statement.
    >>>> I hope explanation is clear ?
    >>>> I have tried to do something (please see codes below).
    >>>> How to use a for loop inside generate.
    >>>> Textbooks and internet resources are not very clear about.
    >>>> Please correct me.
    >>>> Thanks
    >>>> Regards
    >>>> Ved
    >>>>
    >>>> ------Data types---------
    >>>> MatrixInt ---> array (0 to 7 , 0 to 15) of integer range 0 to 8;
    >>>> ---I am calling this Matrix
    >>>>
    >>>> comp_caseSel --> array (0 to 7) of integer range 0 to 8;
    >>>> ---- I am calling this 1D array
    >>>>
    >>>> countArray ---> array (0 to 15) of integer range 0 to 8 ;
    >>>>
    >>>> -------------------------------
    >>>>
    >>>> entity is
    >>>> Matrix2D : in MatrixInt;
    >>>> WordIndexCase: out countArray;
    >>>> end entity
    >>>>
    >>>> architecture......
    >>>>
    >>>> component Comp_Metric is
    >>>> port(
    >>>> IndexCOL : in comp_caseSel;
    >>>> WordIndexCase_c: out integer range 0 to 8
    >>>> );
    >>>> end component;
    >>>> begin
    >>>>
    >>>> gen: for i in 0 to 15 generate ---Generate 16 times
    >>>> for j in 0 to M-1 loop
    >>>> compx: Comp_Metric
    >>>> port map(
    >>>> IndexCOL => Matrix2D(j,i), ---What to do here ??
    >>>> ----1D array <=
    >>>> clolumn of 2D
    >>>> WordIndexCase_c => WordIndexCase(i)
    >>>> );
    >>>> end loop;
    >>>> end generate;
    >>>>
    >>> Ved,
    >>>
    >>> I've not used generate or loop myself yet, but it seems to me
    >>> the loop should also be a generate.

    >> Indeed.
    >> You can't have a loop outside of a process.
    >>
    >> Nicolas

    >
     
    David R Brooks, Sep 26, 2006
    #5
  6. Ved

    Ved Guest

    Hi,
    Generate and process didn't help.

    Andy, what is difference between 2d-array and Array of array ?

    Ved

    Andy wrote:
    > In addition to fixing the generate vs loop issue, try an array of
    > arrays, instead of a two dimensional array. Two dimensional arrays are
    > not usually synthesizable, but arrays of arrays of... are. That way an
    > element of the outer array is an array itself, and can be assigned
    > to/from a single array. The only thing you cannot do is slice it the
    > other way (i.e. automatically create/reference an array consisting of
    > the nth element of all arrays).
    >
    > Hope this helps.
    >
    > Andy
    >
    >
    > Nicolas Matringe wrote:
    > > David Ashley a écrit :
    > > > Ved wrote:
    > > >> Hi all,
    > > >> I have problem in assigning 2 dimensional array column to an array in
    > > >> generate statement.
    > > >> I have to take out columns(array of 8 elements) from 8x16 matrix (i.e.
    > > >> 2-D array) and give it to a component which is to be generated 16
    > > >> times.
    > > >> I am confused in assigning a column array of 2D array to a 1D
    > > >> array(simple array) inside a GENERATE statement.
    > > >> I hope explanation is clear ?
    > > >> I have tried to do something (please see codes below).
    > > >> How to use a for loop inside generate.
    > > >> Textbooks and internet resources are not very clear about.
    > > >> Please correct me.
    > > >> Thanks
    > > >> Regards
    > > >> Ved
    > > >>
    > > >> ------Data types---------
    > > >> MatrixInt ---> array (0 to 7 , 0 to 15) of integer range 0 to 8;
    > > >> ---I am calling this Matrix
    > > >>
    > > >> comp_caseSel --> array (0 to 7) of integer range 0 to 8;
    > > >> ---- I am calling this 1D array
    > > >>
    > > >> countArray ---> array (0 to 15) of integer range 0 to 8 ;
    > > >>
    > > >> -------------------------------
    > > >>
    > > >> entity is
    > > >> Matrix2D : in MatrixInt;
    > > >> WordIndexCase: out countArray;
    > > >> end entity
    > > >>
    > > >> architecture......
    > > >>
    > > >> component Comp_Metric is
    > > >> port(
    > > >> IndexCOL : in comp_caseSel;
    > > >> WordIndexCase_c: out integer range 0 to 8
    > > >> );
    > > >> end component;
    > > >> begin
    > > >>
    > > >> gen: for i in 0 to 15 generate ---Generate 16 times
    > > >> for j in 0 to M-1 loop
    > > >> compx: Comp_Metric
    > > >> port map(
    > > >> IndexCOL => Matrix2D(j,i), ---What to do here ??
    > > >> ----1D array <=
    > > >> clolumn of 2D
    > > >> WordIndexCase_c => WordIndexCase(i)
    > > >> );
    > > >> end loop;
    > > >> end generate;
    > > >>
    > > >
    > > > Ved,
    > > >
    > > > I've not used generate or loop myself yet, but it seems to me
    > > > the loop should also be a generate.

    > >
    > > Indeed.
    > > You can't have a loop outside of a process.
    > >
    > > Nicolas
     
    Ved, Sep 26, 2006
    #6
  7. Ved

    smithodude Guest

    Think you should use another nested 'generate'. I've done this in the
    past and it works. I have also synthesised arbitrary sized 2
    dimensional arrays of std_logic without a problem. Not sure about
    integers though

    begin

    gen: for i in 0 to 15 generate ---Generate 16 times
    gen2 : for j in 0 to M-1 generate
    compx: Comp_Metric
    port map(
    IndexCOL => Matrix2D(j,i), ---What to do here ??
    ----1D array <=
    clolumn of 2D
    WordIndexCase_c => WordIndexCase(i)
    );
    end generate;
    end generate;
     
    smithodude, Sep 26, 2006
    #7
  8. Ved

    Andy Guest

    An array of arrays is declared as follows:

    type row_t is array (0 to 7) of integer range 0 to 8;
    type matrix_t is array (0 to 15) of row_t;

    signal matrix : matrix_t;

    Then matrix(i) is ith row (of type row_t), matrix(i)(j) is jth element
    of ith row.

    You can assign, alias, or reference an entire row, or range of entire
    rows:
    matrix(3) or matrix(4 to 9)

    You can assign, alias, or reference an element or range of elements
    within one row:
    matrix(11)(2) or matrix(11)(0 to 3).

    But you can't do something like (without a function):
    matrix(7 to 11)(14)

    Andy


    Ved wrote:
    > Hi,
    > Generate and process didn't help.
    >
    > Andy, what is difference between 2d-array and Array of array ?
    >
    > Ved
    >
    > Andy wrote:
    > > In addition to fixing the generate vs loop issue, try an array of
    > > arrays, instead of a two dimensional array. Two dimensional arrays are
    > > not usually synthesizable, but arrays of arrays of... are. That way an
    > > element of the outer array is an array itself, and can be assigned
    > > to/from a single array. The only thing you cannot do is slice it the
    > > other way (i.e. automatically create/reference an array consisting of
    > > the nth element of all arrays).
    > >
    > > Hope this helps.
    > >
    > > Andy
    > >
    > >
    > > Nicolas Matringe wrote:
    > > > David Ashley a écrit :
    > > > > Ved wrote:
    > > > >> Hi all,
    > > > >> I have problem in assigning 2 dimensional array column to an array in
    > > > >> generate statement.
    > > > >> I have to take out columns(array of 8 elements) from 8x16 matrix (i.e.
    > > > >> 2-D array) and give it to a component which is to be generated 16
    > > > >> times.
    > > > >> I am confused in assigning a column array of 2D array to a 1D
    > > > >> array(simple array) inside a GENERATE statement.
    > > > >> I hope explanation is clear ?
    > > > >> I have tried to do something (please see codes below).
    > > > >> How to use a for loop inside generate.
    > > > >> Textbooks and internet resources are not very clear about.
    > > > >> Please correct me.
    > > > >> Thanks
    > > > >> Regards
    > > > >> Ved
    > > > >>
    > > > >> ------Data types---------
    > > > >> MatrixInt ---> array (0 to 7 , 0 to 15) of integer range 0 to 8;
    > > > >> ---I am calling this Matrix
    > > > >>
    > > > >> comp_caseSel --> array (0 to 7) of integer range 0 to 8;
    > > > >> ---- I am calling this 1D array
    > > > >>
    > > > >> countArray ---> array (0 to 15) of integer range 0 to 8 ;
    > > > >>
    > > > >> -------------------------------
    > > > >>
    > > > >> entity is
    > > > >> Matrix2D : in MatrixInt;
    > > > >> WordIndexCase: out countArray;
    > > > >> end entity
    > > > >>
    > > > >> architecture......
    > > > >>
    > > > >> component Comp_Metric is
    > > > >> port(
    > > > >> IndexCOL : in comp_caseSel;
    > > > >> WordIndexCase_c: out integer range 0 to 8
    > > > >> );
    > > > >> end component;
    > > > >> begin
    > > > >>
    > > > >> gen: for i in 0 to 15 generate ---Generate 16 times
    > > > >> for j in 0 to M-1 loop
    > > > >> compx: Comp_Metric
    > > > >> port map(
    > > > >> IndexCOL => Matrix2D(j,i), ---What to do here ??
    > > > >> ----1D array <=
    > > > >> clolumn of 2D
    > > > >> WordIndexCase_c => WordIndexCase(i)
    > > > >> );
    > > > >> end loop;
    > > > >> end generate;
    > > > >>
    > > > >
    > > > > Ved,
    > > > >
    > > > > I've not used generate or loop myself yet, but it seems to me
    > > > > the loop should also be a generate.
    > > >
    > > > Indeed.
    > > > You can't have a loop outside of a process.
    > > >
    > > > Nicolas
     
    Andy, Sep 26, 2006
    #8
  9. Ved

    Ved Guest

    Thnaks Andy,
    It worked.

    Andy wrote:
    > An array of arrays is declared as follows:
    >
    > type row_t is array (0 to 7) of integer range 0 to 8;
    > type matrix_t is array (0 to 15) of row_t;
    >
    > signal matrix : matrix_t;
    >
    > Then matrix(i) is ith row (of type row_t), matrix(i)(j) is jth element
    > of ith row.
    >
    > You can assign, alias, or reference an entire row, or range of entire
    > rows:
    > matrix(3) or matrix(4 to 9)
    >
    > You can assign, alias, or reference an element or range of elements
    > within one row:
    > matrix(11)(2) or matrix(11)(0 to 3).
    >
    > But you can't do something like (without a function):
    > matrix(7 to 11)(14)
    >
    > Andy
    >
    >
    > Ved wrote:
    > > Hi,
    > > Generate and process didn't help.
    > >
    > > Andy, what is difference between 2d-array and Array of array ?
    > >
    > > Ved
    > >
    > > Andy wrote:
    > > > In addition to fixing the generate vs loop issue, try an array of
    > > > arrays, instead of a two dimensional array. Two dimensional arrays are
    > > > not usually synthesizable, but arrays of arrays of... are. That way an
    > > > element of the outer array is an array itself, and can be assigned
    > > > to/from a single array. The only thing you cannot do is slice it the
    > > > other way (i.e. automatically create/reference an array consisting of
    > > > the nth element of all arrays).
    > > >
    > > > Hope this helps.
    > > >
    > > > Andy
    > > >
    > > >
    > > > Nicolas Matringe wrote:
    > > > > David Ashley a écrit :
    > > > > > Ved wrote:
    > > > > >> Hi all,
    > > > > >> I have problem in assigning 2 dimensional array column to an array in
    > > > > >> generate statement.
    > > > > >> I have to take out columns(array of 8 elements) from 8x16 matrix (i.e.
    > > > > >> 2-D array) and give it to a component which is to be generated 16
    > > > > >> times.
    > > > > >> I am confused in assigning a column array of 2D array to a 1D
    > > > > >> array(simple array) inside a GENERATE statement.
    > > > > >> I hope explanation is clear ?
    > > > > >> I have tried to do something (please see codes below).
    > > > > >> How to use a for loop inside generate.
    > > > > >> Textbooks and internet resources are not very clear about.
    > > > > >> Please correct me.
    > > > > >> Thanks
    > > > > >> Regards
    > > > > >> Ved
    > > > > >>
    > > > > >> ------Data types---------
    > > > > >> MatrixInt ---> array (0 to 7 , 0 to 15) of integer range 0 to 8;
    > > > > >> ---I am calling this Matrix
    > > > > >>
    > > > > >> comp_caseSel --> array (0 to 7) of integer range 0 to 8;
    > > > > >> ---- I am calling this 1D array
    > > > > >>
    > > > > >> countArray ---> array (0 to 15) of integer range 0 to 8 ;
    > > > > >>
    > > > > >> -------------------------------
    > > > > >>
    > > > > >> entity is
    > > > > >> Matrix2D : in MatrixInt;
    > > > > >> WordIndexCase: out countArray;
    > > > > >> end entity
    > > > > >>
    > > > > >> architecture......
    > > > > >>
    > > > > >> component Comp_Metric is
    > > > > >> port(
    > > > > >> IndexCOL : in comp_caseSel;
    > > > > >> WordIndexCase_c: out integer range 0 to 8
    > > > > >> );
    > > > > >> end component;
    > > > > >> begin
    > > > > >>
    > > > > >> gen: for i in 0 to 15 generate ---Generate 16 times
    > > > > >> for j in 0 to M-1 loop
    > > > > >> compx: Comp_Metric
    > > > > >> port map(
    > > > > >> IndexCOL => Matrix2D(j,i), ---What to do here ??
    > > > > >> ----1D array <=
    > > > > >> clolumn of 2D
    > > > > >> WordIndexCase_c => WordIndexCase(i)
    > > > > >> );
    > > > > >> end loop;
    > > > > >> end generate;
    > > > > >>
    > > > > >
    > > > > > Ved,
    > > > > >
    > > > > > I've not used generate or loop myself yet, but it seems to me
    > > > > > the loop should also be a generate.
    > > > >
    > > > > Indeed.
    > > > > You can't have a loop outside of a process.
    > > > >
    > > > > Nicolas
     
    Ved, Oct 1, 2006
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alf P. Steinbach
    Replies:
    0
    Views:
    454
    Alf P. Steinbach
    Aug 18, 2003
  2. John Harrison
    Replies:
    4
    Views:
    6,956
    Default User
    Aug 19, 2003
  3. Venkat
    Replies:
    4
    Views:
    1,014
    Venkat
    Dec 5, 2003
  4. spidey12345
    Replies:
    6
    Views:
    953
    Thomas Fritsch
    Feb 8, 2007
  5. Olumide
    Replies:
    6
    Views:
    759
    John Bode
    May 17, 2010
Loading...

Share This Page