You are on page 1of 160

 





  


Application
Report

1998

Digital Signal Processing Solutions

Printed in U.S.A., July 1998

SPRA179






 


1998

Application
Report

Digital Sine-Wave Generation


Using the TMS320C2xx

SPRA179
July 1998

Printed on Recycled Paper

IMPORTANT NOTICE
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.
TI warrants performance of its semiconductor products to the specifications applicable at the
time of sale in accordance with TIs standard warranty. Testing and other quality control
techniques are utilized to the extent TI deems necessary to support this warranty. Specific testing
of all parameters of each device is not necessarily performed, except those mandated by
government requirements.
CERTAIN APPLICATIONS USING SEMICONDUCTOR PRODUCTS MAY INVOLVE
POTENTIAL RISKS OF DEATH, PERSONAL INJURY, OR SEVERE PROPERTY OR
ENVIRONMENTAL DAMAGE (CRITICAL APPLICATIONS). TI SEMICONDUCTOR
PRODUCTS ARE NOT DESIGNED, AUTHORIZED, OR WARRANTED TO BE SUITABLE FOR
USE IN LIFE-SUPPORT DEVICES OR SYSTEMS OR OTHER CRITICAL APPLICATIONS.
INCLUSION OF TI PRODUCTS IN SUCH APPLICATIONS IS UNDERSTOOD TO BE FULLY
AT THE CUSTOMERS RISK.
In order to minimize risks associated with the customers 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. TIs publication of information regarding any third partys products or services does
not constitute TIs approval, warranty or endorsement thereof.

Copyright 1998, Texas Instruments Incorporated

Contents
1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
2 Direct Look-Up and Linear Interpolation Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.1 C- and Assembly-Compatible Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.1.1 C-Compatible Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.1.2 Assembly-Compatible Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.2 Interpolation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.3 Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.4 System Utilization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.5 Sine-Generation Precision . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.5.1 One-Sine-Period Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.5.2 Quarter-Sine-Period Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3 Sine/Cosine With Mathematical Series . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3.1 C- and Assembly-Compatible Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3.1.1 C-Compatible Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3.1.2 Assembly-Compatible Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3.2 Sine/Cosine Mathematical Series . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3.3 Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3.4 System Utilization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3.5 Sine-Generation Precision . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3.5.1 One-Sine-Period Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3.5.2 Quarter-Sine-Period Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

2
2
2
2
3
3
3
4
4
7

10
10
10
10
11
11
11
12
13
14

Appendix A Examples of a C Program and an Assembly Program Calling Sine and


Cosine Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-1
A.1 Main C Program to Call Sine or Cosine Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-1
A.2 Main Assembly Program to Call Sine or Cosine Functions . . . . . . . . . . . . . . . . . . . . . . . A-2
A.3 COS Function With Direct Look-Up and Linear Interpolation for Assembly Program . A-4
A.4 COS Function With Direct Look-Up and Linear Interpolation for C Program . . . . . . . . A-7
A.5 SIN Function With Direct Look-Up and Linear Interpolation for
Assembly Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-10
A.6 SIN Function With Direct Look-Up and Linear Interpolation for C Program . . . . . . . . A-13
A.7 Table for COS or SIN Function With Direct Look-Up . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-16
A.8 COS_SIN Function With Direct Look-Up and Linear Interpolation for
Assembly Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-19
A.9 Table for COS_SIN Function With Direct Look-Up . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-23
A.10 SIN With Mathematical Series for Assembly Program . . . . . . . . . . . . . . . . . . . . . . . . . A-27
A.11 SIN With Mathematical Series for C Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-30
A.12 COS With Mathematical Series for Assembly Program . . . . . . . . . . . . . . . . . . . . . . . . A-34
A.13 COS With Mathematical Series for C Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-38

Digital Sine-Wave Generation Using the TMS320C2xx

iii

Figures

List of Figures
1

The Formula and the Resulting Graph for Calculating the Table Interpolation
Value COS of an Angle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

Direct Look-Up With Interpolation of Sine Calculation From 0 to 2* With


a 0.015-Radian Step . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

Error Between the C Floating-Point Result and Direct Look-Up Calculation


From 0 to 2* With a 0.015-Radian Step . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6

Results of Direct Look-Up SIN From 0 to /2 With a 0.0039-Radian Step . . . . . . . . . . . . . . . 7

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

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

Formula for Calculating the Value SIN of an Angle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11

Formula for Calculating the Value COS of an Angle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11

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
2
3
4

Processor Utilization (Maximum) When Using Direct Look-up and Interpolation . . . . . . . . . 4


Memory Utilization When Using Direct Look-up and Interpolation . . . . . . . . . . . . . . . . . . . . . . 4
Processor Utilization (Maximum) When Using Mathematical Series . . . . . . . . . . . . . . . . . . . 11
Memory Utilization When Using Mathematical Series . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12

Digital Sine-Wave Generation Using the TMS320C2xx

vi

SPRA179

Digital Sine-Wave Generation Using the TMS320C2xx


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.

Digital Sine-Wave Generation Using the TMS320C2xx

Direct Look-Up and Linear Interpolation Method

2 Direct Look-Up and Linear Interpolation Method


This section describes the Direct Look-Up and Linear Interpolation method
of implementing a digital sine-wave generator using the TMS320C2xx.

2.1

C- and Assembly-Compatible Functions


The Direct Look-Up method, which uses 100 sine-period values in a table,
reveals the sine/cosine functions. To provide minimum harmonic distortion,
the method includes linear interpolation with a fixed-step table. An extended
table is used for the cosine + sine function and is located in program memory.
Two versions of each function are presented:
C-compatible functions
Assembly-compatible functions
Examples of a C program and an assembly program (that call sine and
cosine functions) are in the appendix.

2.1.1

C-Compatible Functions
Fully C-compatible functions employ C conventions to use the stack for
parameters passed to the functions. Parameters returned by the functions
are passed by a pointer. Responsibilities of called functions are managed
in a postfix expression called the function designator. Stack pointer AR1 is
well-positioned, and the return address of the hardware stack is popped
(retrieved) in case of C-interrupt runtime events using C-function features
(stack). The frame pointer is not modified and registers AR6 and AR7 are
not used.

2.1.2

Assembly-Compatible Functions
Assembly-compatible functions do not use their own variables, but instead,
rely on variables in a software stack where arguments are passed. The AR1
register points to the stack just after the last argument. After the return from
the function, the results are placed in the stack. Registers AR0, AR6, and
AR7 are not modified.

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
Y=?

X x
Y

+
i

x
i+ 1
r =

i+1

( y

i+ 1

y )
i

ratio

x
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
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.
2. Interpolation: solving the above mentioned calculation to obtain Y.

2.3

Functions
Functions SINE, COSINE, and SINE + COSINE are illustrated by example
in the appendix. Conventions to interface with this function are:

2.4

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 1215).

System Utilization
Table 1 shows processor utilization when using the direct look-up and linear
interpolation methods.
Digital Sine-Wave Generation Using the TMS320C2xx

Direct Look-Up and Linear Interpolation Method

Table 1. Processor Utilization (Maximum) When Using


Direct Look-Up and Interpolation
FUNCTION

CYCLES

EXECUTION TIME

SIN assembly call

35

1.75 s

COS assembly call

38

1.90 s

SIN fully C-compatible

42

2.10 s

COS fully C-compatible

45

2.25 s

SIN + COS of an angle

58

2.90 s

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
FUNCTION

ROM
(WORDS)

STACKLEVELS

REGISTERS
USED

RAM
(WORDS)

SIN assembly call

32 + 100

In stack

COS assembly call

34 + 100

In stack

COS and SIN assembly call

66 + 100

In stack

SIN Fully C compatible

42 + 100

In stack

COS assembly call

44 + 100

In stack

COS + SIN in one function


assembly call

55 + 125

In stack

In the case of Sine + Cosine, the same table is used.

2.5

Sine-Generation Precision
Figure 2 and Figure 3 are graphs that present the precision of the direct
look-up and linear interpolation sine functions. The precision measurement
is made by comparing the direct look-up and the floating-point C library
results.

2.5.1

One-Sine-Period Analysis
The sine period provides a general image of error calculation. In Figure 2
and Figure 3, results of the sine calculation are in Q15 format.

SPRA179

Direct Look-Up and Linear Interpolation Method

Figure 2. Direct Look-Up With Interpolation of Sine Calculation From 0 to 2*


With a 0.015-Radian Step

Digital Sine-Wave Generation Using the TMS320C2xx

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

SPRA179

Direct Look-Up and Linear Interpolation Method

2.5.2

Quarter-Sine-Period Analysis
Figure 4, Figure 5, and Figure 6 graph another precise analysis using a
quarter of a half-sine period. In this case, the step is 0.0039 radian. The
interpolation is made at 0.125-radian intervals. In this way, interpolation
error is exposed on the following graphs. Each interval (table approximation)
is displayed with 32 pixels.

Figure 4. Results of Direct Look-Up SIN From 0 to /2 With a 0.0039-Radian Step

Digital Sine-Wave Generation Using the TMS320C2xx

Direct Look-Up and Linear Interpolation Method

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

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 %

Digital Sine-Wave Generation Using the TMS320C2xx

Sine/Cosine With Mathematical Series

3 Sine/Cosine With Mathematical Series


This section explains the second of two methods of implementing a digital
sine-wave generator using the TMS320C2xx.

3.1

C- and Assembly-Compatible Functions


The sine/cosine method calculates the sine/cosine functions with a
mathematical series for the sine period and a mathematical series for
cosine. Calculations are made with fixed-point instructions to optimize the
time calculation. The dynamics used in the calculation fit with maximum
precision without overflow.
Two versions of each function are presented:
C-compatible functions
Assembly-compatible functions
Examples of a C program and an assembly program (that call sine and
cosine functions) are in the appendix.

3.1.1

C-Compatible Functions
Fully C-compatible functions employ C conventions to use the stack for
parameters passed to the functions. Parameters returned by functions are
passed by a pointer. Responsibilities of called functions are managed in a
postfix expression called the function designator. Stack pointer AR1 is
well-positioned, and the return address of the hardware stack is popped
(retrieved) in case of C-interrupt runtime events using C-function features
(stack). The frame pointer is not modified and registers AR6 and AR7 are
not used.

3.1.2

Assembly-Compatible Functions
Assembly-compatible functions do not use their own variables, but instead,
rely on variables in a software stack where arguments are passed. The AR1
register points to the stack just after the last argument. After the return from
the function, the results are placed in the stack. Registers AR0, AR6, and
AR7 are not modified.

