PDA

View Full Version : Arctangent



toofastdave
- 27th June 2006, 05:03
Hello,

I've been poking around for the last two weeks trying to find out how to do an arctangent function with the PIC and finally gave up and joined the forum. I am using a PIC16F628 to read the Parallax HM55B compass module. Unfortunately all of the code I've found is for the Basic Stamp and it doesn't cross in certain places due to the ATN function which is not available to the PIC. I broke down today and ordered a Math Coprocessor from Parallax and a Basic Stamp BS2P-SX just so I can get the compass calibrated and working (functional) to interface to the other half of my project, but I ultimately want to use the PIC if I can.

I did find some ASM code for arctangent but it's pretty confusing and I don't think everything is there to make the code work... I don't have the brain power to understand the ASM side of the PIC unfortunately.

Has anyone worked on something like this before that has any tips or help to offer? I would greatly appreciate anything that would get me going to convert the X, -x, y and -y to brads and then to degrees without having the ATN function available to me.

Can it even be done using PBP?

Thanks for ANY help on this.
Dave

paul borgmeier
- 27th June 2006, 07:42
As a start, skip the math coprocessor and use lookup tables. See these for ideas:

http://www.picbasic.co.uk/forum/showthread.php?t=3708
and
http://list.picbasic.com/forum/messages/8036/8055.html?1142608044
and
http://www.picbasic.co.uk/forum/showthread.php?t=1239&highlight=arctan
and
http://www.picbasic.co.uk/forum/showthread.php?t=718&highlight=Taylor
and
http://www.picbasic.co.uk/forum/showthread.php?t=3704&highlight=lookup

Good Luck,

Paul Borgmeier
Salt Lake City, Utah
USA

toofastdave
- 27th June 2006, 19:43
Awesome. That last link with the explanation from Melanie has got to be one of the best writeups I have even seen. I remember her from way back when I first started playing with PICs. It's been a while since I've broken out the box of PIC stuff but she still holds a place in my list of people to envy for her brain power.

Thanks for the links. I had seen a few of them before, but I hadn't seen Melanie' explanation. I'll sit down and try to digest all of that information tonight... and if nothing else, use the co-processor for the project until I can understand what she was trying to say in all of those formulas. I see it on the screen but may as well be reading Japanese at the moment.

Cheers,
Dave