Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Multi-dimensional array in VHDL

Status
Not open for further replies.

gnudaemon

Member level 1
Member level 1
Joined
Sep 16, 2004
Messages
33
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
338
vhdl array

How to implement in VHDL such structure like array [][] in C/C++?
Thanks in advance.
@gnudaemon
 

nand_gates

Advanced Member level 3
Advanced Member level 3
Joined
Jul 19, 2004
Messages
899
Helped
175
Reputation
350
Reaction score
53
Trophy points
1,308
Activity points
7,037
array vhdl

Here is one example
array of 16 bit data [128][16]

Code:
subtype tmp is std_logic_vector(15 downto 0);
type memory_array is array(integer range 0 to 127, integer range 0 to 15) of tmp;

Hope this helps
 

gnudaemon

Member level 1
Member level 1
Joined
Sep 16, 2004
Messages
33
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
338
vhdl multidimensional array

How to access each element?
 

ravi.srivatsa

Newbie level 2
Newbie level 2
Joined
Nov 26, 2004
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
24
vhdl array of std_logic_vector

Hi,

I just first got the picture of just two dimentional array.

so one example could be

16 bit array[128]

subtype elements is std_logic_vector(15 downto 0);
type 16bit_array is array (0 to 127) of elements;
signal arr : 16bit_array ;

then accesssing the array element could be done by
arr(0) will get first row of 16 bits or one word.

IF it is complicated then for Multidimentional array one can use records and array of records to avoid confusion.

all the best
 

nand_gates

Advanced Member level 3
Advanced Member level 3
Joined
Jul 19, 2004
Messages
899
Helped
175
Reputation
350
Reaction score
53
Trophy points
1,308
Activity points
7,037
array in vhdl

subtype tmp is std_logic_vector(15 downto 0);
type memory_array is array(integer range 0 to 127, integer range 0 to 15) of tmp;
variable mem : memory_array;


Then in this case you can access memory as follows

data <= mem(10,10);

Its simple is'nt it?
 

Mazi3

Advanced Member level 4
Full Member level 1
Joined
May 29, 2002
Messages
101
Helped
5
Reputation
10
Reaction score
3
Trophy points
1,298
Location
Europe
Activity points
960
vhdl two dimensional array

no, no, to acces one element:
type memo is array(0 to 7) of std_logic_vector(23 downto 0);
signal mem:memo;
....
....
...

data<=mem(2)(3);
 

tesla101

Newbie level 4
Newbie level 4
Joined
Jan 10, 2005
Messages
7
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,283
Location
Cheeseland
Activity points
109
vhdl 2 dimensional array

since your multidimensional array typically represents a RAM memory there are two possible usages .

as we suppose that you declared your type and signal identically as other users suggested you :

type memory is array (INTEGER range <>) of std_logic_vector(7 downto 0);

signal GetDescDevice : memory(0 to 92); -- a 93 byte character array


to write one byte you'll refer to :

GetDescDevice(3) <= "10110001"; -- you'll write the 4th byte (an 8 bits vector) of your array


to write one particular bit :

GetDescDevice(3)(4) <= '1';



Should help


Regards,


Tesla101
 

mosgaard2000

Newbie level 3
Newbie level 3
Joined
Dec 18, 2007
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,304
array of std_logic_vector

How do you index 1 bit throug the array?

Using the previous example:

type memory is array (INTEGER range <>) of std_logic_vector(7 downto 0);
signal GetDescDevice : memory(0 to 92); -- a 93 byte character array

to write one byte you'll refer to :
GetDescDevice(3) <= "10110001"; -- you'll write the 4th byte (an 8 bits vector) of your array

to write one particular bit :
GetDescDevice(3)(4) <= '1';

I would loke to set bit8 to '0' in all memory adresses.

GetDescDevice(0 to 92)(7) <= '1';

But I get an errormessage saying '0' isn't declared for type std_logic_vector.
 

Mejdi_tn

Junior Member level 3
Junior Member level 3
Joined
Oct 20, 2007
Messages
28
Helped
7
Reputation
14
Reaction score
6
Trophy points
1,283
Activity points
1,473
multidimensional array vhdl

hi
i have the same probleme! then how to access to data in 2 RAM , and do division between data 1 and data 2
think u
 

xio

Newbie level 1
Newbie level 1
Joined
Sep 21, 2009
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,284
two dimensional array in vhdl

Something like the following should work :

Set1bit: for i in 0 to 92 generate
begin
GetDescDevice(i)(7) <= '1';
end generate Set1bit;
 

sns22

Member level 2
Member level 2
Joined
Jan 15, 2011
Messages
46
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Location
Spain
Activity points
1,708
Re: vhdl two dimensional array

i have the same problem..
i want to access the array as a whole in one part of my code and only a single bit of the array in other part of the code.

port(
Switches : out std_logic_vector(7 downto 0);
);