10

SPRA179

Sine/Cosine With Mathematical Series

3.2

Sine/Cosine Mathematical Series


Figure 7 shows the formula for calculating the value SIN(X) of an angle X.
X in radian,
If (X>=0.0)
SIN(X)=((((0.0372*X)0.2338)*X+0.0544)*X+0.9826)*X+0.0013
else
SIN(X)=((((0.0372*X)+0.2338)*X+0.0544)*X0.9826)*X+0.0013

Figure 7. Formula for Calculating the Value SIN of an Angle


Figure 8 shows the formula for calculating the value COS(X) of an angle X.
X in radian,
If (X>=0.0)
COS(X)=(((((-0.0076*X)+0.0595)*X-0.0211)*X-0.4879)*X-0.0028)*X+1.0
else
COS(X)=(((((0.0076*X)+0.0595)*X+0.0211)*X-0.4879)*X+0.0028)*X+1.0

Figure 8. Formula for Calculating the Value COS of an Angle

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 1215).

3.4

System Utilization
Table 3 shows processor utilization when using the mathematical series
method.
Table 3. Processor Utilization (Maximum) When Using Mathematical Series
FUNCTION

CYCLES

EXECUTION TIME

SIN assembly main

27

1.35 s

COS assembly main

37

1.85 s

SIN fully C-compatible

34

1.70 s

COS fully C-compatible

44

2.20 s

SIN + COS of an angle assembly main

64

3.20 s

Digital Sine-Wave Generation Using the TMS320C2xx

11

Sine/Cosine With Mathematical Series

Table 4 shows memory utilization when using the mathematical series


method.
Table 4. Memory Utilization When Using Mathematical Series

3.5

FUNCTION

ROM
(WORDS)

STACK
LEVELS

REGISTERS USED

RAM
(WORDS)

SIN

54

In stack

COS

67

In stack

SIN

64

In stack

COS

77

In stack

COS and SIN

121

In stack

Sine-Generation Precision
The following graphs present the precision of the mathematical series of
sine functions. The precision measurement is calculated by comparing the
mathematical series and floating-point C library results.

12

SPRA179

Sine/Cosine With Mathematical Series

3.5.1

One-Sine-Period Analysis
The sine period provides a general image of error calculation. In Figure 9
and Figure 10, results of the sine calculation are in Q15 format.

Figure 9. Mathematical Series Sine Calculation From 0 to 2*


With a 0.015-Radian Step
Digital Sine-Wave Generation Using the TMS320C2xx

13

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

3.5.2

Quarter-Sine-Period Analysis
Figure 11, Figure 12, and Figure 13 graph another precise analysis using a
quarter of a half-sine period. In this case, the step is 0.0039 radian.

14

SPRA179

Sine/Cosine With Mathematical Series

Figure 11. Results of Mathematical Series Sine From 0 to /2


With a 0.0039-Radian Step

Digital Sine-Wave Generation Using the TMS320C2xx

15

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 %

Digital Sine-Wave Generation Using the TMS320C2xx

17

18

SPRA179

Examples of a C Program and an Assembly Program Calling Sine and Cosine Functions

Appendix A
A.1

Examples of a C Program and an Assembly Program


Calling Sine and Cosine Functions

Main C Program to Call Sine or Cosine Functions

********************************************************************************
*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);
.
}

Digital Sine-Wave Generation Using the TMS320C2xx

A-1

Examples of a C Program and an Assembly Program Calling Sine and Cosine Functions

A.2

Main Assembly Program to Call Sine or Cosine Functions

**********************************************************************************
*File Name:

Main_trig.asm

*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

*|*
*

**********************************************************************************
.mmregs

.def

_ser_sin

.sect

vectors

_c_int0

**********************************************************************************
* Main routine
**********************************************************************************
.text
_c_int0:
.
.
LAR

AR1,#60h

MAR

*,AR1

A-2

SPRA179

;stack preparation

Examples of a C Program and an Assembly Program Calling Sine and Cosine Functions

LACC

#4000h

;/2

SACL

*+

;parameters in stack

CALL

_ser_sin

;result in ACCU

.
.end

Digital Sine-Wave Generation Using the TMS320C2xx

A-3

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 Lookup and

Interpolation Assembly calling function,

variables in s/w stack.

*Status:

*Processor:

C2xx

*Calling convention:

Input : Angle in stack value 0360 degrees <=>0hFFFFh

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

SACL

LT

*+

;add 0.5 for COS


;variable in size_sin
;*******stack : angle/X

LACC
A-4

#64h
SPRA179

Examples of a C Program and an Assembly Program Calling Sine and Cosine Functions

SACL

*
;*******stack : angle/TEMP

MPYU

PAC
SACH

;integer position in the table


;in High part of Acc

*+

;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

ADD

;address of beginning of the table


;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

MPY

;*******stack : y1/TEMP/remainder
;*******stack : y1/TEMP/remainder
SPH

;interpolation between Y1 and Y2


;*******stack : Y1/temp/remainder

LACC

*+

ADD

*,1

;*******stack : y1/TEMP/remainder
;Y(Xdata) in ACCU

RET

Digital Sine-Wave Generation Using the TMS320C2xx

A-5

Examples of a C Program and an Assembly Program Calling Sine and Cosine Functions

equal_sin
LACC

#Table_sin

ADD

;address of beginning of the table


;address of the pointed indice
;*******stack : RESULT/

TBLR

LACC

*+

end_interp_sin
RET

**********************************************************************************
* Table
**********************************************************************************

Table_sin

.include

Table_sin_end
.word

.end

A-6

SPRA179

sine.tab

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 Lookup and

Interpolation C calling function, variables in C stack.

Fully C compatible

*Status:

*Processor:

C2xx

*Calling convention:

Input : Angle in stack value 0360 degrees <=>0hFFFFh

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

POPD

*+

SAR

AR1,*

LAR

AR2,*,AR2

;C compatibility

Digital Sine-Wave Generation Using the TMS320C2xx

A-7

Examples of a C Program and an Assembly Program Calling Sine and Cosine Functions

SBRK

#3

SPM

LACC

#4000h

ADDS

SACL

LT

*+

;C compatibility

;add 0.5 for COS


;variable in size_sin
;*******stack : angle/X

LACC

#64h

SACL

MPYU

;*******stack : angle/TEMP
PAC
SACH

;integer position in the table


;in High part of Acc

*+

;remainder
;*******stack : angle/indice/X

SACL

LACC

*,15

AND

#0ffffh,15

SACH

;
;*******stack : angle/indice/REMAINDER

;*******stack : angle/INDICE/remainder
BCND

equal_sin,EQ

LACC

#Table_sin

ADD

;address of beginning of the table


;address of the nearest first indice
;*******stack : ANGLE/indice/remainder

TBLR

*+

ADD

#1h

TBLR

;*******stack : y1/INDICE/remainder
;Load Y2 with the ordinate of the
;*******stack : y1/Y2/remainder
;nearest second indice
LACC

SUB

*+

;*******stack : Y1/y2/remainder
;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

LACC

*+

;interpolation between Y1 and Y2


;*******stack : Y1/temp/remainder

;*******stack : y1/TEMP/remainder
ADD

*,1,AR1

;Y(Xdata) in ACCU

MAR

;C compatibility

PSHD

SBRK

#1

RET
equal_sin
LACC

#Table_sin

ADD

TBLR

LACC

*+,0,AR1

;address of beginning of the table


;address of the pointed indice
;*******stack : RESULT/

MAR

PSHD

SBRK

#1

;C compatibility

RET

**********************************************************************************
* Table
**********************************************************************************

Table_sin

.include

sine.tab

Table_sin_end
.word

.end

Digital Sine-Wave Generation Using the TMS320C2xx

A-9

Examples of a C Program and an Assembly Program Calling Sine and Cosine Functions

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 Lookup and Interpolation

Assembly calling function, variables in s/w stack.

*Status:

*Processor:

C2xx

*Calling convention:

Input : Angle in stack value 0360 degrees <=>0hFFFFh

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

*+

LACC

#64h

SACL

;variable in size_sin
;*******stack : angle/X

A-10

SPRA179

Examples of a C Program and an Assembly Program Calling Sine and Cosine Functions

;*******stack : angle/TEMP
MPYU

PAC
SACH

;integer position in the table


;in High part of Acc

*+

;remainder
;*******stack : angle/indice/X

SACL

LACC

*,15

AND

#0ffffh,15

SACH

BCND

equal_sin,EQ

LACC

#Table_sin

ADD

;
;*******stack : angle/indice/REMAINDER

;*******stack : angle/INDICE/remainder
;address of beginning of the table
;address of the nearest first indice
;*******stack : ANGLE/indice/remainder
TBLR

*+

ADD

#1h

TBLR

;*******stack : y1/INDICE/remainder
;Load Y2 with the ordinate of the
;*******stack : y1/Y2/remainder
;nearest second indice
LACC

SUB

*+

;*******stack : Y1/y2/remainder
;difference between the two Y value
;*******stack : y1/Y2/remainder
SACL

*+

LT

;*******stack : y1/temp/REMAINDER
;*******stack : y1/TEMP/remainder
MPY

*
;*******stack : y1/TEMP/remainder

SPH

LACC

*+

;interpolation between Y1 and Y2


;*******stack : Y1/temp/remainder
;*******stack : y1/TEMP/remainder

ADD

*,1

;Y(Xdata) in ACCU

RET
equal_sin

Digital Sine-Wave Generation Using the TMS320C2xx

A-11

Examples of a C Program and an Assembly Program Calling Sine and Cosine Functions

LACC

#Table_sin

ADD

;address of beginning of the table


;address of the pointed indice
;*******stack : RESULT/

TBLR

LACC

*+
;*******stack : result/X

end_interp_sin
RET

*********************************************************************************
* Table
*********************************************************************************

Table_sin

.include

Table_sin_end
.word 0

A-12

SPRA179

sine.tab

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 Lookup + Interpolation

C calling function, variables in C stack.

Fully C compatible

*Status:

*Processor:

C2x

*Calling convention:

Input : Angle in stack value 0360 degrees <=>0hFFFFh

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

POPD

*+

;C compatibility

Digital Sine-Wave Generation Using the TMS320C2xx

A-13

Examples of a C Program and an Assembly Program Calling Sine and Cosine Functions

