

'trig.We include a language tool plugin for MPLAB IDE to allow seamless development using Microchip's development tools. 'LCD defines taken out so that this code would fit in limited size Last edited by ScaleRobotics - 8th February 2009 at 19:35. But then if I run it again, a different value pops up for cos, that still does not get close to expected values. When I input 5461 as the angle, I get the sin=29998, and cos=405. It does compile without errors, but I do not get useful data out. 'ENDPlease let me know if you have any suggestions. Last edited by ScaleRobotics - 6th February 2009 at 23:21. 'ENDI am using this as an includes file, but I am getting values so far from expected, that I can't figure out what is going on. If the angle is in quadrant 1, adjust it to quadrant 2 If the angle is in quadrant 4, adjust it to quadrant 3 Check if the quadrant was originally changed Multiply the _x value by 19898 and divide by 2^14 to scale it Perform adding operations on _x, _y and _ang, shifting the atans right one Divide the _y coordinate by 2 to prevent overflowing Divide the _x coordinate by 2 to prevent overflowing If the point is in quadrant 2 or 3, make _x positive and set flag Calculates the magnitude and direction of the given ordered pair Negate _x if it was initially in quadrant 2 or 3 Increment the counter and exit the loop if done Perform adding operations on _x, _y and _ang

Multiply the angle by 2 to get better resolution Toggle the sign bit and set the '_quad' flag If the angle is in quadrant 2, adjust it to quadrant 1 If the low byte negation causes a carry, negate the upper byte If the angle is in quadrant 3, adjust it to quadrant 4 Check if the angle is less than -16384 (-90°) Check if the angle is greater than 16383 (90°) Calculates the sine and cosine of the given angle Output the calculated angle and hypotenuse values sin_cos: input ang, output x = sin and y = cos LICENSE: Users are free to use, modify, and distribute this code DESCRIPTION: This file contains functions implementing the COORDIC
