Application: 1998 Digital Signal Processing Solutions
Application: 1998 Digital Signal Processing Solutions
Application: 1998 Digital Signal Processing Solutions
Application
Report
1998
Application
Report
Digital Sine-Wave Generation
Using the TMS320C2xx
SPRA179
July 1998
Texas Instruments and its subsidiaries (TI) reserve the right to make changes to their products
or to discontinue any product or service without notice, and advise customers to obtain the latest
version of relevant information to verify, before placing orders, that information being relied on
is current and complete. All products are sold subject to the terms and conditions of sale supplied
at the time of order acknowledgement, including those pertaining to warranty, patent
infringement, and limitation of liability.
In order to minimize risks associated with the customer’s applications, adequate design and
operating safeguards must be provided by the customer to minimize inherent or procedural
hazards.
TI assumes no liability for applications assistance or customer product design. TI does not
warrant or represent that any license, either express or implied, is granted under any patent right,
copyright, mask work right, or other intellectual property right of TI covering or relating to any
combination, machine, or process in which such semiconductor products or services might be
or are used. TI’s publication of information regarding any third party’s products or services does
not constitute TI’s approval, warranty or endorsement thereof.
List of Figures
1 The Formula and the Resulting Graph for Calculating the Table Interpolation
Value COS of an Angle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2 Direct Look-Up With Interpolation of Sine Calculation From 0 to 2*π With
a 0.015-Radian Step . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
3 Error Between the C Floating-Point Result and Direct Look-Up Calculation
From 0 to 2*π With a 0.015-Radian Step . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
4 Results of Direct Look-Up SIN From 0 to π/2 With a 0.0039-Radian Step . . . . . . . . . . . . . . . 7
5 Error Between the C Floating-Point Result and Direct Look-Up SINE Calculation
From 0 to π/4 With a 0.0039-Radian Step in Q15 Format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
6 Error Between the C Floating-Point Result and the Direct Look-Up SINE Calculation
From 0 to π/4 With a 0.0039-Radian Step in % . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
7 Formula for Calculating the Value SIN of an Angle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
8 Formula for Calculating the Value COS of an Angle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
9 Mathematical Series Sine Calculation From 0 to 2*π With a 0.015-Radian Step . . . . . . . . 13
10 Error Between the C Floating-Point Result and the Mathematical Series SINE
Calculation From 0 to 2*π With a 0.015-Radian Step . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
11 Results of Mathematical Series Sine From 0 to π/2 With a 0.0039-Radian Step . . . . . . . . . 15
12 Error Between the C Floating-Point Result and a Mathematical Series SINE
Calculation From 0 to π/4 With a 0.0039-Radian Step in Q15 Format . . . . . . . . . . . . . . . . . 16
13 Error Between the C Floating-Point Result and a Mathematical Series SINE
Calculation From 0 to π/4 With a 0.0039-Radian Step in % . . . . . . . . . . . . . . . . . . . . . . . . . . 17
iv SPRA179
Tables
List of Tables
1 Processor Utilization (Maximum) When Using Direct Look-up and Interpolation . . . . . . . . . 4
2 Memory Utilization When Using Direct Look-up and Interpolation . . . . . . . . . . . . . . . . . . . . . . 4
3 Processor Utilization (Maximum) When Using Mathematical Series . . . . . . . . . . . . . . . . . . . 11
4 Memory Utilization When Using Mathematical Series . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
ABSTRACT
This application report describes two methods for implementing a digital sine-wave
generator using the TMS320C2xx: the use of a direct look-up table with linear
interpolation, and the use of mathematical series. Both methods are explained in
terms of C-compatible and assembly-compatible functions. Formulas used for
calculating and graphing the results are included for each method to demonstrate
the differences.
1 Introduction
Sine-wave generators are fundamental building blocks of signal processing
systems for use in control applications. The following two methods
described in this application report are for implementing a digital sine-wave
generator using the TMS320C2xx:
• Direct look-up with linear interpolation to provide sine waves with a
minimum of harmonic distortion
• Realization of the sine/cosine functions with a mathematical series
The two methods respond to different constraints. The direct look-up
method is fast with minimal errors and is significant in ROM programming
requirements. The mathematical series method is fast and requires
minimum (ROM) programming but results in less precision.
2 SPRA179
Direct Look-Up and Linear Interpolation Method
2.2 Interpolation
Figure 1 shows the formula and the resulting graph for calculating the table
interpolation value COS(X) of an angle X.
y
y i+1
X –x Y=?
i ( y
Y = y + - y ) y
i x x i+ 1 i i
-
i+ 1 i
r = ratio x
x X x
i i+1
where:
{xi} = {first coordinates of the table},
{yi} = {second coordinates of the table},
i chosen so that xi < X < xi+1.
Figure 1. The Formula and the Resulting Graph for Calculating the Table
Interpolation Value COS of an Angle
2.3 Functions
Functions SINE, COSINE, and SINE + COSINE are illustrated by example
in the appendix. Conventions to interface with this function are:
• Input: ANGLE parameters are in the stack pointed by AR1. The value
of this angle is unsigned.
0° <-> 0000h
90° <-> 4000h
180° <-> 8000h
240° <-> C000h
• Output: COS(angle) or SIN(angle) are in ACCUMULATOR in Q15
format (–1 to 1–215).
Table 2 shows memory utilization when using the direct look-up and linear
interpolation method.
Table 2. Memory Utilization When Using Direct Look-Up and Interpolation
ROM REGISTERS RAM
FUNCTION STACKLEVELS
(WORDS) USED (WORDS)
SIN assembly call 32 + 100 3 1 In stack
4 SPRA179
Direct Look-Up and Linear Interpolation Method
Figure 3. Error Between the C Floating-Point Result and Direct Look-Up Calculation
From 0 to 2*π With a 0.015-Radian Step
6 SPRA179
Direct Look-Up and Linear Interpolation Method
Figure 4. Results of Direct Look-Up SIN From 0 to π/2 With a 0.0039-Radian Step
Figure 5. Error Between the C Floating-Point Result and the Direct Look-Up
SINE Calculation From 0 to π/4 With a 0.0039-Radian Step in Q15 Format
8 SPRA179
Direct Look-Up and Linear Interpolation Method
Figure 6. Error Between the C Floating-Point Result and the Direct Look-Up
SINE Calculation From 0 to π/4 With a 0.0039-Radian Step in %
10 SPRA179
Sine/Cosine With Mathematical Series
3.3 Functions
Functions SINE and COSINE are illustrated by example in the appendix.
Conventions to interface with these functions are:
• Input: ANGLE parameters are in the stack pointed to by AR1. The value
of this angle is unsigned.
0° <-> 0000h
90° <-> 4000h
180° <-> 8000h
240° or -90° <-> C000h
• Output: COS(angle) or SIN(angle) are in ACCUMULATOR in Q15
format (–1 to 1–215).
12 SPRA179
Sine/Cosine With Mathematical Series
Figure 10. Error Between the C Floating-Point Result and the Mathematical Series
SINE Calculation From 0 to 2*π With a 0.015-Radian Step
14 SPRA179
Sine/Cosine With Mathematical Series
Figure 12. Error Between the C Floating-Point Result and a Mathematical Series
SINE Calculation From 0 to π/4 With a 0.0039-Radian Step in Q15 Format
16 SPRA179
Sine/Cosine With Mathematical Series
Figure 13. Error Between the C Floating-Point Result and a Mathematical Series
SINE Calculation From 0 to π/4 With a 0.0039-Radian Step in %
void main()
{
double rad;
double a;
int c;
.
.
.
if (rad!=0.0) /*–π < rad < +π*/
c=(int)(32767*rad/3.1415927);
else
c=0;
a=ser_cos(c);
.
}
.def _ser_sin
.sect “vectors”
b _c_int0
b $
**********************************************************************************
* Main routine
**********************************************************************************
.text
_c_int0:
.
.
LAR AR1,#60h ;stack preparation
MAR *,AR1
A-2 SPRA179
Examples of a C Program and an Assembly Program Calling Sine and Cosine Functions
A.3 COS Function With Direct Look-Up and Linear Interpolation for
Assembly Program
**********************************************************************************
*Routine Name: COS *
*Project: DMC Mathematical Library *
*Originator: Pascal DORSTER (Texas Instruments) *
* *
*Description: COS function with Direct Look–up and *
* Interpolation Assembly calling function, *
* variables in s/w stack. *
* *
*Status: *
* *
*Processor: C2xx *
* *
*Calling convention: *
* Input : Angle in stack value 0–360 degrees <=>0h–FFFFh *
* Output : COS(angle)*32767, Q15, in ACCU *
* Pointed register AR1 *
* *
*Stack commentary: *
* Position of current register in Caps *
* Stack at beginning : angle/X *
* *
*Last Update: 16 Oct 96 *
*________________________________________________________________________________*
*Date of Mod | DESCRIPTION *
*––––––––––––––|–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––*
* *
**********************************************************************************
COS
MAR *–
LACC #4000h
ADDS * ;add 0.5 for COS
SACL *
LT *+ ;variable in size_sin
;*******stack : angle/X
LACC #64h
A-4 SPRA179
Examples of a C Program and an Assembly Program Calling Sine and Cosine Functions
SACL *
;*******stack : angle/TEMP
MPYU * ;integer position in the table
PAC ;in High part of Acc
SACH *+ ;remainder
;*******stack : angle/indice/X
SACL * ;
;*******stack : angle/indice/REMAINDER
LACC *,15
AND #0ffffh,15
SACH *–
;*******stack : angle/INDICE/remainder
BCND equal_sin,EQ
LACC #Table_sin ;address of beginning of the table
ADD *– ;address of the nearest first indice
;*******stack : ANGLE/indice/remainder
TBLR *+
;*******stack : y1/INDICE/remainder
ADD #1h
TBLR * ;Load Y2 with the ordinate of the
;*******stack : y1/Y2/remainder
;nearest second indice
LACC *–
;*******stack : Y1/y2/remainder
SUB *+ ;difference between the two Y value
;*******stack : y1/Y2/remainder
SACL *+
;*******stack : y1/temp/REMAINDER
LT *–
;*******stack : y1/TEMP/remainder
MPY *
;*******stack : y1/TEMP/remainder
SPH *– ;interpolation between Y1 and Y2
;*******stack : Y1/temp/remainder
LACC *+
;*******stack : y1/TEMP/remainder
ADD *,1 ;Y(Xdata) in ACCU
RET
equal_sin
LACC #Table_sin ;address of beginning of the table
ADD *– ;address of the pointed indice
;*******stack : RESULT/
TBLR *
LACC *+
end_interp_sin
RET
**********************************************************************************
* Table
**********************************************************************************
A-6 SPRA179
Examples of a C Program and an Assembly Program Calling Sine and Cosine Functions
A.4 COS Function With Direct Look-Up and Linear Interpolation for
C Program
**********************************************************************************
*Routine Name: _COS *
*Project: DMC Mathematical Library *
*Originator: Pascal DORSTER (Texas Instruments) *
* *
*Description: COS function with Direct Look–up and *
* Interpolation C calling function, variables in C stack. *
* Fully C compatible *
* *
*Status: *
* *
*Processor: C2xx *
* *
*Calling convention: *
* Input : Angle in stack value 0–360 degrees <=>0h–FFFFh *
* Output : COS(angle)*32767, Q15, in ACCU *
* Pointed register AR1 *
* *
*Stack commentary: *
* Position of current register in Caps *
* Stack at beginning : angle/X *
* *
*Last Update: 16 Oct 96 *
* *
*________________________________________________________________________________*
*Date of Mod | DESCRIPTION *
*––––––––––––––|–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––*
* | *
* | *
**********************************************************************************
_COS
ADRK #2 ;C compatibility
POPD *+
SAR AR1,*
LAR AR2,*,AR2
SBRK #3 ;C compatibility
SPM 0
LACC #4000h
ADDS * ;add 0.5 for COS
SACL *
LT *+ ;variable in size_sin
;*******stack : angle/X
LACC #64h
SACL *
;*******stack : angle/TEMP
MPYU * ;integer position in the table
PAC ;in High part of Acc
SACH *+ ;remainder
;*******stack : angle/indice/X
SACL * ;
;*******stack : angle/indice/REMAINDER
LACC *,15
AND #0ffffh,15
SACH *–
;*******stack : angle/INDICE/remainder
BCND equal_sin,EQ
LACC #Table_sin ;address of beginning of the table
ADD *– ;address of the nearest first indice
;*******stack : ANGLE/indice/remainder
TBLR *+
;*******stack : y1/INDICE/remainder
ADD #1h
TBLR * ;Load Y2 with the ordinate of the
;*******stack : y1/Y2/remainder
;nearest second indice
LACC *–
;*******stack : Y1/y2/remainder
SUB *+ ;difference between the two Y value
;*******stack : y1/Y2/remainder
SACL *+
;*******stack : y1/temp/REMAINDER
LT *–
A-8 SPRA179
Examples of a C Program and an Assembly Program Calling Sine and Cosine Functions
;*******stack : y1/TEMP/remainder
MPY *
;*******stack : y1/TEMP/remainder
SPH *– ;interpolation between Y1 and Y2
;*******stack : Y1/temp/remainder
LACC *+
;*******stack : y1/TEMP/remainder
ADD *,1,AR1 ;Y(Xdata) in ACCU
MAR *– ;C compatibility
PSHD *–
SBRK #1
RET
equal_sin
LACC #Table_sin ;address of beginning of the table
ADD *– ;address of the pointed indice
;*******stack : RESULT/
TBLR *
LACC *+,0,AR1
MAR *– ;C compatibility
PSHD *–
SBRK #1
RET
**********************************************************************************
* Table
**********************************************************************************
A.5 SIN Function With Direct Look-Up and Linear Interpolation for
Assembly Program
**********************************************************************************
*Routine Name: SIN *
*Project: DMC Mathematical Library *
*Originator: Pascal DORSTER (Texas Instruments) *
* *
*Description: SIN function with Direct Look–up and Interpolation *
* Assembly calling function, variables in s/w stack. *
* *
*Status: *
* *
*Processor: C2xx *
* *
*Calling convention: *
* Input : Angle in stack value 0–360 degrees <=>0h–FFFFh *
* Output : SIN(angle)*32767, Q15, in ACCU *
* Pointed register AR1 *
* *
*Stack commentary: *
* Position of current register in Caps *
* Stack at beginning : angle/X *
* *
* *
*Last Update: 16 Oct 96 *
*________________________________________________________________________________*
*Date of Mod | DESCRIPTION *
*––––––––––––––|–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––*
* | *
* | *
**********************************************************************************
SIN
MAR *+
LT *+ ;variable in size_sin
;*******stack : angle/X
LACC #64h
SACL *
A-10 SPRA179
Examples of a C Program and an Assembly Program Calling Sine and Cosine Functions
;*******stack : angle/TEMP
MPYU * ;integer position in the table
PAC ;in High part of Acc
SACH *+ ;remainder
;*******stack : angle/indice/X
SACL * ;
;*******stack : angle/indice/REMAINDER
LACC *,15
AND #0ffffh,15
SACH *–
;*******stack : angle/INDICE/remainder
BCND equal_sin,EQ
LACC #Table_sin ;address of beginning of the table
ADD *– ;address of the nearest first indice
;*******stack : ANGLE/indice/remainder
TBLR *+
;*******stack : y1/INDICE/remainder
ADD #1h
TBLR * ;Load Y2 with the ordinate of the
;*******stack : y1/Y2/remainder
;nearest second indice
LACC *–
;*******stack : Y1/y2/remainder
SUB *+ ;difference between the two Y value
;*******stack : y1/Y2/remainder
SACL *+
;*******stack : y1/temp/REMAINDER
LT *–
;*******stack : y1/TEMP/remainder
MPY *
;*******stack : y1/TEMP/remainder
SPH *– ;interpolation between Y1 and Y2
;*******stack : Y1/temp/remainder
LACC *+
;*******stack : y1/TEMP/remainder
ADD *,1 ;Y(Xdata) in ACCU
RET
equal_sin
end_interp_sin
RET
*********************************************************************************
* Table
*********************************************************************************
A-12 SPRA179
Examples of a C Program and an Assembly Program Calling Sine and Cosine Functions
A.6 SIN Function With Direct Look-Up and Linear Interpolation for
C Program
**********************************************************************************
*Routine Name: _SIN *
*Project: DMC Mathematical Library *
*Originator: Pascal DORSTER (Texas Instruments) *
* *
*Description: SIN function with Direct Look–up + Interpolation
*
* C calling function, variables in C stack. *
* Fully C compatible *
* *
*Status: *
* *
*Processor: C2x *
* *
*Calling convention: *
* Input : Angle in stack value 0–360 degrees <=>0h–FFFFh *
* Output : SIN(angle)*32767, Q15, in ACCU *
* Pointed register AR1 *
* *
*Stack commentary: *
* Position of current register in Caps *
* Stack at beginning : angle/X *
* *
* *
*Last Update: 16 Oct 96 *
* *
*________________________________________________________________________________*
*Date of Mod | DESCRIPTION *
*––––––––––––––|–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––*
* | *
* | *
**********************************************************************************
_SIN
ADRK #2 ;C compatibility
POPD *+
SAR AR1,*
LAR AR2,*,AR2
SBRK #3 ;C compatibility
SPM 0
LT *+ ;variable in size_sin
;*******stack : angle/X
LACC #64h
SACL *
;*******stack : angle/TEMP
MPYU * ;integer position in the table
PAC ;in High part of Acc
SACH *+ ;remainder
;*******stack : angle/indice/X
SACL * ;
;*******stack : angle/indice/REMAINDER
LACC *,15
AND #0ffffh,15
SACH *–
;*******stack : angle/INDICE/remainder
BCND equal_sin,EQ
LACC #Table_sin ;address of beginning of the table
ADD *– ;address of the nearest first indice
;*******stack : ANGLE/indice/remainder
TBLR *+
;*******stack : y1/INDICE/remainder
ADD #1h
TBLR * ;Load Y2 with the ordinate of the
;*******stack : y1/Y2/remainder
;nearest second indice
LACC *–
;*******stack : Y1/y2/remainder
SUB *+ ;difference between the two Y value
;*******stack : y1/Y2/remainder
SACL *+
;*******stack : y1/temp/REMAINDER
LT *–
;*******stack : y1/TEMP/remainder
A-14 SPRA179
Examples of a C Program and an Assembly Program Calling Sine and Cosine Functions
MPY *
;*******stack : y1/TEMP/remainder
SPH *– ;interpolation between Y1 and Y2
;*******stack : Y1/temp/remainder
LACC *+
;*******stack : y1/TEMP/remainder
ADD *,1,AR1 ;Y(Xdata) in ACCU
MAR *– ;C compatibility
PSHD *–
SBRK #1
RET
equal_sin
LACC #Table_sin ;address of beginning of the table
ADD *– ;address of the pointed indice
;*******stack : RESULT/...
TBLR *
LACC *+,0,AR1
;*******stack : result/X
MAR *– ;C compatibility
PSHD *–
SBRK #1
RET
**********************************************************************************
* Table
**********************************************************************************
Table_sin .include sine.tab
Table_sin_end
.word 0
A-16 SPRA179
Examples of a C Program and an Assembly Program Calling Sine and Cosine Functions
.word 27666
.word 26509
.word 25247
.word 23886
.word 22431
.word 20886
.word 19260
.word 17557
.word 15786
.word 13952
.word 12062
.word 10126
.word 8149
.word 6140
.word 4107
.word 2057
.word 0
.word –2057
.word –4107
.word –6140
.word –8149
.word –10126
.word –12062
.word –13952
.word –15786
.word –17557
.word –19260
.word –20886
.word –22431
.word –23886
.word –25247
.word –26509
.word –27666
.word –28714
.word –29648
.word –30466
.word –31163
.word –31738
.word –32187
.word –32509
.word –32702
.word –32767
.word –32702
.word –32509
.word –32187
.word –31738
.word –31163
.word –30466
.word –29648
.word –28714
.word –27666
.word –26509
.word –25247
.word –23886
.word –22431
.word –20886
.word –19260
.word –17557
.word –15786
.word –13952
.word –12062
.word –10126
.word –8149
.word –6140
.word –4107
.word –2057
A-18 SPRA179
Examples of a C Program and an Assembly Program Calling Sine and Cosine Functions
A.8 COS_SIN Function With Direct Look-Up and Linear Interpolation for
Assembly Program
**********************************************************************************
*Routine Name: COS_SIN *
*Project: DMC Mathematical Library *
*Originator: Pascal DORSTER (Texas Instruments) *
* *
*Description: COS+SIN function with Direct Look–up and Interpolation *
* Assembly calling function, variables in s/w stack. *
* *
*Status: *
* *
*Processor: C2xx *
* *
*Calling convention: *
* Input : Angle in stack value 0–360 degrees <=>0h–FFFFh *
* Output: *
* SIN(angle)*32767, Q15, in stack pointed by AR1–1 *
* COS(angle)*32767,Q15, in stack pointed by AR1 *
* Pointed register AR1 *
* *
*Stack commentary: *
* Position of current register in Caps *
* Stack at beginning : angle/X *
* *
*Last Update: 16 Oct 96 *
*________________________________________________________________________________*
*Date of Mod | DESCRIPTION *
*––––––––––––––|–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––*
* | *
* | *
**********************************************************************************
COS_SIN
MAR *+
LT *+ ;variable in size_sin
;*stack: angle/X
LACC #size_tab
SACL *
;*stack: angle/TEMP
MPYU * ;integer position in the table
PAC ;in High part of Acc
SACH *+ ;remainder
;*stack: angle/indice/X
SACL * ;
;*stack: angle/indice/REMAINDER
LACC *,15
AND #0ffffh,15
SACH *–
;*stack: angle/INDICE/remainder
BCND equal_sin,EQ
LACC #Table_sin_cos ;address of beginning of the table
ADD *– ;address of the nearest first indice
;*stack: ANGLE/indice/remainder
TBLR *+
;*stack: y1/INDICE/remainder
ADD #1h
TBLR *+ ;Load Y2 with the ordinate of the
;nearest second indice
;*stack: y1/y2/REMAINDER
ADRK #1
;*stack: y1/y2/remainder/X
ADD #18h
TBLR *+
;*stack: y1/y2/remainder/yy1/X
ADD #1h
TBLR * ;*stack: y1/y2/remainder/yy1/YY2
A-20 SPRA179
Examples of a C Program and an Assembly Program Calling Sine and Cosine Functions
;*stack: y1/y2/remainder/YY1
SBRK #1
;*stack: y1/y2/REMAINDER/yy1
MPY *
;*stack: y1/y2/REMAINDER/yy1
ADRK #2
;*stack: y1/y2/remainder/yy1/TEMP
SPH *– ;interpolation between Y1 and Y2
;*stack: Y1/y2/remainder/YY1/temp
LACC *+
;*stack: y1/y2/remainder/yy1/TEMP
ADD *–,1 ;Y(Xdata) in ACCU
;*stack: y1/y2/remainder/YY1
SACL *–
;*stack: y1/y2/REMAINDER/cos
;calculate sin interpolate
SBRK #1
;*stack: y1/Y2/remainder/cos
LACC *–
;*stack: Y1/y2/remainder
SUB *+ ;difference between the two Y value
;*stack: y1/Y2/remainder/cos
SACL *+
;*stack: y1/temp/REMAINDER/cos
LT *–
;*stack: y1/TEMP/remainder/cos
MPY *
;*stack: y1/TEMP/remainder/cos
SPH *– ;interpolation between Y1 and Y2
;*stack: Y1/temp/remainder/cos
LACC *+
;*stack: y1/TEMP/remainder/cos
ADD *–,1 ;Y(Xdata) in ACCU
;*stack: y1/temp/remainder/cos
SACL * ;*stack: SIN/temp/remainder/cos
ADRK #3
;*stack: sin/temp/remainder/COS
LACC *
SBRK #2
;*stack: sin/TEMP/remainder/cos
SACL *
;*stack: sin/COS
RET
equal_sin
LALK Table_sin_cos ;address of beginning of the table
;*stack: angle/INDICE/remainder
ADD *– ;address of the pointed indice
;*stack: ANGLE/indice
TBLR *+
;*stack: sin/INDICE/remainder
ADD #19h
TBLR *
;*stack: sin/COS
end_interp_sin
RET
**********************************************************************************
* Table
**********************************************************************************
A-22 SPRA179
Examples of a C Program and an Assembly Program Calling Sine and Cosine Functions
.word 27666
.word 26509
.word 25247
.word 23886
.word 22431
.word 20886
.word 19260
.word 17557
.word 15786
.word 13952
.word 12062
.word 10126
.word 8149
.word 6140
.word 4107
.word 2057
.word 0
.word –2057
.word –4107
.word –6140
.word –8149
.word –10126
.word –12062
.word –13952
.word –15786
.word –17557
.word –19260
.word –20886
.word –22431
.word –23886
.word –25247
.word –26509
.word –27666
.word –28714
.word –29648
.word –30466
.word –31163
.word –31738
A-24 SPRA179
Examples of a C Program and an Assembly Program Calling Sine and Cosine Functions
.word –32187
.word –32509
.word –32702
.word –32767
.word –32702
.word –32509
.word –32187
.word –31738
.word –31163
.word –30466
.word –29648
.word –28714
.word –27666
.word –26509
.word –25247
.word –23886
.word –22431
.word –20886
.word –19260
.word –17557
.word –15786
.word –13952
.word –12062
.word –10126
.word –8149
.word –6140
.word –4107
.word –2057
.word 0
.word 2057
.word 4107
.word 6140
.word 8149
.word 10126
.word 12062
.word 13952
.word 15786
.word 17557
.word 19260
.word 20886
.word 22431
.word 23886
.word 25247
.word 26509
.word 27666
.word 28714
.word 29648
.word 30466
.word 31163
.word 31738
.word 32187
.word 32509
.word 32702
A-26 SPRA179
Examples of a C Program and an Assembly Program Calling Sine and Cosine Functions
sin_ser
SETC SXM
MAR *–
LAC *
BCND angle_neg,LT
angle_pos
LT *+ ;variable in size_sin
;*stack : angle/X
MPY #0c90h ;abscissa scale modify degree –> rad
PAC
SACH *,4 ;angle in rad
;*stack : angle/RAD
LT *+
;*stack : angle/rad/X
MPY #985h ;0.0372
;
;PREG : angle * 0.0372
LACC #0C426h,13 ; in high ACCU
APAC ;ACCU : –0.2338 + angle * 0.0372
SACH * ,3 ;temporary value
;angle in TREG
MPY * ;multiply by temporary value
;temporary value
;*stack : angle/rad/TEMP
LACC #6f69h,10 ;0.0544
APAC ;ACCU: temp + 0.0544
SACH *,2 ;temp
;*stack : angle/RAD/temp
;angle in TREG
;*stack : angle/rad/TEMP
MPY * ;temp
LACC #7dc5h,13 ;0.9826
APAC ;ACCU=0.9826+temp
SACH *,3 ;treg = rad
;temp
MPY * ;rad * temp
;temp * angle
LACC #05532,4 ;0.0013
APAC
SACH * ,3 ;result
LACC *–
;*stack : angle/SIN
RET
A-28 SPRA179
Examples of a C Program and an Assembly Program Calling Sine and Cosine Functions
angle_neg
LT *+ ;variable in size_sin
;*stack : angle/X
MPY #0c90h ;abscisse scale modif degre –> rad
PAC
SACH *,4 ;angle in rad
;*stack : angle/RAD
LT *+
;*stack : angle/rad/X
MPY #985h ;0.0372
;
;PREG : angle * 0.0372
LACC #03bdah,13 ; in high ACCU
APAC ;ACCU : –0.2338 + angle * 0.0372
SACH * ,3 ;temporary value
;angle in TREG
MPY * ;multiply by temporary value
;temporary value
;*stack : angle/rad/TEMP
LACC #6f69h,10 ;0.0544
APAC ;ACCU: temp + 0.0544
SACH *,2 ;temp
;*stack : angle/RAD/temp
;angle in TREG
;*stack : angle/rad/TEMP
MPY * ;temp
LACC #7dc5h,13 ;0.9826
SPAC ;ACCU=0.9826+temp
SACH *,3 ;treg = rad
MPY * ;rad * temp
;temp * angle
LACC #05532,4 ;0.0013
APAC
SACH *,3 ;result
LACC *–
;*stack : angle/SIN
RET
_sin_ser
ADRK #2 ;C compatibility
POPD *+
SAR AR1,*
LAR AR2,*,AR2
SBRK #3 ;C compatibility
A-30 SPRA179
Examples of a C Program and an Assembly Program Calling Sine and Cosine Functions
SPM 0
SETC SXM
LACC *
BCND angle_neg,LT
angle_pos
LT *+ ;variable in size_sin
;*stack : angle/X
MPY #0c90h ;abscissa scale modify degree –> rad
;in
PAC
SACH *,4 ;angle in rad
;*stack : angle/RAD
LT *+
;*stack : angle/rad/X
MPY #985h ;0.0372
;
;PREG : angle * 0.0372
LACC #0C426h,13 ; in high ACCU
APAC ;ACCU : –0.2338 + angle * 0.0372
SACH * ,3 ;temporary value
;angle in TREG
MPY * ;multiply by temporary value
;temporary value
;*stack : angle/rad/TEMP
LACC #6f69h,10 ;0.0544
APAC ;ACCU: temp + 0.0544
SACH *,2 ;temp
;*stack : angle/RAD/temp
;angle in TREG
;*stack : angle/rad/TEMP
MPY * ;temp
LACC #7dc5h,13 ;0.9826
APAC ;ACCU=0.9826+temp
SACH *,3 ;treg = rad
;temp
MPY * ;rad * temp
;temp * angle
LACC #05532,4 ;0.0013
APAC
SACH * ,3 ;result
LACC *–,0,AR1
;*stack : angle/SIN
MAR *– ;C compatibility
PSHD *–
SBRK #1
RET
angle_neg
LT *+ ;variable in size_sin
;*stack : angle/X
MPY #0c90h ;abscisse scale modif degre –> rad
PAC
SACH *,4 ;angle in rad
;*stack : angle/RAD
LT *+
;*stack : angle/rad/X
MPY #985h ;0.0372
;
;PREG : angle * 0.0372
LACC #03bdah,13 ; in high ACCU
APAC ;ACCU : –0.2338 + angle * 0.0372
SACH * ,3 ;temporary value
;angle in TREG
MPY * ;multiply by temporary value
;temporary value
;*stack : angle/rad/TEMP
LACC #6f69h,10 ;0.0544
APAC ;ACCU: temp + 0.0544
SACH *,2 ;temp
;*stack : angle/RAD/temp
;angle in TREG
;*stack : angle/rad/TEMP
MPY * ;temp
A-32 SPRA179
Examples of a C Program and an Assembly Program Calling Sine and Cosine Functions
RET
cos_ser
SETC SXM
MAR *–
LACC *
BCND angle_neg,LT
A-34 SPRA179
Examples of a C Program and an Assembly Program Calling Sine and Cosine Functions
angle_pos
LT *+ ;variable in size_sin
;*stack : angle/X
MPY #0c90h ;abscisse scale modif degre –> rad
PAC
SACH *,4 ;angle in rad
;*stack : angle/RAD
LT *+
;*stack : angle/rad/X
MPY #1070h ;0.0076 neg
;
;PREG : angle * 0.0076
LACC #01e76h,15 ; in high ACCU
APAC ;ACCU : +0.0595 + angle * 0.0076
SACH * ,3 ;temporary value
;angle in TREG
MPY * ;multiply by temporary value
;temporary value
;*stack : angle/rad/TEMP
LACC #0f532h,15 ;0.0211
APAC ;ACCU: temp + 0.0211
SACH * ;temp
;*stack : angle/RAD/temp
;angle in TREG
;*stack : angle/rad/TEMP
MPY * ;temp
LACC #0e0c6h,15 ;0.4879
APAC ;ACCU=0.9826+temp
SETC OVM
SACH *,3
LACC *,16
ADD *,16
SACH *
LACC *–
;*stack : angle/SIN
RET
angle_neg
LT *+ ;variable in size_sin
;*stack : angle/X
MPY #0c90h ;abscisse scale modif degre –> rad
PAC
SACH *,4 ;angle in rad
;*stack : angle/RAD
LT *+
;*stack : angle/rad/X
MPY #0f90h ;0.0076 neg
;
;PREG : angle * 0.0076
LACC #01e76h,15 ; in high ACCU
APAC ;ACCU : +0.0595 + angle * 0.0076
SACH * ,3 ;temporary value
;angle in TREG
MPY * ;multiply by temporary value
;temporary value
;*stack : angle/rad/TEMP
LACC #00aceh,15 ;0.0211
APAC ;ACCU: temp + 0.0211
SACH * ;temp
;*stack : angle/RAD/temp
;angle in TREG
;*stack : angle/rad/TEMP
MPY * ;temp
LACC #0e0c6h,15 ;0.4879
APAC ;ACCU=0.9826+temp
A-36 SPRA179
Examples of a C Program and an Assembly Program Calling Sine and Cosine Functions
_cos_ser
ADRK #2 ;C compatibility
POPD *+
SAR AR1,*
LAR AR2,*,AR2
SBRK #3 ;C compatibility
A-38 SPRA179
Examples of a C Program and an Assembly Program Calling Sine and Cosine Functions
SPM 0
SETC SXM
LAC *
BCND angle_neg,LT
angle_pos
LT *+ ;variable in size_sin
;*stack : angle/X
MPY #0c90h ;abscisse scale modif degre –> rad
PAC
SACH *,4 ;angle in rad
;*stack : angle/RAD
LT *+
;*stack : angle/rad/X
MPY #1070h ;0.0076 neg
;
;PREG : angle * 0.0076
LACC #01e76h,15 ; in high ACCU
APAC ;ACCU : +0.0595 + angle * 0.0076
SACH * ,3 ;temporary value
;angle in TREG
MPY * ;multiply by temporary value
;temporary value
;*stack : angle/rad/TEMP
LACC #0f532h,15 ;0.0211
APAC ;ACCU: temp + 0.0211
SACH * ;temp
;*stack : angle/RAD/temp
;angle in TREG
;*stack : angle/rad/TEMP
MPY * ;temp
LACC #0e0c6h,15 ;0.4879
APAC ;ACCU=0.9826+temp
RET
angle_neg
LT *+ ;variable in size_sin
;*stack : angle/X
MPY #0c90h ;abscisse scale modif degre –> rad
PAC
SACH *,4 ;angle in rad
;*stack : angle/RAD
LT *+
;*stack : angle/rad/X
MPY #0f90h ;0.0076 neg
;
;PREG : angle * 0.0076
LACC #01e76h,15 ; in high ACCU
APAC ;ACCU : +0.0595 + angle * 0.0076
SACH * ,3 ;temporary value
;angle in TREG
MPY * ;multiply by temporary value
A-40 SPRA179
Examples of a C Program and an Assembly Program Calling Sine and Cosine Functions
;temporary value
;*stack : angle/rad/TEMP
LACC #00aceh,15 ;0.0211
APAC ;ACCU: temp + 0.0211
SACH * ;temp
;*stack : angle/RAD/temp
;angle in TREG
;*stack : angle/rad/TEMP
MPY * ;temp
LACC #0e0c6h,15 ;0.4879
APAC ;ACCU=0.9826+temp
RET
ABSTRACT
This application report describes two methods for implementing a digital sine-wave
generator using the TMS320C2xx: the use of a direct look-up table with linear
interpolation, and the use of mathematical series. Both methods are explained in
terms of C-compatible and assembly-compatible functions. Formulas used for
calculating and graphing the results are included for each method to demonstrate
the differences.
B Introduction
Sine-wave generators are fundamental building blocks of signal processing
systems for use in control applications. The following two methods are
described in this application report for implementing a digital sine-wave
generator using the TMS320C2xx:
• Direct look-up with linear interpolation to provide sine waves with a
minimum of harmonic distortion
• Realization of the sine/cosine functions with a mathematical series
The two methods respond to different constraints. The direct look-up
method is fast with minimum errors and is significant in ROM programming
requirements. The mathematical series method is fast and requires
minimum (ROM) programming but results in less precision.
A-2 STDZ001A
Direct Look-Up and Linear Interpolation Method
C.2 Interpolation
Figure B–1 shows the formula and the resulting graph for calculating the
table interpolation value COS(X) of an angle X.
y
y i+1
X –x Y=?
i ( y
Y = y + - y ) y
i x x i+ 1 i i
-
i+ 1 i
r = ratio x
x X x
i i+1
where:
{xi} = {first coordinates of the table},
{yi} = {second coordinates of the table},
i chosen so that xi < X < xi+1.
Figure B–1. The Formula and the Resulting Graph for Calculating the Table
Interpolation Value COS of an Angle
Table interpolation is comprised of two steps:
1. Direct look-up: looking through the table to find the interval [xi, xi+1] at which the
considered angle X is located, with xi < X < xi+1.
• Interpolation: solving the above mentioned calculation to obtain Y.
C.3 Functions
Functions SINE, COSINE, and SINE + COSINE are illustrated by example
in the appendix. Conventions to interface with this function are:
• Input: ANGLE parameters are in the stack pointed by AR1. The value
of this angle is unsigned.
0° <-> 0000h
90° <-> 4000h
180° <-> 8000h
240° <-> C000h
• Output: COS(angle) or SIN(angle) are in ACCUMULATOR in Q15
format (–1 to 1–215).
Table E–2 shows memory utilization when using the direct look-up and
linear interpolation method.
Table E–2. Memory Utilization When Using Direct Look-Up and Interpolation
ROM REGISTERS RAM
FUNCTION STACKLEVELS
(WORDS) USED (WORDS)
SIN ssembly call 32 + 100 3 1 In stack
A-4 STDZ001A
Direct Look-Up and Linear Interpolation Method
Figure B–2. Direct Look-Up With Interpolation of Sine Calculation From 0 to 2*π
With a 0.015-Radian Step
Figure B–3. Error Between the C Floating-Point Result and Direct Look-Up
Calculation From 0 to 2*π With a 0.015-Radian Step
A-6 STDZ001A
Direct Look-Up and Linear Interpolation Method
Figure B–4. Results of Direct Look-Up SIN From 0 to π/2 With a 0.0039-Radian
Step
Figure B–5. Error Between the C Floating-Point Result and Direct Look-Up
SINE Calculation From 0 to π/4 With a 0.0039-Radian Step in Q15 Format
A-8 STDZ001A
Direct Look-Up and Linear Interpolation Method
Figure B–6. Error Between the C Floating-Point Result and Direct Look-Up
SINE Calculation From 0 to π/4 With a 0.0039-Radian Step in %
A-10 STDZ001A
Sine/Cosine With Mathematical Series
D.3 Functions
Functions SINE and COSINE are illustrated by example in the appendix.
Conventions to interface with these functions are:
• Input: ANGLE parameters are in the stack pointed toby AR1. The value
of this angle is unsigned.
0º <-> 0000h
90 º <-> 4000h
180 º <-> 8000h
240 º or -90º <-> C000h
• Output: COS(angle) or SIN(angle) are in ACCUMULATOR in Q15
format (–1 to 1–215).
Table E–4 shows memory utilization when using the mathematical series
method.
Table E–4. Memory Utilization When Using Mathematical Series
ROM STACK RAM
FUNCTION REGISTERS USED
(WORDS) LEVELS (WORDS)
SIN 54 3 1 In stack
COS 67 3 1 In stack
SIN 64 5 1 In stack
COS 77 5 1 In stack
COS and SIN 121 3 1 In stack
A-12 STDZ001A
Sine/Cosine With Mathematical Series
Figure B–10. Error Between the C Floating-Point Result and the Mathematical
Series
SINE Calculation From 0 to 2*π With a 0.015-Radian Step
A-14 STDZ001A
Sine/Cosine With Mathematical Series
A-16 STDZ001A
Sine/Cosine With Mathematical Series
void main()
{
double rad;
double a;
int c;
.
.
.
if (rad!=0.0) /*–π < rad < +π*/
c=(int)(32767*rad/3.1415927);
else
c=0;
a=ser_cos(c);
.
}
**********************************************************************************
*File Name: Main_trig.asm *
*Project: DMC Mathematical Library *
*Originator: Pascal DORSTER (Texas Instruments) *
A-1
* *
*Description: Very simple main which calls COS or SIN function *
* *
*Processor: C2xx *
*Status: *
*Last Update: 19 Oct 96 *
*________________________________________________________________________________*
*Date of Mod | DESCRIPTION *
*––––––––––––––|–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––*
* | *
**********************************************************************************
.mmregs
.def _ser_sin
.sect “vectors”
b _c_int0
b $
**********************************************************************************
* Main routine
**********************************************************************************
.text
_c_int0:
.
.
LAR AR1,#60h ;stack preparation
MAR *,AR1
A-2
LAC #4000h ;π/2
SACL *+ ;parameters in stack
CALL _ser_sin
. ;result in ACCU
.
.end
**********************************************************************************
*Routine Name: COS *
*Project: DMC Mathematical Library *
*Originator: Pascal DORSTER (Texas Instruments) *
* *
*Description: COS function with Direct Look–up and *
* Interpolation Assembly calling function, *
* variables in s/w stack. *
* *
*Status: *
* *
*Processor: C2xx *
* *
*Calling convention: *
* Input : Angle in stack value 0–360 degrees <=>0h–FFFFh *
* Output : COS(angle)*32767, Q15, in ACCU *
* Pointed register AR1 *
* *
*Stack commentary: *
* Position of current register in Caps *
* Stack at beginning : angle/X *
* *
*Last Update: 16 Oct 96 *
*________________________________________________________________________________*
*Date of Mod | DESCRIPTION *
*––––––––––––––|–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––*
* *
**********************************************************************************
COS
MAR *–
LAC #4000h
ADDS * ;add 0.5 for COS
A-3
SACL *
LT *+ ;variable in size_sin
;*******stack : angle/X
LAC #64h
SACL *
;*******stack : angle/TEMP
MPYU * ;integer position in the table
PAC ;in High part of Acc
SACH *+ ;remainder
;*******stack : angle/indice/X
SACL * ;
;*******stack : angle/indice/REMAINDER
LAC *,15
ANDK #0ffffh,15
SACH *–
;*******stack : angle/INDICE/remainder
BCND equal_sin,EQ
LALK Table_sin ;address of beginning of the table
ADD *– ;address of the nearest first indice
;*******stack : ANGLE/indice/remainder
TBLR *+
;*******stack : y1/INDICE/remainder
ADD #1h
TBLR * ;Load Y2 with the ordinate of the
;*******stack : y1/Y2/remainder
;nearest second indice
LAC *–
;*******stack : Y1/y2/remainder
SUB *+ ;difference between the two Y value
;*******stack : y1/Y2/remainder
SACL *+
;*******stack : y1/temp/REMAINDER
LT *–
;*******stack : y1/TEMP/remainder
MPY *
;*******stack : y1/TEMP/remainder
SPH *– ;interpolation between Y1 and Y2
;*******stack : Y1/temp/remainder
A-4
LAC *+
;*******stack : y1/TEMP/remainder
ADD *,1 ;Y(Xdata) in ACCU
RET
equal_sin
LALK Table_sin ;address of beginning of the table
ADD *– ;address of the pointed indice
;*******stack : RESULT/
TBLR *
LAC *+
end_interp_sin
RET
**********************************************************************************
* Table
**********************************************************************************
A-5
* *
*Stack commentary: *
* Position of current register in Caps *
* Stack at beginning : angle/X *
* *
*Last Update: 16 Oct 96 *
* *
*________________________________________________________________________________*
*Date of Mod | DESCRIPTION *
*––––––––––––––|–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––*
* | *
* | *
**********************************************************************************
_COS
ADRK 2 ;C compatibility
POPD *+
SAR AR1,*
LAR AR2,*,AR2
SBRK 3 ;C compatibility
SPM 0
LAC #4000h
ADDS * ;add 0.5 for COS
SACL *
LT *+ ;variable in size_sin
;*******stack : angle/X
LAC #64h
SACL *
;*******stack : angle/TEMP
MPYU * ;integer position in the table
PAC ;in High part of Acc
SACH *+ ;remainder
;*******stack : angle/indice/X
SACL * ;
;*******stack : angle/indice/REMAINDER
LAC *,15
ANDK #0ffffh,15
A-6
SACH *–
;*******stack : angle/INDICE/remainder
BCND equal_sin,EQ
LALK Table_sin ;address of beginning of the table
ADD *– ;address of the nearest first indice
;*******stack : ANGLE/indice/remainder
TBLR *+
;*******stack : y1/INDICE/remainder
ADD #1h
TBLR * ;Load Y2 with the ordinate of the
;*******stack : y1/Y2/remainder
;nearest second indice
LAC *–
;*******stack : Y1/y2/remainder
SUB *+ ;difference between the two Y value
;*******stack : y1/Y2/remainder
SACL *+
;*******stack : y1/temp/REMAINDER
LT *–
;*******stack : y1/TEMP/remainder
MPY *
;*******stack : y1/TEMP/remainder
SPH *– ;interpolation between Y1 and Y2
;*******stack : Y1/temp/remainder
LAC *+
;*******stack : y1/TEMP/remainder
ADD *,1,AR1 ;Y(Xdata) in ACCU
MAR *– ;C compatibility
PSHD *–
SBRK 1
RET
equal_sin
LALK Table_sin ;address of beginning of the table
ADD *– ;address of the pointed indice
;*******stack : RESULT/
TBLR *
LAC *+,0,AR1
A-7
MAR *– ;C compatibility
PSHD *–
SBRK 1
RET
**********************************************************************************
* Table
**********************************************************************************
A-8
*Date of Mod | DESCRIPTION *
*––––––––––––––|–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––*
* | *
* | *
**********************************************************************************
SIN
MAR *+
LT *+ ;variable in size_sin
;*******stack : angle/X
LAC #64h
SACL *
;*******stack : angle/TEMP
MPYU * ;integer position in the table
PAC ;in High part of Acc
SACH *+ ;remainder
;*******stack : angle/indice/X
SACL * ;
;*******stack : angle/indice/REMAINDER
LAC *,15
ANDK #0ffffh,15
SACH *–
;*******stack : angle/INDICE/remainder
BCND equal_sin,EQ
LALK Table_sin ;address of beginning of the table
ADD *– ;address of the nearest first indice
;*******stack : ANGLE/indice/remainder
TBLR *+
;*******stack : y1/INDICE/remainder
ADD #1h
TBLR * ;Load Y2 with the ordinate of the
;*******stack : y1/Y2/remainder
;nearest second indice
LAC *–
;*******stack : Y1/y2/remainder
SUB *+ ;difference between the two Y value
;*******stack : y1/Y2/remainder
SACL *+
A-9
;*******stack : y1/temp/REMAINDER
LT *–
;*******stack : y1/TEMP/remainder
MPY *
;*******stack : y1/TEMP/remainder
SPH *– ;interpolation between Y1 and Y2
;*******stack : Y1/temp/remainder
LAC *+
;*******stack : y1/TEMP/remainder
ADD *,1 ;Y(Xdata) in ACCU
RET
equal_sin
LALK Table_sin ;address of beginning of the table
ADD *– ;address of the pointed indice
;*******stack : RESULT/
TBLR *
LAC *+
;*******stack : result/X
end_interp_sin
RET
*********************************************************************************
* Table
*********************************************************************************
A-10
* *
*Status: *
* *
*Processor: C2x *
* *
*Calling convention: *
* Input : Angle in stack value 0–360 degrees <=>0h–FFFFh *
* Output : SIN(angle)*32767, Q15, in ACCU *
* Pointed register AR1 *
* *
*Stack commentary: *
* Position of current register in Caps *
* Stack at beginning : angle/X *
* *
* *
*Last Update: 16 Oct 96 *
* *
*________________________________________________________________________________*
*Date of Mod | DESCRIPTION *
*––––––––––––––|–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––*
* | *
* | *
**********************************************************************************
_SIN
ADRK 2 ;C compatibility
POPD *+
SAR AR1,*
LAR AR2,*,AR2
SBRK 3 ;C compatibility
SPM 0
LT *+ ;variable in size_sin
;*******stack : angle/X
LAC #64h
SACL *
;*******stack : angle/TEMP
MPYU * ;integer position in the table
A-11
PAC ;in High part of Acc
SACH *+ ;remainder
;*******stack : angle/indice/X
SACL * ;
;*******stack : angle/indice/REMAINDER
LAC *,15
ANDK #0ffffh,15
SACH *–
;*******stack : angle/INDICE/remainder
BCND equal_sin,EQ
LALK Table_sin ;address of beginning of the table
ADD *– ;address of the nearest first indice
;*******stack : ANGLE/indice/remainder
TBLR *+
;*******stack : y1/INDICE/remainder
ADD #1h
TBLR * ;Load Y2 with the ordinate of the
;*******stack : y1/Y2/remainder
;nearest second indice
LAC *–
;*******stack : Y1/y2/remainder
SUB *+ ;difference between the two Y value
;*******stack : y1/Y2/remainder
SACL *+
;*******stack : y1/temp/REMAINDER
LT *–
;*******stack : y1/TEMP/remainder
MPY *
;*******stack : y1/TEMP/remainder
SPH *– ;interpolation between Y1 and Y2
;*******stack : Y1/temp/remainder
LAC *+
;*******stack : y1/TEMP/remainder
ADD *,1,AR1 ;Y(Xdata) in ACCU
MAR *– ;C compatibility
PSHD *–
SBRK 1
RET
A-12
equal_sin
LALK Table_sin ;address of beginning of the table
ADD *– ;address of the pointed indice
;*******stack : RESULT/...
TBLR *
LAC *+,0,AR1
;*******stack : result/X
MAR *– ;C compatibility
PSHD *–
SBRK 1
RET
**********************************************************************************
* Table
**********************************************************************************
Table_sin .include sine.tab
Table_sin_end
.word 0
**********************************************************************************
* TABLE Sine and Cosine for separate functions COS and SIN *
**********************************************************************************
.word 0
.word 2057
.word 4107
.word 6140
.word 8149
.word 10126
.word 12062
.word 13952
.word 15786
.word 17557
.word 19260
.word 20886
.word 22431
.word 23886
.word 25247
.word 26509
.word 27666
.word 28714
A-13
.word 29648
.word 30466
.word 31163
.word 31738
.word 32187
.word 32509
.word 32702
.word 32767
.word 32702
.word 32509
.word 32187
.word 31738
.word 31163
.word 30466
.word 29648
.word 28714
.word 27666
.word 26509
.word 25247
.word 23886
.word 22431
.word 20886
.word 19260
.word 17557
.word 15786
.word 13952
.word 12062
.word 10126
.word 8149
.word 6140
.word 4107
.word 2057
.word 0
.word –2057
.word –4107
.word –6140
.word –8149
.word –10126
A-14
.word –12062
.word –13952
.word –15786
.word –17557
.word –19260
.word –20886
.word –22431
.word –23886
.word –25247
.word –26509
.word –27666
.word –28714
.word –29648
.word –30466
.word –31163
.word –31738
.word –32187
.word –32509
.word –32702
.word –32767
.word –32702
.word –32509
.word –32187
.word –31738
.word –31163
.word –30466
.word –29648
.word –28714
.word –27666
.word –26509
.word –25247
.word –23886
.word –22431
.word –20886
.word –19260
.word –17557
.word –15786
.word –13952
A-15
.word –12062
.word –10126
.word –8149
.word –6140
.word –4107
.word –2057
**********************************************************************************
*Routine Name: COS_SIN *
*Project: DMC Mathematical Library *
*Originator: Pascal DORSTER (Texas Instruments) *
* *
*Description: COS+SIN function with Direct Look–up and Interpolation *
* Assembly calling function, variables in s/w stack. *
* *
*Status: *
* *
*Processor: C2xx *
* *
*Calling convention: *
* Input : Angle in stack value 0–360 degrees <=>0h–FFFFh *
* Output: *
* SIN(angle)*32767, Q15, in stack pointed by AR1–1 *
* COS(angle)*32767,Q15, in stack pointed by AR1 *
* Pointed register AR1 *
* *
*Stack commentary: *
* Position of current register in Caps *
* Stack at beginning : angle/X *
* *
*Last Update: 16 Oct 96 *
*________________________________________________________________________________*
*Date of Mod | DESCRIPTION *
*––––––––––––––|–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––*
* | *
* | *
**********************************************************************************
A-16
COS_SIN
MAR *+
LT *+ ;variable in size_sin
;*stack: angle/X
LAC #size_tab
SACL *
;*stack: angle/TEMP
MPYU * ;integer position in the table
PAC ;in High part of Acc
SACH *+ ;remainder
;*stack: angle/indice/X
SACL * ;
;*stack: angle/indice/REMAINDER
LAC *,15
ANDK #0ffffh,15
SACH *–
;*stack: angle/INDICE/remainder
BCND equal_sin,EQ
LALK Table_sin_cos ;address of beginning of the table
ADD *– ;address of the nearest first indice
;*stack: ANGLE/indice/remainder
TBLR *+
;*stack: y1/INDICE/remainder
ADD #1h
TBLR *+ ;Load Y2 with the ordinate of the
;nearest second indice
;*stack: y1/y2/REMAINDER
ADRK 1
;*stack: y1/y2/remainder/X
ADD #18h
TBLR *+
;*stack: y1/y2/remainder/yy1/X
ADD #1h
TBLR * ;*stack: y1/y2/remainder/yy1/YY2
A-17
SUB *+ ;difference between the two Y value
;*stack: y1/y2/remainder/yy1/YY2
SACL * ;*stack: y1/y2/remainder/yy1/TEMP
LT *–
;*stack: y1/y2/remainder/YY1
SBRK 1
;*stack: y1/y2/REMAINDER/yy1
MPY *
;*stack: y1/y2/REMAINDER/yy1
ADRK 2
;*stack: y1/y2/remainder/yy1/TEMP
SPH *– ;interpolation between Y1 and Y2
;*stack: Y1/y2/remainder/YY1/temp
LAC *+
;*stack: y1/y2/remainder/yy1/TEMP
ADD *–,1 ;Y(Xdata) in ACCU
;*stack: y1/y2/remainder/YY1
SACL *–
;*stack: y1/y2/REMAINDER/cos
;calculate sin interpolate
SBRK 1
;*stack: y1/Y2/remainder/cos
LAC *–
;*stack: Y1/y2/remainder
SUB *+ ;difference between the two Y value
;*stack: y1/Y2/remainder/cos
SACL *+
;*stack: y1/temp/REMAINDER/cos
LT *–
;*stack: y1/TEMP/remainder/cos
MPY *
;*stack: y1/TEMP/remainder/cos
SPH *– ;interpolation between Y1 and Y2
;*stack: Y1/temp/remainder/cos
LAC *+
;*stack: y1/TEMP/remainder/cos
ADD *–,1 ;Y(Xdata) in ACCU
;*stack: y1/temp/remainder/cos
A-18
SACL * ;*stack: SIN/temp/remainder/cos
ADRK 3
;*stack: sin/temp/remainder/COS
LAC *
SBRK 2
;*stack: sin/TEMP/remainder/cos
SACL *
;*stack: sin/COS
RET
equal_sin
LALK Table_sin_cos ;address of beginning of the table
;*stack: angle/INDICE/remainder
ADD *– ;address of the pointed indice
;*stack: ANGLE/indice
TBLR *+
;*stack: sin/INDICE/remainder
ADDK 19h
TBLR *
;*stack: sin/COS
end_interp_sin
RET
**********************************************************************************
* Table
**********************************************************************************
A-19
.word 10126
.word 12062
.word 13952
.word 15786
.word 17557
.word 19260
.word 20886
.word 22431
.word 23886
.word 25247
.word 26509
.word 27666
.word 28714
.word 29648
.word 30466
.word 31163
.word 31738
.word 32187
.word 32509
.word 32702
.word 32767
.word 32702
.word 32509
.word 32187
.word 31738
.word 31163
.word 30466
.word 29648
.word 28714
.word 27666
.word 26509
.word 25247
.word 23886
.word 22431
.word 20886
.word 19260
.word 17557
.word 15786
A-20
.word 13952
.word 12062
.word 10126
.word 8149
.word 6140
.word 4107
.word 2057
.word 0
.word –2057
.word –4107
.word –6140
.word –8149
.word –10126
.word –12062
.word –13952
.word –15786
.word –17557
.word –19260
.word –20886
.word –22431
.word –23886
.word –25247
.word –26509
.word –27666
.word –28714
.word –29648
.word –30466
.word –31163
.word –31738
.word –32187
.word –32509
.word –32702
.word –32767
.word –32702
.word –32509
.word –32187
.word –31738
.word –31163
A-21
.word –30466
.word –29648
.word –28714
.word –27666
.word –26509
.word –25247
.word –23886
.word –22431
.word –20886
.word –19260
.word –17557
.word –15786
.word –13952
.word –12062
.word –10126
.word –8149
.word –6140
.word –4107
.word –2057
.word 0
.word 2057
.word 4107
.word 6140
.word 8149
.word 10126
.word 12062
.word 13952
.word 15786
.word 17557
.word 19260
.word 20886
.word 22431
.word 23886
.word 25247
.word 26509
.word 27666
.word 28714
.word 29648
A-22
.word 30466
.word 31163
.word 31738
.word 32187
.word 32509
.word 32702
**********************************************************************************
*Routine Name: sin_ser *
*Project: DMC Mathematical Library *
*Originator: Pascal DORSTER (Texas Instruments) *
* *
*Description: SIN function with Mathematical Series *
* Assembly calling function, variables in s/w stack. *
* *
*Status: *
* *
*Processor: C2xx *
* *
*Calling convention: *
* Input : Angle in stack value 0–360 degrees <=>0h–FFFFh *
* Output : SIN(angle)*32767, Q15, in ACCU *
* Pointed register AR1 *
* *
*Stack commentary: *
* Position of current register in Caps *
* Stack at beginning : angle/X *
* *
* *
*Last Update: 18 Oct 96 *
*________________________________________________________________________________*
*Date of Mod | DESCRIPTION *
*––––––––––––––|–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––*
* | *
* | *
**********************************************************************************
sin_ser
SETC SXM
A-23
MAR *–
LAC *
BCND angle_neg,LT
angle_pos
LT *+ ;variable in size_sin
;*stack : angle/X
MPYK 0c90h ;abscissa scale modify degree –> rad
PAC
SACH *,4 ;angle in rad
;*stack : angle/RAD
LT *+
;*stack : angle/rad/X
MPYK 985h ;0.0372
;
;PREG : angle * 0.0372
LAC #0C426h,13 ; in high ACCU
APAC ;ACCU : –0.2338 + angle * 0.0372
SACH * ,3 ;temporary value
;angle in TREG
MPY * ;multiply by temporary value
;temporary value
;*stack : angle/rad/TEMP
LAC #6f69h,10 ;0.0544
APAC ;ACCU: temp + 0.0544
SACH *,2 ;temp
;*stack : angle/RAD/temp
;angle in TREG
;*stack : angle/rad/TEMP
MPY * ;temp
LAC #7dc5h,13 ;0.9826
APAC ;ACCU=0.9826+temp
SACH *,3 ;treg = rad
;temp
MPY * ;rad * temp
;temp * angle
LAC #05532,4 ;0.0013
APAC
A-24
SACH * ,3 ;result
LAC *–
;*stack : angle/SIN
RET
angle_neg
LT *+ ;variable in size_sin
;*stack : angle/X
MPYK 0c90h ;abscisse scale modif degre –> rad
PAC
SACH *,4 ;angle in rad
;*stack : angle/RAD
LT *+
;*stack : angle/rad/X
MPYK 985h ;0.0372
;
;PREG : angle * 0.0372
LAC #03bdah,13 ; in high ACCU
APAC ;ACCU : –0.2338 + angle * 0.0372
SACH * ,3 ;temporary value
;angle in TREG
MPY * ;multiply by temporary value
;temporary value
;*stack : angle/rad/TEMP
LAC #6f69h,10 ;0.0544
APAC ;ACCU: temp + 0.0544
SACH *,2 ;temp
;*stack : angle/RAD/temp
;angle in TREG
;*stack : angle/rad/TEMP
MPY * ;temp
LAC #7dc5h,13 ;0.9826
SPAC ;ACCU=0.9826+temp
SACH *,3 ;treg = rad
MPY * ;rad * temp
;temp * angle
LAC #05532,4 ;0.0013
A-25
APAC
SACH *,3 ;result
LAC *–
;*stack : angle/SIN
RET
**********************************************************************************
*Routine Name: _sin_ser *
*Project: DMC Mathematical Library *
*Originator: Pascal DORSTER (Texas Instruments) *
* *
*Description: SIN function with Mathematical Series *
* C calling function, variables in C stack. *
* Fully C compatible *
* *
*Status: *
* *
*Processor: C2xx *
* *
*Calling convention: *
* Input : Angle in stack value 0–360 degrees <=>0h–FFFFh *
* Output : SIN(angle)*32767, Q15, in ACCU *
* Pointed register AR1 *
* *
*Stack commentary: *
* Position of current register in Caps *
* Stack at beginning : angle/X *
* *
*Last Update: 18 Oct 96 *
* *
*________________________________________________________________________________*
*Date of Mod | DESCRIPTION *
*––––––––––––––|–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––*
* | *
* | *
**********************************************************************************
_sin_ser
ADRK 2 ;C compatibility
A-26
POPD *+
SAR AR1,*
LAR AR2,*,AR2
SBRK 3 ;C compatibility
SPM 0
SETC SXM
LAC *
BCND angle_neg,LT
angle_pos
LT *+ ;variable in size_sin
;*stack : angle/X
MPYK 0c90h ;abscissa scale modify degree –> rad
;in
PAC
SACH *,4 ;angle in rad
;*stack : angle/RAD
LT *+
;*stack : angle/rad/X
MPYK 985h ;0.0372
;
;PREG : angle * 0.0372
LAC #0C426h,13 ; in high ACCU
APAC ;ACCU : –0.2338 + angle * 0.0372
SACH * ,3 ;temporary value
;angle in TREG
MPY * ;multiply by temporary value
;temporary value
;*stack : angle/rad/TEMP
LAC #6f69h,10 ;0.0544
APAC ;ACCU: temp + 0.0544
SACH *,2 ;temp
;*stack : angle/RAD/temp
;angle in TREG
;*stack : angle/rad/TEMP
MPY * ;temp
LAC #7dc5h,13 ;0.9826
A-27
APAC ;ACCU=0.9826+temp
SACH *,3 ;treg = rad
;temp
MPY * ;rad * temp
;temp * angle
LAC #05532,4 ;0.0013
APAC
SACH * ,3 ;result
LAC *–,0,AR1
;*stack : angle/SIN
MAR *– ;C compatibility
PSHD *–
SBRK 1
RET
angle_neg
LT *+ ;variable in size_sin
;*stack : angle/X
MPYK 0c90h ;abscisse scale modif degre –> rad
PAC
SACH *,4 ;angle in rad
;*stack : angle/RAD
LT *+
;*stack : angle/rad/X
MPYK 985h ;0.0372
;
;PREG : angle * 0.0372
LAC #03bdah,13 ; in high ACCU
APAC ;ACCU : –0.2338 + angle * 0.0372
SACH * ,3 ;temporary value
;angle in TREG
MPY * ;multiply by temporary value
;temporary value
;*stack : angle/rad/TEMP
LAC #6f69h,10 ;0.0544
APAC ;ACCU: temp + 0.0544
SACH *,2 ;temp
A-28
;*stack : angle/RAD/temp
;angle in TREG
;*stack : angle/rad/TEMP
MPY * ;temp
LAC #7dc5h,13 ;0.9826
SPAC ;ACCU=0.9826+temp
RET
**********************************************************************************
*Routine Name: cos_ser *
*Project: DMC Mathematical Library *
*Originator: Pascal DORSTER (Texas Instruments) *
* *
*Description: COS function with Mathematical Series *
* Assembly calling function, variables in s/w stack. *
* *
*Status: *
* *
*Processor: C2xx *
* *
* *
*Calling convention: *
* Input : Angle in stack value 0–360 degrees <=>0h–FFFFh *
* Output : COS(angle)*32767, Q15, in ACCU *
* Pointed register AR1 *
A-29
* *
*Stack commentary: *
* Position of current register in Caps *
* Stack at beginning : angle/X *
* *
* *
*Last Update: 18 Oct 96 *
*________________________________________________________________________________*
*Date of Mod | DESCRIPTION *
*––––––––––––––|–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––*
* | *
* | *
**********************************************************************************
cos_ser
SETC SXM
MAR *–
LAC *
BCND angle_neg,LT
angle_pos
LT *+ ;variable in size_sin
;*stack : angle/X
MPYK 0c90h ;abscisse scale modif degre –> rad
PAC
SACH *,4 ;angle in rad
;*stack : angle/RAD
LT *+
;*stack : angle/rad/X
MPYK 1070h ;0.0076 neg
;
;PREG : angle * 0.0076
LAC #01e76h,15 ; in high ACCU
APAC ;ACCU : +0.0595 + angle * 0.0076
SACH * ,3 ;temporary value
;angle in TREG
MPY * ;multiply by temporary value
;temporary value
A-30
;*stack : angle/rad/TEMP
LAC #0f532h,15 ;0.0211
APAC ;ACCU: temp + 0.0211
SACH * ;temp
;*stack : angle/RAD/temp
;angle in TREG
;*stack : angle/rad/TEMP
MPY * ;temp
LAC #0e0c6h,15 ;0.4879
APAC ;ACCU=0.9826+temp
angle_neg
LT *+ ;variable in size_sin
;*stack : angle/X
MPYK 0c90h ;abscisse scale modif degre –> rad
PAC
SACH *,4 ;angle in rad
;*stack : angle/RAD
LT *+
;*stack : angle/rad/X
A-31
MPYK 0f90h ;0.0076 neg
;
;PREG : angle * 0.0076
LAC #01e76h,15 ; in high ACCU
APAC ;ACCU : +0.0595 + angle * 0.0076
SACH * ,3 ;temporary value
;angle in TREG
MPY * ;multiply by temporary value
;temporary value
;*stack : angle/rad/TEMP
LAC #00aceh,15 ;0.0211
APAC ;ACCU: temp + 0.0211
SACH * ;temp
;*stack : angle/RAD/temp
;angle in TREG
;*stack : angle/rad/TEMP
MPY * ;temp
LAC #0e0c6h,15 ;0.4879
APAC ;ACCU=0.9826+temp
A-32
**********************************************************************************
*Routine Name: _cos_ser *
*Project: DMC Mathematical Library *
*Originator: Pascal DORSTER (Texas Instruments) *
* *
*Description: COS function with Mathematical Series *
* C calling function, *
* variables in C stack. Fully C compatible *
* *
*Status: *
* *
*Processor: C2xx *
* *
*Calling convention: *
* Input : Angle in stack value 0–360 degrees <=>0h–FFFFh *
* Output : COS(angle)*32767, Q15, in ACCU *
* Pointed register AR1 *
* *
*Stack commentary: *
* Position of current register in Caps *
* Stack at beginning : angle/X *
* *
*Last Update: 18 Oct 96 *
* *
*________________________________________________________________________________*
*Date of Mod | DESCRIPTION *
*––––––––––––––|–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––*
* | *
* | *
**********************************************************************************
_cos_ser
ADRK 2 ;C compatibility
POPD *+
SAR AR1,*
LAR AR2,*,AR2
SBRK 3 ;C compatibility
A-33
SPM 0
SETC SXM
LAC *
BCND angle_neg,LT
angle_pos
LT *+ ;variable in size_sin
;*stack : angle/X
MPYK 0c90h ;abscisse scale modif degre –> rad
PAC
SACH *,4 ;angle in rad
;*stack : angle/RAD
LT *+
;*stack : angle/rad/X
MPYK 1070h ;0.0076 neg
;
;PREG : angle * 0.0076
LAC #01e76h,15 ; in high ACCU
APAC ;ACCU : +0.0595 + angle * 0.0076
SACH * ,3 ;temporary value
;angle in TREG
MPY * ;multiply by temporary value
;temporary value
;*stack : angle/rad/TEMP
LAC #0f532h,15 ;0.0211
APAC ;ACCU: temp + 0.0211
SACH * ;temp
;*stack : angle/RAD/temp
;angle in TREG
;*stack : angle/rad/TEMP
MPY * ;temp
LAC #0e0c6h,15 ;0.4879
APAC ;ACCU=0.9826+temp
A-34
;temp * angle
LAC #0a440h,5 ;0.0028
APAC
SACH *,2 ;result
MPY * ;
LAC #1000h,15 ;1
APAC
SETC OVM
SACH *,3
LAC *,16
ADD *,16
SACH *
LAC *–,0,AR1
;*stack : angle/SIN
MAR *– ;C compatibility
PSHD *–
SBRK 1
RET
angle_neg
LT *+ ;variable in size_sin
;*stack : angle/X
MPYK 0c90h ;abscisse scale modif degre –> rad
PAC
SACH *,4 ;angle in rad
;*stack : angle/RAD
LT *+
;*stack : angle/rad/X
MPYK 0f90h ;0.0076 neg
;
;PREG : angle * 0.0076
LAC #01e76h,15 ; in high ACCU
APAC ;ACCU : +0.0595 + angle * 0.0076
SACH * ,3 ;temporary value
;angle in TREG
MPY * ;multiply by temporary value
;temporary value
A-35
;*stack : angle/rad/TEMP
LAC #00aceh,15 ;0.0211
APAC ;ACCU: temp + 0.0211
SACH * ;temp
;*stack : angle/RAD/temp
;angle in TREG
;*stack : angle/rad/TEMP
MPY * ;temp
LAC #0e0c6h,15 ;0.4879
APAC ;ACCU=0.9826+temp
RET
A-36
A-37
********************************************************************************
*File Name: Main_trig.c *
*Project: DMC Mathematical Library *
*Originator: Pascal DORSTER (Texas Instruments) *
*Description: Very simple main which calls COS or SIN function *
* *
* *
*Processor: C2xx *
* *
*Status: *
* *
*Last Update: 19 Oct 96 *
*______________________________________________________________________________*
*Date of Mod | DESCRIPTION *
*––––––––––––––|–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––*
* | *
********************************************************************************
extern ser_cos();
void main()
{
double rad;
double a;
int c;
.
.
.
if (rad!=0.0) /*–π < rad < +π*/
c=(int)(32767*rad/3.1415927);
else
c=0;
a=ser_cos(c);
.
}
**********************************************************************************
*File Name: Main_trig.asm *
*Project: DMC Mathematical Library *
*Originator: Pascal DORSTER (Texas Instruments) *
A-1
* *
*Description: Very simple main which calls COS or SIN function *
* *
*Processor: C2xx *
*Status: *
*Last Update: 19 Oct 96 *
*________________________________________________________________________________*
*Date of Mod | DESCRIPTION *
*––––––––––––––|–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––*
* | *
**********************************************************************************
.mmregs
.def _ser_sin
.sect “vectors”
b _c_int0
b $
**********************************************************************************
* Main routine
**********************************************************************************
.text
_c_int0:
.
.
LAR AR1,#60h ;stack preparation
MAR *,AR1
A-2
LAC #4000h ;π/2
SACL *+ ;parameters in stack
CALL _ser_sin
. ;result in ACCU
.
.end
**********************************************************************************
*Routine Name: COS *
*Project: DMC Mathematical Library *
*Originator: Pascal DORSTER (Texas Instruments) *
* *
*Description: COS function with Direct Look–up and *
* Interpolation Assembly calling function, *
* variables in s/w stack. *
* *
*Status: *
* *
*Processor: C2xx *
* *
*Calling convention: *
* Input : Angle in stack value 0–360 degrees <=>0h–FFFFh *
* Output : COS(angle)*32767, Q15, in ACCU *
* Pointed register AR1 *
* *
*Stack commentary: *
* Position of current register in Caps *
* Stack at beginning : angle/X *
* *
*Last Update: 16 Oct 96 *
*________________________________________________________________________________*
*Date of Mod | DESCRIPTION *
*––––––––––––––|–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––*
* *
**********************************************************************************
COS
MAR *–
LAC #4000h
ADDS * ;add 0.5 for COS
A-3
SACL *
LT *+ ;variable in size_sin
;*******stack : angle/X
LAC #64h
SACL *
;*******stack : angle/TEMP
MPYU * ;integer position in the table
PAC ;in High part of Acc
SACH *+ ;remainder
;*******stack : angle/indice/X
SACL * ;
;*******stack : angle/indice/REMAINDER
LAC *,15
ANDK #0ffffh,15
SACH *–
;*******stack : angle/INDICE/remainder
BCND equal_sin,EQ
LALK Table_sin ;address of beginning of the table
ADD *– ;address of the nearest first indice
;*******stack : ANGLE/indice/remainder
TBLR *+
;*******stack : y1/INDICE/remainder
ADD #1h
TBLR * ;Load Y2 with the ordinate of the
;*******stack : y1/Y2/remainder
;nearest second indice
LAC *–
;*******stack : Y1/y2/remainder
SUB *+ ;difference between the two Y value
;*******stack : y1/Y2/remainder
SACL *+
;*******stack : y1/temp/REMAINDER
LT *–
;*******stack : y1/TEMP/remainder
MPY *
;*******stack : y1/TEMP/remainder
SPH *– ;interpolation between Y1 and Y2
;*******stack : Y1/temp/remainder
A-4
LAC *+
;*******stack : y1/TEMP/remainder
ADD *,1 ;Y(Xdata) in ACCU
RET
equal_sin
LALK Table_sin ;address of beginning of the table
ADD *– ;address of the pointed indice
;*******stack : RESULT/
TBLR *
LAC *+
end_interp_sin
RET
**********************************************************************************
* Table
**********************************************************************************
A-5
* *
*Stack commentary: *
* Position of current register in Caps *
* Stack at beginning : angle/X *
* *
*Last Update: 16 Oct 96 *
* *
*________________________________________________________________________________*
*Date of Mod | DESCRIPTION *
*––––––––––––––|–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––*
* | *
* | *
**********************************************************************************
_COS
ADRK 2 ;C compatibility
POPD *+
SAR AR1,*
LAR AR2,*,AR2
SBRK 3 ;C compatibility
SPM 0
LAC #4000h
ADDS * ;add 0.5 for COS
SACL *
LT *+ ;variable in size_sin
;*******stack : angle/X
LAC #64h
SACL *
;*******stack : angle/TEMP
MPYU * ;integer position in the table
PAC ;in High part of Acc
SACH *+ ;remainder
;*******stack : angle/indice/X
SACL * ;
;*******stack : angle/indice/REMAINDER
LAC *,15
ANDK #0ffffh,15
A-6
SACH *–
;*******stack : angle/INDICE/remainder
BCND equal_sin,EQ
LALK Table_sin ;address of beginning of the table
ADD *– ;address of the nearest first indice
;*******stack : ANGLE/indice/remainder
TBLR *+
;*******stack : y1/INDICE/remainder
ADD #1h
TBLR * ;Load Y2 with the ordinate of the
;*******stack : y1/Y2/remainder
;nearest second indice
LAC *–
;*******stack : Y1/y2/remainder
SUB *+ ;difference between the two Y value
;*******stack : y1/Y2/remainder
SACL *+
;*******stack : y1/temp/REMAINDER
LT *–
;*******stack : y1/TEMP/remainder
MPY *
;*******stack : y1/TEMP/remainder
SPH *– ;interpolation between Y1 and Y2
;*******stack : Y1/temp/remainder
LAC *+
;*******stack : y1/TEMP/remainder
ADD *,1,AR1 ;Y(Xdata) in ACCU
MAR *– ;C compatibility
PSHD *–
SBRK 1
RET
equal_sin
LALK Table_sin ;address of beginning of the table
ADD *– ;address of the pointed indice
;*******stack : RESULT/
TBLR *
LAC *+,0,AR1
A-7
MAR *– ;C compatibility
PSHD *–
SBRK 1
RET
**********************************************************************************
* Table
**********************************************************************************
A-8
*Date of Mod | DESCRIPTION *
*––––––––––––––|–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––*
* | *
* | *
**********************************************************************************
SIN
MAR *+
LT *+ ;variable in size_sin
;*******stack : angle/X
LAC #64h
SACL *
;*******stack : angle/TEMP
MPYU * ;integer position in the table
PAC ;in High part of Acc
SACH *+ ;remainder
;*******stack : angle/indice/X
SACL * ;
;*******stack : angle/indice/REMAINDER
LAC *,15
ANDK #0ffffh,15
SACH *–
;*******stack : angle/INDICE/remainder
BCND equal_sin,EQ
LALK Table_sin ;address of beginning of the table
ADD *– ;address of the nearest first indice
;*******stack : ANGLE/indice/remainder
TBLR *+
;*******stack : y1/INDICE/remainder
ADD #1h
TBLR * ;Load Y2 with the ordinate of the
;*******stack : y1/Y2/remainder
;nearest second indice
LAC *–
;*******stack : Y1/y2/remainder
SUB *+ ;difference between the two Y value
;*******stack : y1/Y2/remainder
SACL *+
A-9
;*******stack : y1/temp/REMAINDER
LT *–
;*******stack : y1/TEMP/remainder
MPY *
;*******stack : y1/TEMP/remainder
SPH *– ;interpolation between Y1 and Y2
;*******stack : Y1/temp/remainder
LAC *+
;*******stack : y1/TEMP/remainder
ADD *,1 ;Y(Xdata) in ACCU
RET
equal_sin
LALK Table_sin ;address of beginning of the table
ADD *– ;address of the pointed indice
;*******stack : RESULT/
TBLR *
LAC *+
;*******stack : result/X
end_interp_sin
RET
*********************************************************************************
* Table
*********************************************************************************
A-10
* *
*Status: *
* *
*Processor: C2x *
* *
*Calling convention: *
* Input : Angle in stack value 0–360 degrees <=>0h–FFFFh *
* Output : SIN(angle)*32767, Q15, in ACCU *
* Pointed register AR1 *
* *
*Stack commentary: *
* Position of current register in Caps *
* Stack at beginning : angle/X *
* *
* *
*Last Update: 16 Oct 96 *
* *
*________________________________________________________________________________*
*Date of Mod | DESCRIPTION *
*––––––––––––––|–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––*
* | *
* | *
**********************************************************************************
_SIN
ADRK 2 ;C compatibility
POPD *+
SAR AR1,*
LAR AR2,*,AR2
SBRK 3 ;C compatibility
SPM 0
LT *+ ;variable in size_sin
;*******stack : angle/X
LAC #64h
SACL *
;*******stack : angle/TEMP
MPYU * ;integer position in the table
A-11
PAC ;in High part of Acc
SACH *+ ;remainder
;*******stack : angle/indice/X
SACL * ;
;*******stack : angle/indice/REMAINDER
LAC *,15
ANDK #0ffffh,15
SACH *–
;*******stack : angle/INDICE/remainder
BCND equal_sin,EQ
LALK Table_sin ;address of beginning of the table
ADD *– ;address of the nearest first indice
;*******stack : ANGLE/indice/remainder
TBLR *+
;*******stack : y1/INDICE/remainder
ADD #1h
TBLR * ;Load Y2 with the ordinate of the
;*******stack : y1/Y2/remainder
;nearest second indice
LAC *–
;*******stack : Y1/y2/remainder
SUB *+ ;difference between the two Y value
;*******stack : y1/Y2/remainder
SACL *+
;*******stack : y1/temp/REMAINDER
LT *–
;*******stack : y1/TEMP/remainder
MPY *
;*******stack : y1/TEMP/remainder
SPH *– ;interpolation between Y1 and Y2
;*******stack : Y1/temp/remainder
LAC *+
;*******stack : y1/TEMP/remainder
ADD *,1,AR1 ;Y(Xdata) in ACCU
MAR *– ;C compatibility
PSHD *–
SBRK 1
RET
A-12
equal_sin
LALK Table_sin ;address of beginning of the table
ADD *– ;address of the pointed indice
;*******stack : RESULT/...
TBLR *
LAC *+,0,AR1
;*******stack : result/X
MAR *– ;C compatibility
PSHD *–
SBRK 1
RET
**********************************************************************************
* Table
**********************************************************************************
Table_sin .include sine.tab
Table_sin_end
.word 0
**********************************************************************************
* TABLE Sine and Cosine for separate functions COS and SIN *
**********************************************************************************
.word 0
.word 2057
.word 4107
.word 6140
.word 8149
.word 10126
.word 12062
.word 13952
.word 15786
.word 17557
.word 19260
.word 20886
.word 22431
.word 23886
.word 25247
.word 26509
.word 27666
.word 28714
A-13
.word 29648
.word 30466
.word 31163
.word 31738
.word 32187
.word 32509
.word 32702
.word 32767
.word 32702
.word 32509
.word 32187
.word 31738
.word 31163
.word 30466
.word 29648
.word 28714
.word 27666
.word 26509
.word 25247
.word 23886
.word 22431
.word 20886
.word 19260
.word 17557
.word 15786
.word 13952
.word 12062
.word 10126
.word 8149
.word 6140
.word 4107
.word 2057
.word 0
.word –2057
.word –4107
.word –6140
.word –8149
.word –10126
A-14
.word –12062
.word –13952
.word –15786
.word –17557
.word –19260
.word –20886
.word –22431
.word –23886
.word –25247
.word –26509
.word –27666
.word –28714
.word –29648
.word –30466
.word –31163
.word –31738
.word –32187
.word –32509
.word –32702
.word –32767
.word –32702
.word –32509
.word –32187
.word –31738
.word –31163
.word –30466
.word –29648
.word –28714
.word –27666
.word –26509
.word –25247
.word –23886
.word –22431
.word –20886
.word –19260
.word –17557
.word –15786
.word –13952
A-15
.word –12062
.word –10126
.word –8149
.word –6140
.word –4107
.word –2057
**********************************************************************************
*Routine Name: COS_SIN *
*Project: DMC Mathematical Library *
*Originator: Pascal DORSTER (Texas Instruments) *
* *
*Description: COS+SIN function with Direct Look–up and Interpolation *
* Assembly calling function, variables in s/w stack. *
* *
*Status: *
* *
*Processor: C2xx *
* *
*Calling convention: *
* Input : Angle in stack value 0–360 degrees <=>0h–FFFFh *
* Output: *
* SIN(angle)*32767, Q15, in stack pointed by AR1–1 *
* COS(angle)*32767,Q15, in stack pointed by AR1 *
* Pointed register AR1 *
* *
*Stack commentary: *
* Position of current register in Caps *
* Stack at beginning : angle/X *
* *
*Last Update: 16 Oct 96 *
*________________________________________________________________________________*
*Date of Mod | DESCRIPTION *
*––––––––––––––|–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––*
* | *
* | *
**********************************************************************************
A-16
COS_SIN
MAR *+
LT *+ ;variable in size_sin
;*stack: angle/X
LAC #size_tab
SACL *
;*stack: angle/TEMP
MPYU * ;integer position in the table
PAC ;in High part of Acc
SACH *+ ;remainder
;*stack: angle/indice/X
SACL * ;
;*stack: angle/indice/REMAINDER
LAC *,15
ANDK #0ffffh,15
SACH *–
;*stack: angle/INDICE/remainder
BCND equal_sin,EQ
LALK Table_sin_cos ;address of beginning of the table
ADD *– ;address of the nearest first indice
;*stack: ANGLE/indice/remainder
TBLR *+
;*stack: y1/INDICE/remainder
ADD #1h
TBLR *+ ;Load Y2 with the ordinate of the
;nearest second indice
;*stack: y1/y2/REMAINDER
ADRK 1
;*stack: y1/y2/remainder/X
ADD #18h
TBLR *+
;*stack: y1/y2/remainder/yy1/X
ADD #1h
TBLR * ;*stack: y1/y2/remainder/yy1/YY2
A-17
SUB *+ ;difference between the two Y value
;*stack: y1/y2/remainder/yy1/YY2
SACL * ;*stack: y1/y2/remainder/yy1/TEMP
LT *–
;*stack: y1/y2/remainder/YY1
SBRK 1
;*stack: y1/y2/REMAINDER/yy1
MPY *
;*stack: y1/y2/REMAINDER/yy1
ADRK 2
;*stack: y1/y2/remainder/yy1/TEMP
SPH *– ;interpolation between Y1 and Y2
;*stack: Y1/y2/remainder/YY1/temp
LAC *+
;*stack: y1/y2/remainder/yy1/TEMP
ADD *–,1 ;Y(Xdata) in ACCU
;*stack: y1/y2/remainder/YY1
SACL *–
;*stack: y1/y2/REMAINDER/cos
;calculate sin interpolate
SBRK 1
;*stack: y1/Y2/remainder/cos
LAC *–
;*stack: Y1/y2/remainder
SUB *+ ;difference between the two Y value
;*stack: y1/Y2/remainder/cos
SACL *+
;*stack: y1/temp/REMAINDER/cos
LT *–
;*stack: y1/TEMP/remainder/cos
MPY *
;*stack: y1/TEMP/remainder/cos
SPH *– ;interpolation between Y1 and Y2
;*stack: Y1/temp/remainder/cos
LAC *+
;*stack: y1/TEMP/remainder/cos
ADD *–,1 ;Y(Xdata) in ACCU
;*stack: y1/temp/remainder/cos
A-18
SACL * ;*stack: SIN/temp/remainder/cos
ADRK 3
;*stack: sin/temp/remainder/COS
LAC *
SBRK 2
;*stack: sin/TEMP/remainder/cos
SACL *
;*stack: sin/COS
RET
equal_sin
LALK Table_sin_cos ;address of beginning of the table
;*stack: angle/INDICE/remainder
ADD *– ;address of the pointed indice
;*stack: ANGLE/indice
TBLR *+
;*stack: sin/INDICE/remainder
ADDK 19h
TBLR *
;*stack: sin/COS
end_interp_sin
RET
**********************************************************************************
* Table
**********************************************************************************
A-19
.word 10126
.word 12062
.word 13952
.word 15786
.word 17557
.word 19260
.word 20886
.word 22431
.word 23886
.word 25247
.word 26509
.word 27666
.word 28714
.word 29648
.word 30466
.word 31163
.word 31738
.word 32187
.word 32509
.word 32702
.word 32767
.word 32702
.word 32509
.word 32187
.word 31738
.word 31163
.word 30466
.word 29648
.word 28714
.word 27666
.word 26509
.word 25247
.word 23886
.word 22431
.word 20886
.word 19260
.word 17557
.word 15786
A-20
.word 13952
.word 12062
.word 10126
.word 8149
.word 6140
.word 4107
.word 2057
.word 0
.word –2057
.word –4107
.word –6140
.word –8149
.word –10126
.word –12062
.word –13952
.word –15786
.word –17557
.word –19260
.word –20886
.word –22431
.word –23886
.word –25247
.word –26509
.word –27666
.word –28714
.word –29648
.word –30466
.word –31163
.word –31738
.word –32187
.word –32509
.word –32702
.word –32767
.word –32702
.word –32509
.word –32187
.word –31738
.word –31163
A-21
.word –30466
.word –29648
.word –28714
.word –27666
.word –26509
.word –25247
.word –23886
.word –22431
.word –20886
.word –19260
.word –17557
.word –15786
.word –13952
.word –12062
.word –10126
.word –8149
.word –6140
.word –4107
.word –2057
.word 0
.word 2057
.word 4107
.word 6140
.word 8149
.word 10126
.word 12062
.word 13952
.word 15786
.word 17557
.word 19260
.word 20886
.word 22431
.word 23886
.word 25247
.word 26509
.word 27666
.word 28714
.word 29648
A-22
.word 30466
.word 31163
.word 31738
.word 32187
.word 32509
.word 32702
**********************************************************************************
*Routine Name: sin_ser *
*Project: DMC Mathematical Library *
*Originator: Pascal DORSTER (Texas Instruments) *
* *
*Description: SIN function with Mathematical Series *
* Assembly calling function, variables in s/w stack. *
* *
*Status: *
* *
*Processor: C2xx *
* *
*Calling convention: *
* Input : Angle in stack value 0–360 degrees <=>0h–FFFFh *
* Output : SIN(angle)*32767, Q15, in ACCU *
* Pointed register AR1 *
* *
*Stack commentary: *
* Position of current register in Caps *
* Stack at beginning : angle/X *
* *
* *
*Last Update: 18 Oct 96 *
*________________________________________________________________________________*
*Date of Mod | DESCRIPTION *
*––––––––––––––|–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––*
* | *
* | *
**********************************************************************************
sin_ser
SETC SXM
A-23
MAR *–
LAC *
BCND angle_neg,LT
angle_pos
LT *+ ;variable in size_sin
;*stack : angle/X
MPYK 0c90h ;abscissa scale modify degree –> rad
PAC
SACH *,4 ;angle in rad
;*stack : angle/RAD
LT *+
;*stack : angle/rad/X
MPYK 985h ;0.0372
;
;PREG : angle * 0.0372
LAC #0C426h,13 ; in high ACCU
APAC ;ACCU : –0.2338 + angle * 0.0372
SACH * ,3 ;temporary value
;angle in TREG
MPY * ;multiply by temporary value
;temporary value
;*stack : angle/rad/TEMP
LAC #6f69h,10 ;0.0544
APAC ;ACCU: temp + 0.0544
SACH *,2 ;temp
;*stack : angle/RAD/temp
;angle in TREG
;*stack : angle/rad/TEMP
MPY * ;temp
LAC #7dc5h,13 ;0.9826
APAC ;ACCU=0.9826+temp
SACH *,3 ;treg = rad
;temp
MPY * ;rad * temp
;temp * angle
LAC #05532,4 ;0.0013
APAC
A-24
SACH * ,3 ;result
LAC *–
;*stack : angle/SIN
RET
angle_neg
LT *+ ;variable in size_sin
;*stack : angle/X
MPYK 0c90h ;abscisse scale modif degre –> rad
PAC
SACH *,4 ;angle in rad
;*stack : angle/RAD
LT *+
;*stack : angle/rad/X
MPYK 985h ;0.0372
;
;PREG : angle * 0.0372
LAC #03bdah,13 ; in high ACCU
APAC ;ACCU : –0.2338 + angle * 0.0372
SACH * ,3 ;temporary value
;angle in TREG
MPY * ;multiply by temporary value
;temporary value
;*stack : angle/rad/TEMP
LAC #6f69h,10 ;0.0544
APAC ;ACCU: temp + 0.0544
SACH *,2 ;temp
;*stack : angle/RAD/temp
;angle in TREG
;*stack : angle/rad/TEMP
MPY * ;temp
LAC #7dc5h,13 ;0.9826
SPAC ;ACCU=0.9826+temp
SACH *,3 ;treg = rad
MPY * ;rad * temp
;temp * angle
LAC #05532,4 ;0.0013
A-25
APAC
SACH *,3 ;result
LAC *–
;*stack : angle/SIN
RET
**********************************************************************************
*Routine Name: _sin_ser *
*Project: DMC Mathematical Library *
*Originator: Pascal DORSTER (Texas Instruments) *
* *
*Description: SIN function with Mathematical Series *
* C calling function, variables in C stack. *
* Fully C compatible *
* *
*Status: *
* *
*Processor: C2xx *
* *
*Calling convention: *
* Input : Angle in stack value 0–360 degrees <=>0h–FFFFh *
* Output : SIN(angle)*32767, Q15, in ACCU *
* Pointed register AR1 *
* *
*Stack commentary: *
* Position of current register in Caps *
* Stack at beginning : angle/X *
* *
*Last Update: 18 Oct 96 *
* *
*________________________________________________________________________________*
*Date of Mod | DESCRIPTION *
*––––––––––––––|–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––*
* | *
* | *
**********************************************************************************
_sin_ser
ADRK 2 ;C compatibility
A-26
POPD *+
SAR AR1,*
LAR AR2,*,AR2
SBRK 3 ;C compatibility
SPM 0
SETC SXM
LAC *
BCND angle_neg,LT
angle_pos
LT *+ ;variable in size_sin
;*stack : angle/X
MPYK 0c90h ;abscissa scale modify degree –> rad
;in
PAC
SACH *,4 ;angle in rad
;*stack : angle/RAD
LT *+
;*stack : angle/rad/X
MPYK 985h ;0.0372
;
;PREG : angle * 0.0372
LAC #0C426h,13 ; in high ACCU
APAC ;ACCU : –0.2338 + angle * 0.0372
SACH * ,3 ;temporary value
;angle in TREG
MPY * ;multiply by temporary value
;temporary value
;*stack : angle/rad/TEMP
LAC #6f69h,10 ;0.0544
APAC ;ACCU: temp + 0.0544
SACH *,2 ;temp
;*stack : angle/RAD/temp
;angle in TREG
;*stack : angle/rad/TEMP
MPY * ;temp
LAC #7dc5h,13 ;0.9826
A-27
APAC ;ACCU=0.9826+temp
SACH *,3 ;treg = rad
;temp
MPY * ;rad * temp
;temp * angle
LAC #05532,4 ;0.0013
APAC
SACH * ,3 ;result
LAC *–,0,AR1
;*stack : angle/SIN
MAR *– ;C compatibility
PSHD *–
SBRK 1
RET
angle_neg
LT *+ ;variable in size_sin
;*stack : angle/X
MPYK 0c90h ;abscisse scale modif degre –> rad
PAC
SACH *,4 ;angle in rad
;*stack : angle/RAD
LT *+
;*stack : angle/rad/X
MPYK 985h ;0.0372
;
;PREG : angle * 0.0372
LAC #03bdah,13 ; in high ACCU
APAC ;ACCU : –0.2338 + angle * 0.0372
SACH * ,3 ;temporary value
;angle in TREG
MPY * ;multiply by temporary value
;temporary value
;*stack : angle/rad/TEMP
LAC #6f69h,10 ;0.0544
APAC ;ACCU: temp + 0.0544
SACH *,2 ;temp
A-28
;*stack : angle/RAD/temp
;angle in TREG
;*stack : angle/rad/TEMP
MPY * ;temp
LAC #7dc5h,13 ;0.9826
SPAC ;ACCU=0.9826+temp
RET
**********************************************************************************
*Routine Name: cos_ser *
*Project: DMC Mathematical Library *
*Originator: Pascal DORSTER (Texas Instruments) *
* *
*Description: COS function with Mathematical Series *
* Assembly calling function, variables in s/w stack. *
* *
*Status: *
* *
*Processor: C2xx *
* *
* *
*Calling convention: *
* Input : Angle in stack value 0–360 degrees <=>0h–FFFFh *
* Output : COS(angle)*32767, Q15, in ACCU *
* Pointed register AR1 *
A-29
* *
*Stack commentary: *
* Position of current register in Caps *
* Stack at beginning : angle/X *
* *
* *
*Last Update: 18 Oct 96 *
*________________________________________________________________________________*
*Date of Mod | DESCRIPTION *
*––––––––––––––|–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––*
* | *
* | *
**********************************************************************************
cos_ser
SETC SXM
MAR *–
LAC *
BCND angle_neg,LT
angle_pos
LT *+ ;variable in size_sin
;*stack : angle/X
MPYK 0c90h ;abscisse scale modif degre –> rad
PAC
SACH *,4 ;angle in rad
;*stack : angle/RAD
LT *+
;*stack : angle/rad/X
MPYK 1070h ;0.0076 neg
;
;PREG : angle * 0.0076
LAC #01e76h,15 ; in high ACCU
APAC ;ACCU : +0.0595 + angle * 0.0076
SACH * ,3 ;temporary value
;angle in TREG
MPY * ;multiply by temporary value
;temporary value
A-30
;*stack : angle/rad/TEMP
LAC #0f532h,15 ;0.0211
APAC ;ACCU: temp + 0.0211
SACH * ;temp
;*stack : angle/RAD/temp
;angle in TREG
;*stack : angle/rad/TEMP
MPY * ;temp
LAC #0e0c6h,15 ;0.4879
APAC ;ACCU=0.9826+temp
angle_neg
LT *+ ;variable in size_sin
;*stack : angle/X
MPYK 0c90h ;abscisse scale modif degre –> rad
PAC
SACH *,4 ;angle in rad
;*stack : angle/RAD
LT *+
;*stack : angle/rad/X
A-31
MPYK 0f90h ;0.0076 neg
;
;PREG : angle * 0.0076
LAC #01e76h,15 ; in high ACCU
APAC ;ACCU : +0.0595 + angle * 0.0076
SACH * ,3 ;temporary value
;angle in TREG
MPY * ;multiply by temporary value
;temporary value
;*stack : angle/rad/TEMP
LAC #00aceh,15 ;0.0211
APAC ;ACCU: temp + 0.0211
SACH * ;temp
;*stack : angle/RAD/temp
;angle in TREG
;*stack : angle/rad/TEMP
MPY * ;temp
LAC #0e0c6h,15 ;0.4879
APAC ;ACCU=0.9826+temp
A-32
**********************************************************************************
*Routine Name: _cos_ser *
*Project: DMC Mathematical Library *
*Originator: Pascal DORSTER (Texas Instruments) *
* *
*Description: COS function with Mathematical Series *
* C calling function, *
* variables in C stack. Fully C compatible *
* *
*Status: *
* *
*Processor: C2xx *
* *
*Calling convention: *
* Input : Angle in stack value 0–360 degrees <=>0h–FFFFh *
* Output : COS(angle)*32767, Q15, in ACCU *
* Pointed register AR1 *
* *
*Stack commentary: *
* Position of current register in Caps *
* Stack at beginning : angle/X *
* *
*Last Update: 18 Oct 96 *
* *
*________________________________________________________________________________*
*Date of Mod | DESCRIPTION *
*––––––––––––––|–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––*
* | *
* | *
**********************************************************************************
_cos_ser
ADRK 2 ;C compatibility
POPD *+
SAR AR1,*
LAR AR2,*,AR2
SBRK 3 ;C compatibility
A-33
SPM 0
SETC SXM
LAC *
BCND angle_neg,LT
angle_pos
LT *+ ;variable in size_sin
;*stack : angle/X
MPYK 0c90h ;abscisse scale modif degre –> rad
PAC
SACH *,4 ;angle in rad
;*stack : angle/RAD
LT *+
;*stack : angle/rad/X
MPYK 1070h ;0.0076 neg
;
;PREG : angle * 0.0076
LAC #01e76h,15 ; in high ACCU
APAC ;ACCU : +0.0595 + angle * 0.0076
SACH * ,3 ;temporary value
;angle in TREG
MPY * ;multiply by temporary value
;temporary value
;*stack : angle/rad/TEMP
LAC #0f532h,15 ;0.0211
APAC ;ACCU: temp + 0.0211
SACH * ;temp
;*stack : angle/RAD/temp
;angle in TREG
;*stack : angle/rad/TEMP
MPY * ;temp
LAC #0e0c6h,15 ;0.4879
APAC ;ACCU=0.9826+temp
A-34
;temp * angle
LAC #0a440h,5 ;0.0028
APAC
SACH *,2 ;result
MPY * ;
LAC #1000h,15 ;1
APAC
SETC OVM
SACH *,3
LAC *,16
ADD *,16
SACH *
LAC *–,0,AR1
;*stack : angle/SIN
MAR *– ;C compatibility
PSHD *–
SBRK 1
RET
angle_neg
LT *+ ;variable in size_sin
;*stack : angle/X
MPYK 0c90h ;abscisse scale modif degre –> rad
PAC
SACH *,4 ;angle in rad
;*stack : angle/RAD
LT *+
;*stack : angle/rad/X
MPYK 0f90h ;0.0076 neg
;
;PREG : angle * 0.0076
LAC #01e76h,15 ; in high ACCU
APAC ;ACCU : +0.0595 + angle * 0.0076
SACH * ,3 ;temporary value
;angle in TREG
MPY * ;multiply by temporary value
;temporary value
A-35
;*stack : angle/rad/TEMP
LAC #00aceh,15 ;0.0211
APAC ;ACCU: temp + 0.0211
SACH * ;temp
;*stack : angle/RAD/temp
;angle in TREG
;*stack : angle/rad/TEMP
MPY * ;temp
LAC #0e0c6h,15 ;0.4879
APAC ;ACCU=0.9826+temp
RET
A-36
A-37