SAR

AR1,*

LAR

AR2,*,AR2

SBRK

#3

SPM

LT

*+

LACC

#64h

SACL

;C compatibility

;variable in size_sin
;*******stack : angle/X

;*******stack : angle/TEMP
MPYU

PAC

;integer position in the table


;in High part of Acc

SACH

*+

;remainder

SACL

;*******stack : angle/indice/X
;*******stack : angle/indice/REMAINDER
LACC

*,15

AND

#0ffffh,15

SACH

BCND

equal_sin,EQ

LACC

#Table_sin

ADD

;*******stack : angle/INDICE/remainder
;address of beginning of the table
;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

*+

LT

;*******stack : y1/temp/REMAINDER
;*******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

ADD

;address of beginning of the table


;address of the pointed indice
;*******stack : RESULT/...

TBLR

LACC

*+,0,AR1
;*******stack : result/X

MAR

PSHD

SBRK

#1

;C compatibility

RET
**********************************************************************************
* Table
**********************************************************************************
Table_sin

.include

sine.tab

Table_sin_end
.word

Digital Sine-Wave Generation Using the TMS320C2xx

A-15

Examples of a C Program and an Assembly Program Calling Sine and Cosine Functions

A.7

Table for COS or SIN Function With Direct Look-Up

**********************************************************************************
* TABLE Sine and Cosine for separate functions COS and SIN

**********************************************************************************
.word

.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

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

.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

Digital Sine-Wave Generation Using the TMS320C2xx

A-17

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

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 Lookup and Interpolation

Assembly calling function, variables in s/w stack.

*Status:

*Processor:

C2xx

*Calling convention:

Input : Angle in stack value 0360 degrees <=>0hFFFFh

Output:

SIN(angle)*32767, Q15, in stack pointed by AR11

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

*|*
*

**********************************************************************************
size_tab .set

64h

;this is not an error

COS_SIN
MAR

*+

LT

*+

;variable in size_sin

Digital Sine-Wave Generation Using the TMS320C2xx

A-19

Examples of a C Program and an Assembly Program Calling Sine and Cosine Functions

;*stack: angle/X
LACC

#size_tab

SACL

MPYU

;*stack: angle/TEMP
PAC
SACH

;integer position in the table


;in High part of Acc

*+

;remainder
;*stack: angle/indice/X

SACL

;
;*stack: angle/indice/REMAINDER

LACC

*,15

AND

#0ffffh,15

SACH

BCND

equal_sin,EQ

LACC

#Table_sin_cos

ADD

;*stack: angle/INDICE/remainder
;address of beginning of the table

;address of the nearest first indice


;*stack: ANGLE/indice/remainder

TBLR

*+

ADD

#1h

TBLR

*+

;*stack: y1/INDICE/remainder
;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

LACC

;calculate cos interpolate


;*stack: y1/y2/remainder/YY1/yy2

SUB

*+

;difference between the two Y value

SACL

;*stack: y1/y2/remainder/yy1/TEMP

LT

;*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

*+

ADD

*,1

;*stack: y1/y2/remainder/yy1/TEMP
;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

SUB

*+

;*stack: Y1/y2/remainder
;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

LACC

*+

;interpolation between Y1 and Y2


;*stack: Y1/temp/remainder/cos
;*stack: y1/TEMP/remainder/cos

ADD

*,1

;Y(Xdata) in ACCU
;*stack: y1/temp/remainder/cos

SACL

ADRK

#3

;*stack: SIN/temp/remainder/cos
;*stack: sin/temp/remainder/COS

LACC

Digital Sine-Wave Generation Using the TMS320C2xx

A-21

Examples of a C Program and an Assembly Program Calling Sine and Cosine Functions

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
**********************************************************************************

Table_sin_cos

.include sin_cos.tab

Table_sin_cos_end
.word

A-22

SPRA179

Examples of a C Program and an Assembly Program Calling Sine and Cosine Functions

A.9

Table for COS_SIN Function With Direct Look-Up

**********************************************************************************
* TABLE Sine + Cosine for functions COS_SIN

**********************************************************************************
.word

.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

Digital Sine-Wave Generation Using the TMS320C2xx

A-23

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

.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

.word

2057

.word

4107

.word

6140

.word

8149

.word

10126

.word

12062

.word

13952

.word

15786

.word

17557

Digital Sine-Wave Generation Using the TMS320C2xx

A-25

Examples of a C Program and an Assembly Program Calling Sine and Cosine Functions

.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

A.10

SIN With Mathematical Series for Assembly Program

**********************************************************************************
*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 0360 degrees <=>0hFFFFh

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

MAR

LAC

BCND

angle_neg,LT

angle_pos

Digital Sine-Wave Generation Using the TMS320C2xx

A-27

Examples of a C Program and an Assembly Program Calling Sine and Cosine Functions

LT

*+

;variable in size_sin
;*stack : angle/X

MPY

#0c90h

;abscissa scale modify degree > rad

*,4

;angle in rad

PAC
SACH

;*stack : angle/RAD
LT

*+
;*stack : angle/rad/X

MPY

#985h

;0.0372
;
;PREG : angle * 0.0372

LACC

#0C426h,13

APAC
SACH

; in high ACCU
;ACCU : 0.2338 + angle * 0.0372

* ,3

;temporary value
;angle in TREG

MPY

;multiply by temporary value


;temporary value
;*stack : angle/rad/TEMP

LACC

#6f69h,10

APAC
SACH

;0.0544
;ACCU: temp + 0.0544

*,2

;temp
;*stack : angle/RAD/temp
;angle in TREG
;*stack : angle/rad/TEMP

MPY

;temp

LACC

#7dc5h,13

;0.9826

*,3

;treg = rad

APAC
SACH

;ACCU=0.9826+temp
;temp

MPY

;rad * temp
;temp * angle

LACC

#05532,4

;0.0013

SACH

* ,3

;result

LACC

APAC

;*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

MPY

#0c90h

;abscisse scale modif degre > rad

*,4

;angle in rad

;*stack : angle/X
PAC
SACH

;*stack : angle/RAD
LT

*+
;*stack : angle/rad/X

MPY

#985h

;0.0372
;
;PREG : angle * 0.0372

LACC

#03bdah,13

APAC

; in high ACCU
;ACCU : 0.2338 + angle * 0.0372

SACH

* ,3

;temporary value

MPY

;multiply by temporary value

;angle in TREG
;temporary value
;*stack : angle/rad/TEMP
LACC

#6f69h,10

APAC
SACH

;0.0544
;ACCU: temp + 0.0544

*,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

SACH

*,3

;result

LACC

APAC

;*stack : angle/SIN
RET

Digital Sine-Wave Generation Using the TMS320C2xx

A-29

Examples of a C Program and an Assembly Program Calling Sine and Cosine Functions

A.11

SIN With Mathematical Series for C Program

**********************************************************************************
*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 0360 degrees <=>0hFFFFh

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

POPD

*+

SAR

AR1,*

LAR

AR2,*,AR2

SBRK

#3

A-30

SPRA179

;C compatibility

;C compatibility

Examples of a C Program and an Assembly Program Calling Sine and Cosine Functions

SPM

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

LT

*+

;angle in rad
;*stack : angle/RAD
;*stack : angle/rad/X

MPY

#985h

;0.0372
;
;PREG : angle * 0.0372

LACC

#0C426h,13

APAC

; in high ACCU
;ACCU : 0.2338 + angle * 0.0372

SACH

* ,3

;temporary value

MPY

;multiply by temporary value

;angle in TREG
;temporary value
;*stack : angle/rad/TEMP
LACC

#6f69h,10

APAC
SACH

;0.0544
;ACCU: temp + 0.0544

*,2

;temp
;*stack : angle/RAD/temp
;angle in TREG
;*stack : angle/rad/TEMP

MPY

;temp

LACC

#7dc5h,13

;0.9826

APAC
SACH

;ACCU=0.9826+temp
*,3

;treg = rad
;temp

MPY

;rad * temp

Digital Sine-Wave Generation Using the TMS320C2xx

A-31

Examples of a C Program and an Assembly Program Calling Sine and Cosine Functions

;temp * angle
LACC

#05532,4

;0.0013

SACH

* ,3

;result

LACC

*,0,AR1

APAC

;*stack : angle/SIN
MAR

PSHD

SBRK

#1

;C compatibility

RET
angle_neg
LT

*+

;variable in size_sin
;*stack : angle/X

MPY

#0c90h

;abscisse scale modif degre > rad

*,4

;angle in rad

PAC
SACH

;*stack : angle/RAD
LT

*+
;*stack : angle/rad/X

MPY

#985h

;0.0372
;
;PREG : angle * 0.0372

LACC

#03bdah,13

APAC
SACH

; in high ACCU
;ACCU : 0.2338 + angle * 0.0372

* ,3

;temporary value
;angle in TREG

MPY

;multiply by temporary value


;temporary value
;*stack : angle/rad/TEMP

LACC

#6f69h,10

APAC
SACH

;0.0544
;ACCU: temp + 0.0544

*,2

;temp
;*stack : angle/RAD/temp
;angle in TREG
;*stack : angle/rad/TEMP

MPY
A-32

*
SPRA179

;temp

Examples of a C Program and an Assembly Program Calling Sine and Cosine Functions

LACC

#7dc5h,13

SPAC

;0.9826
;ACCU=0.9826+temp

SACH

*,3

;treg = rad

MPY

;rad * temp
;temp * angle

LACC

#05532,4

;0.0013

SACH

*,3

;result

LACC

*,0,AR1

APAC

;*stack : angle/SIN
MAR

PSHD

SBRK

#1

;C compatibility

RET

Digital Sine-Wave Generation Using the TMS320C2xx

A-33

Examples of a C Program and an Assembly Program Calling Sine and Cosine Functions

A.12

COS With Mathematical Series for Assembly Program

**********************************************************************************
*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 0360 degrees <=>0hFFFFh

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
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

SACH

*,4

;angle in rad

LT

*+

PAC
;*stack : angle/RAD
;*stack : angle/rad/X
MPY

#1070h

;0.0076 neg
;
;PREG : angle * 0.0076

LACC

#01e76h,15

; in high ACCU

* ,3

;temporary value

APAC
SACH

;ACCU : +0.0595 + angle * 0.0076


;angle in TREG

MPY

;multiply by temporary value


;temporary value
;*stack : angle/rad/TEMP