type register_ram is array (0 to 63) of std_logic_vector (7 downto 0);
signal reg_ram_s :register_ram;



switches(0) <= reg_ram_s(10);
the problem is that here i am tryin to write 8 bits (reg_ram_s 10 signal) to one bit of switches(0)
how to get the one bit from the signal: reg_ram_s(10) ?

---------- Post added at 00:21 ---------- Previous post was at 00:17 ----------

i did it thnks
 

sizler

Newbie level 1
Newbie level 1
Joined
Jul 27, 2011
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,284
Re: vhdl array of std_logic

Hi,

I just first got the picture of just two dimentional array.

so one example could be

16 bit array[128]

subtype elements is std_logic_vector(15 downto 0);
type 16bit_array is array (0 to 127) of elements;
signal arr : 16bit_array ;

then accesssing the array element could be done by
arr(0) will get first row of 16 bits or one word.

IF it is complicated then for Multidimentional array one can use records and array of records to avoid confusion.

all the best

how can we fetch the dta in this type of array? can ny1 xplain ?
 

vipinlal

Full Member level 6
Full Member level 6
Joined
Mar 8, 2010
Messages
357
Helped
76
Reputation
152
Reaction score
60
Trophy points
1,308
Location
India
Activity points
3,191
Your question has the answer in it. arr(0) will be the first element, arr(1) the second and so on..

If you want to access a particular bit in the 16 bit word then you can use arr(0)(3 downto 0) which will get LSB 4 bits of the first array element.
 

jhunjhun

Member level 1
Member level 1
Joined
Dec 12, 2011
Messages
32
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Location
shilong
Activity points
1,456
how can i access each element of array
reg [7:0] array[3:0][3:0]
 

wtr

Full Member level 5
Full Member level 5
Joined
May 1, 2014
Messages
298
Helped
29
Reputation
58
Reaction score
25
Trophy points
1,308
Activity points
4,095
Re: array vhdl

Is the following possible?

Code:
TYPE track IS ARRAY(0 TO 17) OF BIT;
TYPE side IS ARRAY(0 TO 79) OF track;
TYPE disk IS ARRAY(0 TO 1) OF side;

What I'm trying to achieve it
Code:
TYPE 3d_array IS ARRAY (0 TO 1, 0 TO 79, 0 TO 17) OF BIT;

THANKS
 

TrickyDicky

Advanced Member level 7
Advanced Member level 7
Joined
Jun 7, 2010
Messages
7,109
Helped
2,080
Reputation
4,179
Reaction score
2,045
Trophy points
1,393
Activity points
39,763
Yes, the first example is possible. But it is not the same as the 3d array you posted. Your first one is a 1d array of 1d array of 1d array. What exactly are you trying to acheive. The 3d array you posted is perfectly legal.

I would not recommend making your own array of bit though. There is an array already defined for that (bit_vector).
 

wtr

Full Member level 5
Full Member level 5
Joined
May 1, 2014
Messages
298
Helped
29
Reputation
58
Reaction score
25
Trophy points
1,308
Activity points
4,095
Thanks TrickyDicky. I know that Bit_vector is an unconstrained array, & therefore my first declaration of track is just a subtype of that array.

Given that the disk array declaration is a 1d array of 1d array side of 1d array track.

Is it possible to locate(index) a possition within like you can with a 3d array? Will there ever be a need for such a tree/branch-like structure?

With regards to what i'm trying to achieve...nothing... I'm just curious. There was a exercise in Peter J. Ashenens book "The Students Guide to VHDL" which said

"The data on a diskette is arranged in 18 sectors per track, 80 tracks per side & two sides per diskette. A computer system maintains a map of free sectors. Write a three-dimensional array type declaration to represent such a map, with a '1' element representing a free sector & a '0' element representing an occupied sector. Write a set of nested for loops to scan a variable of this type to find the location of the first free sector."

Which I successfully answered...but it got me curious about cascading arrays.
 

TrickyDicky

Advanced Member level 7
Advanced Member level 7
Joined
Jun 7, 2010
Messages
7,109
Helped
2,080
Reputation
4,179
Reaction score
2,045
Trophy points
1,393
Activity points
39,763
your track type is NOT a subtype of bit_vector. it is a completly new type. Therefore any functions for bit_vector will NOT work with your track type.

a subtype is declared as
subtype track is bit_vector(0 to 17);

To locate an index in a 3d array, you can just write:

result <= disk(a,b,c);

With your 1d array types, it would be:
result <= disk(a)(b)(c);

There are major differences. With the 3d array type, you can only return single bits. You could not return a whole track for example.
With the 1d array types, you can return a whole track, side or bit:

bit <= disk(a)(b)(c);
side <= disk(a)(b);
track <= disk(a);
 
  • Like
Reactions: wtr

    wtr

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top