# Matrix of Records of Arrays

Discussion in 'VHDL' started by mostafa.elhoushi, Feb 12, 2011.

1. ### mostafa.elhoushi

Joined:
Feb 12, 2011
Messages:
2
Dear All,

This is the first time I post a question here in Velocity Reviews.
I hope that in the future I can get more experience so that I may help answering other people's questions.

I am developing a VHDL application dealing with complex numbers - and I decided to develop complex numbers using fixed point representation (using IEEE fixed_pkg):

Code (Text):
use ieee.fixed_float_types.all;
use ieee.fixed_pkg.all;

....

type complex_fixed is record
RE : sfixed (1 downto -10);
IM : sfixed (1 downto -10);
end record;
Using this package, we can represent y=6.5 by:
1- Defining
Code (Text):
signal y : sfixed (4 downto –5);
which means that y has 4 binary digits before the decimal point and 5 binary digits after the decimal point.
then we use either:
Code (Text):
y <= "0011010000"; -- y = 6.5 = “00110.10000”
OR
Code (Text):
y <= to_sfixed(6.5);
For more details search Google for: "Fixed point package user’s guide"

Therefore I have defined the following function to ease the definition of complex numbers:
Code (Text):
function to_cplxfixed (RE, IM: real) return complex_fixed;
....
function to_cplxfixed (RE, IM: real) return complex_fixed is
begin
return (to_sfixed(RE, -1, 10), to_sfixed(IM, -1, 10));
end function;
Therefore a complex number such as alpha = 1 + 0i can be represented as:
Code (Text):
alpha: complex_fixed := to_cplxfixed((1.0, 0.0));
Within my application, I want to deal with a matrix of complex numbers:
Code (Text):
type cmplx_matrix is array (natural range<>, natural range<>) of complex_fixed;
The problem I am asking for is this:
When I define the following matrix:
Code (Text):
constant I: cmplx_matrix(0 to 1, 0 to 1) := ((to_cplxfixed((1.0,0.0)), to_cplxfixed((0.0,0.0))),
(to_cplxfixed((0.0,0.0)), to_cplxfixed((1.0,0.0)))
);
It passes by compilation stage in ModelSim (vcom), however an error appears to me in vsim:
Code (Text):
# ** Fatal: (vsim-3420) Array lengths do not match. Left is 12 (1 downto -10). Right is 0 (0 downto 1 (null array)).
#    Time: 0 ns  Iteration: 0  Region: /quantum_systems File: COMPLEX_FIXED.vhd Line: 27
i.e. When it deals with I cmplx_matrix assignment, it considers the length of one dimension of the matrix being 0 to 1, and tries to equate it to the length of the result of s_fixed function.

What can the solution be?

mostafa.elhoushi, Feb 12, 2011

2. ### mostafa.elhoushi

Joined:
Feb 12, 2011
Messages:
2
I would like to note that I later tried:
Code (Text):
constant I: cmplx_matrix(0 to 1, 0 to 1) := ( ((B"0_1_0000000000",B"0_0_0000000000"), (B"0_0_0000000000",B"0_0_0000000000")),
((B"0_0_0000000000",B"0_0_0000000000"), (B"0_1_0000000000",B"0_0_0000000000"))
);
without using my defined function... and the error no longer appeared.

But I would like to know why the function to_cplxfield does not work with arrays.
The function is needed to make my code generic -- or is there another way?

Last edited: Feb 12, 2011
mostafa.elhoushi, Feb 12, 2011