how to declare two dimensional arrays and their elements in VHDL

user2481101 picture user2481101 · Jun 18, 2013 · Viewed 27.1k times · Source

i need to declared the values that the counter is to take in a 2D array. Also, how do i select elements from the array and use them (say assign them to another variable) how do i declare the elements of this 2D array ?

type lutable is array (0 to 4, 0 to 63) of integer range 0 to 4000;

Answer

baldyHDL picture baldyHDL · Jun 18, 2013

in a 2D array e.g.:

type lutable is array (0 to 4, 0 to 2) of integer range 0 to 4000;

signal sample_array: lutable;

you can assign elements to another signal as follows:

out_signal<=sample_array(in_a, in_b);

the contents of the array can be declared e.g. as defaults (caution, this is not supported by all synthesis-tools!):

signal sample_array: lutable:=( (1000, 2000, 3000),
                        (4000, 3000, 2000),
                        (100, 200, 300),
                        (1,2,3),
                        (5,6,7));

or over a constant-array, e.g.:

signal sample_array: lutable;
constant sample_array_init: lutable:=(  (1000, 2000, 3000),
                        (4000, 3000, 2000),
                        (100, 200, 300),
                        (1,2,3),
                        (5,6,7));
 ...
 sample_array<=sample_array_init;
 ...

or, of course, element by element:

 sample_array(1,1)<=1000;
 ...