DRM148
DRM148
1. Introduction Contents
Sinusoidal Permanent Magnet Synchronous Motors 1. Introduction........................................................................ 1
(PMSM) are getting more and more popular, replacing 2. PMSM Control Theory ...................................................... 2
brushed DC, universal, and other motors in a wide 2.1. 3-phase PMSM ....................................................... 2
2.2. Mathematical description of PMSM ....................... 2
application area. Here are some of the reasons: 2.3. PMSM field-oriented control .................................. 6
3. Software Design ............................................................... 14
Better reliability when compared to brushed DC 3.1. Data types ............................................................. 14
motors. 3.2. Scaling of analog quantities .................................. 15
3.3. Application overview ............................................ 16
Better efficiency when compared to AC 3.4. Synchronizing motor-control algorithms .............. 17
Induction Motors (ACIM) because the rotor flux 3.5. Calling algorithms................................................. 18
is generated by magnets. 3.6. Main state machine ............................................... 19
3.7. Motor state machine.............................................. 22
Lower acoustic noise. 3.8. Sensorless PMSM control ..................................... 27
4. Acronyms and Abbreviations ........................................... 38
Smaller dimensions when compared to ACIM. 5. List of Symbols ................................................................ 39
The disadvantage of the PMSM drives is the need for a 6. Revision History .............................................................. 40
more sophisticated electronic circuit. Nowadays, most
applications need electronic speed or torque regulation
and other features with the necessity of electronic
control. When a system with electronic control is used,
it only takes small system cost increase to implement
more advanced drives, such as the sinusoidal PMSM
with a digitally-controlled switching inverter and a
DC-bus circuit. It is only necessary to have a
cost-effective controller with a good calculation
performance. PMSMs are used in domestic appliances
(such as refrigerators, washing machines, dishwashers),
pumps, compressors, fans, and other appliances that
require high reliability and efficiency.
The control algorithms are divided into two general groups. The first group is called scalar control (SC).
The constant Volt per Hertz control represents the scalar control. The other group is called vector
control (VC), or field-oriented control (FOC). The FOC technique brings overall improvements in drive
performance when compared to the scalar control (higher efficiency, full torque control from zero to
nominal motor speed, decoupled control of flux and torque, improved dynamics, etc.). For the PMSM
control, it is necessary to know the exact rotor position. This application uses special algorithms to
estimate the speed and position instead of using a physical position sensor.
The software algorithms consist of software blocks (such as the state machine, motor-control drivers
(MCDRV), and motor-control application tuning (MCAT) tool) supporting online application tuning.
This design reference manual describes the basic motor theory and software design.
In this aspect, the PMSM is equivalent to induction motors, where the air gap magnetic field is produced
by permanent magnets, so the rotor magnetic field is constant. The PMSMs offer a number of
advantages in designing modern motion-control systems. The use of a permanent magnet to generate
a substantial air gap magnetic flux makes it possible to design highly efficient PMSMs.
Complex space vectors are described using only two orthogonal axes. Using the 2-phase motor model
reduces the number of equations and simplifies the control design.
where a and a2 are the spatial operators = 2/3 , 2 = 4/3 , and k is the transformation constant
k=2/3. Figure 2 shows the stator-current space vector projection. The space vector defined by Eq. 3 can
be expressed using the 2-axis theory. The real part of the space vector is equal to the instantaneous value
of the direct-axis stator current component is, and its imaginary part is equal to the quadrature-axis
stator current component is. Thus, the stator-current space vector in the stationary reference frame
attached to the stator is expressed as:
Eq. 3 = +
phase-b
isc
isb
is
_
is
isb
isa is phase-a,
isc
phase-c
In symmetrical 3-phase machines, the direct and quadrature axis stator currents (is , is) are fictitious
quadrature-phase (2-phase) current components, which are related to the actual 3-phase stator currents
as:
Eq. 4 =
Eq. 5 = ( )
where k=2/3 is the transformation constant, so that the final equation is:
Eq. 6 = ( )
The space vectors of other motor quantities (such as voltages, currents, magnetic fluxes) can be defined
in the same way as the stator-current space vector.
Eq. 8 = +
Eq. 9 = +
where uSA, uSB, and uSC are the instantaneous values of stator voltages, iSA, iSB, and iSC are the
instantaneous values of stator currents, and SA, SB, SC are the instantaneous values of the stator flux
linkages in phases SA, SB, and SC. Due to a large number of equations in the instantaneous form, (Eq. 7,
Eq. 8, and Eq. 9), it is better to rewrite the instantaneous equations using the 2-axis theory (Clarke
transformation). The PMSM is then expressed as:
Eq. 10 = +
Eq. 11 = +
Eq. 12 = +
Eq. 13 = +
Eq. 14 =
The equations Eq. 10 to Eq. 14 represent the model of a PMSM in the stationary frame , , fixed to the
stator.
Besides the stationary reference frame attached to the stator, the motor model voltage space vector
equations can be formulated in a general reference frame that rotates at a general speed g. Using a
general reference frame with the direct and quadrature axes (x and y) rotating at a general instantaneous
speed g=dg/dt (as shown in Figure 3) where g is the angle between the direct axis of the stationary
reference frame () attached to the stator and the real axis (x) of the general reference frame, Eq. 15
defines the stator-current space vector in a general reference frame as:
Eq. 15
=
= +
__ g
is is, isg x
is
The stator-voltage and flux-linkage space vectors can be obtained similarly in the general reference
frame.
Similar considerations are held for the space vectors of the rotor voltages, currents, and flux linkages.
The real axis (r) of the reference frame attached to the rotor is displaced from the direct axis of the
stator reference frame by the rotor angle r. The angle between the real axis (x) of the general reference
frame and the real axis of the reference frame rotating with the rotor (r) is g-r. In the general
reference frame, the space vector of the rotor currents is expressed as:
Eq. 16
= = +
where is the space vector of the rotor current in the rotor reference frame.
The space vectors of the rotor voltages and rotor flux linkages in the general reference frame can be
expressed similarly.
The motor model voltage equations in the general reference frame can be expressed using the introduced
transformations of the motor quantities from one reference frame to the general reference frame.
The PMSM model is often used in vector-control algorithms. The aim of the vector control is to
implement the control schemes that produce high-dynamic performance and are similar to those used to
control DC machines. To achieve this, the reference frames must be aligned with the stator flux-linkage
space vector, the rotor flux-linkage space vector, or the magnetizing space vector. The most popular
reference frame is the reference frame attached to the rotor flux-linkage space vector with the direct axis
(d) and the quadrature axis (q).
Transformed into the d, q coordinates, the motor model is:
Eq. 17 = +
Eq. 18 = +
Eq. 19 = +
Eq. 20 =
Eq. 21 =
Considering that the below base speed is isd=0, Eq. 21 can be reduced as:
Eq. 22 =
In Eq. 22, the torque is dependent and can be directly controlled by the current isq only.
Phase A d d Phase A
Process
3-Phase Stationary Rotating
Control
Phase B Phase B
Phase C
to
2-Phase
to
Rotating
q q to SVM
Stationary Phase C
AC DC AC
DC Bus Voltage
Vdc
PMSM
PMSM
6
Load
Application
Control
DC Bus A, B, C
PWM
Voltage Currents
PWM ADC
DRIVER DRIVER
A, B, C Phase
Duty cycles
2 Currents
Speed Application Sinus
Command Sector
Control Waveform
Modulation
The fast control loop executes these tasks that are necessary to achieve an independent control of the
stator-current components:
3-phase current reconstruction
Forward Clark transformation
Forward and backward Park transformations
DC-bus voltage ripple elimination
Space vector modulation (SVM)
The slow control loop executes the speed controller and lower-priority control tasks. The PI speed
controller output sets a reference for the torque-producing quadrature-axis component of the stator
current (isq).
+
uDC-Bus /2 S At S Bt S Ct
=
-
+
uDC-Bus /2
= S Ab IA S Bb IB S Cb IC
-
u AB u BC
u CA
B
uR
ub
uL
u ib
ua O u ic
u L u ia uL
uR uc uR
A C
Figure 6. Power stage schematic diagram
The combination of ON/OFF states in the power stage switches for each voltage vector is coded in
Figure 7 by the three-digit number in parentheses. Each digit represents one phase. For each phase, a
value of 1 means that the upper switch is ON and the bottom switch is OFF. A value of 0 means that the
upper switch is OFF and the bottom switch is ON. These states, together with the resulting instantaneous
output line-to-line voltages, phase voltages, and voltage vectors, are listed in Table 1.
0 0 0 0 0 0 0 0 0 O000
1 1 1 0 0 0 0 0 0 O111
U120 U60
(010) -axis (110)
[1/3,-1] [1/3,1]
V.
[-1/3,-1] [-1/3,1]
U240 U300
(001) (101)
Figure 7. Basic space vectors and voltage vector projection
SVM is a technique used as a direct bridge between the vector control (voltage space vector) and PWM.
The SVM technique consists of these steps:
1. Sector identification
2. Space voltage vector decomposition into directions of sector base vectors Ux and Ux60
3. PWM duty cycle calculation
The principle of SVM is the application of voltage vectors Uxxx and Oxxx for certain instances in such
way that the mean vector of the PWM period TPWM is equal to the desired voltage vector.
This method provides greatest variability in arranging of the zero and non-zero vectors during the PWM
period. You can arrange these vectors to lower switching losses; another might want to reach a different
result, such as center-aligned PWM, edge-aligned PWM, minimal switching, and so on.
For the SVM chosen, this rule is defined:
The desired space voltage vector is created only by applying the sector base vectors: the
non-zero vectors on the sector side, (Ux, Ux60) and the zero vectors (O000 or O111).
These expressions define the principle of SVM:
Eq. 23 [,] = + + ( )
Eq. 24 = + +
To solve the time periods T0, T1, and T2, decompose the space voltage vector US[,] into directions of the
sector base vectors Ux and Ux60. Eq. 23 splits into Eq. 25 and Eq. 26.
Eq. 25 =
Eq. 26 () =
By solving this set of equations, you can obtain the necessary duration for the application of the sector
base vectors Ux and Ux60 during the PWM period TPWM to produce the right stator voltages.
| |
Eq. 27 = | |
for vector UX
| |
Eq. 28 = for vector UX60
q
unknown rotor position (not
aligned)
M
zero rotor position
(aligned) field=0
S d
The observer is applied to the PMSM motor with an estimator model excluding the extended back-EMF
term. The extended back-EMF term is estimated using the observer (as shown in Figure 9), which
utilizes a simple observer of the PMSM stator current. The back-EMF observer presented here is
realized within the rotating reference frame (d,q). The estimator of the d,q axes consists of the stator
current observer based on the RL motor circuit with estimated motor parameters. This current observer
is fed the sum of the actual applied motor voltage (cross-coupled rotational term) which corresponds to
the motor saliency (Ld-Lq), and the compensator corrective output. The observer provides the back-EMF
signals as a disturbance, because the back-EMF is not included in the observer model.
Figure 9. Luenberger-type stator current observer acting as state filter for back-EMF
Figure 10. Block diagram of proposed PLL scheme for position estimation
3. Software Design
This application is written as a simple C project with the inclusion of Embedded Software Libraries
(FSLESL). Download these libraries from www.nxp.com/fslesl. They contain the necessary algorithms,
math functions, observers, filters, and other features used in the application.
This section describes the software design of the sensorless PMSM FOC application. It describes the
numerical scaling in the fixed-point fractional arithmetic of the controller first. Then it describes specific
issues, such as speed and current sensing. In the end, it describes the control software implementation.
where:
Fractional Valuefractional representation of quantities []
Real Valuereal quantity in physical units [..]
Real Quantity Rangemaximum defined quantity value used for scaling in physical units [..]
Some examples of the quantities scaling are provided in the following subsections.
Eq. 32 () =
=
= .
This 16-bit fractional variable is stored internally as a 16-bit integer variable:
Eq. 33 () = () . = . . =
Figure 11 shows the previous equations of voltage scaling into a fractional number. The voltage value is
read by the ADC as a 12-bit signed number with left justification for a 16-bit number.
In case a floating-point number representation of this value is needed, the fractional number is converted
to a floating-point number as:
Eq. 34 () = ()
DC Bus Voltage
Vdc
PMSM
PMSM
6
Load
Application
Control
DC Bus A, B, C
PWM
Voltage Currents
PWM ADC
DRIVER DRIVER
A, B, C Phase
Duty cycles
2 Currents
Speed Application Sinus
Command Sector
Control Waveform
Modulation
The rotor position and speed are provided by the BEMF observer and the tracking observer.
The BEMF observer calculates the error of the angle using the d/q voltage, d/q current, and speed.
The error angle of the BEMF is fed to the tracking observer, which returns the position and speed.
Based on the measured feedback signals, the FOC algorithm performs a vector-control technique,
as described in Section 2.3.2, FOC algorithm.
Two independent current PI controllers are executed to achieve the desired behavior of the motor.
The output from the FOC is a stator-voltage space vector, which is transformed into PWM signals using
space vector modulation. The 3-phase stator voltage is generated using a 3-phase voltage source inverter
and applied to the motor, which is connected to the power stage terminals.
RELOAD RELOAD
Top PWM
Trigger Trigger
Bottom PWM
Conversion
complete
ADC conversion
The slow-loop interrupt service routine is executed periodically when the independent FlexTimer
reloads. It is basically a speed control.
The background loop is executed in the main application. It handles non-critical timing tasks, such as the
communication with FreeMASTER over UART.
The interrupt service routine calls the state machine function. The state machine function depends on the
particular state. When in a dependent state, the particular state machine function is called, and it ensures
that the correct state-machine logic and control algorithm is called. The state machine is described in the
following sections.
SM_CTRL_STARTthis flag informs the system that there is a command to go from the Stop
state to the Run state. The transition function is called; nevertheless, the action must be
acknowledged. The reason is that sometimes it can take time before the system is ready to be
switched on.
SM_CTRL_RUN_ACKthis flag acknowledges that the system can proceed from the Stop
state to the Run state.
SM_CTRL_STOPthis flag informs the system that there is a command to go from the Run
state to the Stop state. The transition function is called; nevertheless, the action must be
acknowledged. The reason is that the system must be switched off properly, which takes time.
SM_CTRL_STOP_ACKthis flag acknowledges that the system can proceed from the Run
state to the Stop state.
RESET
SM_CTRL_FAULT SM_CTRL_INIT_DONE
INIT
Transition
Init -> Fault
Transition
Init -> Stop
SM_CTRL_FAULT_CLEAR Transition
Fault -> Stop
SM_CTRL_FAULT
FAULT STOP
Transition
Stop -> Fault
SM_CTRL_START
SM_CTRL_STOP_ACK
Transition
Stop -> Run
Transition Transition
Run -> Fault Run -> Stop
SM_CTRL_RUN_ACK
SM_CTRL_FAULT
RUN SM_CTRL_STOP
The implementation of this state machine structure is done in the state_machine.c and state_machine.h
files. The following code lines define the state machine structure:
/* State machine control structure */
typedef struct
{
SM_APP_STATE_FCN_T const* psState; /* State functions */
SM_APP_TRANS_FCN_T const* psTrans; /* Transition functions */
SM_APP_CTRL uiCtrl; /* Control flags */
SM_APP_STATE_T eState; /* State */
} SM_APP_CTRL_T;
The user transient state machine functions are defined in this structure:
/* User state-transition functions structure*/
typedef struct
{
PFCN_VOID_VOID FaultInit;
PFCN_VOID_VOID InitFault;
PFCN_VOID_VOID InitStop;
PFCN_VOID_VOID StopFault;
PFCN_VOID_VOID StopRun;
PFCN_VOID_VOID RunFault;
PFCN_VOID_VOID RunStop;
} SM_APP_TRANS_FCN_T;
Call the state machine from the code periodically using the following inline function. This functions
input is the pointer to the state machine structure described above. This structure is declared and
initialized in the code where the state machine is called:
/* State machine function */
static inline void SM_StateMachineFast(SM_APP_CTRL_T *sAppCtrl)
{
gSM_STATE_TABLE_FAST[sAppCtrl -> eState](sAppCtrl);
}
An example of initializing and using the state machine structure is described in the following section.
The Run sub-states are called when the state machine is in the Run state. The Run sub-state functions
are:
Calib:
The current channels ADC offset calibration.
The DC-bus voltage is measured and filtered.
The PWM is set to 50 % and its output is enabled.
The current channel offsets are measured and filtered.
After the calibration time expires, the system is switched to Ready.
Ready:
The PWM is set to 50 % and its output is enabled.
The current is measured and the ADC channels are set up.
The DC-bus voltage is measured.
Certain variables are initialized.
Align:
The current is measured and the ADC channels are set up.
The DC-bus voltage is measured and filtered.
The rotor-alignment algorithm is called and the PWM is updated.
After the alignment time expires, the system is switched to Startup.
Startup:
The current is measured and the ADC channels are set up.
The BEMF observer algorithm is called to estimate the speed and position.
The FOC algorithm is called and the PWM is updated.
The DC-bus voltage is measured and filtered.
The open-loop start-up algorithm is called.
The estimated speed is filtered (in case the filter is necessary).
If the startup is successful, the system is switched to the Spin state; otherwise, it is
switched to the Freewheel state.
Spin:
The current is measured and the ADC channels are set up.
The BEMF observer algorithm is called to estimate the speed and position.
The FOC algorithm is called and the PWM is updated.
The motor starts spinning.
The DC-bus voltage is measured and filtered.
The estimated speed is filtered (in case the filter is necessary).
The speed ramp and the speed PI controller algorithms are called.
Freewheel:
The PWM output is disabled and the module is set to 50 %.
The current is measured and the ADC channels are set up.
The DC-bus voltage is measured and filtered.
The system waits in this sub-state for a certain time, which is generated due to the rotor
inertia. That means it waits until the rotor stops.
The system evaluates the conditions and enters either the Align state or the Ready state.
Stop -> Run
Calibration time passed Transition
CALIB Calib -> Ready READY
Speed command == 0
Transition
Freewheel -> Ready
Speed command == 0
FREEWHEEL
Speed command != 0
Transition
Align -> Ready
Transition
Ready -> Align
Transition
Spin -> Freewheel
Transition
Startup -> Freewheel
Speed command == 0 ALIGN
& Speed < min speed
Startup fail
SPIN Alignment time passed
Startup ok Transition
Transition
STARTUP Align -> Startup
Startup -> Spin
The Run sub-states also have transition functions that are called in between the sub-states transitions.
The sub-state transition functions are:
Calib > Readycalibration done; entering the Ready state.
Ready > Alignnon-zero speed command; entering the Align state.
Certain variables are initialized (voltage, speed, and position).
The startup counter is set to 1.
The alignment time is set up.
Align > Readyzero-speed command; entering the Ready state.
Certain voltage and current variables are zeroed.
The PWM is set to 50 %.
The state machine is called from the interrupt service routine, as mentioned in Section 3.5,
Calling algorithms. The code syntax used for calling the state machine is:
/* StateMachine call */
SM_StateMachine(&gsM1_Ctrl);
Inside the user Run state function, the sub-state functions are called as:
/* Run sub-state function */
mM1_STATE_RUN_TABLE[meM1_StateRun]();
where the variable identifies the Run sub-state.
Figure 13 shows that the application requires sensors and estimators (current, DC-bus voltage, estimated
speed, etc.) and actuators (PWM, etc.) to observe and control the whole system. The sensors and
actuators are encapsulated into the dedicated modules within the unified interface called MCDRV.
For more information on MCDRV, see Sensorless PMSM Field-Oriented Control on Kinetis KV
(document AN5237).
Sensorless PMSM Field-Oriented Control, Design Reference Manual, Rev. 1, 02/2016
Freescale Semiconductor, Inc. 27
Software Design
The structure referred to by the input/output structure pointer is defined in this example:
Example 1. Field-oriented current control code
typedef struct
{
GFLIB_CTRL_PI_P_AW_T_A32 sIdPiParams; /* Id PI controller parameters */
GFLIB_CTRL_PI_P_AW_T_A32 sIqPiParams; /* Iq PI controller parameters */
GDFLIB_FILTER_IIR1_T_F32 sUDcBusFilter; /* Dc bus voltage filter */
GMCLIB_3COOR_T_F16 sIABC; /* Measured 3-phase current */
GMCLIB_2COOR_ALBE_T_F16 sIAlBe; /* Alpha/Beta current */
GMCLIB_2COOR_DQ_T_F16 sIDQ; /* DQ current */
GMCLIB_2COOR_DQ_T_F16 sIDQReq; /* DQ required current */
GMCLIB_2COOR_DQ_T_F16 sIDQError; /* DQ current error */
GMCLIB_3COOR_T_F16 sDutyABC; /* Applied duty cycles ABC */
GMCLIB_2COOR_ALBE_T_F16 sUAlBeReq; /* Required Alpha/Beta voltage */
GMCLIB_2COOR_ALBE_T_F16 sUAlBeComp; /* Compensated to DC bus Alpha/Beta voltage
GMCLIB_2COOR_DQ_T_F16 sUDQReq; /* Required DQ voltage */
GMCLIB_2COOR_DQ_T_F16 sUDQEst; /* BEMF observer input DQ voltages */
GMCLIB_2COOR_SINCOS_T_F16 sAnglePosEl; /* Electrical position sin/cos (at the
moment of PWM current reading) */
AMCLIB_BEMF_OBSRV_DQ_T_A32 sBemfObsrv; /* BEMF observer in DQ */
AMCLIB_TRACK_OBSRV_T_F32 sTo; /* Tracking observer */
GDFLIB_FILTER_IIR1_T_F32 sSpeedElEstFilt; /* Estimated speed filter */
frac16_t f16SpeedElEst; /* Rotor electrical speed estimated */
uint16_t ui16SectorSVM; /* SVM sector */
frac16_t f16PosEl; /* Electrical position */
frac16_t f16PosElExt; /* Electrical position set from external
function - sensor, open loop */
frac16_t f16PosElEst; /* Rotor electrical position estimated*/
frac16_t f16DutyCycleLimit; /* Max. allowable duty cycle in frac */
frac16_t f16UDcBus; /* DC bus voltage */
frac16_t f16UDcBusFilt; /* Filtered DC bus voltage */
bool_t bCurrentLoopOn; /* Flag enabling calculation of current
control loop */
bool_t bPosExtOn; /* Flag enabling use of electrical position
passed from other functions */
bool_t bOpenLoop; /* Position estimation loop is open */
bool_t bIdPiStopInteg; /* Id PI controller manual stop integration
bool_t bIqPiStopInteg; /* Iq PI controller manual stop integration
} MCS_PMSM_FOC_A1_T;
This structure contains all the necessary variables or sub-structures for the field-oriented control
algorithm implementation. The types used in this structure are defined in the Embedded Software
Libraries (FSLESL). Here is a description of the items used in this application:
D and Q current PI controllersserve to control the D and Q currents.
DC-bus voltage first-order IIR filterserves to filter the DC-bus voltage.
A, B, and C currentsmeasured 3-phase current; input to the algorithm.
Alpha and beta currentscurrents transformed into the alpha/beta frame.
D and Q currentscurrents transformed into the D/Q frame.
Required D and Q currentsrequired currents in the D/Q frame; input to the algorithm.
D and Q current errorerror (difference) between the required and the measured D/Q currents.
A, B, and C duty cycles3-phase duty cycles; output from the algorithm.
Required alpha and beta voltagesrequired voltages in the alpha/beta frame.
Compensated required alpha and beta voltagesthe previous item recalculated on the actual
level of the DC-bus voltage.
Required D and Q voltagesrequired voltages in the alpha/beta frame; outputs from the PI
controllers.
Sin/Cos anglerotor estimated electrical angle (sine, cosine).
Duty cycle limitthis variable limits the maximum value of the A, B, and C duty cycles.
DC-bus voltagemeasured DC-bus voltage.
Filtered DC-bus voltagefiltered value of the previous item.
SVM sectorsector information; output from the SVM algorithm.
D current saturation flagsaturation flag for the D-current PI controller.
Q current saturation flagsaturation flag for the Q-current PI controller.
Speed startup flagindicates that the motor is in startup.
This routine calculates the field-oriented control. The inputs to this routine include the 3-phase current,
DC-bus voltage, the electrical position, and the required D and Q currents. The output from this routine
are the 3-phase duty cycle, SVM sector, and the saturation flags of the PI controllers. The PI controllers
and filters have structures that must be initialized before using this routine.
This routine is called in the fast loop state machine and its process flow chart is shown in the below
figure. This function uses algorithms from the Embedded Software Libraries (FSLESL); the functions
names may differ from one platform to another.
Use estimated or
External position?
bPosExtOn
Current control enabled DCbus voltage, max Duty cycle, D controller voltage
bCurrentLoopOn
Q controller limit
The first structure referred to by the input/output structure pointer is the same as for the current control
mode described in Section 3.8.1, MCSfield-oriented control. The second structure has the proper
scalar control variables defined in Example 2.
Example 2. Scalar control code
typedef struct
{
GFLIB_RAMP_T_F32 sFreqRampParams; /* Parameters of frequency ramp */
GMCLIB_2COOR_DQ_T_F16 sUDQReq; /* Required voltage vector in d,q coordinates */
GFLIB_INTEGRATOR_T_A32 sFreqIntegrator; /* integrator parameters (integrates the omega
to get the position */
frac16_t f16FreqCmd; /* required electrical frequency from master
system */
frac16_t f16FreqRamp; /* Required frequency limited by ramp - the ramp
output */
frac16_t f16PosElScalar; /* Electrical angle of the rotor */
frac16_t f16VHzGain; /* VHz_factor constant gain for scalar control
int16_t f16VHzGainShift; /* VHz_factor constant shift for scalar control
} MCS_PMSM_SCALAR_CTRL_A1_T;
This structure contains the additional necessary variables or sub-structures for the scalar control
algorithm implementation. The types used in this structure are defined in the Embedded Software
Libraries (FSLESL). Here is a description of the items used in this application:
Frequency rampthe parameters for the frequency ramp generation.
Required D and Q voltagesthe required voltages in the alpha/beta frame; outputs from the
V/Hz algorithm.
Frequency integratorthe parameters for the frequency integrator, where its output is the
position.
Frequency commandthe required frequency commanded by the user application.
Ramped frequencythe output from the frequency ramp algorithm.
Electrical positionthe electrical position of the rotor.
V/Hz gainthe factor to calculate the required Q voltage based on the frequency.
V/Hz gain shiftthe shift of the factor to calculate the required Q voltage based on frequency.
This routine calculates the Q voltage based on the actual electrical rotor frequency. The inputs to this
routine include the required speed and the V/rpm factor. The outputs of this routine are the 3-phase duty
cycle and the SVM sector. The filters have structures that must be initialized before using this routine.
This routine is called in the fast-loop state machine and its process flow chart is shown in Figure 21.
This function reuses the MCS_PMSMFocCtrlA1 described in Section 3.8.1, MCSfield-oriented
control. This function uses algorithms from the Embedded Software Libraries (FSLESL); the
functions names may differ from one platform to another.
Required frequency
Frequency Ramp
Ramped frequency
Volt/Hertz calculation
Required D,Q voltage
Frequency integration
Required D,Q voltage,
Electrical position
FOC control
A,B,C duty cycles, SVM sector
This function uses the FOC structure described in Section 3.8.1, MCSfield-oriented control.
The alignment variables are contained in the alignment structure referred to by the second pointer.
The alignment structure definition is:
Example 3. Alignment code
typedef struct
{
frac16_t f16UdReq; /* Required D voltage at alignment */
uint16_t ui16Time; /* Alignment time duration */
uint16_t ui16TimeHalf; /* Alignment half time duration */
}MCS_ALIGNMENT_A1_T; /* PMSM simple two-step Ud voltage alignment */
The structure contains the variables necessary to perform the rotor alignment. The structure is described
as follows:
D voltagethe required voltage applied in the D axis during the alignment.
Alignment durationthe duration of the alignment.
Alignment halftimethe time for which the 120-degree position is required; when this time
passes, the 0-degree position is applied.
The routine applies the D voltage defined in the alignment structure. This voltage command is applied
during the alignment. The alignment duration is split into two segments:
1. The angle of 120 degrees is forced (from the beginning of the alignment until the halftime).
2. The angle of 0 degrees is forced (from the alignment halftime to the end).
This function calls the MCS_PMSMFocCtrlA1 function. The alignment algorithm flowchart is shown in
this figure:
Align function call
No
Align. Half time > 0
Yes
D voltage
El. position
FOC control
The function uses its own start-up structure that is referred to by the input/output structure pointers.
Its definition is:
Example 4. Scalar control code
typedef struct
{
GFLIB_INTEGRATOR_T_A32 sSpeedIntegrator; /* Speed integrator structure*/
GFLIB_RAMP_T_F32 sSpeedRampOpenLoopParams; /* Parameters of startup speed ramp */
frac16_t f16SpeedReq; /* Required speed */
frac16_t f16PosEst; /* Fractional electrical position */
frac16_t f16SpeedRampOpenLoop; /* Open loop startup speed ramp */
Sensorless PMSM Field-Oriented Control, Design Reference Manual, Rev. 1, 02/2016
Freescale Semiconductor, Inc. 33
Software Design
The structure contains the variables necessary to perform the open-loop startup. The start-up procedure
is shown in Figure 23. The structure is described as follows:
Speed integration structureintegrates the speed resulting the position in the correct position
scale.
Speed ramp structuregenerates the speed ramp during the open-loop startup.
Required speedthe required speed set by the user.
Open-loop mode speed ramp outputthe speed generated from the ramp during the open-loop
mode.
Estimated electrical positionthe electrical position estimated by the BEMF observer.
Merging coefficientdefines the duration increment of the position-merging process.
Merging ratio the ratio that determines how much of the generated and the estimated position
information is used as the merging output.
Open-loop mode positionthe position generated as the integration of the speed ramp output
during the open-loop mode.
Merged positionthe generated and estimated position output of the merging process.
Catch-up speeddetermines where to start the merging of the generated open-loop and BEMF
observer estimated position.
Start-up currentthe Q current applied to start the motor.
Start-up freewheel timethe duration applied due to the rotor inertia after a start-up process is
terminated by the user (entering zero-speed command during the initiated start-up process).
Open-loop modethe switch that determines whether the observer feedback is in the open-loop
mode or the closed-loop mode.
Estimated (observer)
Predicted (generated)
Speed
Start-up current
Q current
100 %
Merge
Observer on
Reached
Start-up catch-up speed Speed control closed-loop
commences
BEMF observer closed-loop
The start-up procedure is a complex process which is based on applying the torque and expecting the
speed to respond accordingly. Therefore, the torque is proportional to the Q current which is kept
constant.
The speed is ramped with the constant acceleration while the Q current is kept at the defined level.
When the catch-up speed is reached, the merging ratio is incremented with the merging coefficient.
This ratio determines how much of the estimated position information is merged with the generated
(predicted) position information. At the beginning, it is 0 % for the estimated position information and
100 % for the predicted position information. Their sum is always 1.
After the system finishes merging the BEMF position, the loop is closed, and the motor is successfully
started with the speed control turned on.
Estimated speed
Speed filter
Speed filtered
Speed control
Required Q current
The speed loop contains the structure of the variables necessary to perform the speed control.
The structure is described as follows:
Speed first-order IIR filterfilters the speed.
Speed PI controller structurecontrols the speed.
Speed ramp structuregenerates the speed ramp.
Speedthe speed of the motor.
Filtered speedthe filtered speed of the motor.
Speed errorthe error between the required speed and the measured speed.
Ramped speedthe speed ramp algorithm output.
Required speedthe speed input to the ramp algorithm.
Speed commandthe speed requested by the user or a higher layer of the application.
Speed PI controller saturation flagdetermines whether the PI controller is in saturation.
The measured speed can use the filter that filters out the noise. In that case, the
MCS_PMSMFocCtrlSpeedA1 speed-control function is called.
DC Direct current
SC Scalar Control
VC Vector Control
5. List of Symbols
This table lists the symbols used in this document:
Table 3. List of symbols
Symbol Definition
d,q Rotational orthogonal coordinate system
isx, isy Stator current space vector components in general reference frame
irx, iry Rotor current space vector components in general reference frame
J Mechanical inertia
KM Motor constant
ke BEMF constant
Ls Stator-phase inductance
Rs Stator-phase resistance
s Derivative operator
TL Load torque
6. Revision History
This table summarizes the changes made to this document since the initial release.
Table 4. Revision history
Revision
Date Substantive changes
number
0 04/2014 Initial release.
Updated the document to correspond to the new software structure. Updated the state machine
1 02/2016
description. Added Section 4, Acronyms and Abbreviations and Section 5, List of Symbols.
Freescale and the Freescale logo are trademarks of Freescale Semiconductor, Inc.,
Reg. U.S. Pat. & Tm. Off. All other product or service names are the property of their
respective owners. All rights reserved.