FIGURE 9:
PWM FOR PERIOD T
000
PWM1
PWM2
PWM3
T0/4
CODE DESCRIPTION
The vector control source code was developed in
®
MPLAB
using the Microchip MPLAB C30 tool suite.
The main application is written in C and all the primary
vector control functions are written in assembly and
optimized for speed of execution.
Conventions
A description of the functions is contained in the header
of each source file. The equivalent C code for the func-
tion is also included in the header for reference. The C
lines of code are used as comments in the optimized
assembly code so that code flow can easily be
followed.
At the beginning of each function the pertinent vari-
ables are moved to specific working (W) registers that
are used by the DSP and math instructions. The
variables are moved back to their respective register
locations at the end of the code function. Most of these
variables are grouped into structures of related param-
eters to provide efficient access from the C or assembly
code.
Each W register used in an assembly module has been
assigned a descriptive name that tells what value the
register holds during the calculation. The re-naming of
the W registers makes the code easier to follow and
avoids register usage conflicts.
2004 Microchip Technology Inc.
100
110
111
T1/2
T2/2
T0/4
111
110
100
T0/4
T2/2
T1/2
T
Variable Definition and Scaling
Most variables are stored in 1.15 fractional format,
which is one of the inherent math modes in the dsPIC
devices. A signed fixed-point integer is represented as
follows:
• MSB is the sign bit
• range -1 to +.9999
• 0x8000 = -1
• 0000 = 0
• 0x7FFF = .9999
All values are normalized using the Per Unit system
(PU).
V
= V
/V
PU
ACT
B
Then scaled so that the base quantity = .125
This allows for values of 8 times the base value.
V
= 230V, V
=120V, V
B
ACT
PU
→
Scaling
V
= .125 = 0x0FFF (1.15)
B
120V = .5 * .125 = 0x07FF (1.15)
AN908
000
T0/4
= 120/230 =.5PU,
DS00908A-page 7
Need help?
Do you have a question about the AN908 and is the answer not in the manual?