To answer your questions (A little more about the problem). Using Timer 1 on a 16C64 Micro, I wish to generate an acceleration profile. This profile is governed by the equation: N = 1/2 * a * t * t which is the standard positional equation based on time. I'm interested in obtaining the time that I have to wait before a whole unit of movement (ie until N = N + 1). This can be worked out to the equation below: dt = sqrt(2/a) * sqrt(N) - sqrt(N-1) Where N is the position and N-1 is the previous position. My current best uses Newton's method. Newton's method involves an iterative solution to the find the root of an equation. If we want to set up a standard newton's method to approximate the square root, we would set up an equation similar to: f(x) = x * x - r the derivative of which is f'(x) = x. Newton's method will converge at the root of a function, and is a recursive function as follows: Let A be the current approximation and Ap be the previous approximation, A = Ap - f'(Ap)/f(Ap) If you plug in the above to equations this yeilds the iterative approximation A = (Ap + r/Ap) / 2 so A is the square root of r. If I used the floating point math package, this would work, but I'd like to accomplish this in under 380 instruction cycles if possible. To eliminate floating point math, I decided to distribute the 32768 multiplier. This results in the need to do integer math (division, addition, and subtraction) on 40-bit (minimum) math. I'm not sure whether I can do this in my desired amount of instructions. -----Original Message----- From: Bob Buege To: PICLIST@MITVMA.MIT.EDU Date: Wednesday, November 05, 1997 1:11 PM Subject: Re: Algorithm Help >In a message dated 97-11-05 14:01:04 EST, Keith Ballantyne wrote: > >> I'm currently working on a project using a PIC16C64. I need to solve the >> following equation: >> >> T = sqrt(2/A) * ( sqrt(N) - sqrt(N-1) ) >> >> I've seen a number of spiffy square root routines, mostly derived from >> newton's method, but some other, more innovative ones as well. >> >> Any suggestions as to the most effecient way to do this. >> >> - Keith >> >Could you please send a few details about this equation? > >Are the numbers 8 bits, 16 bits, or larger? >Are A and N integers or fractions? >Are they positive or do you need to consider imaginary numbers? >What precision do you need for T? >What is the range for A and N? >Is there anything about the problem which will allow the substitution of an >easier equation which approximates >the actual equation for the range needed? >How much memory do you have left in your PIC for this equation? >Is speed, accuracy, or program space the major concern? > >Bob