On Mon, 31 Jan 2000, Phu T. Van wrote: > Hi. I've got a problem I don't quite know how to tackle. > I need to program the following function for a 16F84 : > > P(n) = x - (x^3/6) + (x^5/120) - (x^7/5040) > > I don't know what this approximation is called or if it really works the > way it's supposed to. I got it from a local math whiz; supposedly it > will approximate sine of x where x is the angle in radians. > > Anyhow, I need a reliable, fast and efficient way to calculate sine in > realtime to do navigation. I've heard about lookup tables but apparently > that is said to consume a huge amount of memory and processing power. > I'd like to stick with the PIC if possible. The fastest way to compute the sine function on a pic is with a lookup table. Period. I'll buy anyone a beer who can write a program (on a pic) that can evaluate the sine faster than: http://www.brouhaha.com/~eric/pic/sine.html You can't beat 13 cycles (or 6 if you know the quadrant of the angle prior to the call). But as I've said perhaps before, Eric's implementation does no linear interpolation between the samples. Consequently you'll get some 'stair stepping' or quantization errors. I have no idea what your ultimate application is, but if you need a more precise sine calculation then see: http://www.dattalo.com/technical/software/pic/picsine.html I've recently improved the execution time so that it only takes 48 cycles to compute the sine(). If you're using the 18cxxx family, then you may wish to consider this http://www.dattalo.com/technical/software/pic/sine18.asm This one only takes 30 cycles. If you wish to roll your own sine wave algorithm, then visit http://www.dattalo.com/technical/theory/sinewave.html Where you'll find a comparison of different techniques/algorithms for computing the sine(). As far as arbitrary math stuff, I'll add to the advice given by others by suggesting you visit: http://www.dattalo.com/technical/software/software.html There you'll find pic code for arcsine, arctan, sqrt, and logarithms. Scott