LACC

#0f532h,15

APAC
SACH

;0.0211
;ACCU: temp + 0.0211

;temp
;*stack : angle/RAD/temp
;angle in TREG
;*stack : angle/rad/TEMP

MPY

;temp

LACC

#0e0c6h,15

;0.4879

APAC

;ACCU=0.9826+temp

SACH

*,2

;treg = rad

MPY

;rad * temp
;temp * angle

LACC

#0a440h,5

;0.0028

SACH

*,2

;result

MPY

LACC

#1000h,15

;1

APAC

APAC

Digital Sine-Wave Generation Using the TMS320C2xx

A-35

Examples of a C Program and an Assembly Program Calling Sine and Cosine Functions

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

*,4

;angle in rad

PAC
SACH

;*stack : angle/RAD
LT

*+
;*stack : angle/rad/X

MPY

#0f90h

;0.0076 neg
;
;PREG : angle * 0.0076

LACC

#01e76h,15

; in high ACCU

* ,3

;temporary value

APAC
SACH

;ACCU : +0.0595 + angle * 0.0076


;angle in TREG

MPY

;multiply by temporary value


;temporary value
;*stack : angle/rad/TEMP

LACC

#00aceh,15

APAC
SACH

;0.0211
;ACCU: temp + 0.0211

;temp
;*stack : angle/RAD/temp
;angle in TREG
;*stack : angle/rad/TEMP

MPY

;temp

LACC

#0e0c6h,15

;0.4879

APAC

A-36

;ACCU=0.9826+temp

SPRA179

Examples of a C Program and an Assembly Program Calling Sine and Cosine Functions

SACH

*,2

;treg = rad
;temp

MPY

;rad * temp
;temp * angle

LACC

#05bc0h,5

;0.0028

APAC
SACH

*,2

;result

MPY

LACC

#1000h,15

;1

APAC
SETC

OVM

SACH

*,3

LACC

*,16

ADD

*,16

SACH

LACC

*
;*stack : angle/SIN

RET

Digital Sine-Wave Generation Using the TMS320C2xx

A-37

Examples of a C Program and an Assembly Program Calling Sine and Cosine Functions

A.13

COS With Mathematical Series for C Program

**********************************************************************************
*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 0360 degrees <=>0hFFFFh

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

POPD

*+

SAR

AR1,*

LAR

AR2,*,AR2

SBRK

#3

A-38

SPRA179

;C compatibility

;C compatibility

Examples of a C Program and an Assembly Program Calling Sine and Cosine Functions

SPM

SETC

SXM

LAC

BCND

angle_neg,LT

angle_pos
LT

*+

;variable in size_sin
;*stack : angle/X

MPY

#0c90h

;abscisse scale modif degre > rad

SACH

*,4

;angle in rad

LT

*+

PAC
;*stack : angle/RAD
;*stack : angle/rad/X
MPY

#1070h

;0.0076 neg
;
;PREG : angle * 0.0076

LACC

#01e76h,15

APAC

; in high ACCU
;ACCU : +0.0595 + angle * 0.0076

SACH

* ,3

;temporary value

MPY

;multiply by temporary value

;angle in TREG
;temporary value
;*stack : angle/rad/TEMP
LACC

#0f532h,15

APAC
SACH

;0.0211
;ACCU: temp + 0.0211

;temp
;*stack : angle/RAD/temp
;angle in TREG
;*stack : angle/rad/TEMP

MPY

;temp

LACC

#0e0c6h,15

;0.4879

APAC
SACH

;ACCU=0.9826+temp
*,2

;treg = rad
;temp

Digital Sine-Wave Generation Using the TMS320C2xx

A-39

Examples of a C Program and an Assembly Program Calling Sine and Cosine Functions

MPY

;rad * temp
;temp * angle

LACC

#0a440h,5

;0.0028

SACH

*,2

;result

MPY

LACC

#1000h,15

;1

APAC

APAC
SETC

OVM

SACH

*,3

LACC

*,16

ADD

*,16

SACH

LACC

*,0,AR1
;*stack : angle/SIN

MAR

PSHD

SBRK

#1

;C compatibility

RET
angle_neg
LT

*+

;variable in size_sin
;*stack : angle/X

MPY

#0c90h

;abscisse scale modif degre > rad

*,4

;angle in rad

PAC
SACH

;*stack : angle/RAD
LT

*+

MPY

#0f90h

;*stack : angle/rad/X
;0.0076 neg
;
;PREG : angle * 0.0076
LACC

#01e76h,15

APAC
SACH

; in high ACCU
;ACCU : +0.0595 + angle * 0.0076

* ,3

;temporary value
;angle in TREG

MPY
A-40

*
SPRA179

;multiply by temporary value

Examples of a C Program and an Assembly Program Calling Sine and Cosine Functions

;temporary value
;*stack : angle/rad/TEMP
LACC

#00aceh,15

APAC
SACH

;0.0211
;ACCU: temp + 0.0211

;temp
;*stack : angle/RAD/temp
;angle in TREG
;*stack : angle/rad/TEMP

MPY

;temp

LACC

#0e0c6h,15

;0.4879

APAC

;ACCU=0.9826+temp

SACH

*,2

;treg = rad

MPY

;rad * temp
;temp * angle in Q28

LACC

#05bc0h,5

;0.0028

SACH

*,2

;result

MPY

LACC

#1000h,15

;1

APAC
SETC

OVM

SACH

*,3

LACC

*,16

ADD

*,16

SACH

LACC

*,0,AR1
;*stack : angle/SIN

MAR

PSHD

SBRK

#1

;C compatibility

RET

Digital Sine-Wave Generation Using the TMS320C2xx

A-41

A-42

SPRA179

Digital Sine-Wave Generation Using the TMS320C2xx


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.

Digital Sine-Wave Generation Using the TMS320C2xx

A-1

Direct Look-Up and Linear Interpolation Method

C Direct Look-Up and Linear Interpolation Method


This section describes the Direct Look- Up and Linear Interpolation method
of implementing a digital sine-wave generator using the TMS320C2xx.

C.1

C- and Assembly-Compatible Functions


The Direct Look-Up method, which uses 100 sine-period values in a table,
reveals the sine/cosine functions. To provide minimum harmonic distortion,
the method includes linear interpolation with a fixed-step table. An extended
table is used for the cosine + sine function and is located in program memory.
Two versions of each function are presented :
C-compatible functions
Assembly-compatible functions
Examples of a C program and an assembly program (that call sine and
cosine functions) are in the appendix.

C.1.1

C-Compatible Functions
Fully C-compatible functions employ C conventions to use the stack for
parameters passed to the functions. Parameters returned by the functions
are passed by a pointer. Responsibilities of called functions are managed
in a postfix expression called the function designator. Stack pointer AR1 is
well-positioned, and the return address of the hardware stack is popped
(retrieved) in case of C-interrupt runtime events using C-function features
(stack). The frame pointer is not modified and registers AR6 and AR7 are
not used.

C.1.2

Assembly-Compatible Functions
Assembly-compatible functions do not use their own variables, but instead,
rely on variables in a software stack where arguments are passed. The AR1
register points to the stack just after the last argument. After the return from
the function, the results are placed in the stack. Registers AR0, AR6, and
AR7 are not modified.

A-2

STDZ001A

Direct Look-Up and Linear Interpolation Method

C.2

Interpolation
Figure B1 shows the formula and the resulting graph for calculating the
table interpolation value COS(X) of an angle X.
y

y
X x
Y

+
i

x
i+ 1
r =

i+1
Y=?

( y

i+ 1

y )
i

ratio

x
i+1

where:
{xi} = {first coordinates of the table},
{yi} = {second coordinates of the table},
i chosen so that xi < X < xi+1.

Figure B1. 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.

C.3

Interpolation: solving the above mentioned calculation to obtain Y.

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 1215).

C.4

System Utilization
Table E1 shows processor utilization when using the direct look-up and
linear interpolation methods.
Digital Sine-Wave Generation Using the TMS320C2xx

A-3

Direct Look-Up and Linear Interpolation Method

Table E1. Processor Utilization (Maximum) When Using


Table Look-Up and Interpolation
FUNCTION

CYCLES

EXECUTION TIME

SIN assembly call

35

1.75 s

COS assembly call

38

1.90 s

SIN fully C-compatible

42

2.10 s

COS fully C-compatible

45

2.25 s

SIN + COS of an angle

58

2.90 s

Table E2 shows memory utilization when using the direct look-up and
linear interpolation method.
Table E2. Memory Utilization When Using Direct Look-Up and Interpolation
FUNCTION

ROM
(WORDS)

STACKLEVELS

REGISTERS
USED

RAM
(WORDS)

SIN ssembly call

32 + 100

In stack

COS assembly call

34 + 100

In stack

COS and SINassembly call

66 + 100

In stack

SIN Fully C compatible

42 + 100

In stack

COS assembly call

44 + 100

In stack

COS + SIN in one function


assembly call

55 + 125

In stack

In the case of Sine + Cosine, the same table is used.

C.5

Sine-Generation Precision
Figure B2 and Figure B3 are graphs that present the precision of the
direct look-up and linear interpolation sine functions. The precision
measurement is made by comparing the direct look-up and the floating-point
C library results.

C.5.1

One-Sine-Period Analysis
The sine period provides a general image of error calculation. In Figure B2
and Figure B3, results of the sine calculation are in Q15 format.

A-4

STDZ001A

Direct Look-Up and Linear Interpolation Method

Figure B2. Direct Look-Up With Interpolation of Sine Calculation From 0 to 2*


With a 0.015-Radian Step

Digital Sine-Wave Generation Using the TMS320C2xx

A-5

Direct Look-Up and Linear Interpolation Method

Figure B3. 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

C.5.2

Quarter-Sine-Period Analysis
Figure B4, Figure B5, and Figure B6 graph another precise analysis
using a quarter of a half-sine period. In this case, the step is 0.0039 radian.
The interpolation is made at 0.125-radian intervals. In this way, interpolation
error is exposed on the following graphs. Each interval (table approximation)
is displayed with 32 pixels.

Figure B4. Results of Direct Look-Up SIN From 0 to /2 With a 0.0039-Radian


Step

Digital Sine-Wave Generation Using the TMS320C2xx

A-7

Direct Look-Up and Linear Interpolation Method

Figure B5. 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 B6. Error Between the C Floating-Point Result and Direct Look-Up
SINE Calculation From 0 to /4 With a 0.0039-Radian Step in %

