Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Error when using math_real library

Status
Not open for further replies.

jdh_1984

Member level 2
Joined
Aug 11, 2010
Messages
52
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Location
Norway
Activity points
1,854
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),alphaEstimated);
END IF;
END PROCESS;
END Behavior;
 

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.
 

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.
 

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.
 

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;
 

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.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top