Gerhard Fiedler wrote: > On 2008-12-30 04:39:48, solarwind wrote: > > > On Tue, Dec 30, 2008 at 1:20 AM, Vitaliy wrote: > >> Use a higher end PIC. ;-) > > > Anyway, I don't think I *need* a higher end pic, these pics work fine > > for what I need to do. I just need an accurate math library. If my 20 > > year old hp rpn calculator can accurately compute trig functions, I > > have no doubt that my state-of-the-art PIC 16F can do it. > > I have little doubt that it can do it, but you wanted to know how you > can make it do it -- efficiently :) > > So here's what I see as options (which definitely are not all possible > ones): > > - Make sure you don't have an error in your experiment with the HiTech > doubles that returned the wrong value. > - Fix the HiTech library. > - Use the Microchip library (AFAIK they have a floating point lib in > assembly) and integrate that with your HiTech build (not easy, but not > impossible either). > - Write your own library. > > The thing is that it's rather rare that someone uses floating point on a > 16F. What transcendental functions do you need? How fast? This last question is important in the choice between speed and size. In application implementation consider the use of trig identities to eliminate the need for libraries. (Define them with macros) Scale the problem most trig functions operate between + - 1.0 use a signed int and treat it as fract. Consider the use of a circle with 256 (or some other 2^^n) points instead or radians (or degrees) All of these can decrease the computational complexity. Some of the most efficient trig implementations have been developed by the computer gaming industry. (Google is your friend) SIN/COS has often been implemented as a simple table with linear interpretation. Scott Dattalo and others have regularly posted trig functions for small PIC's. Byte Craft implemented fixed point data types and used them for a transcendental library. The computational complexity of float vs fixed is very similar. Float gives larger dynamic range fixed increased precision. Our customers experience has been to effectively use trig functions on the small and medium PIC's Cordic on small processors with only single bit shifts may not be as efficient as alternatives. All the best in the New Year -- Walter Banks Byte Craft Limited http://www.bytecraft.com -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist