High-performance drive applications require fast, reliable, and robust control systems. Therefore, there is
a significant demand for well-equipped digital motor control (DMC) platforms to educate the next
generation of engineers. In this users guide, a number of introductory-level digital motor control
methodologies and laboratory tools are presented. These tools help engineers learn how to easily
construct their own systems using TI provided device drivers, APIs, utilities, and libraries. Also described
is Texas Instruments' motor control developer’s kits, software framework, and DMC library. These
documents provide a modular development strategy which allows the user to experiment incrementally
from a basic to an advanced level.
1Introduction
Digital motor control has been a challenging subject since the beginning of early implementations.
Although digital control techniques and the availability of high-speed microcontrollers made life
significantly easier for engineers, highly non-linear motor models, designing and tuning multiple control
loops, math intensive sensorless algorithms, parameter and temperature dependencies, and complex
software structures still have the potential to slow down development.
Texas Instruments understands the challenges facing motor control developers, and provides materials
and tools that significantly accelerate development and troubleshooting of motor-control systems.
Thorough documentation, a rich set of digital motor control and math libraries, modular software
strategies, incremental build processes, code development environments with real time debugging
support, and sample motor control kits at different voltage levels designed for all major motor types with
open source hardware support, lead developers through the process of creating a complete motor-control
system. These tools enable developers to quickly determine the processing resources required to
implement basic motor control. From this baseline, they are then able to bring in advanced algorithms to
trade-off the remaining processing capacity for greater accuracy, better performance, and higher power
efficiency, control of multiple motors or integrated power stages like digital power factor correction, and a
myriad of other options. In this way, developers can architect systems specifically optimized for their
application constraints and requirements.
User's Guide
SPRUGI6–September 2010
TMS320C2000 Motor Control Primer
2Software Tools
2.1IQ Math Library
2.1.1What is IQ Math Library
Real-time control algorithms used in industry are typically computationally intensive, where optimal
execution speed and high accuracy is required. When C is used to develop control algorithm code,
generic math libraries can be used for computing math functions such as trigonometric functions, division,
etc. However, this approach may not result in the most cycle efficient code. Therefore, TI provides a
library of highly optimized and high precision math functions in the form of the IQMath library. Using the
math routines in the IQ Math library the user can achieve execution speeds considerably faster than
equivalent code written in standard ANSI C language.
The IQ Math library is available in both fixed- and floating-point versions, enabling easy migration from
float to fixed devices. The fixed-point library uses Q-arithmetic to emulate the fractional point (explained in
the following section), whereas the floating-point version uses the floating-point instruction set and
hardware FPU present on the device.
2
TMS320C2000 Motor Control PrimerSPRUGI6–September 2010
S I I I I I I I . F F F F F F F F F F F F F F F F F F F F F F F F
2I+ 2
I-1
+ … + 21+ 20. 2-1+ 2
- 2
+ … + 2
-F
www.ti.com
2.1.2Q Format and Preferred Global Q for DMC
Q Format is a way of representing a numeric value containing a sign, integer and fraction portion in a fixed
bit location field. Figure 1. The following image illustrates a 32-bit binary number where the bits are
partitioned to represent the sign, integer, and fractional parts.
Thus, the fixed bit location acts as a virtual floating point. The IQ Math library makes use of such a
representation to compute the functions on a fixed-point device. The IQ Math library further allows the
user to select the appropriate numeric range and resolution by choosing where the decimal point is
located, i.e., how many bits of the binary represented number are integers and how many are the
quotient/fraction.
A value of a number represented in the format above can be interpreted as:
Software Tools
The number of fraction bits determines the Q format of the number. For a given word length (e.g., 32 bits),
the greater the number of fractional bits, the higher the resolution, and the smaller the dynamic range.
Table 1 shows some examples regarding the range and resolution of 32-bit, fixed-point numbers for
different Q format representations.
Table 1. Range and Resolution of 32-bit Fixed-point Number for Different Q-format Representation
A high resolution and large dynamic range is typically needed for precise control algorithm execution.
Motor control applications formats between Q31 to Q27 do not provide enough dynamic range, and
formats of Q18 or lower result in significant quantization errors, due to insufficient resolution. Therefore, a
format of Q24 is used by the TI motor control software because it provides enough high resolution and
enough dynamic range to tackle a wide variety of motor applications. Note that all the motor control
projects are implemented based on per unit (pu) system variables and the Q used by these variables is by
default, Q24. For floating-point devices, single-precision IEEE float is used. Also note that although the
default Q is 24, the DMC library can be made to use any other Q format by changing the GLOBAL_Q
value.
2.1.3Summary of the IQ Math Functions
The routines included within the IQmath library can be classified as:
Table 2. Some IQMath Functions Used Often in Motor Control Applications
CC++Operation
_IQ(float)IQ(float)Constant
++Add
--Subtract
_IQmpy*Multiply
_IQdiv/Divide
_IQsqrtsqrtSquare root
_IQisqrtisqrt1/Square root
_IQsinsinSine
_IQcoscosCosine
_IQatanatanArc tangent
_IQatan2atan2Arc tangent 2 opr.
_IQsinPUsinPUSine per unit
_IQcosPUcosPUCosine per unit
_IQatan2PUatan2PUArc tangent 2 opr. per unit
_IQsatsatSaturation
_IQabsabsAbsolute value
2.1.4Calling an IQMath Function in C
The IQ Math library is very user-friendly and comes with detailed documentation explaining the features
and usage of each library function, along with example code. The following sample code shows how to
write a Park transform function using IQ Math library trigonometric and multiplication functions:
Note that in the above example, the variables are declared not as fixed or float but as “iq.” The iq type is
interpreted at compile time, and is substituted for a fixed- or floating-point variable type, depending on the
device type being used. Consequently, the code above can be run on a fixed-point or a floating-point
device without any changes, therefore enabling easy migration between floating- and fixed-point devices.
2.1.5Advantages of the IQMath Library for Motor Control
IQmath uses the instructions present on the C28x™ devices in the most efficient way to compute the
various math functions. Briefly, the benefits and contributions of the IQMath Library in C2000™-based
digital motor control can be summarized as follows:
•Selection of dynamic range and resolution on fixed point devices: For fixed-point devices, a
choice of Q can be made depending on dynamic range and resolution requirements of the system.
Q24 is used by default but can be changed easily to select another Q format if needed.
•Float to fixed migration: All the functions available in the floating-point version of the library are
available on fixed-point version and vice versa; hence, migration from float to fixed becomes very easy.
The use of “iq” type while writing code enables the compiler to interpret the math type to be used for
the variables at compile time. Thus, no or little change is required to the source code when migrating
from floating- to fixed-point devices.
4
TMS320C2000 Motor Control PrimerSPRUGI6–September 2010
•Highly optimized function: This function enables faster and multiple control loop execution than what
is possible using standard ANSI-C routines.
2.2Digital Motor Control (DMC) Library
2.2.1DMCLib Overview
The digital motor control library is composed of C functions (or macros) developed for C2000 motor
control users. These modules are represented as modular blocks in C2000 literature in order to explain
system-level block diagrams clearly by means of software modularity. The DMC library modules cover
nearly all of the target-independent mathematical functions and target-specific peripheral configuration
functions, which are essential for motor control. These modules can be classified as:
Transformation and Observer ModulesClarke, Park, Phase Voltage Calculation, Sliding Mode
Signal Generators and Control ModulesPID, Commutation Trigger Generator, V/f Controller,
Peripheral DriversPWM abstraction for multiple topologies and techniques,
Real-Time Debugging ModulesDLOG module for CCS graph window utility, PWMDAC
Software Tools
Observer, BEMF Commutation, Direct Flux Estimator,
Speed Calculators and Estimators, Position Calculators
and Estimators etc.
Impulse Generator, Mod 6 Counter, Slew Rate Controllers,
Sawtooth & Ramp generators, Space Vector Generators
etc.
ADC Drivers, Hall Sensor Driver, QEP Driver, CAP Driver
etc
module for monitoring the control variables through
oscilloscope.
In the DMC library, each module is separately documented with source code, use, and background
technical theory. All DMC modules allow users to quickly build, or customize their own systems. The
library supports three principal motor types (induction motor, BLDC and PM motors) but is not limited to
these motors.
The DMC modules — implemented in IQmath — are used to construct both sensored and sensorless
control systems. An earlier version of the DMC library (legacy) was released for the F281x series
SPRC080, and F280x series SPRC215. Starting in 2010, the libraries were revised with optimized macro
usage for system examples using F2803x (Piccolo) and F2833x (Delfino) families and integrated into
controlSUITE. For more on the motor control methodology and available resources, visit the TI Motor
Control Site. There are two releases of the math_blocks in controlSUITE; the fixedv1.1 supports all three
motor types and is only valid for fixed processors. The v2.0 supports both fixed (all) and float (induction
motor and PM motors) system examples.
The DMC library components have been used by TI to provide system-level motor control examples. In
the motor control code, all DMC library modules are initialized according to the system specific
parameters, and the modules are inter-connected to each other. At run-time the modules are called in
order. Each motor control system is built using an incremental build approach, which allows some sections
of the code to be built at a time, so that the developer can verify each section of the application one step
at a time. This is critical in real-time control applications, where so many different variables can affect the
system, and where many different motor parameters need to be tuned.
2.2.2Incremental System Build Methodology
It is well known that, regardless of how much planning has gone into a system engineering project;
chances are the final system won’t work for the first time, usually because some subtle target dependency
or requirement has been overlooked. This is normal engineering, and if a contingency plan or debug
methodology has been comprehended, it’s not a problem. However, if not anticipated ahead of time, this
can become frustrating and time-consuming. To prevent this, the system comes pre-packaged within a
framework, incorporating various system build levels or debug steps as part of the normal system software
flow. A customer can move from a current build level to any other build level quickly, and without risk of
losing configuration or run-time information related to previous build levels.
SPRUGI6–September 2010TMS320C2000 Motor Control Primer
This framework also allows a user to commission system software in a step-by-step manner, and at each
step validate key vital signs before moving on. The number of build levels may vary depending on final
system complexity, but an important point to note is that regardless of the number of build levels, this
framework becomes a common point of reference. In either case, it will greatly improve the chances of
system software success. As will be seen later, incremental system build levels are supported by
frameworks with various configurations of interconnected modules. Frameworks also provide invaluable
skeletons for users to modify or customize as required to suit their own target system requirements.
2.2.3Well Defined Module Variables Provide Clear Debug Points
Because the system/module framework has one-to-one mapping with the system signal flow diagram, it is
easy to probe signals of interest and to visualize them in real time. TI provides useful utility modules which
can display time-varying signals (i.e., software variables) via hardware DAC using an oscilloscope, or on
screen with Code Composer Studio™ using a data-logging software module. The PWMDAC and
DATA_LOG modules can be readily connected by way of pointers during run-time, to any module terminal
variable and internal module variables for greater software visibility.
2.2.4Known Working Library Eases the Development
Modules can provide a valuable starting point, even if they are not exactly the final requirement. Known
good modules can be used initially on a “trust-for-now” basis as a system is built up and valuable
experience is gained. Later on, these standard modules can be investigated on an as-needed basis, to
learn more, or to modify or customize to suit. A modular approach is ideal for this, allowing standard
modules to be swapped out for customized ones later on without risk or delays.
www.ti.com
2.2.5Code Composer Studio and Documentation Completes the Package
The solutions collateral outlined so far for the digital motor control systems software is comprehensive with
many component parts. To bring it all together and to allow customers to test drive many solutions quickly,
TI offers Code Composer Studio™ (CCS) for the C2000 platform as the Integrated Development
Environment (IDE). Ready-to-run CCS projects and workspaces ensure customers are jump-started into
productivity quickly. To complement the IDE, clear module and system documentation tie the solutions
together and help customers understand how theory, implementation, and debug all come together to
provide a working solution.
2.3Software Modularity
The benefits of structured, modular software are well known. This is especially true for large, complex
systems with many sub-blocks contributed by many individuals. In these cases, there is a strong common
set of needs. Efforts by contributors should only be used one time, and are reusable for future projects.
The contributed software blocks (modules) must be predictable in their behavior and compatible with other
blocks, both functionally and numerically. Industry has learned the benefits of these methodologies, and
has realized the impact they can make on smoother system integration; reducing debug and
troubleshooting time, providing a higher degree of visibility inside the software, and allowing quicker
system reconfiguration. These attributes have significant impact on getting quality products out to market
in a timely manner.
Such methodologies needed to be applied to high-performance motor control systems and to address this,
TI introduced the modular DMC library in early 2000. Within the digital control systems space, the
algorithm standard has been used to address the specific needs of application areas such as digital motor
control, industrial electronics, uninterruptible power supplies, plus a host of other control-related areas.
The familiar signal flow block diagram representation of digital control systems, as seen in control texts
and university publications, lend themselves well to effective implementation by software-interconnected
module blocks (i.e., functions or macros) with well-defined input and output ports.
6
TMS320C2000 Motor Control PrimerSPRUGI6–September 2010
Once a rich set of library modules is available with a well-defined and proven interconnect methodology,
systems can be realized fairly quickly. The logical extension is that various “what-if” scenarios of system
topologies and/or configurations can be explored relatively easily and with little overhead. As a more basic
or fundamental need, this same ease of module connection allows a system designer to have a number of
incremental build levels, ranging from a rudimentary system (3-4 modules) used to check out key life
signs, to a fully featured final system with a large number of connected modules. This is analogous to the
commissioning steps or process which is typical in large engineering projects. This approach to system
software commissioning is invaluable during the system integration phase and can greatly reduce the time
and effort required.
2.3.1Consistency Between Software Modules and Control Block Diagrams
It is well known that systems and control engineers like to visualize systems or control strategies in the
form of signal flow block diagrams. It makes good sense to separate main functions and to show how
each is interrelated by explicit connection to other functions. Each function should be self-contained, and
its boundaries or interface clearly delineated. A digital motor control system is a good example of this
interrelation of functions. Figure 2 shows a typical signal flow block diagram of an AC induction motor
controlled by a field-oriented control strategy. This is a useful representation, and it is found in many
classical texts on motor control. However, several limitations are evident when attempting to realize this
diagram in software form.
Figure 2. ACI Sensored FOC - System Block Diagram
Software Tools
It is not usually clear how software variables are related to the signal parameters on the diagram, nor
where in the software these parameters can be found and accessed. Moreover, the boundary between
software and hardware is blurred (i.e., where the software controls the on-chip peripheral and where the
peripheral output pins control the external hardware, such as the PWM-to-inverter interface). By adopting
a modular strategy and enforcing some clear definitions, the classic block diagram shown in Figure 2 can
be rearranged and redrawn to reveal a great amount of information about the actual software which is
used to implement such a system. This new style of system representation can be seen in Figure 3. The
advantages and features of such a representation will be expanded upon in later sections, but a summary
of key points are given here:
•The system block diagram has a clear one-to-one mapping to the modular system software.
•Each module graphic or block represents a self-contained software function or object of the same
name.
•Input and output terminals of each module correspond exactly to global variables within the software
function.
SPRUGI6–September 2010TMS320C2000 Motor Control Primer
•Modules are categorized (color coded) to clearly designate dependencies on peripherals and target
hardware.
•Connections between modules show data flow via corresponding input/output variables.
•Each module is reusable and has its own documentation explaining usage and instantiation.
Figure 3. ACI Sensored FOC – System Block Diagram Showing Clear One-to-One Mapping to Software
2.3.2Reusability, Compatibility, and Expandability
Engineering reuse in today’s competitive environment is critical and software modularity is the perfect
vehicle to achieve this, especially in DMC systems. If we examine various motor control systems, it
becomes clear that a large degree of commonality exists between them. The PID regulator, for example,
is useful across all systems. Therefore, if each module is realized only once, but implemented according
to well defined guidelines, then compatibility and predictability can be assured across all modules. Since
this approach allows efficient reusability, efforts which may typically be used to “reinvent the wheel” can be
re-deployed on expanding the module library base for greater functionality and features.
There are several DMC blocks common for 3-phase motor control in general. On the other hand, in most
cases, the difference between a sensored and sensorless system is only one or two modules, e.g., a
position or speed estimator. The remaining modules are again common. Therefore, in keeping with the
reuse philosophy, design efforts can be focused on expanding the library with more robust estimators
which meet various system requirements, rather than recreating entire system infrastructures.
2.3.3Target Independent Modules and Drivers
Understanding the exact dependencies of a software module is very important. This knowledge is
invaluable during debugging, software porting from one target to another, and on planning a system
commissioning strategy. The modules which are part of the DMC Library (examples of which are shown in
Table 3) are categorized into two main types:
8
•Target (microcontroller) independent (TI)
•Drivers (i.e., target dependent and application configurable)
Table 3. Sample of DMC Module Descriptions and Type Category
NumberModuleDescriptionType
1bldcpwm_drvBLDC PWM driver – uses high-sideDrv
2cap_event_drvCapture input event driverDrv
3hall_gpio_drvHall effect interface driver for sensoredDrv
TMS320C2000 Motor Control PrimerSPRUGI6–September 2010
For convenience, the module graphics throughout the documentation are color coded to help customers
quickly identify a modules dependency within a system. Color designation is as follows:
• Target independent/application configurable :TI/AC pale red
• Drivers (target dependent/applicationDRV blue
configurable) :
Examples of target independent modules are given in Figure 4 and Figure 5. Target independent modules
do not directly access or modify control or status registers of any on-chip peripherals, i.e., target
microcontroller-specific resources. These modules are dependent only on the CPU core. TI/AI modules
are typically characterized by mathematical type functions (e.g., transforms, matrix operations, waveform
generators, etc.). These functions are fixed and fairly standardized, and do not require configuration,
knowledge of peripherals, or the end application itself. TI/AC modules also do not need knowledge of
device peripherals, but do need to be configured depending on the end application. Examples of these
modules are PID controllers, position/speed estimators, voltage and current models, etc.
www.ti.com
Figure 4. Target and Application Independent Modules - Examples
On the other hand, driver modules are the interface between software and target microcontroller-specific
peripheral hardware. Examples of such modules are shown in Figure 6. These modules have direct
access to peripheral control and status registers. Using these driver modules or taking them as a
reference, one can easily develop application specific drivers to configure microcontroller peripherals such
as PWMs, ADCs, QEP, CAP etc., as required.
Figure 6. Target Dependent Drive Module
10
TMS320C2000 Motor Control PrimerSPRUGI6–September 2010