2004 Microchip Technology Inc.
DS00908A-page 73
AN908
.word 0,1608,3212,4808,6393,7962,9512,11039
.word 12540,14010,15446,16846,18205,19520,20787,22005
.word 23170,24279,25330,26319,27245,28106,28898,29621
.word 30273,30852,31357,31785,32138,32413,32610,32728
.word 32767,32728,32610,32413,32138,31785,31357,30852
.word 30273,29621,28898,28106,27245,26319,25330,24279
.word 23170,22005,20787,19520,18205,16846,15446,14010
.word 12540,11039,9512,7962,6393,4808,3212,1608
.word 0,-1608,-3212,-4808,-6393,-7962,-9512,-11039
.word -12540,-14010,-15446,-16846,-18205,-19520,-20787,-22005
.word -23170,-24279,-25330,-26319,-27245,-28106,-28898,-29621
.word -30273,-30852,-31357,-31785,-32138,-32413,-32610,-32728
.word -32767,-32728,-32610,-32413,-32138,-31785,-31357,-30852
.word -30273,-29621,-28898,-28106,-27245,-26319,-25330,-24279
.word -23170,-22005,-20787,-19520,-18205,-16846,-15446,-14010
.word -12540,-11039,-9512,-7962,-6393,-4808,-3212,-1608
;=================== CODE =====================
.section
.text
.global
_SinCos
.global
SinCos
_SinCos:
SinCos:
;; Base of qAngle, qSin, qCos group in ParkParm structure
mov.w
#_P#Park_qAngle,ParkParmW
;; Calculate Index and Remainder for fetching and interpolating Sin
mov.w
#TableSize,Work0W
mov.w
[Pa+],Work1W
; load qAngle & inc ptr to qCos
mul.uu
Work0W,Work1W,RemainderW
; high word in IndexW
;; Double Index since offsets are in bytes not words
add.w
IndexW,IndexW,IndexW
;; Note at this point the IndexW register has a value 0x00nn where nn
;; is the offset in bytes from the TabBase. If below we always
;; use BYTE operations on the IndexW register it will automatically
;; wrap properly for a TableSize of 128.
mov.w
#SinTable,pTabBaseW ;
Pointer into table base
;; Check for zero remainder
cp0.w
RemainderW
bra
nz,jInterpolate
;; Zero remainder allows us to skip the interpolation and use the
;; table value directly
add.w
IndexW,pTabBaseW,pTabPtrW
mov.w
[pTabPtrW],[Pa+]
; write qSin & inc pt to qCos
;; Add 0x40 to Sin index to get Cos index. This may go off end of
;; table but if we use only BYTE operations the wrap is automatic.
add.b
#0x40,IndexW
add.w
IndexW,pTabBaseW,pTabPtrW
mov.w
[pTabPtrW],[ParkParmW]
; write qCos
return
jInterpolate:
;; Get Y1-Y0 = SinTable[Index+1] - SinTable[Index]
add.w
IndexW,pTabBaseW,pTabPtrW
mov.w
[pTabPtrW],Y0W
; Y0
inc2.b
IndexW,IndexW
; (Index += 2)&0xFF