![Microchip Technology AN908 Using Manual Download Page 8](http://html1.mh-extra.com/html/microchip-technology/an908/an908_using-manual_1785807008.webp)
AN908
DS00908A-page 8
2004 Microchip Technology Inc.
Individual Source File Descriptions
This section describes the functions contained in each
source file.
UserParms.h
All user definable parameters are located in the User-
Parms.h file. These parameters include motor data and
control loop tuning values. More information on the
parameters is provided in the Software Tuning section
of this document.
The ACIM.c file is the primary source code file for the
application. This file contains the main software loop
and all ISR handlers. This file calls all hardware and
variable initialization routines.
To accomplish high performance closed loop control
the entire vector control loop must be executed every
PWM cycle. This is done in the ISR for the ADC con-
verter. The PWM timebase is used to trigger ADC
conversions. When the ADC conversion is complete,
an interrupt is generated.
When not in the ISR, a main software loop is run that
handles the user interface. A software count variable is
maintained in the ISR so that the user interface is run
at periodic intervals. As written, the user interface code
is scheduled to run every 50 milliseconds. This param-
eter can be changed by modifying the UserParms.h
file.
A software diagnostics mode can be enabled by un-
commenting the
#define DIAGNOSTICS
statement
in the UserParms.h file. The diagnostics mode enables
output compare channels OC7 and OC8 as PWM out-
puts. These outputs can be filtered using simple RC fil-
ters and used like a D/A converter to observe the time
history of software variables. The diagnostics output
simplifies tuning of the PI control loops. More informa-
tion on the diagnostics output is provided in the Soft-
ware Tuning section of this document.
This file contains the
InitCurModScaling()
func-
tion, which is called from the setup routines in the
ACIM.c file. This function is used to calculated fixed-
point scaling factors that are used in the current model
equations from floating point values. The current model
scaling factors are a function of the rotor time constant,
vector calculation loop period, number of motor poles
and the maximum motor velocity in revolutions per
second.
This file contains the
CalcRefVec()
function, which
calculates the scaled 3-phase voltage output vector,
(V
r1
, V
r2
, V
r3
), from v
α
and v
β
. The function implements
the inverse Clarke function, which translates the volt-
age vector components from a 2-coordinate system
back to a 3-coordinate system that can be used by the
3-phase PWM. The method is a modified inverse
Clarke transform where v
α
and v
β
are swapped com-
pared to the normal Inverse Clarke. The modified
method must be used to produce the proper phase
alignment of the voltage vector.
This file has three functions,
InitCalcVel()
,
CalcVelIrp()
and
CalcVel()
, which are used to
determine the motor velocity. The
InitCalcVel()
function initializes key variables associated with the
velocity calculations.
The
CalcVelIrp()
function is called at each vector
control interrupt period. The interrupt interval,
VelPeriod
, MUST be less than the minimum time
required for 1/2 revolution at maximum speed.
This routine accumulates the change for a specified
number of interrupt periods, then copies the accumula-
tion value to the
iDeltaCnt
variable for use by the
CalcVel()
routine to calculate velocity. The accumu-
lation is set back to zero and a new accumulation
starts.
The
CalcVel()
routine is only called when new
velocity information is available. For the default
software values, the
CalcVel()
routine is called every
30 interrupt periods. This interval gives new velocity
information every 1.5msec for a 50usec interrupt
period. The velocity control loop is run each time new
velocity information is obtained.
This file contains the function
ClarkePark()
and
calculates Clarke and Park transforms. The function
uses the sine and cosine values of the flux position
angle to calculate the quadrature current values of I
d
and I
q
. This routine works the same for both integer
scaling and 1.15 scaling.
This file contains the
CurModel()
and
InitCur-
Model()
functions. The
CurModel()
function
executes the rotor current model equation to determine
a new rotor flux angle as a function of the rotor velocity
and the transformed stator current components. The
InitCurModel()
function is used to clear variables
associated with the
CurModel()
routine.
Note:
If you are viewing an electronic version of
this application note, you can click on the
following file names to navigate to the
code in