Sin and Cos in Spin
Are there any objects already released that do Sin and Cos calculations.· If not, I could just use a floating point co-processor; I would just rather do it with software.
Thanks,
crgwbr
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
NerdMaster
For
Life
Thanks,
crgwbr
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
NerdMaster
For
Life

Comments
·
Here are a few routines that can be incorporated into any object.· Keep in mind, that the Propeller contains a ROM table for 1/4 of SIN.· Based on your degree value you either flip and/or mirror the data to get the proper quadrant. (The routine below does this for you).· The·SIN·angle is represented as a 13-bit value, while the returned value is represented as a signed 16-bit value.
·
PUB DEG2PROP(Deg) 'Convert Deg to 13-bit Propeller angle Result := (Deg * 1024)/45 PUB Cos(angle) 'Cos angle is 13-bit ; Returns a 16-bit signed value Result := sin(angle + $800) PUB Sin(angle) 'Sin angle is 13-bit ; Returns a 16-bit signed value Result := angle << 1 & $FFE if angle & $800 Result := word[noparse][[/noparse]$F000 - Result] else Result := word[noparse][[/noparse]$E000 + Result] if angle & $1000 -Result▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
So to use those routines, I would use something like:
PropAng := DEG2PROP(270)
CosAng := Cos(PropAng)
SinAng := Sin(PropAng)
Would this work?
Thanks Again,
crgwbr
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
NerdMaster
For
Life
CosAng := Cos(DEG2PROP(270))
SinAng := Sin(DEG2PROP(270))
Here is an alternaive method to code the Sin routine that resolves the 4 quadrants using a case statement:
PRI Sin(pangle) | q ' prop angle is 0 to 2^13 (0 to 8191) for 0 to 360 degrees q := pangle >> 11 ' quadrant is 2 highest bits result := (pangle & $7ff) << 1 ' 0 to 90- degrees, 11 bits, times two for word offset into sine table case q ' result by quadrant, lookup in HUB SINE table 0 : result := word[noparse][[/noparse]$E000 + result] 1 : result := word[noparse][[/noparse]$F000 - result] 2 : result := -word[noparse][[/noparse]$E000 + result] 3 : result := -word[noparse][[/noparse]$F000 - result] return▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
NerdMaster
For
Life
http://en.wikipedia.org/wiki/Cordic
My intention was to releas the code in two forms, assembly to be inserted in to other assembly programs and as a high speed cordic object. The cordic method can be used for other things like sqrt and 1/x so it could sit in a cog and just churn out what was asked of it. I just need time to sit down and put it together but after my move I am still no quite unpacked.
I did release a basic demo program here though:
http://forums.parallax.com/forums/default.aspx?f=25&m=150119
Graham
Thanks Anyway,
crgwbr
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
NerdMaster
For
Life