Digital Sine-Wave Generation Using the TMS320C2xx

A-9

Sine/Cosine With Mathematical Series

D Sine/Cosine With Mathematical Series


This section explains the second of two methods of implementing a digital
sine-wave generator using the TMS320C2xx.

D.1

C- and Assembly-Compatible Functions


The sine/cosine method calculates the sine/cosine functions with a
mathematical series for the sine period and a mathematical series for
cosine. Calculations are made with fixed-point instructions to optimize the
time calculation. The dynamics used in the calculation fit with maximum
precision without overflow.
Two versions of each function are presented :
C-compatible functions
Assembly-compatible functions
Examples of a C program and an assembly program (that call sine and
cosine functions) are in the appendix.

D.1.1

C-Compatible Functions
Fully C-compatible functions employ C conventions to use the stack for
parameters passed to the functions. Parameters returned by functions are
passed by a pointer. Responsibilities of called functions are managed in a
postfix expression called the function designator. Stack pointer AR1 is
well-positioned, and the return address of the hardware stack is popped
(retrieved) in case of C-interrupt runtime events using C-function features
(stack). The frame pointer is not modified and registers AR6 and AR7 are
not used.

D.1.2

Assembly-Compatible Functions
Assembly-compatible functions do not use their own variables, but instead,
rely on variables in a software stack where arguments are passed. The AR1
register points to the stack just after the last argument. After the return from
the function, the results are placed in the stack. Registers AR0, AR6, and
AR7 are not modified.

A-10

STDZ001A

Sine/Cosine With Mathematical Series

D.2

Sine/Cosine Mathematical Series


Figure B7 shows the formula for calculating the value SIN(X) of an angle
X.
X in radian,
If (X>=0.0)
SIN(X)=((((0.0372*X)0.2338)*X+0.0544)*X+0.9826)*X+0.0013
else
SIN(X)=((((0.0372*X)+0.2338)*X+0.0544)*X0.9826)*X+0.0013

Figure B7. Formula for Calculating the Value SIN of an Angle


Figure B8 shows the formula for calculating the value COS(X) of an angle
X.
X in radian,
If (X>=0.0)
COS(X)=(((((-0.0076*X)+0.0595)*X-0.0211)*X-0.4879)*X-0.0028)*X+1.0
else
COS(X)=(((((0.0076*X)+0.0595)*X+0.0211)*X-0.4879)*X+0.0028)*X+1.0

Figure B8. Formula for Calculating the Value COS of an Angle

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 1215).

D.4

System Utilization
Table E3 shows processor utilization when using the mathematical series
method.

Table E3. Processor Utilization (Maximum) When Using Mathematical Series


FUNCTION

CYCLES

EXECUTION TIME

SIN assembly main

27

1.35 s

COS assembly main

37

1.85 s

SIN fully C-compatible

34

1.70 s

COS fully C-compatible

44

2.20 s

SIN + COS of an angle assembly main

64

3.20 s

Digital Sine-Wave Generation Using the TMS320C2xx

A-11

Sine/Cosine With Mathematical Series

Table E4 shows memory utilization when using the mathematical series


method.
Table E4. Memory Utilization When Using Mathematical Series

D.5

FUNCTION

ROM
(WORDS)

STACK
LEVELS

REGISTERS USED

RAM
(WORDS)

SIN

54

In stack

COS

67

In stack

SIN

64

In stack

COS

77

In stack

COS and SIN

121

In stack

Sine-Generation Precision
The following graphs present the precision of the mathematical series of
sine functions. The precision measurement is calculated by comparing the
mathematical series and floating-point C library results.

A-12

STDZ001A

Sine/Cosine With Mathematical Series

D.5.1

One-Sine-Period Analysis
The sine period provides a general image of error calculation. In Figure B9
and Figure B10, results of the sine calculation are in Q15 format.

Figure B9. Mathematical Series Sine Calculation From 0 to 2*


With a 0.015-Radian Step
Digital Sine-Wave Generation Using the TMS320C2xx

A-13

Sine/Cosine With Mathematical Series

Figure B10. Error Between the C Floating-Point Result and the Mathematical
Series
SINE Calculation From 0 to 2* With a 0.015-Radian Step

D.5.2

Quarter-Sine-Period Analysis
Figure B11, Figure B12, and Figure B13 graph another precise analysis
using a quarter of a half-sine period. In this case, the step is 0.0039 radian.

A-14

STDZ001A

Sine/Cosine With Mathematical Series

Figure B11.

Results of Mathematical Series Sine From 0 to /2


With a 0.0039-Radian Step

Digital Sine-Wave Generation Using the TMS320C2xx

A-15

Sine/Cosine With Mathematical Series

Figure B12. 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

A-16

STDZ001A

Sine/Cosine With Mathematical Series

Figure B13. Error Between the C Floating-Point Result and a Mathematical


Series Sine Calculation From 0 to /4 With a 0.0039-Radian Step in %

Digital Sine-Wave Generation Using the TMS320C2xx

A-17

********************************************************************************
*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

_c_int0

**********************************************************************************
* Main routine
**********************************************************************************
.text
_c_int0:
.
.
LAR

AR1,#60h

MAR

*,AR1

A-2

;stack preparation

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 Lookup and

Interpolation Assembly calling function,

variables in s/w stack.

*Status:

*Processor:

C2xx

*Calling convention:

Input : Angle in stack value 0360 degrees <=>0hFFFFh

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

PAC
SACH

;integer position in the table


;in High part of Acc

*+

;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

TBLR

*+

;*******stack : ANGLE/indice/remainder
;*******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

*+

SACL

*+

;difference between the two Y value


;*******stack : y1/Y2/remainder
;*******stack : y1/temp/REMAINDER

LT

*
;*******stack : y1/TEMP/remainder

MPY

SPH

;*******stack : y1/TEMP/remainder
;interpolation between Y1 and Y2
;*******stack : Y1/temp/remainder
A-4

LAC

*+
;*******stack : y1/TEMP/remainder

ADD

*,1

;Y(Xdata) in ACCU

LALK

Table_sin

;address of beginning of the table

ADD

;address of the pointed indice

RET
equal_sin

;*******stack : RESULT/
TBLR

LAC

*+

end_interp_sin
RET
**********************************************************************************
* Table
**********************************************************************************
Table_sin

.include

sine.tab

Table_sin_end
.word

.end
**********************************************************************************
*Routine Name:

_COS

*Project:

DMC Mathematical Library

*Originator:

Pascal DORSTER (Texas Instruments)

*Description:

COS function with Direct Lookup and

Interpolation C calling function, variables in C stack.

Fully C compatible

*Status:

*Processor:

C2xx

*Calling convention:

Input : Angle in stack value 0360 degrees <=>0hFFFFh

Output : COS(angle)*32767, Q15, in ACCU

Pointed register AR1

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

POPD

*+

SAR

AR1,*

LAR

AR2,*,AR2

SBRK

SPM

LAC

#4000h

ADDS

SACL

LT

*+

LAC

#64h

SACL

MPYU

;C compatibility

;C compatibility

;add 0.5 for COS


;variable in size_sin
;*******stack : angle/X

;*******stack : angle/TEMP
PAC
SACH

;integer position in the table


;in High part of Acc

*+

;remainder
;*******stack : angle/indice/X

SACL

LAC

*,15

ANDK

#0ffffh,15

;
;*******stack : angle/indice/REMAINDER

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

SUB

*+

;*******stack : Y1/y2/remainder
;difference between the two Y value
;*******stack : y1/Y2/remainder
SACL

*+
;*******stack : y1/temp/REMAINDER

LT

MPY

;*******stack : y1/TEMP/remainder
;*******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

RET
equal_sin
LALK

Table_sin

;address of beginning of the table

ADD

;address of the pointed indice

TBLR

LAC

*+,0,AR1

;*******stack : RESULT/

A-7

MAR

PSHD

SBRK

;C compatibility

RET
**********************************************************************************
* Table
**********************************************************************************
Table_sin

.include

sine.tab

Table_sin_end
.word

.end
**********************************************************************************
*Routine Name:

SIN

*Project:

DMC Mathematical Library

*Originator:

Pascal DORSTER (Texas Instruments)

*Description:

SIN function with Direct Lookup and Interpolation

Assembly calling function, variables in s/w stack.

*Status:

*Processor:

C2xx

*
*

*Calling convention:

Input : Angle in stack value 0360 degrees <=>0hFFFFh

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

*________________________________________________________________________________*
A-8

*Date of Mod

DESCRIPTION

*|*
*

**********************************************************************************
SIN
MAR

*+

LT

*+

;variable in size_sin
;*******stack : angle/X

LAC

#64h

SACL

*
;*******stack : angle/TEMP

MPYU

PAC

;integer position in the table


;in High part of Acc

SACH

*+

;remainder

SACL

;*******stack : angle/indice/X
;*******stack : angle/indice/REMAINDER
LAC

*,15

ANDK

#0ffffh,15

SACH

BCND

equal_sin,EQ

LALK

Table_sin

;address of beginning of the table

ADD

;address of the nearest first indice

TBLR

*+

;*******stack : angle/INDICE/remainder

;*******stack : ANGLE/indice/remainder
;*******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

SPH

;*******stack : y1/TEMP/remainder
;interpolation between Y1 and Y2
;*******stack : Y1/temp/remainder
LAC

*+
;*******stack : y1/TEMP/remainder

ADD

*,1

;Y(Xdata) in ACCU

LALK

Table_sin

;address of beginning of the table

ADD

;address of the pointed indice

RET
equal_sin

;*******stack : RESULT/
TBLR

LAC

*+
;*******stack : result/X

end_interp_sin
RET

*********************************************************************************
* Table
*********************************************************************************

Table_sin

.include

sine.tab

Table_sin_end
.word 0
**********************************************************************************
*Routine Name:

_SIN

*Project:

DMC Mathematical Library

*Originator:

Pascal DORSTER (Texas Instruments)

*Description:
*

SIN function with Direct Lookup + Interpolation

C calling function, variables in C stack.

Fully C compatible

A-10

*Status:

*Processor:

C2x

*Calling convention:

Input : Angle in stack value 0360 degrees <=>0hFFFFh

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

POPD

*+

SAR

AR1,*

LAR

AR2,*,AR2

SBRK

SPM

LT

*+

;C compatibility

;C compatibility

;variable in size_sin
;*******stack : angle/X

