Matrix of Records of Arrays

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

  1. mostafa.elhoushi

    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:
    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?
    mostafa.elhoushi, Feb 12, 2011
    #1
    1. Advertising

  2. mostafa.elhoushi

    mostafa.elhoushi

    Joined:
    Feb 12, 2011
    Messages:
    2
    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: Feb 12, 2011
    mostafa.elhoushi, Feb 12, 2011
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. lvcargnini

    Matrix composed by two matrix

    lvcargnini, Jul 4, 2006, in forum: VHDL
    Replies:
    3
    Views:
    2,638
    Jonathan Bromley
    Jul 5, 2006
  2. Holgerson

    Matrix*Vector and Vector*Matrix

    Holgerson, Oct 25, 2007, in forum: C++
    Replies:
    3
    Views:
    391
    Holgerson
    Oct 26, 2007
  3. Philipp
    Replies:
    21
    Views:
    1,093
    Philipp
    Jan 20, 2009
  4. Terry Reedy
    Replies:
    0
    Views:
    538
    Terry Reedy
    Apr 2, 2009
  5. Robert Kern
    Replies:
    0
    Views:
    573
    Robert Kern
    Apr 2, 2009
Loading...

Share This Page