Sin, Cos, Atan

Hey Guys,

I know that Trig functions on the Controller were discussed a lot and everybody is afraid of using floats and so on. But since I really need to use sin, cos, and atan in order to make our Program work I tried to figure out how to do that the best way.

I would really like to use Team 296’s CORDIC Functions but I don’t know how to work with 24 bit binary radians nor how to printf() these …

What would be the easiest way for me to go and how do I Debug whatever you would suggest (if not int, char, or etc.) …

Thanks for all Help


There are 256 binary radians (also called “brads”) to a circle, just as there are 360 degrees to a circle. With this, you should be able to figure out how to convert degrees to brads. Once you have the result from the 296 CORDIC library, I would drop the 8 least significant bits (answer>>=8) and then cast that as an integer. Good luck.

Thanks for your Help but I still have a little problem with that:

When I test it with my function:


void sin_test(short long value)
short long result; // int p_result, int p_value;

result = sin((short long)value);


printf("Sin of %d = %d
", (int)result, (int)result);

I always get 0’s back (for value and for result). I tried result>>8 instead but that always gave me value for both (for value and for result) …

what am I doing wrong?

Nevermind my last post I had the typcasting wrong, now it seems to work but I’m still not sure how to convert all this to Degree. What is the maximum degree that you can put into the function, does sin (2^23 / 2) = sin (360) = ? or how does it work …
Any Idea?

PS: Thanks for your help so far I would have never guessed that : )