Professional Documents
Culture Documents
Application
Report
1998
SPRA179
1998
Application
Report
SPRA179
July 1998
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.
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
iii
Figures
List of Figures
1
The Formula and the Resulting Graph for Calculating the Table Interpolation
Value COS of an Angle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
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
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
12
13
iv
SPRA179
Tables
List of Tables
1
2
3
4
vi
SPRA179
1 Introduction
Sine-wave generators are fundamental building blocks of signal processing
systems for use in control applications. The following two methods
described in this application report are for implementing a digital sine-wave
generator using the TMS320C2xx:
Direct look-up with linear interpolation to provide sine waves with a
minimum of harmonic distortion
Realization of the sine/cosine functions with a mathematical series
The two methods respond to different constraints. The direct look-up
method is fast with minimal errors and is significant in ROM programming
requirements. The mathematical series method is fast and requires
minimum (ROM) programming but results in less precision.
2.1
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
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
System Utilization
Table 1 shows processor utilization when using the direct look-up and linear
interpolation methods.
Digital Sine-Wave Generation Using the TMS320C2xx
CYCLES
EXECUTION TIME
35
1.75 s
38
1.90 s
42
2.10 s
45
2.25 s
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)
32 + 100
In stack
34 + 100
In stack
66 + 100
In stack
42 + 100
In stack
44 + 100
In stack
55 + 125
In stack
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
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
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 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
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 %
3.1
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
3.2
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
27
1.35 s
37
1.85 s
34
1.70 s
44
2.20 s
64
3.20 s
11
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
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
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.
13
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
15
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
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 %
17
18
SPRA179
Examples of a C Program and an Assembly Program Calling Sine and Cosine Functions
Appendix A
A.1
********************************************************************************
*File Name:
Main_trig.c
*Project:
*Originator:
*Description:
*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);
.
}
A-1
Examples of a C Program and an Assembly Program Calling Sine and Cosine Functions
A.2
**********************************************************************************
*File Name:
Main_trig.asm
*Project:
*Originator:
*Description:
*
*
*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
A-3
Examples of a C Program and an Assembly Program Calling Sine and Cosine Functions
A.3
**********************************************************************************
*Routine Name:
COS
*Project:
*Originator:
*Description:
*Status:
*Processor:
C2xx
*Calling convention:
*Stack commentary:
*Last Update:
16 Oct 96
*________________________________________________________________________________*
*Date of Mod
DESCRIPTION
*|*
*
**********************************************************************************
COS
MAR
LACC
#4000h
ADDS
SACL
LT
*+
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
*+
;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
TBLR
*+
;*******stack : y1/INDICE/remainder
ADD
#1h
TBLR
LACC
*
;*******stack : Y1/y2/remainder
SUB
*+
SACL
*+
;*******stack : y1/temp/REMAINDER
LT
MPY
;*******stack : y1/TEMP/remainder
;*******stack : y1/TEMP/remainder
SPH
LACC
*+
ADD
*,1
;*******stack : y1/TEMP/remainder
;Y(Xdata) in ACCU
RET
A-5
Examples of a C Program and an Assembly Program Calling Sine and Cosine Functions
equal_sin
LACC
#Table_sin
ADD
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
**********************************************************************************
*Routine Name:
_COS
*Project:
*Originator:
*Description:
Fully C compatible
*Status:
*Processor:
C2xx
*Calling convention:
*Stack commentary:
*Last Update:
16 Oct 96
*________________________________________________________________________________*
*Date of Mod
DESCRIPTION
*|*
*
**********************************************************************************
_COS
ADRK
#2
POPD
*+
SAR
AR1,*
LAR
AR2,*,AR2
;C compatibility
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
LACC
#64h
SACL
MPYU
;*******stack : angle/TEMP
PAC
SACH
*+
;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
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
*+
;*******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
MAR
PSHD
SBRK
#1
;C compatibility
RET
**********************************************************************************
* Table
**********************************************************************************
Table_sin
.include
sine.tab
Table_sin_end
.word
.end
A-9
Examples of a C Program and an Assembly Program Calling Sine and Cosine Functions
A.5
**********************************************************************************
*Routine Name:
SIN
*Project:
*Originator:
*Description:
*Status:
*Processor:
C2xx
*Calling convention:
*Stack commentary:
*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
*+
;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
*+
ADD
*,1
;Y(Xdata) in ACCU
RET
equal_sin
A-11
Examples of a C Program and an Assembly Program Calling Sine and Cosine Functions
LACC
#Table_sin
ADD
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
**********************************************************************************
*Routine Name:
_SIN
*Project:
*Originator:
*Description:
*
Fully C compatible
*Status:
*Processor:
C2x
*Calling convention:
*Stack commentary:
*Last Update:
16 Oct 96
*________________________________________________________________________________*
*Date of Mod
DESCRIPTION
*|*
*
**********************************************************************************
_SIN
ADRK
#2
POPD
*+
;C compatibility
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
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
LACC
*
;*******stack : Y1/y2/remainder
SUB
*+
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
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
TBLR
LACC
*+,0,AR1
;*******stack : result/X
MAR
PSHD
SBRK
#1
;C compatibility
RET
**********************************************************************************
* Table
**********************************************************************************
Table_sin
.include
sine.tab
Table_sin_end
.word
A-15
Examples of a C Program and an Assembly Program Calling Sine and Cosine Functions
A.7
**********************************************************************************
* 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
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
**********************************************************************************
*Routine Name:
COS_SIN
*Project:
*Originator:
*Description:
*Status:
*Processor:
C2xx
*Calling convention:
Output:
*Stack commentary:
*Last Update:
16 Oct 96
*________________________________________________________________________________*
*Date of Mod
DESCRIPTION
*|*
*
**********************************************************************************
size_tab .set
64h
COS_SIN
MAR
*+
LT
*+
;variable in size_sin
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
*+
;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
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
SUB
*+
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
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
*+
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
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
ADD
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 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
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
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
**********************************************************************************
*Routine Name:
sin_ser
*Project:
*Originator:
*Description:
*Status:
*Processor:
C2xx
*Calling convention:
*Stack commentary:
*Last Update:
18 Oct 96
*________________________________________________________________________________*
*Date of Mod
DESCRIPTION
*|*
*
**********************************************************************************
sin_ser
SETC
SXM
MAR
LAC
BCND
angle_neg,LT
angle_pos
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
*,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
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
*,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
;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
A-29
Examples of a C Program and an Assembly Program Calling Sine and Cosine Functions
A.11
**********************************************************************************
*Routine Name:
_sin_ser
*Project:
*Originator:
*Description:
Fully C compatible
*Status:
*Processor:
C2xx
*Calling convention:
*Stack commentary:
*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
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
;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
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
*,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
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
A-33
Examples of a C Program and an Assembly Program Calling Sine and Cosine Functions
A.12
**********************************************************************************
*Routine Name:
cos_ser
*Project:
*Originator:
*Description:
*Status:
*Processor:
C2xx
*Calling convention:
*Stack commentary:
*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
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
MPY
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
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
*,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
MPY
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
A-37
Examples of a C Program and an Assembly Program Calling Sine and Cosine Functions
A.13
**********************************************************************************
*Routine Name:
_cos_ser
*Project:
*Originator:
*Description:
C calling function,
*Status:
*Processor:
C2xx
*Calling convention:
*Stack commentary:
*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
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
;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
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
*,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
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
A-41
A-42
SPRA179
B Introduction
Sine-wave generators are fundamental building blocks of signal processing
systems for use in control applications. The following two methods are
described in this application report for implementing a digital sine-wave
generator using the TMS320C2xx:
Direct look-up with linear interpolation to provide sine waves with a
minimum of harmonic distortion
Realization of the sine/cosine functions with a mathematical series
The two methods respond to different constraints. The direct look-up
method is fast with minimum errors and is significant in ROM programming
requirements. The mathematical series method is fast and requires
minimum (ROM) programming but results in less precision.
A-1
C.1
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
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
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
CYCLES
EXECUTION TIME
35
1.75 s
38
1.90 s
42
2.10 s
45
2.25 s
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)
32 + 100
In stack
34 + 100
In stack
66 + 100
In stack
42 + 100
In stack
44 + 100
In stack
55 + 125
In stack
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
A-5
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
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.
A-7
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
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 %
A-9
D.1
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
D.2
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.
CYCLES
EXECUTION TIME
27
1.35 s
37
1.85 s
34
1.70 s
44
2.20 s
64
3.20 s
A-11
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
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
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.
A-13
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
Figure B11.
A-15
A-16
STDZ001A
A-17
********************************************************************************
*File Name:
Main_trig.c
*Project:
*Originator:
*Description:
*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:
*Originator:
A-1
*Description:
*
*
*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:
*Originator:
*Description:
*Status:
*Processor:
C2xx
*Calling convention:
*Stack commentary:
*Last Update:
16 Oct 96
*________________________________________________________________________________*
*Date of Mod
DESCRIPTION
*|*
*
**********************************************************************************
COS
MAR
LAC
#4000h
ADDS
A-3
SACL
LT
*+
;variable in size_sin
;*******stack : angle/X
LAC
#64h
SACL
*
;*******stack : angle/TEMP
MPYU
PAC
SACH
*+
;remainder
;*******stack : angle/indice/X
SACL
;
;*******stack : angle/indice/REMAINDER
LAC
*,15
ANDK
#0ffffh,15
SACH
*
;*******stack : angle/INDICE/remainder
BCND
equal_sin,EQ
LALK
Table_sin
ADD
TBLR
*+
;*******stack : ANGLE/indice/remainder
;*******stack : y1/INDICE/remainder
ADD
#1h
TBLR
LAC
*
;*******stack : Y1/y2/remainder
SUB
*+
SACL
*+
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
ADD
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:
*Originator:
*Description:
Fully C compatible
*Status:
*Processor:
C2xx
*Calling convention:
A-5
*Stack commentary:
*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
;*******stack : angle/TEMP
PAC
SACH
*+
;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
ADD
TBLR
*+
;*******stack : y1/INDICE/remainder
ADD
#1h
TBLR
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
LAC
*+
;*******stack : y1/TEMP/remainder
ADD
*,1,AR1
;Y(Xdata) in ACCU
MAR
;C compatibility
PSHD
SBRK
RET
equal_sin
LALK
Table_sin
ADD
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:
*Originator:
*Description:
*Status:
*Processor:
C2xx
*
*
*Calling convention:
*Stack commentary:
*
*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
SACH
*+
;remainder
SACL
;*******stack : angle/indice/X
;*******stack : angle/indice/REMAINDER
LAC
*,15
ANDK
#0ffffh,15
SACH
BCND
equal_sin,EQ
LALK
Table_sin
ADD
TBLR
*+
;*******stack : angle/INDICE/remainder
;*******stack : ANGLE/indice/remainder
;*******stack : y1/INDICE/remainder
ADD
#1h
TBLR
LAC
*
;*******stack : Y1/y2/remainder
SUB
*+
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
ADD
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:
*Originator:
*Description:
*
Fully C compatible
A-10
*Status:
*Processor:
C2x
*Calling convention:
*Stack commentary:
*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
A-11
PAC
SACH
;remainder
;*******stack : angle/indice/X
SACL
;
;*******stack : angle/indice/REMAINDER
LAC
*,15
ANDK
#0ffffh,15
SACH
*
;*******stack : angle/INDICE/remainder
BCND
equal_sin,EQ
LALK
Table_sin
ADD
TBLR
*+
;*******stack : y1/INDICE/remainder
ADD
#1h
TBLR
LAC
*
;*******stack : Y1/y2/remainder
SUB
*+
SACL
*+
LT
MPY
;*******stack : y1/TEMP/remainder
;*******stack : y1/TEMP/remainder
SPH
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
ADD
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:
*Originator:
*Description:
*Status:
*Processor:
C2xx
*Calling convention:
Output:
*Stack commentary:
*Last Update:
16 Oct 96
*________________________________________________________________________________*
*Date of Mod
DESCRIPTION
*|*
*
**********************************************************************************
size_tab .set
A-16
64h
COS_SIN
MAR
*+
LT
*+
;variable in size_sin
;*stack: angle/X
LAC
#size_tab
SACL
*
;*stack: angle/TEMP
MPYU
PAC
SACH
*+
;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
ADD
TBLR
*+
;*stack: y1/INDICE/remainder
ADD
#1h
TBLR
*+
ADRK
ADD
#18h
TBLR
*+
ADD
#1h
TBLR
;*stack: y1/y2/remainder/yy1/YY2
LAC
;*stack: y1/y2/remainder/X
;*stack: y1/y2/remainder/yy1/X
;*stack: y1/y2/remainder/YY1/yy2
A-17
SUB
*+
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
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
*+
SACL
*+
;*stack: y1/temp/REMAINDER/cos
LT
MPY
;*stack: y1/TEMP/remainder/cos
;*stack: y1/TEMP/remainder/cos
SPH
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
ADD
TBLR
*+
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:
*Originator:
*Description:
*Status:
*Processor:
C2xx
*Calling convention:
*Stack commentary:
*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
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
;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
*,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
MPY
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:
*Originator:
*Description:
Fully C compatible
*Status:
*Processor:
C2xx
*Calling convention:
*Stack commentary:
*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
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
;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
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
MPY
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:
*Originator:
*Description:
*Status:
*Processor:
C2xx
*Calling convention:
A-29
*Stack commentary:
*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
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
;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
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
;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:
*Originator:
*Description:
C calling function,
*Status:
*Processor:
C2xx
*Calling convention:
*Stack commentary:
*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
*,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
MPY
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
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
;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:
*Originator:
*Description:
*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:
*Originator:
A-1
*Description:
*
*
*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:
*Originator:
*Description:
*Status:
*Processor:
C2xx
*Calling convention:
*Stack commentary:
*Last Update:
16 Oct 96
*________________________________________________________________________________*
*Date of Mod
DESCRIPTION
*|*
*
**********************************************************************************
COS
MAR
LAC
#4000h
ADDS
A-3
SACL
LT
*+
;variable in size_sin
;*******stack : angle/X
LAC
#64h
SACL
*
;*******stack : angle/TEMP
MPYU
PAC
SACH
*+
;remainder
;*******stack : angle/indice/X
SACL
;
;*******stack : angle/indice/REMAINDER
LAC
*,15
ANDK
#0ffffh,15
SACH
*
;*******stack : angle/INDICE/remainder
BCND
equal_sin,EQ
LALK
Table_sin
ADD
TBLR
*+
;*******stack : ANGLE/indice/remainder
;*******stack : y1/INDICE/remainder
ADD
#1h
TBLR
LAC
*
;*******stack : Y1/y2/remainder
SUB
*+
SACL
*+
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
ADD
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:
*Originator:
*Description:
Fully C compatible
*Status:
*Processor:
C2xx
*Calling convention:
A-5
*Stack commentary:
*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
;*******stack : angle/TEMP
PAC
SACH
*+
;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
ADD
TBLR
*+
;*******stack : y1/INDICE/remainder
ADD
#1h
TBLR
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
LAC
*+
;*******stack : y1/TEMP/remainder
ADD
*,1,AR1
;Y(Xdata) in ACCU
MAR
;C compatibility
PSHD
SBRK
RET
equal_sin
LALK
Table_sin
ADD
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:
*Originator:
*Description:
*Status:
*Processor:
C2xx
*
*
*Calling convention:
*Stack commentary:
*
*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
SACH
*+
;remainder
SACL
;*******stack : angle/indice/X
;*******stack : angle/indice/REMAINDER
LAC
*,15
ANDK
#0ffffh,15
SACH
BCND
equal_sin,EQ
LALK
Table_sin
ADD
TBLR
*+
;*******stack : angle/INDICE/remainder
;*******stack : ANGLE/indice/remainder
;*******stack : y1/INDICE/remainder
ADD
#1h
TBLR
LAC
*
;*******stack : Y1/y2/remainder
SUB
*+
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
ADD
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:
*Originator:
*Description:
*
Fully C compatible
A-10
*Status:
*Processor:
C2x
*Calling convention:
*Stack commentary:
*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
A-11
PAC
SACH
;remainder
;*******stack : angle/indice/X
SACL
;
;*******stack : angle/indice/REMAINDER
LAC
*,15
ANDK
#0ffffh,15
SACH
*
;*******stack : angle/INDICE/remainder
BCND
equal_sin,EQ
LALK
Table_sin
ADD
TBLR
*+
;*******stack : y1/INDICE/remainder
ADD
#1h
TBLR
LAC
*
;*******stack : Y1/y2/remainder
SUB
*+
SACL
*+
LT
MPY
;*******stack : y1/TEMP/remainder
;*******stack : y1/TEMP/remainder
SPH
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
ADD
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:
*Originator:
*Description:
*Status:
*Processor:
C2xx
*Calling convention:
Output:
*Stack commentary:
*Last Update:
16 Oct 96
*________________________________________________________________________________*
*Date of Mod
DESCRIPTION
*|*
*
**********************************************************************************
size_tab .set
A-16
64h
COS_SIN
MAR
*+
LT
*+
;variable in size_sin
;*stack: angle/X
LAC
#size_tab
SACL
*
;*stack: angle/TEMP
MPYU
PAC
SACH
*+
;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
ADD
TBLR
*+
;*stack: y1/INDICE/remainder
ADD
#1h
TBLR
*+
ADRK
ADD
#18h
TBLR
*+
ADD
#1h
TBLR
;*stack: y1/y2/remainder/yy1/YY2
LAC
;*stack: y1/y2/remainder/X
;*stack: y1/y2/remainder/yy1/X
;*stack: y1/y2/remainder/YY1/yy2
A-17
SUB
*+
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
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
*+
SACL
*+
;*stack: y1/temp/REMAINDER/cos
LT
MPY
;*stack: y1/TEMP/remainder/cos
;*stack: y1/TEMP/remainder/cos
SPH
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
ADD
TBLR
*+
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:
*Originator:
*Description:
*Status:
*Processor:
C2xx
*Calling convention:
*Stack commentary:
*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
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
;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
*,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
MPY
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:
*Originator:
*Description:
Fully C compatible
*Status:
*Processor:
C2xx
*Calling convention:
*Stack commentary:
*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
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
;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
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
MPY
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:
*Originator:
*Description:
*Status:
*Processor:
C2xx
*Calling convention:
A-29
*Stack commentary:
*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
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
;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
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
;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:
*Originator:
*Description:
C calling function,
*Status:
*Processor:
C2xx
*Calling convention:
*Stack commentary:
*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
*,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
MPY
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
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
;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