[more] Smoky Mountain Regional : 18d 15h 14m ... Orlando Regional : 25d 15h 14m ... Peachtree Regional : 32d 15h 14m ...
Go to Post Learn the ideas, look up the formulas. The other way round will drive you mad - Joe Johnson [more]
Home
Go Back   Chief Delphi > CD-Media > White Papers
Team 51   CD-Events   CD-Media   CD-Swap   CD-Spy   FRC-Spy   Unsung FIRST Heroes   WFA
portal register members calendar search Today's Posts Mark Forums Read FAQ rules
VEXpro
The Chief Delphi Forums are sponsored by Innovation First International, Inc.
221 Robotic Systems
ADVERTISEMENT

photos

papers

everything



CORDIC Trigonometric Math Library

By: Pat Fairbank
New: 07-25-2007 08:58 PM
Updated: 01-22-2008 09:51 PM
Total downloads: 741 times


Provides functions to calculate the sine and cosine of angles, and the magnitude and direction (arctangent) of Cartesian coordinates, using integer math and minimal memory space.

This is an updated version of Team 296's CORDIC trigonometric math library.

The CORDIC algorithm simultaneously calculates the sine and cosine of a given angle, or the
arctangent and magnitude of a given pair of co-ordinates, using only a small table of arctangent values and the bit-shift and addition/subtraction operators. This implementation uses 16-bit integer math throughout, and is generally accurate to within 0.01%.

Improvements from the last version include:
- Returning the sine & cosine (or arctangent & magnitude) in a structure so that both can be used
- 16-bit math instead of 24-bit math (because 24 bits is overkill)
- Re-writing of the functions from C to PIC assembly for a 2.5x speed increase

Instructions for use are found in trig.h.

Attached Files

  • zip CORDIC Trigonometric Math Library - Revision 2

    trig_rev2.zip

    downloaddownload file

    uploaded: 01-22-2008 09:51 PM
    filetype: zip
    filesize: 3.54kb
    downloads: 739



Recent Downloaders

  • Guest

Discussion

view entire thread

Reply

07-25-2007 09:10 PM

Pat Fairbank


Unread Re: paper: CORDIC Trigonometric Math Library

I felt like doing some programming, so I updated the CORDIC math library I posted a few years ago.

I made a few changes such as returning both the sine and cosine values instead of throwing one away (since CORDIC calculates both at once), and downgrading from 24-bit math to 16-bit math in the interest of speed. However, the biggest change is that the library is now written in PIC assembly instead of C, since I was curious to see if there was any speed advantage to be had.

I did some speed testing by calling the function as many times as possible in one Process_Data_From_Master_uP() loop before the RC crashed. The assembly implementation of the sin_cos() function took 4500 calls to crash while the C implementation took 1800 calls; the atan2_sqrt() function took 4700 and 1900, respectively. So it seems that the assembly implementation is about 2.5 times faster than the C implementation.

Any questions or comments are welcome.



01-22-2008 10:00 PM

Pat Fairbank


Unread Re: paper: CORDIC Trigonometric Math Library

I just uploaded a second revision to the trig library. There was a bug in the way the previous versions were handling the C function calls in assembly - the software stack wasn't being manipulated properly, with the result that the trig functions would work as expected when called from a function that didn't have local variables, but would return strange values when called from a function that did.

So if you're using the library and are seeing strange return values, you probably have an older version and need to update to Revision 2.



02-09-2008 12:15 AM

comphappy


Unread Re: paper: CORDIC Trigonometric Math Library

EDIT: Ignore this post, I can not delete it



02-09-2008 12:54 AM

neutrino15


Unread Re: paper: CORDIC Trigonometric Math Library

What is the advantage to using this vs a lookup table to the desired degree of accuracy?

How much more accurate and slow is the built in <math.h>?



02-09-2008 01:11 AM

Uberbots


Unread Re: paper: CORDIC Trigonometric Math Library

Quote:
Originally Posted by neutrino15 View Post
What is the advantage to using this vs a lookup table to the desired degree of accuracy?

How much more accurate and slow is the built in <math.h>?
Well, the math.h implementation can be called ~100 times per second (speed test that was posted on CD at some point this month), and this function takes a half second for 4500 calls (a half second being the max time a loop can execute before the OI says it 'crashed')

so id say its about... 90x faster?

someone call me on this if my math is wrong.



02-09-2008 01:36 AM

comphappy


Unread Re: paper: CORDIC Trigonometric Math Library

Ok i just found out what is needed to get this code to compile with the new 3.02 or higher compiler,
you need to replace all instances of AARGB3 with the new definition of __AARGB3
you can see the reference to this naming change here:
http://ww1.microchip.com/downloads/e...03-README.html
ref (27624)



view entire thread

Reply

Tags

loading ...



All times are GMT -5. The time now is 01:45 PM.

The Chief Delphi Forums are sponsored by Innovation First, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Copyright © Delphi and Pontiac Central High School