Maker Pro
Maker Pro

PIC ARCTAN in assembler code

R

Roy

Jan 1, 1970
0
I want to know how to program ARCTAN in assembler code.

Any help appreciated

:-( Roy
 
T

Tim Daneliuk

Jan 1, 1970
0
Roy said:
I want to know how to program ARCTAN in assembler code.

Any help appreciated

:-( Roy

To truly compute it, you probably would have to do a MacLaurin Series:

http://mathworld.wolfram.com/InverseTangent.html

There are likely numerical methods to speed that up, however.

Depending on your problem domain and range, and the processor memory
capacity, it is frequently simpler to precompute a range of values,
store them in a table, and then interpolate as needed at runtime. This
tends to work well in PIC-type applications where you are not usually
looking for 14-digits of precision. This would be my preferred approach
assuming that I could store enough values to make interpolation reasonable
for the desired precision in the problem set...
 
U

Unbeliever

Jan 1, 1970
0
To truly compute it, you probably would have to do a MacLaurin Series:

http://mathworld.wolfram.com/InverseTangent.html

There are likely numerical methods to speed that up, however.

Depending on your problem domain and range, and the processor memory
capacity, it is frequently simpler to precompute a range of values,
store them in a table, and then interpolate as needed at runtime. This
tends to work well in PIC-type applications where you are not usually
looking for 14-digits of precision. This would be my preferred approach
assuming that I could store enough values to make interpolation reasonable
for the desired precision in the problem set...
--

Yepp, that's the way to do it. Unfortunately atan's a nasty function to
interpolate from a fixed interval domain. I've found that building a
logarithmic interval domain, using binary bit pattern is a useful approach.
One way I've achieved this in the past is by working with fixed point math
with an integer part in the high byte of a 16 bit word, and a fractional
part in the low order byte. Thus the values 1 to 65535 can represent the
numbers 1/256 to 255 and 255/256ths or about .004 to 255.996. A logarithmic
indexed lookup table of 32 entries can be made using the values 1, 2, 3, 4,
6, 8, 12, ... (2^n, 2^n + 2^(n-1), 2^(n+1), 2^(n+1)+2^n ... To get greater
accuracy at the expense of a large table you can use 3 bits instead of 2.
You can still get a reasonable approximation with a linear interpolation
from this, I worked out the maximum error once, but can't remember, I think
it was on the order of 0.1 degree for 32 entries.

I'm not sure if you'll find this method in any text book, as I came up with
it independently (but it probably does exist and is named after some Indian
mathematician, somewhere).

Cheers
 
S

Spehro Pefhany

Jan 1, 1970
0
I want to know how to program ARCTAN in assembler code.

Any help appreciated

Here's some C code suitable for 8-bit micros. Porting it to assembler
code in whatever processor you are using is left as an exercise. Often
ATAN2 is more useful in real applications.

http://www.abvolt.com/func.zip

Best regards,
Spehro Pefhany
 
W

Wim Ton

Jan 1, 1970
0
I want to know how to program ARCTAN in assembler code.

SNIP
To truly compute it, you probably would have to do a MacLaurin Series:
SNIP

If you first determine in which octant the result will be (from the sign and
magnitude of x and y) you will need only very few term of the series:
x -x**3/3 + x**5/5 -x**7/7 etc, as x<1 and the higher powers will deminish
quickly. With some experimenting with Excel, I found that x-x**3/5 gives a
deviation of maximum 3% in one octant

Wim
 
Top