LAC

#64h

SACL

*
;*******stack : angle/TEMP

MPYU

;integer position in the table

A-11

PAC
SACH

;in High part of Acc


*+

;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

*+

SACL

*+

;difference between the two Y value


;*******stack : y1/Y2/remainder
;*******stack : y1/temp/REMAINDER

LT

MPY

;*******stack : y1/TEMP/remainder
;*******stack : y1/TEMP/remainder
SPH

;interpolation between Y1 and Y2


;*******stack : Y1/temp/remainder

LAC

*+

ADD

*,1,AR1

;Y(Xdata) in ACCU

MAR

;C compatibility

PSHD

SBRK

;*******stack : y1/TEMP/remainder

RET
A-12

equal_sin
LALK

Table_sin

;address of beginning of the table

ADD

;address of the pointed indice

TBLR

LAC

*+,0,AR1

MAR

PSHD

SBRK

;*******stack : RESULT/...

;*******stack : result/X
;C compatibility

RET
**********************************************************************************
* Table
**********************************************************************************
Table_sin

.include

sine.tab

Table_sin_end
.word

**********************************************************************************
* TABLE Sine and Cosine for separate functions COS and SIN

**********************************************************************************
.word

.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

.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 Lookup and Interpolation

Assembly calling function, variables in s/w stack.

*Status:

*Processor:

C2xx

*Calling convention:

Input : Angle in stack value 0360 degrees <=>0hFFFFh

Output:

SIN(angle)*32767, Q15, in stack pointed by AR11

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

*|*
*

**********************************************************************************
size_tab .set
A-16

64h

;this is not an error

COS_SIN
MAR

*+

LT

*+

;variable in size_sin
;*stack: angle/X

LAC

#size_tab

SACL

*
;*stack: angle/TEMP

MPYU

PAC
SACH

;integer position in the table


;in High part of Acc

*+

;remainder
;*stack: angle/indice/X

SACL

LAC

*,15

ANDK

#0ffffh,15

SACH

;
;*stack: angle/indice/REMAINDER

;*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

ADD

#18h

TBLR

*+

ADD

#1h

TBLR

;*stack: y1/y2/remainder/yy1/YY2

LAC

;calculate cos interpolate

;*stack: y1/y2/remainder/X

;*stack: y1/y2/remainder/yy1/X

;*stack: y1/y2/remainder/YY1/yy2

A-17

SUB

*+

;difference between the two Y value


;*stack: y1/y2/remainder/yy1/YY2

SACL

LT

;*stack: y1/y2/remainder/yy1/TEMP
;*stack: y1/y2/remainder/YY1

SBRK

MPY

;*stack: y1/y2/REMAINDER/yy1
;*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

SACL

;Y(Xdata) in ACCU
;*stack: y1/y2/remainder/YY1
;*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

MPY

;*stack: y1/TEMP/remainder/cos
;*stack: y1/TEMP/remainder/cos
SPH

;interpolation between Y1 and Y2


;*stack: Y1/temp/remainder/cos

LAC

*+

ADD

*,1

;*stack: y1/TEMP/remainder/cos
;Y(Xdata) in ACCU
;*stack: y1/temp/remainder/cos
A-18

SACL

ADRK

;*stack: SIN/temp/remainder/cos
;*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

TBLR

*+

;address of the pointed indice


;*stack: ANGLE/indice
;*stack: sin/INDICE/remainder

ADDK

19h

TBLR

*
;*stack: sin/COS

end_interp_sin
RET
**********************************************************************************
* Table
**********************************************************************************
Table_sin_cos

.include sin_cos.tab

Table_sin_cos_end
.word

**********************************************************************************
* TABLE Sine + Cosine for functions COS_SIN

**********************************************************************************
.word

.word

2057

.word

4107

.word

6140

.word

8149

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

.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

.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 0360 degrees <=>0hFFFFh

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

MPYK

0c90h

;abscissa scale modify degree > rad

SACH

*,4

;angle in rad

LT

*+

;*stack : angle/X
PAC
;*stack : angle/RAD
;*stack : angle/rad/X
MPYK

985h

;0.0372
;
;PREG : angle * 0.0372

LAC

#0C426h,13

APAC

; in high ACCU
;ACCU : 0.2338 + angle * 0.0372

SACH

* ,3

;temporary value

MPY

;multiply by temporary value

;angle in TREG
;temporary value
;*stack : angle/rad/TEMP
LAC

#6f69h,10

APAC
SACH

;0.0544
;ACCU: temp + 0.0544

*,2

;temp
;*stack : angle/RAD/temp
;angle in TREG
;*stack : angle/rad/TEMP

MPY

;temp

LAC

#7dc5h,13

;0.9826

APAC
SACH

;ACCU=0.9826+temp
*,3

;treg = rad
;temp

MPY

;rad * temp

LAC

#05532,4

;0.0013

;temp * angle
APAC
A-24

SACH

* ,3

LAC

;result
;*stack : angle/SIN

RET
angle_neg
LT

*+

;variable in size_sin
;*stack : angle/X

MPYK

0c90h

;abscisse scale modif degre > rad

*,4

;angle in rad

PAC
SACH

;*stack : angle/RAD
LT

*+
;*stack : angle/rad/X

MPYK

985h

;0.0372
;
;PREG : angle * 0.0372

LAC

#03bdah,13

; in high ACCU

* ,3

;temporary value

APAC
SACH

;ACCU : 0.2338 + angle * 0.0372


;angle in TREG

MPY

;multiply by temporary value


;temporary value
;*stack : angle/rad/TEMP

LAC

#6f69h,10

APAC
SACH

;0.0544
;ACCU: temp + 0.0544

*,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

LAC

;result
;*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 0360 degrees <=>0hFFFFh

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
A-26

;C compatibility

POPD

*+

SAR

AR1,*

LAR

AR2,*,AR2

SBRK

SPM

SETC

SXM

LAC

BCND

angle_neg,LT

;C compatibility

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

*+

MPYK

985h

;*stack : angle/rad/X
;0.0372
;
;PREG : angle * 0.0372
LAC

#0C426h,13

APAC

; in high ACCU
;ACCU : 0.2338 + angle * 0.0372

SACH

* ,3

;temporary value

MPY

;multiply by temporary value

;angle in TREG
;temporary value
;*stack : angle/rad/TEMP
LAC

#6f69h,10

APAC
SACH

;0.0544
;ACCU: temp + 0.0544

*,2

;temp
;*stack : angle/RAD/temp
;angle in TREG
;*stack : angle/rad/TEMP

MPY

;temp

LAC

#7dc5h,13

;0.9826

A-27

APAC
SACH

;ACCU=0.9826+temp
*,3

;treg = rad
;temp

MPY

;rad * temp
;temp * angle

LAC

#05532,4

;0.0013

SACH

* ,3

;result

LAC

*,0,AR1

APAC

;*stack : angle/SIN
MAR

PSHD

SBRK

;C compatibility

RET
angle_neg
LT

*+

;variable in size_sin
;*stack : angle/X

MPYK

0c90h

;abscisse scale modif degre > rad

SACH

*,4

;angle in rad

LT

*+

PAC
;*stack : angle/RAD
;*stack : angle/rad/X
MPYK

985h

;0.0372
;
;PREG : angle * 0.0372

LAC

#03bdah,13

; in high ACCU

* ,3

;temporary value

APAC
SACH

;ACCU : 0.2338 + angle * 0.0372


;angle in TREG

MPY

;multiply by temporary value


;temporary value
;*stack : angle/rad/TEMP

LAC

#6f69h,10

APAC
SACH
A-28

;0.0544
;ACCU: temp + 0.0544

*,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

SACH

*,3

;result

LAC

*,0,AR1

APAC

;*stack : angle/SIN
MAR

PSHD

SBRK

;C compatibility

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 0360 degrees <=>0hFFFFh

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

MPYK

0c90h

;abscisse scale modif degre > rad

SACH

*,4

;angle in rad

LT

*+

;*stack : angle/X
PAC
;*stack : angle/RAD
;*stack : angle/rad/X
MPYK

1070h

;0.0076 neg
;
;PREG : angle * 0.0076

LAC

#01e76h,15

APAC

; in high ACCU
;ACCU : +0.0595 + angle * 0.0076

SACH

* ,3

;temporary value

MPY

;multiply by temporary value

;angle in TREG
;temporary value
A-30

;*stack : angle/rad/TEMP
LAC

#0f532h,15

APAC
SACH

;0.0211
;ACCU: temp + 0.0211

;temp
;*stack : angle/RAD/temp
;angle in TREG
;*stack : angle/rad/TEMP

MPY

;temp

LAC

#0e0c6h,15

;0.4879

APAC

;ACCU=0.9826+temp

SACH

*,2

;treg = rad

MPY

;rad * temp

LAC

#0a440h,5

;0.0028

;temp * angle
APAC
SACH

*,2

;result

MPY

LAC

#1000h,15

;1

APAC
SETC

OVM

SACH

*,3

LAC

*,16

ADD

*,16

SACH

LAC

*
;*stack : angle/SIN

RET
angle_neg
LT

*+

;variable in size_sin
;*stack : angle/X

MPYK

0c90h

;abscisse scale modif degre > rad

SACH

*,4

;angle in rad

LT

*+

PAC
;*stack : angle/RAD
;*stack : angle/rad/X

A-31

MPYK

0f90h

;0.0076 neg
;
;PREG : angle * 0.0076

LAC

#01e76h,15

APAC

; in high ACCU
;ACCU : +0.0595 + angle * 0.0076

SACH

* ,3

;temporary value

MPY

;multiply by temporary value

;angle in TREG
;temporary value
;*stack : angle/rad/TEMP
LAC

#00aceh,15

APAC
SACH

;0.0211
;ACCU: temp + 0.0211

;temp
;*stack : angle/RAD/temp
;angle in TREG
;*stack : angle/rad/TEMP

MPY

;temp

LAC

#0e0c6h,15

;0.4879

APAC
SACH

;ACCU=0.9826+temp
*,2

;treg = rad
;temp

MPY

;rad * temp
;temp * angle

LAC

#05bc0h,5

;0.0028

APAC
SACH

*,2

;result

MPY

LAC

#1000h,15

;1

APAC
SETC

OVM

SACH

*,3

LAC

*,16

ADD

*,16

SACH

LAC

*
;*stack : angle/SIN

RET
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 0360 degrees <=>0hFFFFh

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

