This user's guide describes the General Motor Control Library (GMCLIB) for the family
of DSP56800E core-based digital signal controllers. This library contains optimized
functions.
1.1.2
Data types
GMCLIB supports several data types: (un)signed integer, fractional, and accumulator.
The integer data types are useful for general-purpose computation; they are familiar to
the MPU and MCU programmers. The fractional data types enable powerful numeric and
digital-signal-processing algorithms to be implemented. The accumulator data type is a
combination of both; that means it has the integer and fractional portions.
The following list shows the integer types defined in the libraries:
• Unsigned 16-bit integer —<0 ; 65535> with the minimum resolution of 1
• Signed 16-bit integer —<-32768 ; 32767> with the minimum resolution of 1
• Unsigned 32-bit integer —<0 ; 4294967295> with the minimum resolution of 1
• Signed 32-bit integer —<-2147483648 ; 2147483647> with the minimum resolution
of 1
The following list shows the fractional types defined in the libraries:
• Fixed-point 16-bit fractional —<-1 ; 1 - 2
• Fixed-point 32-bit fractional —<-1 ; 1 - 2
-15
> with the minimum resolution of 2
-31
> with the minimum resolution of 2
-15
-31
GMCLIB User's Guide, Rev. 2, 10/2015
Freescale Semiconductor, Inc.5
Introduction
The following list shows the accumulator types defined in the libraries:
• Fixed-point 16-bit accumulator —<-256.0 ; 256.0 - 2-7> with the minimum
resolution of 2
GMCLIB uses the types mentioned in the previous section. To enable simple usage of the
algorithms, their names use set prefixes and postfixes to distinguish the functions'
versions. See the following example:
• lss—the types of the function inputs; if all the inputs have the same type as the
output, the inputs are not marked
The input and output types are described in the following table:
Table 1-1. Input/output types
TypeOutputInput
frac16_tF16s
frac32_tF32l
acc32_tA32a
1.1.4Supported compilers
GMCLIB for the DSP56800E core is written in assembly language with C-callable
interface. The library is built and tested using the following compilers:
• CodeWarrior™ Development Studio
For the CodeWarrior™ Development Studio, the library is delivered in the gmclib.lib
file.
GMCLIB User's Guide, Rev. 2, 10/2015
6Freescale Semiconductor, Inc.
Chapter 1 Library
The interfaces to the algorithms included in this library are combined into a single public
interface include file, gmclib.h. This is done to lower the number of files required to be
included in your application.
1.1.5Special issues
1. The equations describing the algorithms are symbolic. If there is positive 1, the
number is the closest number to 1 that the resolution of the used fractional type
allows. If there are maximum or minimum values mentioned, check the range
allowed by the type of the particular function version.
2. The library functions require the core saturation mode to be turned off, otherwise the
results can be incorrect. Several specific library functions are immune to the setting
of the saturation mode.
3. The library functions round the result (the API contains Rnd) to the nearest (two's
complement rounding) or to the nearest even number (convergent round). The mode
used depends on the core option mode register (OMR) setting. See the core manual
for details.
4. All non-inline functions are implemented without storing any of the volatile registers
(refer to the compiler manual) used by the respective routine. Only the non-volatile
registers (C10, D10, R5) are saved by pushing the registers on the stack. Therefore, if
the particular registers initialized before the library function call are to be used after
the function call, it is necessary to save them manually.
1.2
Library integration into project (CodeWarrior™
Development Studio)
This section provides a step-by-step guide to quickly and easily integrate the GMCLIB
into an empty project using CodeWarrior™ Development Studio. This example uses the
MC56F8257 part, and the default installation path (C:\Freescale\FSLESL
\DSP56800E_FSLESL_4.2) is supposed. If you have a different installation path, you
must use that path instead.
1.2.1
To start working on an application, create a new project. If the project already exists and
is open, skip to the next section. Follow the steps given below to create a new project.
1. Launch CodeWarrior™ Development Studio.
Freescale Semiconductor, Inc.7
New project
GMCLIB User's Guide, Rev. 2, 10/2015
Library integration into project (CodeWarrior™ Development Studio)
2. Choose File > New > Bareboard Project, so that the "New Bareboard Project" dialog
appears.
3. Type a name of the project, for example, MyProject01.
4. If you don't use the default location, untick the “Use default location” checkbox, and
type the path where you want to create the project folder; for example, C:
\CWProjects\MyProject01, and click Next. See Figure 1-1.
Figure 1-1. Project name and location
5. Expand the tree by clicking the 56800/E (DSC) and MC56F8257. Select the
Application option and click Next. See Figure 1-2.
Figure 1-2. Processor selection
6. Now select the connection that will be used to download and debug the application.
In this case, select the option P&E USB MultiLink Universal[FX] / USB MultiLink
and Freescale USB TAP, and click Next. See Figure 1-3.
GMCLIB User's Guide, Rev. 2, 10/2015
8Freescale Semiconductor, Inc.
Chapter 1 Library
Figure 1-3. Connection selection
7. From the options given, select the Simple Mixed Assembly and C language, and
click Finish. See Figure 1-4.
Figure 1-4. Language choice
The new project is now visible in the left-hand part of CodeWarrior™ Development
Studio. See Figure 1-5.
Figure 1-5. Project folder
1.2.2
Library path variable
To make the library integration easier, create a variable that will hold the information
about the library path.
1. Right-click the MyProject01 node in the left-hand part and click Properties, or select
Project > Properties from the menu. The project properties dialog appears.
GMCLIB User's Guide, Rev. 2, 10/2015
Freescale Semiconductor, Inc.9
Library integration into project (CodeWarrior™ Development Studio)
2. Expand the Resource node and click Linked Resources. See Figure 1-6.
Figure 1-6. Project properties
3. Click the 'New…' button on the right-hand side.
4. In the dialog that appears (see Figure 1-7), type this variable name into the Name
box: FSLESL_LOC
5. Select the library parent folder by clicking 'Folder…' or just typing the following
path into the Location box: C:\Freescale\FSLESL\DSP56800E_FSLESL_4.2_CW
and click OK.
6. Click OK in the previous dialog.
GMCLIB User's Guide, Rev. 2, 10/2015
10Freescale Semiconductor, Inc.
Figure 1-7. New variable
Chapter 1 Library
1.2.3
Library folder addition
To use the library, add it into the CodeWarrior Project tree dialog.
1. Right-click the MyProject01 node in the left-hand part and click New > Folder, or
select File > New > Folder from the menu. A dialog appears.
2. Click Advanced to show the advanced options.
3. To link the library source, select the third option—Link to alternate location (Linked
Folder).
4. Click Variables…, and select the FSLESL_LOC variable in the dialog that appears,
click OK, and/or type the variable name into the box. See Figure 1-8.
5. Click Finish, and you will see the library folder linked in the project. See Figure 1-9
GMCLIB User's Guide, Rev. 2, 10/2015
Freescale Semiconductor, Inc.11
Library integration into project (CodeWarrior™ Development Studio)
Figure 1-8. Folder link
Figure 1-9. Projects libraries paths
1.2.4
Library path setup
GMCLIB requires MLIB and GFLIB to be included too. Therefore, the following steps
show the inclusion of all dependent modules.
1. Right-click the MyProject01 node in the left-hand part and click Properties, or select
Project > Properties from the menu. A dialog with the project properties appears.
GMCLIB User's Guide, Rev. 2, 10/2015
12Freescale Semiconductor, Inc.
Chapter 1 Library
2. Expand the C/C++ Build node, and click Settings.
3. In the right-hand tree, expand the DSC Linker node, and click Input. See Figure 1-11.
4. In the third dialog Additional Libraries, click the 'Add…' icon, and a dialog appears.
5. Look for the FSLESL_LOC variable by clicking Variables…, and then finish the
path in the box by adding one of the following:
• ${FSLESL_LOC}\MLIB\mlib_SDM.lib—for small data model projects
• ${FSLESL_LOC}\MLIB\mlib_LDM.lib—for large data model projects
6. Tick the box Relative To, and select FSLESL_LOC next to the box. See Figure 1-9.
Click OK.
7. Click the 'Add…' icon in the third dialog Additional Libraries.
8. Look for the FSLESL_LOC variable by clicking Variables…, and then finish the
path in the box by adding one of the following:
• ${FSLESL_LOC}\GFLIB\gflib_SDM.lib—for small data model projects
• ${FSLESL_LOC}\GFLIB\gflib_LDM.lib—for large data model projects
9. Tick the box Relative To, and select FSLESL_LOC next to the box. Click OK.
10. Click the 'Add…' icon in the Additional Libraries dialog.
11. Look for the FSLESL_LOC variable by clicking Variables…, and then finish the
path in the box by adding one of the following:
• ${FSLESL_LOC}\GMCLIB\gmclib_SDM.lib—for small data model projects
• ${FSLESL_LOC}\GMCLIB\gmclib_LDM.lib—for large data model projects
12. Tick the box Relative To, and select FSLESL_LOC next to the box. Click OK.
13. Now, you will see the libraries added in the box. See Figure 1-11.
Figure 1-10. Library file inclusion
GMCLIB User's Guide, Rev. 2, 10/2015
Freescale Semiconductor, Inc.13
Library integration into project (CodeWarrior™ Development Studio)
Figure 1-11. Linker setting
14. In the tree under the DSC Compiler node, click Access Paths.
15. In the Search User Paths dialog (#include “…”), click the 'Add…' icon, and a dialog
will appear.
16. Look for the FSLESL_LOC variable by clicking Variables…, and then finish the
path in the box to be: ${FSLESL_LOC}\MLIB\include.
17. Tick the box Relative To, and select FSLESL_LOC next to the box. See Figure 1-12.
Click OK.
18. Click the 'Add…' icon in the Search User Paths dialog (#include “…”).
19. Look for the FSLESL_LOC variable by clicking Variables…, and then finish the
path in the box to be: ${FSLESL_LOC}\GFLIB\include.
20. Tick the box Relative To, and select FSLESL_LOC next to the box. Click OK.
21. Click the 'Add…' icon in the Search User Paths dialog (#include “…”).
22. Look for the FSLESL_LOC variable by clicking Variables…, and then finish the
path in the box to be: ${FSLESL_LOC}\GMCLIB\include.
23. Tick the box Relative To, and select FSLESL_LOC next to the box. Click OK.
24. Now you will see the paths added in the box. See Figure 1-13. Click OK.
GMCLIB User's Guide, Rev. 2, 10/2015
14Freescale Semiconductor, Inc.
Figure 1-12. Library include path addition
Chapter 1 Library
Figure 1-13. Compiler setting
The final step is typing the #include syntax into the code. Include the library into the
main.c file. In the left-hand dialog, open the Sources folder of the project, and doubleclick the main.c file. After the main.c file opens up, include the following lines into the
#include section:
When you click the Build icon (hammer), the project will be compiled without errors.
GMCLIB User's Guide, Rev. 2, 10/2015
Freescale Semiconductor, Inc.15
Library integration into project (CodeWarrior™ Development Studio)
GMCLIB User's Guide, Rev. 2, 10/2015
16Freescale Semiconductor, Inc.
Chapter 2
Algorithms in detail
2.1GMCLIB_Clark
The
GMCLIB_Clark function calculates the Clarke transformation, which is used to
transform values (flux, voltage, current) from the three-phase coordinate system to the
two-phase (α-β) orthogonal coordinate system, according to the following equations:
Equation 1
Equation 2
2.1.1
Available versions
This function is available in the following versions:
• Fractional output - the output is the fractional portion of the result; the result is
within the range <-1 ; 1). The result may saturate.
The available versions of the GMCLIB_Clark function are shown in the following table:
Clarke transformation of a 16-bit fractional three-phase system input to a 16-bit fractional twophase system. The input and output are within the fractional range <-1 ; 1).
GMCLIB User's Guide, Rev. 2, 10/2015
Freescale Semiconductor, Inc.17
GMCLIB_ClarkInv
2.1.2Declaration
The available GMCLIB_Clark functions have the following declarations:
/* Periodical function or interrupt */
void Isr(void)
{
/* Clarke Transformation calculation */
GMCLIB_Clark_F16(&sAbc, &sAlphaBeta);
}
2.2
GMCLIB_ClarkInv
The GMCLIB_ClarkInv function calculates the Clarke transformation, which is used to
transform values (flux, voltage, current) from the two-phase (α-β) orthogonal coordinate
system to the three-phase coordinate system, according to the following equations:
Equation 3
Equation 4
Equation 5
GMCLIB User's Guide, Rev. 2, 10/2015
18Freescale Semiconductor, Inc.
Chapter 2 Algorithms in detail
2.2.1Available versions
This function is available in the following versions:
• Fractional output - the output is the fractional portion of the result; the result is
within the range <-1 ; 1). The result may saturate.
The available versions of the GMCLIB_ClarkInv function are shown in the following
table:
Inverse Clarke transformation with a 16-bit fractional two-phase system input and a 16-bit
fractional three-phase output. The input and output are within the fractional range <-1 ; 1).
2.2.2Declaration
The available GMCLIB_ClarkInv functions have the following declarations:
/* Periodical function or interrupt */
void Isr(void)
{
/* Inverse Clarke Transformation calculation */
GMCLIB_ClarkInv_F16(&sAlphaBeta, &sAbc);
}
GMCLIB User's Guide, Rev. 2, 10/2015
Freescale Semiconductor, Inc.19
GMCLIB_Park
2.3GMCLIB_Park
The GMCLIB_Park function calculates the Park transformation, which transforms values
(flux, voltage, current) from the stationary two-phase (α-β) orthogonal coordinate system
to the rotating two-phase (d-q) orthogonal coordinate system, according to the following
equations:
Equation 6
Equation 7
where:
• θ is the position (angle)
2.3.1
Available versions
This function is available in the following versions:
• Fractional output - the output is the fractional portion of the result; the result is
within the range <-1 ; 1). The result may saturate.
The available versions of the GMCLIB_Park function are shown in the following table:
The Park transformation of a 16-bit fractional two-phase stationary system input to a 16-bit
fractional two-phase rotating system, using a 16-bit fractional angle two-component (sin / cos)
position information. The inputs and the output are within the fractional range <-1 ; 1).
2.3.2Declaration
The available GMCLIB_Park functions have the following declarations:
/* Periodical function or interrupt */
void Isr(void)
{
/* Park Transformation calculation */
GMCLIB_Park_F16(&sAlphaBeta, &sAngle, &sDQ);
}
2.4
GMCLIB_ParkInv
The GMCLIB_ParkInv function calculates the Park transformation, which transforms
values (flux, voltage, current) from the rotating two-phase (d-q) orthogonal coordinate
system to the stationary two-phase (α-β) coordinate system, according to the following
equations:
Equation 8
Equation 9
where:
• θ is the position (angle)
GMCLIB User's Guide, Rev. 2, 10/2015
Freescale Semiconductor, Inc.21
GMCLIB_ParkInv
2.4.1Available versions
This function is available in the following versions:
• Fractional output - the output is the fractional portion of the result; the result is
within the range <-1 ; 1). The result may saturate.
The available versions of the GMCLIB_ParkInv function are shown in the following
table:
Inverse Park transformation of a 16-bit fractional two-phase rotating system input to a 16-bit
fractional two-phase stationary system, using a 16-bit fractional angle two-component (sin / cos)
position information. The inputs and the output are within the fractional range <-1 ; 1).
2.4.2Declaration
The available GMCLIB_ParkInv functions have the following declarations:
The GMCLIB_DecouplingPMSM function calculates the cross-coupling voltages to
eliminate the d-q axis coupling that causes nonlinearity of the control.
The d-q model of the motor contains cross-coupling voltage that causes nonlinearity of
the control. Figure 2-1 represents the d-q model of the motor that can be described using
the following equations, where the underlined portion is the cross-coupling voltage:
Equation 10
where:
• ud, uq are the d and q voltages
• id, iq are the d and q currents
• Rs is the stator winding resistance
• Ld, Lq are the stator winding d and q inductances
• ωel is the electrical angular speed
• ψr is the rotor flux constant
GMCLIB User's Guide, Rev. 2, 10/2015
Freescale Semiconductor, Inc.23
GMCLIB_DecouplingPMSM
Figure 2-1. The d-q PMSM model
To eliminate the nonlinearity, the cross-coupling voltage is calculated using the
GMCLIB_DecouplingPMSM algorithm, and feedforwarded to the d and q voltages. The
decoupling algorithm is calculated using the following equations:
Equation 11
where:
• ud, uq are the d and q voltages; inputs to the algorithm
• u
ddec
, u
are the d and q decoupled voltages; outputs from the algorithm
qdec
The fractional representation of the d-component equation is as follows:
Equation 12
The fractional representation of the q-component equation is as follows:
GMCLIB User's Guide, Rev. 2, 10/2015
24Freescale Semiconductor, Inc.
Equation 13
where:
• kd, kq are the scaling coefficients
• i
• u
• ω
is the maximum current
max
is the maximum voltage
max
el_max
is the maximum electrical speed
The kd and kq parameters must be set up properly.
The principle of the algorithm is depicted in Figure 2-2 :
Chapter 2 Algorithms in detail
Figure 2-2. Algorithm diagram
2.5.1
Available versions
This function is available in the following versions:
• Fractional output - the output is the fractional portion of the result; the result is
within the range <-1 ; 1). The result may saturate. The parameters use the
accumulator types.
GMCLIB User's Guide, Rev. 2, 10/2015
Freescale Semiconductor, Inc.25
GMCLIB_DecouplingPMSM
The available versions of the GMCLIB_DecouplingPMSM function are shown in the
following table:
Table 2-5. Function versions
Function nameInput/output typeResult type
GMCLIB_DecouplingPMSM_F16
Input
Parameters
Output
The PMSM decoupling with a 16-bit fractional d-q voltage, current inputs, and a 16bit fractional electrical speed input. The parameters are 32-bit accumulator types.
The output is a 16-bit fractional decoupled d-q voltage. The inputs and the output are
within the range <-1 ; 1).
a32KdGainacc32_tDirect axis decoupling parameter. The parameter is within the range <0 ; 65536.0)
a32KqGainacc32_tQuadrature axis decoupling parameter. The parameter is within the range <0 ;
65536.0)
2.5.3Declaration
The available GMCLIB_DecouplingPMSM functions have the following declarations:
/* Motor parameters for decoupling Kd = 40, Kq = 20 */
sDecouplingParam.a32KdGain = ACC32(40.0);
sDecouplingParam.a32KqGain = ACC32(20.0);
}
/* Periodical function or interrupt */
void Isr(void)
{
/* Decoupling calculation */
GMCLIB_DecouplingPMSM_F16(&sVoltageDQ, &sCurrentDQ, f16AngularSpeed, &sDecouplingParam,
&sVoltageDQDecoupled);
}
2.6
GMCLIB_ElimDcBusRipFOC
The GMCLIB_ElimDcBusRipFOC function is used for the correct PWM duty cycle
output calculation, based on the measured DC-bus voltage. The side effect is the
elimination of the the DC-bus voltage ripple in the output PWM duty cycle. This function
is meant to be used with a space vector modulation, whose modulation index (with
respect to the DC-bus voltage) is an inverse square root of 3.
The general equation to calculate the duty cycle for the above-mentioned space vector
modulation is as follows:
Equation 14
where:
• U
• u
• u
is the duty cycle output
PWM
is the real FOC voltage
FOC
is the real measured DC-bus voltage
dcbus
Using the previous equations, the GMCLIB_ElimDcBusRipFOC function compensates
an amplitude of the direct-α and the quadrature-β component of the stator-reference
voltage vector, using the formula shown in the following equations:
GMCLIB User's Guide, Rev. 2, 10/2015
Freescale Semiconductor, Inc.27
GMCLIB_ElimDcBusRipFOC
where:
• Uα* is the direct-α duty cycle ratio
• Uβ* is the direct-β duty cycle ratio
• Uα is the direct-α voltage
• Uβ is the quadrature-β voltage
Equation 15
Equation 16
If the fractional arithmetic is used, the FOC and DC-bus voltages have their scales, which
take place in Equation 14 on page 27; the equation is as follows:
Equation 17
where:
• U
• U
• U
• U
is the scaled FOC voltage
FOC
is the scaled measured DC-bus voltage
dcbus
FOC_max
dcbus_max
is the FOC voltage scale
is the DC-bus voltage scale
If this algorithm is used with the space vector modulation with the ratio of square root
equal to 3, then the FOC voltage scale is expressed as follows :
Equation 18
The equation can be simplified as follows:
GMCLIB User's Guide, Rev. 2, 10/2015
28Freescale Semiconductor, Inc.
Chapter 2 Algorithms in detail
Equation 19
The GMCLIB_ElimDcBusRipFOC function compensates an amplitude of the direct-α
and the quadrature-β component of the stator-reference voltage vector in the fractional
arithmetic, using the formula shown in the following equations:
Equation 20
Equation 21
where:
• Uα* is the direct-α duty cycle ratio
• Uβ* is the direct-β duty cycle ratio
• Uα is the direct-α voltage
• Uβ is the quadrature-β voltage
The GMCLIB_ElimDcBusRipFOC function can be used in general motor-control
applications, and it provides elimination of the voltage ripple on the DC-bus of the power
stage. Figure 2-3 shows the results of the DC-bus ripple elimination, while compensating
the ripples of the rectified voltage using a three-phase uncontrolled rectifier.
GMCLIB User's Guide, Rev. 2, 10/2015
Freescale Semiconductor, Inc.29
GMCLIB_ElimDcBusRipFOC
Figure 2-3. Results of the DC-bus voltage ripple elimination
2.6.1
Available versions
This function is available in the following versions:
• Fractional output - the output is the fractional portion of the result; the result is
within the range <-1 ; 1). The result may saturate.
The available versions of the GMCLIB_ElimDcBusRipFOC function are shown in the
following table:
Compensation of a 16-bit fractional two-phase system input to a 16-bit fractional
two-phase system, using a 16-bit fractional DC-bus voltage information. The DCbus voltage input is within the fractional range <0 ; 1); the stationary (α-β) voltage
input and the output are within the fractional range <-1 ; 1).
2.6.2Declaration
The available GMCLIB_ElimDcBusRipFOC functions have the following declarations:
/* DC bus voltage initialization */
f16DcBus = FRAC16(0.8);
}
/* Periodical function or interrupt */
void Isr(void)
{
/* FOC Ripple elimination calculation */
GMCLIB_ElimDcBusRipFOC_F16(f16UDcBus, &sUAlBe, &sUAlBeComp);
}
2.7
Freescale Semiconductor, Inc.31
GMCLIB_ElimDcBusRip
GMCLIB User's Guide, Rev. 2, 10/2015
GMCLIB_ElimDcBusRip
The GMCLIB_ElimDcBusRip function is used for a correct PWM duty cycle output
calculation, based on the measured DC-bus voltage. The side effect is the elimination of
the the DC-bus voltage ripple in the output PWM duty cycle. This function can be used
with any kind of space vector modulation; it has an additional input - the modulation
index (with respect to the DC-bus voltage).
The general equation to calculate the duty cycle is as follows:
Equation 22
where:
• U
• u
• u
• i
mod
is the duty cycle output
PWM
is the real FOC voltage
FOC
is the real measured DC-bus voltage
dcbus
is the space vector modulation index
Using the previous equations, the GMCLIB_ElimDcBusRip function compensates an
amplitude of the direct-α and the quadrature-β component of the stator-reference voltage
vector, using the formula shown in the following equations:
Equation 23
Equation 24
where:
• Uα* is the direct-α duty cycle ratio
• Uβ* is the direct-β duty cycle ratio
• Uα is the direct-α voltage
• Uβ is the quadrature-β voltage
If the fractional arithmetic is used, the FOC and DC-bus voltages have their scales, which
take place in Equation 22 on page 32; the equation is as follows:
GMCLIB User's Guide, Rev. 2, 10/2015
32Freescale Semiconductor, Inc.
where:
Chapter 2 Algorithms in detail
Equation 25
• U
• U
• U
• U
is the scaled FOC voltage
FOC
is the scaled measured DC-bus voltage
dcbus
FOC_max
dcbus_max
is the FOC voltage scale
is the DC-bus voltage scale
Thus, the modulation index in the fractional representation is expressed as follows :
Equation 26
where:
• i
is the space vector modulation index in the fractional arithmetic
modfr
The GMCLIB_ElimDcBusRip function compensates an amplitude of the direct-α and the
quadrature-β component of the stator-reference voltage vector in the fractional
arithmetic, using the formula shown in the following equations:
Equation 27
Equation 28
where:
• Uα* is the direct-α duty cycle ratio
• Uβ* is the direct-β duty cycle ratio
• Uα is the direct-α voltage
• Uβ is the quadrature-β voltage
GMCLIB User's Guide, Rev. 2, 10/2015
Freescale Semiconductor, Inc.33
GMCLIB_ElimDcBusRip
The GMCLIB_ElimDcBusRip function can be used in general motor-control
applications, and it provides elimination of the voltage ripple on the DC-bus of the power
stage. Figure 2-4 shows the results of the DC-bus ripple elimination, while compensating
the ripples of the rectified voltage, using a three-phase uncontrolled rectifier.
Figure 2-4. Results of the DC-bus voltage ripple elimination
2.7.1
Available versions
This function is available in the following versions:
• Fractional output - the output is the fractional portion of the result; the result is
within the range <-1 ; 1). The result may saturate. The modulation index is a nonnegative accumulator type value.
GMCLIB User's Guide, Rev. 2, 10/2015
34Freescale Semiconductor, Inc.
Chapter 2 Algorithms in detail
The available versions of the GMCLIB_ElimDcBusRip function are shown in the
following table:
Compensation of a 16-bit fractional two-phase system input to a 16-bit fractional
two-phase system using a 16-bit fractional DC-bus voltage information and a 32-bit
accumulator modulation index. The DC-bus voltage input is within the fractional
range <0 ; 1); the modulation index is a non-negative value; the stationary (α-β)
voltage input and output are within the fractional range <-1 ; 1).
2.7.2Declaration
type
The available GMCLIB_ElimDcBusRip functions have the following declarations:
The GMCLIB_SvmStd function calculates the appropriate duty-cycle ratios, which are
needed for generation of the given stator-reference voltage vector, using a special
standard space vector modulation technique.
The GMCLIB_SvmStd function for calculating the duty-cycle ratios is widely used in
modern electric drives. This function calculates the appropriate duty-cycle ratios, which
are needed for generating the given stator reference voltage vector, using a special space
vector modulation technique, called standard space vector modulation.
The basic principle of the standard space vector modulation technique can be explained
using the power stage diagram shown in Figure 2-5.
Figure 2-5. Power stage schematic diagram
GMCLIB User's Guide, Rev. 2, 10/2015
36Freescale Semiconductor, Inc.
Chapter 2 Algorithms in detail
The top and bottom switches are working in a complementary mode; for example, if the
top switch SAt is on, then the corresponding bottom switch SAb is off, and vice versa.
Considering that the value 1 is assigned to the ON state of the top switch, and value 0 is
assigned to the ON state of the bottom switch, the switching vector [a, b, c]T can be
defined. Creating of such vector allows for numerical definition of all possible switching
states. Phase-to-phase voltages can then be expressed in terms of the following states:
Equation 29
where U
DCBus
is the instantaneous voltage measured on the DC-bus.
Assuming that the motor is completely symmetrical, it is possible to write a matrix
equation, which expresses the motor phase voltages shown in Equation 29 on page 37.
Equation 30
In a three-phase power stage configuration (as shown in Figure 2-5), eight possible
switching states (shown in Figure 2-6) are feasible. These states, together with the
resulting instantaneous output line-to-line and phase voltages, are listed in Table 2-8.
The quantities of the direct-α and the quadrature-β components of the two-phase
orthogonal coordinate system, describing the three-phase stator voltages, are expressed
using the Clark transformation, arranged in a matrix form:
GMCLIB User's Guide, Rev. 2, 10/2015
Freescale Semiconductor, Inc.37
GMCLIB_SvmStd
Equation 31
The three-phase stator voltages - Ua, Ub, and Uc, are transformed using the Clark
transformation into the direct-α and the quadrature-β components of the two-phase
orthogonal coordinate system. The transformation results are listed in Table 2-9.
Table 2-9. Switching patterns and space vectors
ABCU
00000O
1002U
110U
010-U
011-2U
001-U
101U
11100O
α
/30U
DCBus
/3U
DCBus
/3U
DCBus
/30U
DCBus
/3-U
DCBus
/3-U
DCBus
U
β
/√3U
DCBus
/√3U
DCBus
/√3U
DCBus
/√3U
DCBus
Vector
000
0
60
120
240
300
360
111
Figure 2-6 depicts the basic feasible switching states (vectors). There are six nonzero
vectors - U0, U60,U
120
, U
180
, U
, and U
240
, and two zero vectors - O
300
111
and O
, usable
000
for switching. Therefore, the principle of the standard space vector modulation lies in
applying the appropriate switching states for a certain time, and thus generating a voltage
vector identical to the reference one.
GMCLIB User's Guide, Rev. 2, 10/2015
38Freescale Semiconductor, Inc.
Chapter 2 Algorithms in detail
Figure 2-6. Basic space vectors
Referring to this principle, the objective of the standard space vector modulation is an
approximation of the reference stator voltage vector US, with an appropriate combination
of the switching patterns, composed of basic space vectors. The graphical explanation of
this objective is shown in Figure 2-7 and Figure 2-8.
GMCLIB User's Guide, Rev. 2, 10/2015
Freescale Semiconductor, Inc.39
GMCLIB_SvmStd
Figure 2-7. Projection of reference voltage vector in the respective sector
The stator reference voltage vector US is phase-advanced by 30° from the direct-α, and
thus can be generated with an appropriate combination of the adjacent basic switching
states U0 and U60. These figures also indicate the resultant direct-α and quadrature-β
components for space vectors U0 and U60.
GMCLIB User's Guide, Rev. 2, 10/2015
40Freescale Semiconductor, Inc.
Chapter 2 Algorithms in detail
Figure 2-8. Detail of the voltage vector projection in the respective sector
In this case, the reference stator voltage vector US is located in sector I, and can be
generated using the appropriate duty-cycle ratios of the basic switching states U0 and
U60. The principal equations concerning this vector location are as follows:
Equation 32
where T60 and T0 are the respective duty-cycle ratios, for which the basic space vectors
T60 and T0 should be applied within the time period T. T
vectors O
000
and O
are applied. Those duty-cycle ratios can be calculated using the
111
is the time, for which the null
null
following equations:
GMCLIB User's Guide, Rev. 2, 10/2015
Freescale Semiconductor, Inc.41
GMCLIB_SvmStd
Equation 33
Considering that normalized magnitudes of basic space vectors are |U60| = |U0| = 2 / √3,
and by the substitution of the trigonometric expressions sin 60° and tan 60° by their
quantities 2 / √3, and √3, respectively, the Equation 33 on page 42 can be rearranged for
the unknown duty-cycle ratios T60 / T and T0 / T as follows:
Equation 34
Sector II is depicted in Figure 2-9. In this particular case, the reference stator voltage
vector US is generated using the appropriate duty-cycle ratios of the basic switching
states T60 and T
. The basic equations describing this sector are as follows:
120
Equation 35
where T
U
and U60 should be applied within the time period T. T
120
null vectors O
and T60 are the respective duty-cycle ratios, for which the basic space vectors
120
is the time, for which the
null
000
and O
are applied. These resultant duty-cycle ratios are formed from
111
the auxiliary components, termed A and B. The graphical representation of the auxiliary
components is shown in Figure 2-10.
GMCLIB User's Guide, Rev. 2, 10/2015
42Freescale Semiconductor, Inc.
Chapter 2 Algorithms in detail
Figure 2-9. Projection of the reference voltage vector in the respective sector
GMCLIB User's Guide, Rev. 2, 10/2015
Freescale Semiconductor, Inc.43
GMCLIB_SvmStd
Figure 2-10. Detail of the voltage vector projection in the respective sector
The equations describing those auxiliary time-duration components are as follows:
Equation 36
Equations in Equation 36 on page 44 have been created using the sine rule.
The resultant duty-cycle ratios T
/ T and T60 / T are then expressed in terms of the
120
auxiliary time-duration components, defined by Equation 37 on page 44 as follows:
Equation 37
GMCLIB User's Guide, Rev. 2, 10/2015
44Freescale Semiconductor, Inc.
Chapter 2 Algorithms in detail
Using these equations, and also considering that the normalized magnitudes of the basic
space vectors are |U
cycle ratios of basic space vectors T
| = |U60| = 2 / √3 , the equations expressed for the unknown duty-
120
/ T and T60 / T can be expressed as follows:
120
Equation 38
The duty-cycle ratios in the remaining sectors can be derived using the same approach.
The resulting equations will be similar to those derived for sector I and sector II.
Equation 39
To depict the duty-cycle ratios of the basic space vectors for all sectors, we define:
• Three auxiliary variables:
Equation 40
• Two expressions - t_1 and t_2, which generally represent the duty-cycle ratios of the
basic space vectors in the respective sector (for example, for the first sector, t_1 and
t_2), represent duty-cycle ratios of the basic space vectors U60 and U0; for the second
sector, t_1 and t_2 represent duty-cycle ratios of the basic space vectors U
120
and
U60, and so on.
The expressions t_1 and t_2, in terms of auxiliary variables X, Y, and Z for each sector,
are listed in Table 2-10.
Table 2-10. Determination of t_1 and t_2 expressions
SectorsU0, U
t_1XZ-XZ-ZY
t_2-ZYZ-X-Y-X
60
U60, U
120
U
120
, U
180
U
180
, U
240
U
240
, U
300
U
, U
300
0
For the determination of auxiliary variables X, Y, and Z, the sector number is required.
This information can be obtained using several approaches. The approach discussed here
requires the use of modified Inverse Clark transformation to transform the direct-α and
quadrature-β components into balanced three-phase quantities u
ref1
, u
ref2
, and u
ref3
, used
for straightforward calculation of the sector number, to be shown later.
GMCLIB User's Guide, Rev. 2, 10/2015
Freescale Semiconductor, Inc.45
GMCLIB_SvmStd
Equation 41
The modified Inverse Clark transformation projects the quadrature-uβ component into
u
, as shown in Figure 2-11 and Figure 2-12, whereas voltages generated by the
ref1
conventional Inverse Clark transformation project the direct-uα component into u
ref1
.
Figure 2-11. Direct-ua and quadrature-ub components of the stator reference voltage
Figure 2-11 depicts the direct-uα and quadrature-uβ components of the stator reference
voltage vector US, which were calculated using equations uα = cos ϑ and uβ = sin ϑ,
respectively.
GMCLIB User's Guide, Rev. 2, 10/2015
46Freescale Semiconductor, Inc.
Chapter 2 Algorithms in detail
Figure 2-12. Reference voltages U
ref1
, U
ref2
, and U
ref3
The sector identification tree shown in Figure 2-13 can be a numerical solution of the
approach shown in GMCLIB_SvmStd_Img8.
Figure 2-13. Identification of the sector number
In the worst case, at least three simple comparisons are required to precisely identify the
sector of the stator reference voltage vector. For example, if the stator reference voltage
vector is located as shown in Figure 2-7, the stator-reference voltage vector is phaseadvanced by 30° from the direct α-axis, which results in the positive quantities of u
and u
, and the negative quantity of u
ref2
; see Figure 2-12. If these quantities are used
ref3
ref1
as the inputs for the sector identification tree, the product of those comparisons will be
sector I. The same approach identifies sector II, if the stator-reference voltage vector is
GMCLIB User's Guide, Rev. 2, 10/2015
Freescale Semiconductor, Inc.47
GMCLIB_SvmStd
located as shown in Figure 2-9. The variables t1, t2, and t3, which represent the switching
duty-cycle ratios of the respective three-phase system, are calculated according to the
following equations:
Equation 42
where T is the switching period, and t_1 and t_2 are the duty-cycle ratios of the basic
space vectors given for the respective sector; Table 2-10, Equation 31 on page 38, and
Equation 42 on page 48 are specific solely to the standard space vector modulation
technique; other space vector modulation techniques discussed later will require deriving
different equations.
The next step is to assign the correct duty-cycle ratios - t1, t2, and t3, to the respective
motor phases. This is a simple task, accomplished in a view of the position of the stator
reference voltage vector; see Table 4.
Table 2-11. Assignment of the duty-cycle ratios to motor phases
SectorsU0, U
pwm_at
pwm_bt
pwm_ct
3
2
1
60
U60, U
t
2
t
3
t
1
120
U
120
, U
t
t
t
180
1
3
2
U
180
, U
t
t
t
240
1
2
3
U
240
, U
t
t
t
300
2
1
3
U
, U
300
0
t
3
t
1
t
2
The principle of the space vector modulation technique consists of applying the basic
voltage vectors U
XXX
and O
for certain time, in such a way that the main vector
XXX
generated by the pulse width modulation approach for the period T is equal to the original
stator reference voltage vector US. This provides a great variability of arrangement of the
basic vectors during the PWM period T. These vectors might be arranged either to lower
the switching losses, or to achieve diverse results, such as center-aligned PWM, edgealigned PWM, or a minimal number of switching states. A brief discussion of the widely
used center-aligned PWM follows.
Generating the center-aligned PWM pattern is accomplished by comparing the threshold
levels pwm_a, pwm_b, and pwm_c with a free-running up-down counter. The timer
counts to one, and then down to zero. It is supposed that when a threshold level is larger
than the timer value, the respective PWM output is active. Otherwise, it is inactive; see
Figure 2-14.
GMCLIB User's Guide, Rev. 2, 10/2015
48Freescale Semiconductor, Inc.
Chapter 2 Algorithms in detail
Figure 2-14. Standard space vector modulation technique — center-aligned PWM
Figure 2-15 shows the waveforms of the duty-cycle ratios, calculated using standard
space vector modulation.
For the accurate calculation of the duty-cycle ratios, direct-α, and quadrature-β
components of the stator reference voltage vector, it must be considered that the duty
cycle cannot be higher than one (100 %); in other words, the assumption must be
met.
GMCLIB User's Guide, Rev. 2, 10/2015
Freescale Semiconductor, Inc.49
GMCLIB_SvmStd
Figure 2-15. Standard space vector modulation technique
2.8.1
Available versions
This function is available in the following versions:
• Fractional output - the output is the fractional portion of the result; the result is
within the range <0 ; 1). The result may saturate.
GMCLIB User's Guide, Rev. 2, 10/2015
50Freescale Semiconductor, Inc.
Chapter 2 Algorithms in detail
The available versions of the GMCLIB_SvmStd function are shown in the following
table.
Standard space vector modulation with a 16-bit fractional stationary (α-β) input and a 16-bit
fractional three-phase output. The result type is a 16-bit unsigned integer, which indicates the
actual SVM sector. The input is within the range <-1 ; 1); the output duty cycle is within the range
<0 ; 1). The output sector is an integer value within the range <0 ; 7>.
2.8.2Declaration
The available GMCLIB_SvmStd functions have the following declarations:
/* Periodical function or interrupt */
void Isr(void)
{
/* SVM calculation */
u16Sector = GMCLIB_SvmStd_F16(&sAlphaBeta, &sAbc);
}
2.9
Freescale Semiconductor, Inc.51
GMCLIB_SvmIct
GMCLIB User's Guide, Rev. 2, 10/2015
GMCLIB_SvmIct
The GMCLIB_SvmIct function calculates the appropriate duty-cycle ratios, which are
needed for generation of the given stator-reference voltage vector using the general
sinusoidal modulation technique.
The GMCLIB_SvmIct function calculates the appropriate duty-cycle ratios, needed for
generation of the given stator reference voltage vector using the conventional Inverse
Clark transformation. Finding the sector in which the reference stator voltage vector U
resides is similar to GMCLIB_SvmStd. This is achieved by first converting the direct-α
and the quadrature-β components of the reference stator voltage vector US into the
balanced three-phase quantities u
ref1
, u
ref2
, and u
using the modified Inverse Clark
ref3
transformation:
Equation 43
S
The calculation of the sector number is based on comparing the three-phase reference
voltages u
ref1
, u
ref2
, and u
with zero. This computation is described by the following
ref3
set of rules:
Equation 44
After passing these rules, the modified sector numbers are then derived using the
following formula:
Equation 45
The sector numbers determined by this formula must be further transformed to
correspond to those determined by the sector identification tree. The transformation
which meets this requirement is shown in the following table:
Table 2-13. Transformation of the sectors
Sector*123456
Sector261435
GMCLIB User's Guide, Rev. 2, 10/2015
52Freescale Semiconductor, Inc.
Chapter 2 Algorithms in detail
Use the Inverse Clark transformation for transforming values such as flux, voltage, and
current from an orthogonal rotating coordination system (uα, uβ) to a three-phase rotating
coordination system (ua, ub, and uc). The original equations of the Inverse Clark
transformation are scaled here to provide the duty-cycle ratios in the range <0 ; 1). These
scaled duty cycle ratios pwm_a, pwm_b, and pwm_c can be used directly by the registers
of the PWM block.
Equation 46
The following figure shows the waveforms of the duty-cycle ratios calculated using the
Inverse Clark transformation.
GMCLIB User's Guide, Rev. 2, 10/2015
Freescale Semiconductor, Inc.53
GMCLIB_SvmIct
Figure 2-16. Inverse Clark transform modulation technique
For an accurate calculation of the duty-cycle ratios and the direct-α and quadrature-β
components of the stator reference voltage vector, the duty cycle cannot be higher than
one (100 %); in other words, the assumption must be met.
2.9.1
Available versions
This function is available in the following versions:
• Fractional output - the output is the fractional portion of the result; the result is
within the range <0 ; 1). The result may saturate.
GMCLIB User's Guide, Rev. 2, 10/2015
54Freescale Semiconductor, Inc.
Chapter 2 Algorithms in detail
The available versions of the GMCLIB_SvmIct function are shown in the following
table:
General sinusoidal space vector modulation with a 16-bit fractional stationary (α-β) input and a
16-bit fractional three-phase output. The result type is a 16-bit unsigned integer, which indicates
the actual SVM sector. The input is within the range <-1 ; 1); the output duty cycle is within the
range <0 ; 1). The output sector is an integer value within the range <0 ; 7>.
2.9.2Declaration
The available GMCLIB_SvmIct functions have the following declarations:
/* Periodical function or interrupt */
void Isr(void)
{
/* SVM calculation */
u16Sector = GMCLIB_SvmIct_F16(&sAlphaBeta, &sAbc);
}
2.10
Freescale Semiconductor, Inc.55
GMCLIB_SvmU0n
GMCLIB User's Guide, Rev. 2, 10/2015
GMCLIB_SvmU0n
The GMCLIB_SvmU0n function calculates the appropriate duty-cycle ratios, which are
needed for generation of the given stator-reference voltage vector using the general
sinusoidal modulation technique.
The GMCLIB_SvmU0n function for calculating of duty-cycle ratios is widely used in
modern electric drives. This function calculates the appropriate duty-cycle ratios, which
are needed for generating the given stator reference voltage vector using a special space
vector modulation technique called space vector modulation with O
one type of null vector O
is used (all bottom switches are turned on in the invertor).
000
nulls, where only
000
The derivation approach of the space vector modulation technique with O
nulls is in
000
many aspects identical to the approach presented in GMCLIB_SvmStd. However, a
distinct difference lies in the definition of the variables t1, t2, and t3 that represent
switching duty-cycle ratios of the respective phases:
Equation 47
where T is the switching period, and t_1 and t_2 are the duty-cycle ratios of the basic
space vectors that are defined for the respective sector in Table 2-10.
The generally used center-aligned PWM is discussed briefly in the following sections.
Generating the center-aligned PWM pattern is accomplished practically by comparing the
threshold levels pwm_a, pwm_b, and pwm_c with the free-running up/down counter. The
timer counts up to 1 (0x7FFF) and then down to 0 (0x0000). It is supposed that when a
threshold level is larger than the timer value, the respective PWM output is active.
Otherwise it is inactive (see Figure 2-17).
GMCLIB User's Guide, Rev. 2, 10/2015
56Freescale Semiconductor, Inc.
Chapter 2 Algorithms in detail
Figure 2-17. Space vector modulation technique with O
nulls — center-aligned PWM
000
Figure Figure 2-17 shows calculated waveforms of the duty cycle ratios using space
vector modulation with O
000
nulls.
For an accurate calculation of the duty-cycle ratios, direct-α, and quadrature-β
components of the stator reference voltage vector, consider that the duty cycle cannot be
higher than one (100 %); in other words, the assumption must be met.
GMCLIB User's Guide, Rev. 2, 10/2015
Freescale Semiconductor, Inc.57
GMCLIB_SvmU0n
2.10.1
Figure 2-18. Space vector modulation technique with O
Available versions
000
nulls
This function is available in the following versions:
• Fractional output - the output is the fractional portion of the result; the result is
within the range <0 ; 1). The result may saturate.
GMCLIB User's Guide, Rev. 2, 10/2015
58Freescale Semiconductor, Inc.
Chapter 2 Algorithms in detail
The available versions of the GMCLIB_SvmU0n function are shown in the following
table:
General sinusoidal space vector modulation with a 16-bit fractional stationary (α-β) input, and a
16-bit fractional three-phase output. The result type is a 16-bit unsigned integer, which indicates
the actual SVM sector. The input is within the range <-1 ; 1); the output duty cycle is within the
range <0 ; 1). The output sector is an integer value within the range <0 ; 7>.
2.10.2Declaration
The available GMCLIB_SvmU0n functions have the following declarations:
/* Periodical function or interrupt */
void Isr(void)
{
/* SVM calculation */
u16Sector = GMCLIB_SvmU0n_F16(&sAlphaBeta, &sAbc);
}
2.11
Freescale Semiconductor, Inc.59
GMCLIB_SvmU7n
GMCLIB User's Guide, Rev. 2, 10/2015
GMCLIB_SvmU7n
The GMCLIB_SvmU7n function calculates the appropriate duty-cycle ratios, which are
needed for generation of the given stator-reference voltage vector, using the general
sinusoidal modulation technique.
The GMCLIB_SvmU7n function for calculating the duty-cycle ratios is widely used in
modern electric drives. This function calculates the appropriate duty-cycle ratios, which
are needed for generating the given stator reference voltage vector using a special space
vector modulation technique called space vector modulation with O
one type of null vector O
is used (all top switches are turned on in the invertor).
111
nulls, where only
111
The derivation approach of the space vector modulation technique with O
nulls is
111
identical (in many aspects) to the approach presented in GMCLIB_SvmStd. However, a
distinct difference lies in the definition of variables t1, t2, and t3 that represent switching
duty-cycle ratios of the respective phases:
Equation 48
where T is the switching period, and t_1 and t_2 are the duty-cycle ratios of the basic
space vectors defined for the respective sector in Table 2-10.
The generally-used center-aligned PWM is discussed briefly in the following sections.
Generating the center-aligned PWM pattern is accomplished by comparing threshold
levels pwm_a, pwm_b, and pwm_c with the free-running up/down counter. The timer
counts up to 1 (0x7FFF) and then down to 0 (0x0000). It is supposed that when a
threshold level is larger than the timer value, the respective PWM output is active.
Otherwise, it is inactive (see Figure 2-19).
GMCLIB User's Guide, Rev. 2, 10/2015
60Freescale Semiconductor, Inc.
Chapter 2 Algorithms in detail
Figure 2-19. Space vector modulation technique with O
nulls — center-aligned PWM
111
Figure Figure 2-19 shows calculated waveforms of the duty-cycle ratios using Space
Vector Modulation with O
111
nulls.
For an accurate calculation of the duty-cycle ratios, direct-α, and quadrature-β
components of the stator reference voltage vector, it must be considered that the duty
cycle cannot be higher than one (100 %); in other words, the assumption
must be
met.
GMCLIB User's Guide, Rev. 2, 10/2015
Freescale Semiconductor, Inc.61
GMCLIB_SvmU7n
2.11.1
Figure 2-20. Space vector modulation technique with O
Available versions
111
nulls
This function is available in the following versions:
• Fractional output - the output is the fractional portion of the result; the result is
within the range <0 ; 1). The result may saturate.
GMCLIB User's Guide, Rev. 2, 10/2015
62Freescale Semiconductor, Inc.
Chapter 2 Algorithms in detail
The available versions of the GMCLIB_SvmU7n function are shown in the following
table:
General sinusoidal space vector modulation with a 16-bit fractional stationary (α-β) input and a
16-bit fractional three-phase output. The result type is a 16-bit unsigned integer, which indicates
the actual SVM sector. The input is within the range <-1 ; 1); the output duty cycle is within the
range <0 ; 1). The output sector is an integer value within the range <0 ; 7>.
2.11.2Declaration
The available GMCLIB_SvmU7n functions have the following declarations:
/* Periodical function or interrupt */
void Isr(void)
{
/* SVM calculation */
u16Sector = GMCLIB_SvmU7n_F16(&sAlphaBeta, &sAbc);
}
GMCLIB User's Guide, Rev. 2, 10/2015
Freescale Semiconductor, Inc.63
GMCLIB_SvmU7n
GMCLIB User's Guide, Rev. 2, 10/2015
64Freescale Semiconductor, Inc.
Appendix A
Library types
A.1bool_t
The
bool_t type is a logical 16-bit type. It is able to store the boolean variables with two
states: TRUE (1) or FALSE (0). Its definition is as follows:
typedef unsigned short bool_t;
The following figure shows the way in which the data is stored by this type:
Table A-1. Data storage
1514131211109876543210
ValueUnused
TRUE
FALSE
0000000000000001
0001
0000000000000000
0000
Logi
cal
To store a logical value as bool_t, use the FALSE or TRUE macros.
A.2
uint8_t
The uint8_t type is an unsigned 8-bit integer type. It is able to store the variables within
the range <0 ; 255>. Its definition is as follows:
typedef unsigned char int8_t;
The following figure shows the way in which the data is stored by this type:
GMCLIB User's Guide, Rev. 2, 10/2015
Freescale Semiconductor, Inc.65
uint16_t
Table A-2. Data storage
76543210
ValueInteger
255
11
124
159
11111111
FF
00001011
0B
01111100
7C
10011111
9F
A.3uint16_t
The uint16_t type is an unsigned 16-bit integer type. It is able to store the variables
within the range <0 ; 65535>. Its definition is as follows:
typedef unsigned short uint16_t;
The following figure shows the way in which the data is stored by this type:
Table A-3. Data storage
1514131211109876543210
ValueInteger
65535
5
15518
40768
1111111111111111
FFFF
0000000000000101
0005
0011110010011110
3C9E
1001111101000000
9F40
A.4uint32_t
GMCLIB User's Guide, Rev. 2, 10/2015
66Freescale Semiconductor, Inc.
Appendix A Library types
The uint32_t type is an unsigned 32-bit integer type. It is able to store the variables
within the range <0 ; 4294967295>. Its definition is as follows:
typedef unsigned long uint32_t;
The following figure shows the way in which the data is stored by this type:
The int8_t type is a signed 8-bit integer type. It is able to store the variables within the
range <-128 ; 127>. Its definition is as follows:
typedef char int8_t;
The following figure shows the way in which the data is stored by this type:
Table A-5. Data storage
76543210
ValueSignInteger
127
-128
60
-97
01111111
7F
10000000
80
00111100
3C
10011111
9F
GMCLIB User's Guide, Rev. 2, 10/2015
Freescale Semiconductor, Inc.67
int16_t
A.6int16_t
The int16_t type is a signed 16-bit integer type. It is able to store the variables within the
range <-32768 ; 32767>. Its definition is as follows:
typedef short int16_t;
The following figure shows the way in which the data is stored by this type:
Table A-6. Data storage
1514131211109876543210
ValueSignInteger
32767
-32768
15518
-24768
0111111111111111
7FFF
1000000000000000
8000
0011110010011110
3C9E
1001111101000000
9F40
A.7int32_t
The int32_t type is a signed 32-bit integer type. It is able to store the variables within the
range <-2147483648 ; 2147483647>. Its definition is as follows:
typedef long int32_t;
The following figure shows the way in which the data is stored by this type:
Table A-7. Data storage
3124 2316 158 70
ValueSInteger
21474836477FFFFFFF
-214748364880000000
5597729603562550
-843915468CDB2DF34
GMCLIB User's Guide, Rev. 2, 10/2015
68Freescale Semiconductor, Inc.
Appendix A Library types
A.8frac8_t
The frac8_t type is a signed 8-bit fractional type. It is able to store the variables within
the range <-1 ; 1). Its definition is as follows:
typedef char frac8_t;
The following figure shows the way in which the data is stored by this type:
Table A-8. Data storage
76543210
ValueSignFractional
0.99219
-1.0
0.46875
-0.75781
01111111
7F
10000000
80
00111100
3C
10011111
9F
To store a real number as frac8_t, use the FRAC8 macro.
A.9
frac16_t
The frac16_t type is a signed 16-bit fractional type. It is able to store the variables within
the range <-1 ; 1). Its definition is as follows:
typedef short frac16_t;
The following figure shows the way in which the data is stored by this type:
Table A-9. Data storage
1514131211109876543210
ValueSignFractional
0.99997
-1.01000000000000000
0111111111111111
7FFF
Table continues on the next page...
GMCLIB User's Guide, Rev. 2, 10/2015
Freescale Semiconductor, Inc.69
frac32_t
Table A-9. Data storage (continued)
8000
0.47357
-0.75586
0011110010011110
3C9E
1001111101000000
9F40
To store a real number as frac16_t, use the FRAC16 macro.
A.10
The
frac32_t
frac32_t type is a signed 32-bit fractional type. It is able to store the variables within
the range <-1 ; 1). Its definition is as follows:
typedef long frac32_t;
The following figure shows the way in which the data is stored by this type:
Table A-10. Data storage
3124 2316 158 70
ValueSFractional
0.99999999957FFFFFFF
-1.080000000
0.0260664597003562550
-0.3929787632CDB2DF34
To store a real number as frac32_t, use the FRAC32 macro.
A.11
acc16_t
The acc16_t type is a signed 16-bit fractional type. It is able to store the variables within
the range <-256 ; 256). Its definition is as follows:
typedef short acc16_t;
The following figure shows the way in which the data is stored by this type:
GMCLIB User's Guide, Rev. 2, 10/2015
70Freescale Semiconductor, Inc.
Table A-11. Data storage
1514131211109876543210
ValueSignIntegerFractional
255.9921875
-256.0
1.0
-1.0
13.7890625
-89.71875
0111111111111111
7FFF
1000000000000000
8000
0000000010000000
0080
1111111110000000
FF80
0000011011100101
06E5
1101001100100100
D324
Appendix A Library types
To store a real number as acc16_t, use the ACC16 macro.
A.12
acc32_t
The acc32_t type is a signed 32-bit accumulator type. It is able to store the variables
within the range <-65536 ; 65536). Its definition is as follows:
typedef long acc32_t;
The following figure shows the way in which the data is stored by this type:
Table A-12. Data storage
3124 2316 158 70
ValueSIntegerFractional
65535.9999697FFFFFFF
-65536.080000000
1.000008000
-1.0FFFF8000
23.789734000BE516
-1171.306793FDB658BC
To store a real number as acc32_t, use the ACC32 macro.
GMCLIB User's Guide, Rev. 2, 10/2015
Freescale Semiconductor, Inc.71
GMCLIB_3COOR_T_F16
A.13GMCLIB_3COOR_T_F16
The GMCLIB_3COOR_T_F16 structure type corresponds to the three-phase stationary
coordinate system, based on the A, B, and C components. Each member is of the frac16_t
data type. The structure definition is as follows:
Table A-13. GMCLIB_3COOR_T_F16 members description
TypeNameDescription
frac16_tf16AA component; 16-bit fractional type
frac16_tf16BB component; 16-bit fractional type
frac16_tf16CC component; 16-bit fractional type
A.14GMCLIB_2COOR_ALBE_T_F16
The GMCLIB_2COOR_ALBE_T_F16 structure type corresponds to the two-phase
stationary coordinate system, based on the Alpha and Beta orthogonal components. Each
member is of the frac16_t data type. The structure definition is as follows:
Table A-14. GMCLIB_2COOR_ALBE_T_F16 members description
TypeNameDescription
frac16_tf16Aphaα-component; 16-bit fractional type
frac16_tf16Betaβ-component; 16-bit fractional type
GMCLIB User's Guide, Rev. 2, 10/2015
72Freescale Semiconductor, Inc.
Appendix A Library types
A.15GMCLIB_2COOR_DQ_T_F16
The GMCLIB_2COOR_DQ_T_F16 structure type corresponds to the two-phase rotating
coordinate system, based on the D and Q orthogonal components. Each member is of the
frac16_t data type. The structure definition is as follows:
Table A-15. GMCLIB_2COOR_DQ_T_F16 members description
TypeNameDescription
frac16_tf16DD-component; 16-bit fractional type
frac16_tf16QQ-component; 16-bit fractional type
A.16GMCLIB_2COOR_DQ_T_F32
The GMCLIB_2COOR_DQ_T_F32 structure type corresponds to the two-phase rotating
coordinate system, based on the D and Q orthogonal components. Each member is of the
frac32_t data type. The structure definition is as follows:
Table A-16. GMCLIB_2COOR_DQ_T_F32 members description
TypeNameDescription
frac32_tf32DD-component; 32-bit fractional type
frac32_tf32QQ-component; 32-bit fractional type
A.17GMCLIB_2COOR_SINCOS_T_F16
GMCLIB User's Guide, Rev. 2, 10/2015
Freescale Semiconductor, Inc.73
FALSE
The GMCLIB_2COOR_SINCOS_T_F16 structure type corresponds to the two-phase
coordinate system, based on the Sin and Cos components of a certain angle. Each
member is of the frac16_t data type. The structure definition is as follows:
Information in this document is provided solely to enable system and
software implementers to use Freescale products. There are no express
or implied copyright licenses granted hereunder to design or fabricate
any integrated circuits based on the information in this document.
Freescale reserves the right to make changes without further notice to
any products herein.
Freescale makes no warranty, representation, or guarantee regarding
the suitability of its products for any particular purpose, nor does
Freescale assume any liability arising out of the application or use of
any product or circuit, and specifically disclaims any and all liability,
including without limitation consequential or incidental damages.
“Typical” parameters that may be provided in Freescale data sheets
and/or specifications can and do vary in different applications, and
actual performance may vary over time. All operating parameters,
including “typicals,” must be validated for each customer application by
customer's technical experts. Freescale does not convey any license
under its patent rights nor the rights of others. Freescale sells products
pursuant to standard terms and conditions of sale, which can be found
at the following address: www.freescale.com/salestermsandconditions.
Freescale and the Freescale logo are trademarks of Freescale
Semiconductor, Inc. All other product or service names are the property
of their respective owners.