+ Post New Thread
Results 1 to 6 of 6
  1. #1
    Member level 2
    Points: 668, Level: 5

    Join Date
    Aug 2010
    Location
    Norway
    Posts
    52
    Helped
    0 / 0
    Points
    668
    Level
    5

    Error when using math_real library

    Hi
    I am trying to use the acos function in the math_real library, but this gives the following error in the quartus 9.1 compiler:

    Error (10482): VHDL error at Akselerometer.vhd(29): object "ACOS" is used but not declared

    I know floating point numbers and fpga is not a good match, so maybe I should use look up tables instead(what is your opinion)?
    My code is as follows:

    Library ieee;
    USE ieee.std_logic_1164.all;
    use ieee.numeric_std.all;
    library ieee_proposed;
    use ieee_proposed.fixed_pkg.all;
    use ieee.math_real.all;

    ENTITY Akselerometer IS
    PORT(
    y : IN sfixed(7 downto -4);--Readed accelerometer value
    Clock : IN STD_LOGIC;
    alphaEstimated : OUT sfixed(7 downto -4));

    END Akselerometer;

    ARCHITECTURE Behavior OF Akselerometer IS
    SIGNAL bias : sfixed(7 downto -4);
    SIGNAL argCosREAL,alphaREAL : REAL;
    SIGNAL argCos : sfixed(12 downto -10);

    BEGIN
    bias<=to_sfixed(1.586,bias);--fixed bias =1.586V
    PROCESS(y)--Start processing when a new value enters y-pins
    BEGIN
    IF (y>=bias)THEN
    argCos<=bias/y;
    argCosREAL<=to_REAL(argCos);
    alphaREAL<=ACOS(argCosREAL);
    alphaEstimated<=to_sfixed(alphaREAL,alphaEstimated );
    ELSIF (y<bias) THEN
    argCos<=y/bias;
    argCosREAL<=to_REAL(argCos);
    alphaREAL<=ACOS(argCosREAL);
    alphaEstimated<=to_sfixed((alphaREAL),alphaEstimat ed);
    END IF;
    END PROCESS;
    END Behavior;

    •   AltAdvertisment

        
       

  2. #2
    Super Moderator
    Points: 249,046, Level: 100
    Awards:
    1st Helpful Member

    Join Date
    Jan 2008
    Location
    Bochum, Germany
    Posts
    43,337
    Helped
    13177 / 13177
    Points
    249,046
    Level
    100

    Re: Error when using math_real library

    I know floating point numbers and fpga is not a good match.
    The stament is missing the point. As a simple fact, IEEE.math_real isn't supported for synthesis at all. It's intended for simulation purposes, and you can use it with a design compiler like Quartus to calculate constants at compile time, and e.g. calculate a look-up-table. This applies to the real type in general as well to the functions provided by the library. Beside tables, CORDIC is a common way to generate trigonometric functions in FPGAs.



    •   AltAdvertisment

        
       

  3. #3
    Member level 2
    Points: 668, Level: 5

    Join Date
    Aug 2010
    Location
    Norway
    Posts
    52
    Helped
    0 / 0
    Points
    668
    Level
    5

    Re: Error when using math_real library

    Quote Originally Posted by FvM View Post
    The stament is missing the point. As a simple fact, IEEE.math_real isn't supported for synthesis at all. It's intended for simulation purposes, and you can use it with a design compiler like Quartus to calculate constants at compile time, and e.g. calculate a look-up-table. This applies to the real type in general as well to the functions provided by the library. Beside tables, CORDIC is a common way to generate trigonometric functions in FPGAs.
    Hi
    Tnx for replay, then I have to find another solution for the problem.



    •   AltAdvertisment

        
       

  4. #4
    Full Member level 6
    Points: 3,477, Level: 13
    Achievements:
    7 years registered
    vipinlal's Avatar
    Join Date
    Mar 2010
    Location
    India
    Posts
    354
    Helped
    76 / 76
    Points
    3,477
    Level
    13

    Re: Error when using math_real library

    I think you can use fixed_pkg library alone for the calculation of cos_inverse. You just need to implement the equation given in this link:
    Taylor series - Wikipedia, the free encyclopedia
    for cos inverse.

    The equation ideally contains infinite terms but since you just want only 5 bits fractional you can implement the function using first 4 or 5 terms.



  5. #5
    Member level 2
    Points: 668, Level: 5

    Join Date
    Aug 2010
    Location
    Norway
    Posts
    52
    Helped
    0 / 0
    Points
    668
    Level
    5

    Re: Error when using math_real library

    Quote Originally Posted by vipinlal View Post
    I think you can use fixed_pkg library alone for the calculation of cos_inverse. You just need to implement the equation given in this link:
    Taylor series - Wikipedia, the free encyclopedia
    for cos inverse.

    The equation ideally contains infinite terms but since you just want only 5 bits fractional you can implement the function using first 4 or 5 terms.
    Hi
    Good idea:)


    I wrote a conversion program using Taylor series, but when I tried to simulate it, I get the following warnings for every signal I tried to track. (only In and out signals is shown ok in the quartus 9.1 simulation report)

    "Warning: Ignored node in vector source file. Can't find corresponding node name "n[0]" in design."

    I obviously doing something wrong because it will not work on the evaluation board either.
    Could it be the way I am treating y in the Process sensitivity list? I am using it like an interrupt, but is this the way to do it VHDL?

    The code is as follows:

    Library ieee;
    USE ieee.std_logic_1164.all;
    use ieee.numeric_std.all;
    library ieee_proposed;
    use ieee_proposed.fixed_pkg.all;


    ENTITY Akselerometer IS
    PORT(
    y : IN sfixed(7 downto -4); --Readed accelerometer value
    Clock : IN STD_LOGIC;
    alphaEstOut : OUT sfixed(7 downto -4)); --Outputed accelerometer value (rad)


    END Akselerometer;

    ARCHITECTURE Behavior OF Akselerometer IS
    SIGNAL Pi : sfixed(3 downto -5);
    SIGNAL Factorial : sfixed(7 downto 0);
    SIGNAL n : unsigned(2 downto 0);
    SIGNAL nSfixed : sfixed(2 downto 0);
    SIGNAL x : sfixed(7 downto -4);
    SIGNAL bias : sfixed(7 downto -4);
    SIGNAL binit,b,c,d,e,f : sfixed(7 downto -4);
    SIGNAL alphaEst : sfixed(7 downto -4);
    --For simulation purpose
    SIGNAL FactorialSim :sfixed(7 downto 0);

    BEGIN
    bias<=to_sfixed(1.586,bias);--fixed bias =1.586V
    Pi<=to_sfixed(3.1415,Pi); --Pi = 3.1415....
    PROCESS(y)--Start processing when a new value enters y-pins
    BEGIN
    Factorial<=to_sfixed(1,Factorial); --Initial value;
    FactorialSim<=to_sfixed(1,FactorialSim);--Initial value;
    binit<=to_sfixed(4,binit); --Initial value;
    b<=to_sfixed(1,b); --Initial value;
    c<=to_sfixed(0,c); --Initial value;
    d<=to_sfixed(0,d); --Initial value;
    E<=to_sfixed(0,E); --Initial value;
    f<=to_sfixed(0,f); --Initial value;
    x<=to_sfixed(0,x); --Initial value;
    n<="000"; --Initial value;
    nSfixed<=to_sfixed(0,nSfixed); --Initial value;
    alphaEst<=to_sfixed(0,alphaEst); --Initial value;
    IF (y>=bias)THEN
    x<=resize(bias/y,x); --Calculate the argument for the arccos function
    ELSIF (y<bias) THEN
    x<=resize(y/bias,x); --Calculate the argument for the arccos function
    END IF;
    alphaEst<=resize((Pi/2)-x,alphaEst); --for term n=0 in Taylor series (Pi/2-n0)
    FOR i IN 1 TO 5 LOOP
    n<=n+1;
    nSfixed<=sfixed(n);
    Factorial<=resize(Factorial*nSfixed,Factorial);--Factorial,n=1=>1,n=2=>2,n=2=>6 etc
    FactorialSim<=Factorial; --Just for Sim. purpose
    b<=resize(b*binit,b); --For use in the Taylor series calculation
    c<=resize(2*nSfixed+1,c); --For use in the Taylor series calculation
    d<=resize(b*Factorial*Factorial*c,E); --For use in the Taylor series calculation
    Case n IS --For use in the Taylor series calculation
    WHEN "000"=>
    e<=e;
    WHEN "001"=>
    e<=resize(x*x*x,e);
    WHEN "010"=>
    e<=resize(x*x*x*x*x,e);
    WHEN "011"=>
    e<=resize(x*x*x*x*x*x*x,e);
    WHEN "100"=>
    e<=resize(x*x*x*x*x*x*x*x*x,e);
    WHEN "101"=>
    e<=resize(x*x*x*x*x*x*x*x*x*x*x,e);
    WHEN "110"=>
    e<=e;
    WHEN "111"=>
    e<=e;
    END CASE;
    f<=resize(2*Factorial*e,f); --For use in the Taylor series calculation
    alphaEst<=resize(alphaEst-(f/d),alphaEst); --Prev Taylor calculation(incl.Pi/2) - current Taylor calculation
    END LOOP;
    alphaEstOut<=alphaEst;
    END PROCESS;

    END Behavior;



    •   AltAdvertisment

        
       

  6. #6
    Full Member level 6
    Points: 3,477, Level: 13
    Achievements:
    7 years registered
    vipinlal's Avatar
    Join Date
    Mar 2010
    Location
    India
    Posts
    354
    Helped
    76 / 76
    Points
    3,477
    Level
    13

    Re: Error when using math_real library

    I think you should clock the process.
    process(clock)
    ...
    ..
    end process

    Synchronize everything and remove y from the sensitivity list. You may have to make some changes in the body of the process too.



--[[ ]]--