POPD

*+

SAR

AR1,*

LAR

AR2,*,AR2

SBRK

;C compatibility

;C compatibility

A-33

SPM

SETC

SXM

LAC

BCND

angle_neg,LT

angle_pos
LT

*+

;variable in size_sin
;*stack : angle/X

MPYK

0c90h

;abscisse scale modif degre > rad

*,4

;angle in rad

PAC
SACH

;*stack : angle/RAD
LT

*+
;*stack : angle/rad/X

MPYK

1070h

;0.0076 neg
;
;PREG : angle * 0.0076

LAC

#01e76h,15

; in high ACCU

* ,3

;temporary value

APAC
SACH

;ACCU : +0.0595 + angle * 0.0076


;angle in TREG

MPY

;multiply by temporary value


;temporary value
;*stack : angle/rad/TEMP

LAC

#0f532h,15

APAC
SACH

;0.0211
;ACCU: temp + 0.0211

;temp
;*stack : angle/RAD/temp
;angle in TREG
;*stack : angle/rad/TEMP

MPY

;temp

LAC

#0e0c6h,15

;0.4879

APAC
SACH

;ACCU=0.9826+temp
*,2

;treg = rad
;temp

MPY
A-34

;rad * temp

;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

MAR

PSHD

SBRK

;*stack : angle/SIN
;C compatibility

RET
angle_neg
LT

*+

;variable in size_sin

MPYK

0c90h

;abscisse scale modif degre > rad

SACH

*,4

;angle in rad

LT

*+

;*stack : angle/X
PAC
;*stack : angle/RAD
;*stack : angle/rad/X
MPYK

0f90h

;0.0076 neg
;
;PREG : angle * 0.0076

LAC

#01e76h,15

APAC

; in high ACCU
;ACCU : +0.0595 + angle * 0.0076

SACH

* ,3

;temporary value

MPY

;multiply by temporary value

;angle in TREG
;temporary value

A-35

;*stack : angle/rad/TEMP
LAC

#00aceh,15

APAC
SACH

;0.0211
;ACCU: temp + 0.0211

;temp
;*stack : angle/RAD/temp
;angle in TREG
;*stack : angle/rad/TEMP

MPY

;temp

LAC

#0e0c6h,15

;0.4879

APAC

;ACCU=0.9826+temp

SACH

*,2

;treg = rad

MPY

;rad * temp
;temp * angle in Q28

LAC

#05bc0h,5

;0.0028

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

PSHD

SBRK

RET

A-36

;C compatibility

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

_c_int0

**********************************************************************************
* Main routine
**********************************************************************************
.text
_c_int0:
.
.
LAR

AR1,#60h

MAR

*,AR1

A-2

;stack preparation

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 Lookup and

Interpolation Assembly calling function,

variables in s/w stack.

*Status:

*Processor:

C2xx

*Calling convention:

Input : Angle in stack value 0360 degrees <=>0hFFFFh

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

PAC
SACH

;integer position in the table


;in High part of Acc

*+

;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

TBLR

*+

;*******stack : ANGLE/indice/remainder
;*******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

*+

SACL

*+

;difference between the two Y value


;*******stack : y1/Y2/remainder
;*******stack : y1/temp/REMAINDER

LT

*
;*******stack : y1/TEMP/remainder

MPY

SPH

;*******stack : y1/TEMP/remainder
;interpolation between Y1 and Y2
;*******stack : Y1/temp/remainder
A-4

LAC

*+
;*******stack : y1/TEMP/remainder

ADD

*,1

;Y(Xdata) in ACCU

LALK

Table_sin

;address of beginning of the table

ADD

;address of the pointed indice

RET
equal_sin

;*******stack : RESULT/
TBLR

LAC

*+

end_interp_sin
RET
**********************************************************************************
* Table
**********************************************************************************
Table_sin

.include

sine.tab

Table_sin_end
.word

.end
**********************************************************************************
*Routine Name:

_COS

*Project:

DMC Mathematical Library

*Originator:

Pascal DORSTER (Texas Instruments)

*Description:

COS function with Direct Lookup and

Interpolation C calling function, variables in C stack.

Fully C compatible

*Status:

*Processor:

C2xx

*Calling convention:

Input : Angle in stack value 0360 degrees <=>0hFFFFh

Output : COS(angle)*32767, Q15, in ACCU

Pointed register AR1

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

POPD

*+

SAR

AR1,*

LAR

AR2,*,AR2

SBRK

SPM

LAC

#4000h

ADDS

SACL

LT

*+

LAC

#64h

SACL

MPYU

;C compatibility

;C compatibility

;add 0.5 for COS


;variable in size_sin
;*******stack : angle/X

;*******stack : angle/TEMP
PAC
SACH

;integer position in the table


;in High part of Acc

*+

;remainder
;*******stack : angle/indice/X

SACL

LAC

*,15

ANDK

#0ffffh,15

;
;*******stack : angle/indice/REMAINDER

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

SUB

*+

;*******stack : Y1/y2/remainder
;difference between the two Y value
;*******stack : y1/Y2/remainder
SACL

*+
;*******stack : y1/temp/REMAINDER

LT

MPY

;*******stack : y1/TEMP/remainder
;*******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

RET
equal_sin
LALK

Table_sin

;address of beginning of the table

ADD

;address of the pointed indice

TBLR

LAC

*+,0,AR1

;*******stack : RESULT/

A-7

MAR

PSHD

SBRK

;C compatibility

RET
**********************************************************************************
* Table
**********************************************************************************
Table_sin

.include

sine.tab

Table_sin_end
.word

.end
**********************************************************************************
*Routine Name:

SIN

*Project:

DMC Mathematical Library

*Originator:

Pascal DORSTER (Texas Instruments)

*Description:

SIN function with Direct Lookup and Interpolation

Assembly calling function, variables in s/w stack.

*Status:

*Processor:

C2xx

*
*

*Calling convention:

Input : Angle in stack value 0360 degrees <=>0hFFFFh

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

*________________________________________________________________________________*
A-8

*Date of Mod

DESCRIPTION

*|*
*

**********************************************************************************
SIN
MAR

*+

LT

*+

;variable in size_sin
;*******stack : angle/X

LAC

#64h

SACL

*
;*******stack : angle/TEMP

MPYU

PAC

;integer position in the table


;in High part of Acc

SACH

*+

;remainder

SACL

;*******stack : angle/indice/X
;*******stack : angle/indice/REMAINDER
LAC

*,15

ANDK

#0ffffh,15

SACH

BCND

equal_sin,EQ

LALK

Table_sin

;address of beginning of the table

ADD

;address of the nearest first indice

TBLR

*+

;*******stack : angle/INDICE/remainder

;*******stack : ANGLE/indice/remainder
;*******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

SPH

;*******stack : y1/TEMP/remainder
;interpolation between Y1 and Y2
;*******stack : Y1/temp/remainder
LAC

*+
;*******stack : y1/TEMP/remainder

ADD

*,1

;Y(Xdata) in ACCU

LALK

Table_sin

;address of beginning of the table

ADD

;address of the pointed indice

RET
equal_sin

;*******stack : RESULT/
TBLR

LAC

*+
;*******stack : result/X

end_interp_sin
RET

*********************************************************************************
* Table
*********************************************************************************

Table_sin

.include

sine.tab

Table_sin_end
.word 0
**********************************************************************************
*Routine Name:

_SIN

*Project:

DMC Mathematical Library

*Originator:

Pascal DORSTER (Texas Instruments)

*Description:
*

SIN function with Direct Lookup + Interpolation

C calling function, variables in C stack.

Fully C compatible

A-10

*Status:

*Processor:

C2x

*Calling convention:

Input : Angle in stack value 0360 degrees <=>0hFFFFh

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

POPD

*+

SAR

AR1,*

LAR

AR2,*,AR2

SBRK

SPM

LT

*+

;C compatibility

;C compatibility

;variable in size_sin
;*******stack : angle/X

LAC

#64h

SACL

*
;*******stack : angle/TEMP

MPYU

;integer position in the table

A-11

PAC
SACH

;in High part of Acc


*+

;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

*+

SACL

*+

;difference between the two Y value


;*******stack : y1/Y2/remainder
;*******stack : y1/temp/REMAINDER

LT

MPY

;*******stack : y1/TEMP/remainder
;*******stack : y1/TEMP/remainder
SPH

;interpolation between Y1 and Y2


;*******stack : Y1/temp/remainder

LAC

*+

ADD

*,1,AR1

;Y(Xdata) in ACCU

MAR

;C compatibility

PSHD

SBRK

;*******stack : y1/TEMP/remainder

RET
A-12

equal_sin
LALK

Table_sin

;address of beginning of the table

ADD

;address of the pointed indice

TBLR

LAC

*+,0,AR1

MAR

PSHD

SBRK

;*******stack : RESULT/...

;*******stack : result/X
;C compatibility

RET
**********************************************************************************
* Table
**********************************************************************************
Table_sin

.include

sine.tab

Table_sin_end
.word

**********************************************************************************
* TABLE Sine and Cosine for separate functions COS and SIN

**********************************************************************************
.word

.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

.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 Lookup and Interpolation

Assembly calling function, variables in s/w stack.

*Status:

*Processor:

C2xx

*Calling convention:

Input : Angle in stack value 0360 degrees <=>0hFFFFh

Output:

SIN(angle)*32767, Q15, in stack pointed by AR11

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

*|*
*

**********************************************************************************
size_tab .set
A-16

64h

;this is not an error

COS_SIN
MAR

*+

LT

*+

;variable in size_sin
;*stack: angle/X

LAC

#size_tab

SACL

*
;*stack: angle/TEMP

MPYU

PAC
SACH

;integer position in the table


;in High part of Acc

*+

;remainder
;*stack: angle/indice/X

SACL

LAC

*,15

ANDK

#0ffffh,15

SACH

;
;*stack: angle/indice/REMAINDER

;*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

ADD

#18h

TBLR

*+

ADD

#1h

TBLR

;*stack: y1/y2/remainder/yy1/YY2

LAC

;calculate cos interpolate

;*stack: y1/y2/remainder/X

;*stack: y1/y2/remainder/yy1/X

;*stack: y1/y2/remainder/YY1/yy2

A-17

SUB

*+

;difference between the two Y value


;*stack: y1/y2/remainder/yy1/YY2

SACL

LT

