Searching \ for '[PIC]: CORDIC Arctan Function?' in subject line. ()
Help us get a faster server
FAQ page: www.piclist.com/techref/microchip/devices.htm?key=pic
Search entire site for: 'CORDIC Arctan Function?'.

Exact match. Not showing close matches.
'[PIC]: CORDIC Arctan Function?'
2001\04\05@172401 by

I'm working on a compass project where I have two magneto resistive sensors
connected to a couple PIC analog inputs.  This effectively generates a sin
and cos value for the angle of the magnetic field.  What is the trig,
CORDIC, or whatever function that I need to use to turn the sin and cos
value into a single angle value?

Thanks.

Mark P

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email listservmitvma.mit.edu with SET PICList DIGEST in the body

At 04:21 PM 4/5/01 -0500, Mark Peterson wrote:
>I'm working on a compass project where I have two magneto resistive sensors
>connected to a couple PIC analog inputs.  This effectively generates a sin
>and cos value for the angle of the magnetic field.  What is the trig,
>CORDIC, or whatever function that I need to use to turn the sin and cos
>value into a single angle value?

You're trying to convert rectangular to polar coordinates, I think.

--
Dave's Engineering Page: http://www.dvanhorn.org
Where's dave? http://www.findu.com/cgi-bin/find.cgi?kc6ete-9

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email listservmitvma.mit.edu with SET PICList DIGEST in the body

You want the arctangent.  That's tangent in, angle out.  And you
get the tangent from (sin/cos).  (Sine divided by cosine).

ArcTan is just the tangent table read backwards.

IANAM (I am not a mathematician) so count to 10 and look for
posted corrections before following my advice.

Barry

At 04:21 PM 4/5/01 -0500, you wrote:
{Quote hidden}

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email listservmitvma.mit.edu with SET PICList DIGEST in the body

The tangent goes infinite at 90 & 270 degrees.  Hard on conversions.  You might
try a sin & cos comparison, which will also give you the quadrant information
you need.

Jim

Barry Gershenfeld wrote:

{Quote hidden}

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email listservmitvma.mit.edu with SET PICList DIGEST in the body

On Thu, 5 Apr 2001, Mark Peterson wrote:

> I'm working on a compass project where I have two magneto resistive sensors
> connected to a couple PIC analog inputs.  This effectively generates a sin
> and cos value for the angle of the magnetic field.  What is the trig,
> CORDIC, or whatever function that I need to use to turn the sin and cos
> value into a single angle value?

http://www.dattalo.com/technical/software/pic/arctan.asm

For other trig/math functions:

http://www.dattalo.com/technical/software/software.html

Scott

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email listservmitvma.mit.edu with SET PICList DIGEST in the body

> I'm working on a compass project where I have two magneto resistive
sensors
> connected to a couple PIC analog inputs.  This effectively generates a sin
> and cos value for the angle of the magnetic field.  What is the trig,
> CORDIC, or whatever function that I need to use to turn the sin and cos
> value into a single angle value?

Arctangent.

********************************************************************
Olin Lathrop, embedded systems consultant in Littleton Massachusetts
(978) 742-9014, olinembedinc.com, http://www.embedinc.com

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email listservmitvma.mit.edu with SET PICList DIGEST in the body

> The tangent goes infinite at 90 & 270 degrees.  Hard on conversions.

Right, that's why you don't do SIN/COS and take the arctangent.  You use SIN
and COS separately in the arctangent process.  Most math libraries have a
routine for this, usually called something like ARCTAN2.

********************************************************************
Olin Lathrop, embedded systems consultant in Littleton Massachusetts
(978) 742-9014, olinembedinc.com, http://www.embedinc.com

--
http://www.piclist.com hint: To leave the PICList
piclist-unsubscribe-requestmitvma.mit.edu

As I mentioned earlier, you might try a sin & cos comparison, which will also
you need.  To elaborate on that, doing an arcsin will give you two possible
angles.  Doing an arccos will give you two possible angles, one of which will
be identical to the output from the arcsin, and is the angle you are looking
for.  You will then need to do some quadrant arithmetic.  I'm sure  you're
already aware that the usual azimuth convention sets 0 at north which is a 90
degree offset from the usual math convention, and that the azimuth angles
increase in the opposite direction from the usual math convention.  Don't you
need a third sensor to derive the dip of the field (tip angle)?

Jim

Barry Gershenfeld wrote:

> You want the arctangent.  That's tangent in, angle out.  And you

Mark Peterson wrote:

{Quote hidden}

--
http://www.piclist.com hint: To leave the PICList
piclist-unsubscribe-requestmitvma.mit.edu

On Fri, 6 Apr 2001, Olin Lathrop wrote:

> > The tangent goes infinite at 90 & 270 degrees.  Hard on conversions.
>
> Right, that's why you don't do SIN/COS and take the arctangent.  You use SIN
> and COS separately in the arctangent process.  Most math libraries have a
> routine for this, usually called something like ARCTAN2.

True. The link to the arctan routine I posted yesterday performs more like the
"arctan" function and not the "arctan2". However, in this particular case the
sine and cosine values are known and so the quadrant can be determined. In my
routine, you need to know the octant. But again, that's easily determined...

So to use my routine you'd have to jump through this psuedo hoop:

s = sin value
c = cos value

angle = 0;
if(s<0) {
angle += 90;  // 90 degrees shift if sine is < 0
s += 1;       // make positive. note, you can't
// just take the absolute value
}

if(c<0) {
angle += 180;  // 180 degrees shift for cosine
c += 1;
}

if(c == 0)
return angle;

if(s>c) {
swap s and c
angle += 45;
}

ratio = s/c;

return angle + arctan(ratio);

The FRACDIC routine (within the arctan.asm link I posted earlier) does the
division and swapping.

Scott

--
http://www.piclist.com hint: To leave the PICList
piclist-unsubscribe-requestmitvma.mit.edu

Mark, I'm also working on a compass project using the Vector 2X module.
PNI has put the Vector 2X manual on their web site. It includes the math
to do calibration of the module in the raw mode. A great article on
using an electronic compass in robot navigation systems is in Circuit
Cellar, #81 April 1997. It goes into all the math and has a good
description of the CORDIC method.

http://www.pnicorp.com/prec.html
http://www.circellar.com/

- Tom

At 04:21 PM 4/5/01 -0500, Mark Peterson wrote:
{Quote hidden}

------------------------------------------------------------------------
Tom Handley
New Age Communications
Since '75 before "New Age" and no one around here is waiting for UFOs ;-)

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email listservmitvma.mit.edu with SET PICList DIGEST in the body

'[PIC]: CORDIC Arctan Function?'
2001\05\01@165418 by
Hi Mark.

Yes it is CORDIC. You are pushing one value down to
zero and two others are becoming magnitude and angle.
It's easy to search altavista for details.

WBR Dmitry.

> I'm working on a compass project where I have two magneto resistive sensors
> connected to a couple PIC analog inputs.  This effectively generates a sin
> and cos value for the angle of the magnetic field.  What is the trig,
> CORDIC, or whatever function that I need to use to turn the sin and cos
> value into a single angle value?
>
> Thanks. Mark P

--
http://www.piclist.com hint: To leave the PICList
piclist-unsubscribe-requestmitvma.mit.edu

More... (looser matching)
- Last day of these posts
- In 2001 , 2002 only
- Today
- New search...