Continue to Site

# How can I formulate matrices using VHDL?

Status
Not open for further replies.

#### dimitris01

##### Newbie level 3
hi can anyone tell me how can I formulate matrices using VHDL?

Re: VHDL design

// definition of matrix m*n of integers (0, 1...9)
TYPE matrix IS array (m-1 downto 0, n-1 downto 0) of integer range 9 downto 0;

// instantiating matrix
VARIABLE matrix_instance: matrix;

// using matrix
matrix_instance( 1 , 1 ) := 5;

### dimitris01

Points: 2
VHDL design

matrix_instance( 1 , 1 ) := 5; can u explain me this line?

thx

dimitris

Re: VHDL design

"matrix_instance" is the matrix of integers range from 0 to 9. So, the element with index (1,1) take on a value 5.
(note: elements of matrix are instaniate like variables. That is why I wrote :=)

### dimitris01

Points: 2
VHDL design

ok if i want to create a Nx1 matrix I write?

constant N : integer := 1;
constant M : integer := 7;
type NM is array(0 to N, 0 to M) of integer;

and by using the matrix_instance I can assign the values of the elements of the matrix?

thx

Re: VHDL design

matrix_instance is only the name of instance. It is not a keyword. In your case you can operate with matrix elements using something like this:

constant N : integer := 1;
constant M : integer := 7;
type NM is array(0 to N, 0 to M) of integer;

VARIABLE matrix_instance: NM;
VARIABLE some_variable: integer;
...
NM(1,2) := 1;
some_variable := NM(0,3);
...

Points: 2