atan of the cordicobject
Hey,
I'trying to use the codicobject written by Gaham Stabler. However, I'm not really sure what value I should pass to the atan function of the object.
I have two pins that are getting values from two A/D converter, namely the sine and cosine, and I want to use these values to track my motor.
should I use the following code: after including and starting all the objects.
where I transform the value retrieved in cosPin and sinPin into decimal values
I'trying to use the codicobject written by Gaham Stabler. However, I'm not really sure what value I should pass to the atan function of the object.
I have two pins that are getting values from two A/D converter, namely the sine and cosine, and I want to use these values to track my motor.
should I use the following code: after including and starting all the objects.
cordic.atan(convertToDec(ina[noparse][[/noparse]cosPin])/convertToDec(ina[noparse][[/noparse]sinPin]))
where I transform the value retrieved in cosPin and sinPin into decimal values
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Paul Baker
Propeller Applications Engineer
Parallax, Inc.
As you will see if you look back at that thread, the choice of number to represent unity or pi is somewhat arbitrary, and I am not sure what Graham chose in the end. But it will certainly be a binary signed integer, and not involve any conversion to decimal. ATAN2 will involve two integers, and the ratio will be calculated by the program. Where did you download the object you are using?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
The object that i'm using, i got it from the thread you are referring to in your post. I did read and re-read that thread as well as the example (Gaphics_cordic.spin).
not really subject related, but I don't really think that it deserves a full threat.
If I want to check the execution time of my spin code can I do the following:
·If yes isn't this suppose to return the execution time each time.
Post Edited (Landry) : 4/22/2008 7:46:22 AM GMT
Graham
Firstly doing a simple division in Spin will not provide you with the fraction required for the atan where 1 = $FFFF_FFFF
So you should use the cordic.cart2polar function. This has two arguments, one is a pointer to the input arguments and another is a pointer to where you want the result to be placed.
The variables are defined in the order, R, theta, x, y when using cart2polar x is supplied as the pointer to the input arguments and the values stored in x and y are loaded in to the function. When complete the answers are loaded in to R and theta.
For the example above you get 141421 as the result for R and 536880225 for the angle, why because $FFFF_FFFF equates to 360 degrees and zero degrees. So 536880225 is actually 45 degrees (well 45.0007).
Perhaps interger maths is not really what you want but I hope this clears up how to use the (still unfinished) object.
Graham
p.s. Notice my code uses PropTerminal so you don't need a display for TV outputs.