rumi29
Junior Member level 1
Hi everybody! I'm new on this world of FPGA's.
Well I'm trying to implement the function Sin and Cos in VHDL but I have a problem because my FPGA's doesn't works with float numbers and I can't use any kind of math libraries. I did a program in C language to calculate Sin() with the Taylor series aproximation but the question is...how can I translate this program to VHDL? I don't need to calculate exactly the Sin() value...only a relative good value of it. For example: Sin(30º)=0.45 or something like that
Thanks guys for your help! (and sorry for my english...)
#include <iostream>
using namespace std;
int main()
{
int c,square,d, fat, expden;
float x, seno, y;
seno=0;
expden=1; //Value of the exponent
cout <<"Insert value of the angle"<<endl;
cin >>x;
x=x*3.1415/180; //Degree to Rad
for(c=1;c<=5;c++) //Number of iterations
{
fat=1;
for(d=1;d<=expden;d++)
{fat=fat*d;}
y=1;
for(square=1;square<=expden;square++){ //Loop to elevate to square
y=x*y;
}
if(c%2==0)
{seno=seno-(y/fat);
}
else
{seno=seno+(y/fat);
}
expden=expden+2;
}
cout <<"Sinus = ";
cout <<seno<<endl;
system("pause");
return 0;
}
Well I'm trying to implement the function Sin and Cos in VHDL but I have a problem because my FPGA's doesn't works with float numbers and I can't use any kind of math libraries. I did a program in C language to calculate Sin() with the Taylor series aproximation but the question is...how can I translate this program to VHDL? I don't need to calculate exactly the Sin() value...only a relative good value of it. For example: Sin(30º)=0.45 or something like that
Thanks guys for your help! (and sorry for my english...)
#include <iostream>
using namespace std;
int main()
{
int c,square,d, fat, expden;
float x, seno, y;
seno=0;
expden=1; //Value of the exponent
cout <<"Insert value of the angle"<<endl;
cin >>x;
x=x*3.1415/180; //Degree to Rad
for(c=1;c<=5;c++) //Number of iterations
{
fat=1;
for(d=1;d<=expden;d++)
{fat=fat*d;}
y=1;
for(square=1;square<=expden;square++){ //Loop to elevate to square
y=x*y;
}
if(c%2==0)
{seno=seno-(y/fat);
}
else
{seno=seno+(y/fat);
}
expden=expden+2;
}
cout <<"Sinus = ";
cout <<seno<<endl;
system("pause");
return 0;
}