Matrix of Records of Arrays

Joined
Feb 12, 2011
Messages
2
Reaction score
0
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:
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:
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:
y <= "0011010000"; -- y = 6.5 = “00110.10000”
OR
Code:
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:
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:
alpha: complex_fixed := to_cplxfixed((1.0, 0.0));

Within my application, I want to deal with a matrix of complex numbers:
Code:
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:
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:
# ** 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
# FATAL ERROR while loading design

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?
 
Joined
Feb 12, 2011
Messages
2
Reaction score
0
I would like to note that I later tried:
Code:
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:

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top