;*stack: y1/y2/remainder/yy1/TEMP
;*stack: y1/y2/remainder/YY1

SBRK

MPY

;*stack: y1/y2/REMAINDER/yy1
;*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

SACL

;Y(Xdata) in ACCU
;*stack: y1/y2/remainder/YY1
;*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

MPY

;*stack: y1/TEMP/remainder/cos
;*stack: y1/TEMP/remainder/cos
SPH

;interpolation between Y1 and Y2


;*stack: Y1/temp/remainder/cos

LAC

*+

ADD

*,1

;*stack: y1/TEMP/remainder/cos
;Y(Xdata) in ACCU
;*stack: y1/temp/remainder/cos
A-18

SACL

ADRK

;*stack: SIN/temp/remainder/cos
;*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

TBLR

*+

;address of the pointed indice


;*stack: ANGLE/indice
;*stack: sin/INDICE/remainder

ADDK

19h

TBLR

*
;*stack: sin/COS

end_interp_sin
RET
**********************************************************************************
* Table
**********************************************************************************
Table_sin_cos

.include sin_cos.tab

Table_sin_cos_end
.word

**********************************************************************************
* TABLE Sine + Cosine for functions COS_SIN

**********************************************************************************
.word

.word

2057

.word

4107

.word

6140

.word

8149

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

.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

.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 0360 degrees <=>0hFFFFh

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

MPYK

0c90h

;abscissa scale modify degree > rad

SACH

*,4

;angle in rad

LT

*+

;*stack : angle/X
PAC
;*stack : angle/RAD
;*stack : angle/rad/X
MPYK

985h

;0.0372
;
;PREG : angle * 0.0372

LAC

#0C426h,13

APAC

; in high ACCU
;ACCU : 0.2338 + angle * 0.0372

SACH

* ,3

;temporary value

MPY

;multiply by temporary value

;angle in TREG
;temporary value
;*stack : angle/rad/TEMP
LAC

#6f69h,10

APAC
SACH

;0.0544
;ACCU: temp + 0.0544

*,2

;temp
;*stack : angle/RAD/temp
;angle in TREG
;*stack : angle/rad/TEMP

MPY

;temp

LAC

#7dc5h,13

;0.9826

APAC
SACH

;ACCU=0.9826+temp
*,3

;treg = rad
;temp

MPY

;rad * temp

LAC

#05532,4

;0.0013

;temp * angle
APAC
A-24

SACH

* ,3

LAC

;result
;*stack : angle/SIN

RET
angle_neg
LT

*+

;variable in size_sin
;*stack : angle/X

MPYK

0c90h

;abscisse scale modif degre > rad

*,4

;angle in rad

PAC
SACH

;*stack : angle/RAD
LT

*+
;*stack : angle/rad/X

MPYK

985h

;0.0372
;
;PREG : angle * 0.0372

LAC

#03bdah,13

; in high ACCU

* ,3

;temporary value

APAC
SACH

;ACCU : 0.2338 + angle * 0.0372


;angle in TREG

MPY

;multiply by temporary value


;temporary value
;*stack : angle/rad/TEMP

LAC

#6f69h,10

APAC
SACH

;0.0544
;ACCU: temp + 0.0544

*,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

LAC

;result
;*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 0360 degrees <=>0hFFFFh

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
A-26

;C compatibility

POPD

*+

SAR

AR1,*

LAR

AR2,*,AR2

SBRK

SPM

SETC

SXM

LAC

BCND

angle_neg,LT

;C compatibility

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

*+

MPYK

985h

;*stack : angle/rad/X
;0.0372
;
;PREG : angle * 0.0372
LAC

#0C426h,13

APAC

; in high ACCU
;ACCU : 0.2338 + angle * 0.0372

SACH

* ,3

;temporary value

MPY

;multiply by temporary value

;angle in TREG
;temporary value
;*stack : angle/rad/TEMP
LAC

#6f69h,10

APAC
SACH

;0.0544
;ACCU: temp + 0.0544

*,2

;temp
;*stack : angle/RAD/temp
;angle in TREG
;*stack : angle/rad/TEMP

MPY

;temp

LAC

#7dc5h,13

;0.9826

A-27

APAC
SACH

;ACCU=0.9826+temp
*,3

;treg = rad
;temp

MPY

;rad * temp
;temp * angle

LAC

#05532,4

;0.0013

SACH

* ,3

;result

LAC

*,0,AR1

APAC

;*stack : angle/SIN
MAR

PSHD

SBRK

;C compatibility

RET
angle_neg
LT

*+

;variable in size_sin
;*stack : angle/X

MPYK

0c90h

;abscisse scale modif degre > rad

SACH

*,4

;angle in rad

LT

*+

PAC
;*stack : angle/RAD
;*stack : angle/rad/X
MPYK

985h

;0.0372
;
;PREG : angle * 0.0372

LAC

#03bdah,13

; in high ACCU

* ,3

;temporary value

APAC
SACH

;ACCU : 0.2338 + angle * 0.0372


;angle in TREG

MPY

;multiply by temporary value


;temporary value
;*stack : angle/rad/TEMP

LAC

#6f69h,10

APAC
SACH
A-28

;0.0544
;ACCU: temp + 0.0544

*,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

SACH

*,3

;result

LAC

*,0,AR1

APAC

;*stack : angle/SIN
MAR

PSHD

SBRK

;C compatibility

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 0360 degrees <=>0hFFFFh

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

MPYK

0c90h

;abscisse scale modif degre > rad

SACH

*,4

;angle in rad

LT

*+

;*stack : angle/X
PAC
;*stack : angle/RAD
;*stack : angle/rad/X
MPYK

1070h

;0.0076 neg
;
;PREG : angle * 0.0076

LAC

#01e76h,15

APAC

; in high ACCU
;ACCU : +0.0595 + angle * 0.0076

SACH

* ,3

;temporary value

MPY

;multiply by temporary value

;angle in TREG
;temporary value
A-30

;*stack : angle/rad/TEMP
LAC

#0f532h,15

APAC
SACH

;0.0211
;ACCU: temp + 0.0211

;temp
;*stack : angle/RAD/temp
;angle in TREG
;*stack : angle/rad/TEMP

MPY

;temp

LAC

#0e0c6h,15

;0.4879

APAC

;ACCU=0.9826+temp

SACH

*,2

;treg = rad

MPY

;rad * temp

LAC

#0a440h,5

;0.0028

;temp * angle
APAC
SACH

*,2

;result

MPY

LAC

#1000h,15

;1

APAC
SETC

OVM

SACH

*,3

LAC

*,16

ADD

*,16

SACH

LAC

*
;*stack : angle/SIN

RET
angle_neg
LT

*+

;variable in size_sin
;*stack : angle/X

MPYK

0c90h

;abscisse scale modif degre > rad

SACH

*,4

;angle in rad

LT

*+

PAC
;*stack : angle/RAD
;*stack : angle/rad/X

A-31

MPYK

0f90h

;0.0076 neg
;
;PREG : angle * 0.0076

LAC

#01e76h,15

APAC

; in high ACCU
;ACCU : +0.0595 + angle * 0.0076

SACH

* ,3

;temporary value

MPY

;multiply by temporary value

;angle in TREG
;temporary value
;*stack : angle/rad/TEMP
LAC

#00aceh,15

APAC
SACH

;0.0211
;ACCU: temp + 0.0211

;temp
;*stack : angle/RAD/temp
;angle in TREG
;*stack : angle/rad/TEMP

MPY

;temp

LAC

#0e0c6h,15

;0.4879

APAC
SACH

;ACCU=0.9826+temp
*,2

;treg = rad
;temp

MPY

;rad * temp
;temp * angle

LAC

#05bc0h,5

;0.0028

APAC
SACH

*,2

;result

MPY

LAC

#1000h,15

;1

APAC
SETC

OVM

SACH

*,3

LAC

*,16

ADD

*,16

SACH

LAC

*
;*stack : angle/SIN

RET
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 0360 degrees <=>0hFFFFh

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

POPD

*+

SAR

AR1,*

LAR

AR2,*,AR2

SBRK

;C compatibility

;C compatibility

A-33

SPM

SETC

SXM

LAC

BCND

angle_neg,LT

angle_pos
LT

*+

;variable in size_sin
;*stack : angle/X

MPYK

0c90h

;abscisse scale modif degre > rad

*,4

;angle in rad

PAC
SACH

;*stack : angle/RAD
LT

*+
;*stack : angle/rad/X

MPYK

1070h

;0.0076 neg
;
;PREG : angle * 0.0076

LAC

#01e76h,15

; in high ACCU

* ,3

;temporary value

APAC
SACH

;ACCU : +0.0595 + angle * 0.0076


;angle in TREG

MPY

;multiply by temporary value


;temporary value
;*stack : angle/rad/TEMP

LAC

#0f532h,15

APAC
SACH

;0.0211
;ACCU: temp + 0.0211

;temp
;*stack : angle/RAD/temp
;angle in TREG
;*stack : angle/rad/TEMP

MPY

;temp

LAC

#0e0c6h,15

;0.4879

APAC
SACH

;ACCU=0.9826+temp
*,2

;treg = rad
;temp

MPY
A-34

;rad * temp

;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

MAR

PSHD

SBRK

;*stack : angle/SIN
;C compatibility

RET
angle_neg
LT

*+

;variable in size_sin

MPYK

0c90h

;abscisse scale modif degre > rad

SACH

*,4

;angle in rad

LT

*+

;*stack : angle/X
PAC
;*stack : angle/RAD
;*stack : angle/rad/X
MPYK

0f90h

;0.0076 neg
;
;PREG : angle * 0.0076

LAC

#01e76h,15

APAC

; in high ACCU
;ACCU : +0.0595 + angle * 0.0076

SACH

* ,3

;temporary value

MPY

;multiply by temporary value

;angle in TREG
;temporary value

A-35

;*stack : angle/rad/TEMP
LAC

#00aceh,15

APAC
SACH

;0.0211
;ACCU: temp + 0.0211

;temp
;*stack : angle/RAD/temp
;angle in TREG
;*stack : angle/rad/TEMP

MPY

;temp

LAC

#0e0c6h,15

;0.4879

APAC

;ACCU=0.9826+temp

SACH

*,2

;treg = rad

MPY

;rad * temp
;temp * angle in Q28

LAC

#05bc0h,5

;0.0028

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

PSHD

SBRK

RET

A-36

;C compatibility

A-37

You might also like