Forum Discussion
Altera_Forum
Honored Contributor
14 years agoNo. There are no sin or cosine functions available in synthsisable VHDL.
You will need to setup a lookup table of fixed point values but you can use the sin/cosine functions for the real type to set this up. You will need a function to setup your ROM, but this is a great example of a initialisation function: eg:
type sin_table_t is array(0 to 1023) sfixed(0 downto -15);
function set_sin_table return sin_table_t is
variable ret_table : sin_table_t;
begin
for i in 0 to 1023 loop
ret_table(i) := to_sfixed( (real(i) * MATH_PI) / 1024.0, 0, -15);
end loop;
return ret_table;
end function set_sin_table;
--This look up table has 1024 points of sin 0 - PI
constant SIN_TABLE : sin_table_t := set_sin_table;
Then you use the input to the table to be the fraction of pi for the value output <= SIN_TABLE(X); X here represents the fraction of PI, so setting X to 500 in real terms means sin(PIx500 / 1024).