2004 Microchip Technology Inc.
DS00908A-page 11
AN908
This file contains the
SinCos()
function, which calcu-
lates sine and cosine for a specified angle using linear
interpolation on a table of 128 words.
To save data memory space, the 128-word sine wave
table is placed in program memory and accessed using
the program space visibility (PSV) feature of the dsPIC
architecture. PSV allows a portion of program memory
to be mapped into data memory space so that constant
data can be accessed as if it were in RAM.
This routine works the same for both integer scaling
and 1.15 scaling. For integer scaling the angle is scaled
such that 0
≤
angle < 2
Π
corresponds to 0
≤
angle <
0xFFFF. The resulting Sine and Cosine values are
returned, scaled to -32769 to +32767 (i.e., 0x8000 to
0x7FFF).
For 1.15 scaling, the angle is scaled such that -
Π
≤
angle <
Π
corresponds to -1 to +0.9999 (i.e., 0x8000
≤
angle < 0x7FFF). The resulting sine and cosine values
are returned scaled to -1 to +0.9999 (i.e., 0x8000 to
0x7FFF).
DEMO HARDWARE
The vector control application can be run on the
dsPICDEM™ MC1 Motor Control Development
System. You will need the following hardware:
• Microchip dsPICDEM MC1 Motor Control
Development Board
• 9 VDC power supply
• Microchip dsPICDEM MC1H 3-Phase High
Voltage Power Module
• Power supply cable for the power module
• 3-Phase AC induction motor with shaft encoder
Recommended Motor and Encoder
The following motor and encoder combination was
used to develop this application and select the software
tuning parameters:
• Leeson Cat# 102684 motor, 1/3 HP, 3450 RPM
• U.S. Digital encoder, model E3-500-500-IHT
The Leeson motor can be obtained from Microchip
or an electric motor distributor. The encoder can
be ordered from the U.S. Digital web site,
www.usdigital.com. This model of encoder is shipped
with a mounting alignment kit and a self-sticking
encoder body. The encoder can be mounted directly on
the front face of the motor, as shown in Figure 12. Any
other similar encoder with 500 lines of resolution may
be used instead of the U.S. Digital device, if desired.
FIGURE 11:
HARDWARE SETUP USING
dsPICDEM MOTOR
CONTROL DEVELOPMENT
SYSTEM
FIGURE 12:
LEESON MOTOR WITH
MOUNTED INCREMENTAL
ENCODER
If You Select Another Motor...
If another motor is selected, you will likely have to
experiment with the control loop tuning parameters to
get good response from the control algorithm. At a min-
imum, you will need to determine the rotor electrical
time constant in seconds. This information can be
obtained from the motor manufacturer. The application
will run without the proper rotor time constant, but the
response of the system to transient changes will not be
ideal.
If the above referenced Leeson motor and a 500-line
encoder are used, no adjustment of software tuning
parameters should be necessary to get the demo
running properly.
Note:
An encoder of at least 250 lines per
revolution should be used. The upper limit
would be 32,768 lines per revolution.