![Microchip Technology AN908 Using Manual Download Page 72](http://html1.mh-extra.com/html/microchip-technology/an908/an908_using-manual_1785807072.webp)
AN908
DS00908A-page 72
2004 Microchip Technology Inc.
Trig.s
;*******************************************************************
; Trig
;
; Description:
; Calculate Sine and Cosine for specified angle using linear interpolation
; on a table of 128 words.
;
; This routine works the same for both integer scaling and 1.15 scaling.
;
; For integer scaling the Angle is scaled such that 0 <= Angle < 2*pi
; corresponds to 0 <= Ang < 0xFFFF. The resulting Sin and Cos
; values are returned scaled to -32769 -> 32767 i.e. (0x8000 -> 0x7FFF).
;
; For 1.15 scaling the Angle is scaled such that -pi <= Angle < pi
; corresponds to -1 -> 0.9999 i.e. (0x8000 <= Ang < 0x7FFF). The
; resulting Sin and Cos values are returned scaled to -1 -> 0.9999
; i.e. (0x8000 -> 0x7FFF).
;
; Functional prototype:
;
void SinCos( void )
;
;
On Entry: ParkParm structure must contain qAngle
;
On Exit: ParkParm will contain qSin, qCos. qAngle is unchanged.
;
; Parameters:
; Input
arguments:
;
None
;
Return:
;
Void
;
SFR Settings required:
;
CORCON.IF = 0
;
Support routines required:
;
None
;
Local Stack usage:
;
0
;
Registers modified:
;
w0-w7
;
Timing:
;
About 28 instruction cycles
;*******************************************************************
;
.include "general.inc"
;
External references
.include "park.inc"
;
Constants
.equ TableSize,128
;
Local register usage
.equ Work0W,
w0
; Working register
.equ Work1W,
w1
; Working register
.equ RemainderW,
w2
; Fraction for interpolation: 0->0xFFFF
.equ IndexW,
w3
; Index into table
.equ pTabPtrW,
w4
; Pointer into table
.equ pTabBaseW,
w5
; Pointer into table base
.equ Y0W,
w6
; Y0 = SinTable[Index]
.equ ParkParmW,
w7
; Base of ParkParm structure
;; Note: RemainderW and Work0W must be even registers
;=================== LOCAL DATA =====================
.section .ndata, "d"
SinTable: