VHDL array initialization 
Author Message
 VHDL array initialization

I am trying to initialize an array constant within a package declaration.
The array size is unconstrained until the constant is declared as shown below.
There seems to be type problems and unexpected aggregate length problems.  

  CONSTANT n : natural := 4;
  CONSTANT m : natural := 1;
  SUBTYPE fixed IS signed (1 TO 12);
  TYPE matrix IS ARRAY (natural RANGE <>,natural RANGE <>) OF fixed;
  CONSTANT A: matrix(1 TO n, 1 TO n) := (
    ("000011100101", "111111111110", "000111010110", "000000010100" ) ,
    ("111111111111", "000011100111", "111110101010", "000110000010" ) ,
    ("111111111111", "111111111111", "000100101100", "000000011000" ) ,
    ("000000000000", "111111111111", "111110011101", "000011001010" ) );

Everything is ok for this initialization since this is a 4x4.  
But as in this case...

  CONSTANT C: matrix(1 TO m, 1 TO n) := (
    ("000000000000", "000000000000", "111100001000", "111110000100" ) );

This is a 1x4 and my compiler complains about type errors and aggregate
lengths.

ERROR: src/ABCD.vhdl(33): Type error in string literal        (4 of these)
ERROR: src/ABCD.vhdl(33): Aggregate length is 4. Expected length is 1.

I've tried a variety of aggregate structures but this one makes the most
sense to me.  How can I perform the initialization of a 1xn or nx1 array
constant?  Help!  Thanks.

--

 Past IEEE Student Branch Vice Chair     Mentor Graphics SysAdm, EE & ISC, UMR
               Home     573-364-8827     Office     573-341-6557
                          http://www.*-*-*.com/ ~jkelly/



Mon, 01 Mar 1999 03:00:00 GMT  
 VHDL array initialization

Quote:

> Everything is ok for this initialization since this is a 4x4.
> But as in this case...

>   CONSTANT C: matrix(1 TO m, 1 TO n) := (
>     ("000000000000", "000000000000", "111100001000", "111110000100" ) );

> This is a 1x4 and my compiler complains about type errors and aggregate
> lengths.

Use this:

    CONSTANT C: matrix(1 TO m, 1 TO n) := (
     1=>("000000000000", "000000000000", "111100001000", "111110000100" ) );

or:

    CONSTANT C: matrix(1 TO m, 1 TO n) := (
  others=>("000000000000", "000000000000", "111100001000", "111110000100" ));

The problem here is the distinction between a one element array and a single
element (the element itself being an an array of string literals). You have to
disambiguify.

--

USA http://vhdl.org/~rouillard   EU http://ismea.imt-mrs.fr/~rouillar
---------------------- Va savoir, Charles --------------------------
Ne reponds pas au fou selon    |Reponds au fou selon sa demence
 sa demence, que tu ne l'egales| de peur qu'il ne soit sage
 toi aussi [Prov 26:4]         | a ses yeux [Prov 26:5]
--------------------------------------------------------------------



Tue, 02 Mar 1999 03:00:00 GMT  
 VHDL array initialization

  CONSTANT C: matrix(1 TO m, 1 TO n) := (
    ("000000000000", "000000000000", "111100001000", "111110000100" ) );

This is the infamous single-element aggregate problem.  Instead of a
two-dimensional array aggregate, you have written a one-dimensional
aggregate enclosed in parentheses.  (There is a difference!)

Try using named association:

  CONSTANT C: matrix(1 TO m, 1 TO n) := (
    1 => ("000000000000", "000000000000", "111100001000", "111110000100" ) );

Paul



Tue, 02 Mar 1999 03:00:00 GMT  
 VHDL array initialization

:     CONSTANT C: matrix(1 TO m, 1 TO n) := (
:      1=>("000000000000", "000000000000", "111100001000", "111110000100" ) );

: or:

:     CONSTANT C: matrix(1 TO m, 1 TO n) := (
:   others=>("000000000000", "000000000000", "111100001000", "111110000100" ));

: The problem here is the distinction between a one element array and a single
: element (the element itself being an an array of string literals). You have to
: disambiguify.

I tried the same structure with arrays of integers and experienced the same
problem.  I actually have a program generate the ASCII package definition from
arrays A, B, C, and D whose sizes vary from 1x1 to whatever, not always square.
Your suggestion above worked but I don't see why my method doesn't work
for arrays of integers or some other scalar.  I prefer to not use the
named association notation since it complicates my authoring code.  

Why won't the positional notation work with 1xn or nx1 arrays of scalars?

--

 Past IEEE Student Branch Vice Chair     Mentor Graphics SysAdm, EE & ISC, UMR
               Home     573-364-8827     Office     573-341-6557
                          http://www.umr.edu/~jkelly/



Tue, 02 Mar 1999 03:00:00 GMT  
 VHDL array initialization

Quote:
> I tried the same structure with arrays of integers and experienced the same
> problem.  I actually have a program generate the ASCII package definition from
> arrays A, B, C, and D whose sizes vary from 1x1 to whatever, not always square.
> Your suggestion above worked but I don't see why my method doesn't work
> for arrays of integers or some other scalar.  I prefer to not use the
> named association notation since it complicates my authoring code.

> Why won't the positional notation work with 1xn or nx1 arrays of scalars?

When you have (x,y,z) in the appropriate context, it can be interpreted only as a 3
elements array. (x,y) as a 2 elmts array. But (x) is just a value between
parenthesis, just like (((((x))))), the same by the way, and if you think of it,
you may want that 'feature'.
In positionnal notation, the language does not 'count' the number of parenthesis to
determine the dimension of the object. It counts how many comma-separated-values are
nested. No comma, no new dimension.
So you *have* to use a syntax for your aggregate that exhibits the appropriate
dimension. If there is only one element, the named notation is the best choice.

(1 => value) or (others => value)

A {*filter*} workaround:

(value, others=> anything)  -- assuming the constraint has only one bucket,
        -- others refers to nothing but forces the analysis to guess the dimension.

so you can also write:

(value1, value2, value3, others => anything) assuming there are only 3 buckets.

and you get some symmetry between single and multiple element arrays. But we are
speaking style, here.

--

USA http://www.*-*-*.com/ ~rouillard   EU http://www.*-*-*.com/ ~rouillar
---------------------- Va savoir, Charles --------------------------
Ne reponds pas au fou selon    |Reponds au fou selon sa demence
 sa demence, que tu ne l'egales| de peur qu'il ne soit sage
 toi aussi [Prov 26:4]         | a ses yeux [Prov 26:5]
--------------------------------------------------------------------



Tue, 02 Mar 1999 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Initialization of an unconstrained array object to the null array

2. ROM initialization in VHDL for Virtex

3. (Dumb) Array Initialization Question

4. Compiler default initialization of array types

5. array initialization

6. Aggregate initialization of arrays

7. initialization of 2D array?

8. array initialization

9. character array initialization

10. character array initialization

11. g77 array initialization

12. Array initialization problem

 

 
Powered by phpBB® Forum Software