I pop-up again, sorry.
The problem is not easy as what I expected. Now I want to ask about
the EXP function implementation skills in FPGA board. I've known that
FPGA board only deals with the fixed point values. If my design needs
the result of EXP as temparary coefficient for the
other caculation. How to deals with the floating things then? I used
to manage the simple floating problem to fixed point value, e.g 2**{-
A}, A is an integer. I don't know how to convert the 'e**' to the
fixed point value. Any body has been experienced the simlar thing to
design EXP implementation? Please give me some tip on this. Thank you
very much.
Unfortunatly, pretty much everything from the math_real and
math_complex are completly unsynthesizable. You should NOT use them in
FPGA designs because they will NOT work. They are only there for
system modelling and testbenching. They can only be used for generics
to set up your design, Otherwise they need converting to fixed point
values.
If you are handling floating point numbers, you may have to find
floating point libraries that use std_logic_vectors in the standard
32/64 bit IEEE float standard. I know Xilinx offer floating point
libraries (developed by QinetiQ) that include things likefloating
point adder/multiplier/divider/square root etc. Handing of floating
point in VHDL is non trivial in synthesizable designs.
You will have to stick with fixed point values throughout the design.
I have a function that converts reals to slv's, but these must be
elaborated as setup parameters only and cannot be used inside a
functioning design:
--casts a real to an integer, with or without rounding
function real_to_int( x : real; round : boolean := false) return
integer is
variable ret : integer;
variable temp : integer;
begin
if round then
ret := integer(x);
else
temp := integer(x);
--always round towards 0
if temp >= 0 then
--rounds positive numbers down
if real(temp) > x then
ret := temp - 1;
else
ret := temp;
end if;
else
--rounds -ve numbers up
if real(temp) < x then
ret := temp + 1;
else
ret := temp;
end if;
end if;
end if;
return ret;
end function;
function real_to_slv(x : real; m, f : natural; s, round : boolean :=
false ) return std_logic_vector is
variable ret_slv : std_logic_vector(m+f-1 downto 0);
variable size_int : integer := 1;
begin
--this loop determins the multiplcation that happens on the real
number, to give it a meaningful value in an integer range
size_loop : for i in 0 to f-1 loop --extra loop to account for
size_int starting at 1
size_int := size_int * 2;
end loop;
--real to integer conversion
if s then
ret_slv := std_logic_vector(to_signed( real_to_int( x *
real(size_int), round) , ret_slv'length));
else
ret_slv := std_logic_vector(to_unsigned( abs( real_to_int( x *
real(size_int), round )) , ret_slv'length));
end if;
return ret_slv;
end function real_to_slv;