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
--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
;
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;