TMS320C2000 Motor Control Primer

From Texas Instruments Embedded Processors Wiki

Jump to: navigation, search
Translate this page to   

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.

Contents

Introduction

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.

Software Tools

IQ Math Library

What 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.


Q 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.

Figure 1. Sign, Integer, Fractional Parts
32bit number prugi6.gif

where

S: Sign Bit (1 bit)

I: Integer Bits (7 bits)

F: Fraction Bits (24 bits)

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:

Fraction number prugi6.gif

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

GLOBAL_Q
Max Val
Min Val
Resolution
28
7.999 999 996
-8
0.000 000 004
24
127.999 999 940
-128
0.000 000 060
20
2047.999 999 046
-2048
0.000 000 954


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.

Summary of the IQ Math Functions

The routines included within the IQmath library can be classified as:

Some of the IQmath library functions used often in motor control are shown in Table 2.


Table 2. Some IQMath Functions Used Often in Motor Control Applications

C
C++
Operation
_IQ(float)
IQ(float)
Constant
+
+
Add
-
-
Subtract
_IQmpy
*
Multiply
_IQdiv
/
Divide
_IQsqrt
sqrt
Square root
_IQisqrt
isqrt
1/Square root
_IQsin
sin
Sine
_IQcos
cos
Cosine
_IQatan
atan
Arc tangent
_IQatan2
atan2
Arc tangent 2 opr.
_IQsinPU
sinPU
Sine per unit
_IQcosPU
cosPU
Cosine per unit
_IQatan2PU
atan2PU
Arc tangent 2 opr. per unit
_IQsat
sat
Saturation
_IQabs
abs
Absolute value

Calling 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:

#include "math.h"
#include "IQmathLib.h"
#define TWO_PI 6.28318530717959
void park_calc(PARK *v)
{
_iq cos_ang, sin_ang;
sin_ang = _IQsinPU (v->angle);
cos_ang = _IQcosPU (v->angle);
v->de = _IQmpy(v->ds ,cos_ang) + _IQmpy(v->qs ,sin_ang);
v->qe = _IQmpy(v->qs ,cos_ang) -_IQmpy(v->ds ,sin_ang);
}

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.

Advantages 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:

Digital Motor Control (DMC) Library

DMCLib 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 Modules Clarke, Park, Phase Voltage Calculation, Sliding Mode Observer, BEMF Commutation, Direct Flux Estimator, Speed Calculators and Estimators, Position Calculators and Estimators etc.
Signal Generators and Control Modules PID, Commutation Trigger Generator, V/f Controller, Impulse Generator, Mod 6 Counter, Slew Rate Controllers, Sawtooth & Ramp generators, Space Vector Generators etc.
Peripheral Drivers PWM abstraction for multiple topologies and techniques, ADC Drivers, Hall Sensor Driver, QEP Driver, CAP Driver etc.
Real-Time Debugging Modules DLOG module for CCS graph window utility, PWMDAC module for monitoring the control variables through socilloscope


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.

Incremental 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.


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.

Well 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.

Known 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.

2Code 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.

Software 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.

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.

Consistency 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
ACI Sensored FOC System BD.gif

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:

Figure 3. ACI Sensored FOC – System Block Diagram Showing Clear One-to-One Mapping to Software
ACI Sensored FOC System BD 1to1 Mapping.gif

Reusability, 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.

Target 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:


Table 3. Sample of DMC Module Descriptions and Type Category

Number
Module
Description
Type
1
bldcpwm_drv
BLDC PWM driver – uses high-side chopping and fixed on/off for low side
Drv
2
cap_event_drv
Capture input event driver
Drv
3
hall_gpio_drv
Hall effect interface driver for sensored 3-phase BLDC trapezoidal control
Drv
4
pwm_drv
PWM driver (configurable for active high/low, dead-band, or asm/sym)
Drv
5
bdc_pwm_drv
Brushed DC-Motor PWM driver
Drv
6
qep_theta_drv
Quadrature encoder pulse interface driver with position (theta) as output
Drv
7
qep_no_index_drv
Quadrature encoder pulse interface driver without index pulse
Drv
8
ileg_vdc
Analog to digital conversion drive
Drv
9
resolver_drv
Position and speed calculations for resolver sensor
Drv
10
data_log
Data logging utility – useful for variable graphing in code composer
Util
11
pwm_dac_drv
4-channel DAC driver useful for displaying real-time variables on scope
Util
12
aci_fe
Flux estimator for 3-phase induction motor vector control
TI/AC
13
aci_se
Speed estimator of the 3-ph induction motor
TI/AC
14
clarke
Clark transform – 3-phase to 2-phase (quadrature) conversion
TI/AI
15
comtn_trig
Commutation trigger for BLDC sensorless trapezoidal/BEMF/ZC tech.
TI/AC
16
cur_mod
Rotor flux position estimator for 3-phase induction motor vector control
TI/AC
17
i_park
Inverse park transform – Rotating to stationary reference frame conversion
TI/AI
18
impulse
Impulse generator module
TI/AI
19
mod6_cnt
Modulo 6 counter counts from state 0 through 5 and reset
TI/AI
20
park
Park transform – Stationary to rotating reference frame conversion
TI/AI
21
phase_volt_calc
3-phase voltage recontruction function based on PWM duty cycle inputs
TI/AI
22
pid_reg3
Proportional/integral/derivative controller with anti windup feature
TI/AC
23
ramp_gen
Sawtooth generator with adjustable gain, frequency and dc offset
TI/AI
24
rmp2cntl
Ramp up and ramp down module
TI/AI
25
rmp3cntl
Ramp down module
TI/AI
26
rmp_cntl
Ramp up and ramp down module used to control slew rate
TI/AI
27
smopos
sliding mode observer for position estimation in sensorless vector drives
TI/AC
28
speed_est
Motor speed estimator using the estimated rotor position
TI/AC
29
speed_frq
Speed calculator based on frequency measurement – tacho style method
TI/AI
30
speed_prd
Speed calculator based on period measurement between events
TI/AI
31
svgen_dq
Space vector generator function with quadrature control
TI/AI
32
svgen_mf
Space vector generator function with magnitude and frequency control
TI/AI
33
v_hz_profile
Volts/hertz profile for induction motor (voltage vs. frequency)
TI/AC

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:

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.

Figure 4. Target and Application Independent Modules -Examples </center <center>Target and Application Ind Modules.gif


Figure 5. Target Independent/Application Configurable Modules
Target Ind App Config Modules.gif

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
Target Dep Drive Modules.gif

Utility/Debug Modules

Utility and/or debug modules are mainly used during the software development and debug process. Typically they are removed at time of software completion; however they can also be left in the code for system diagnosis if required during field tests or evaluation. Two examples of these modules are shown in Figure 7. These modules allow the software designer to probe any of the system variables, and display them in real time via a scope or a graphical output within Texas Instruments' Code Composer Studio.

The PWMDAC module allows the user to monitor waveforms of software variables through a scope, while DLOG_VIEW provides a memory buffer with a trigger feature that allows Code Composer to display two graphical waveforms in real-time. Graphical waveforms are continuously updated via the JTAG debug link while the customer’s application software continues to run. Both JTAG and the real-time data flow are non-intrusive to application software running on any devices.

Figure 7. Utility/Debug Modules
Utility Debug Modules.gif

Quick Module Evaluation and Testing

Apart from the more obvious benefits of software modularity previously described, some of the same ideas can be used to facilitate quick module testing or evaluation, i.e., checking how applicable or how a module performs. Additionally, it becomes easy to test several “what if” scenarios by simply reconnecting modules and evaluating several alternatives. Figure 8 shows a “module under test” setup where a known input stimulus is applied. The input stimulus and output response of this module under test can be conveniently monitored in real time on a scope via the PWMDAC or DLOG utility modules.

Apart from evaluating or confirming operation of a known good software module, this technique is useful when developing new modules. During debug, input stimulus signals can be swept over the entire input range to look for boundary condition problems or discontinuities in output response. It should be noted that this process is valid, provided known good stimulus modules are used as input signals. This technique allows a software designer to check validity of variable ranges, and to ensure waveform integrity over a required frequency range and system sampling rates.


Figure 8. Testing and Evaluating Modules
Testing Evaluating Modules.gif

DMC Library Documentation Support

TI seeks to offer a rich selection of software examples and working systems which are clearly documented. One area which has received much attention and improvement is the description or documentation of application software. Through the use of software modularity, it is possible to delineate and give an unambiguous one-to-one mapping between a system block (signal flow) diagram and the actual software code in question. This, together with module documentation for each software block, shows the customer clearly where each piece of software is, what it is doing, and more importantly, the parameters or variables being passed and executed upon. All TI applications which are part of the software offering, now consist of module documents and system documents. System documents always include the system block or signal flow diagram, which among control engineers, remains one of the most useful communication tools.

Module Level DMC Library Documents

The pdf files included in the library folders provide necessary information regarding the modules. The outline of the module documents is standard and can be itemized as follows:

Figure 9 shows these library documents and their location in controlSUITE , both in the desktop and in the C: folders.


Figure 9. Library Documents and Their Location in controlSUITE
Library Docs Location controlSUITE.gif

As shown in Figure 10, a target independent transformation module is described and the module inputs/outputs are shown explicitly in the introduction part. In addition, module type, target devices, and related files are explained in this section.

Figure 10. Snapshot of Typical Target Independent Module
Snapshot Typ Target Ind Module.gif


Following the module description, all the necessary information is provided for C interface of the DMC module, the introduction of which is shown below in Figure 11. This section explains the structure of the module object; name, description, and format of the module input and outputs. It also explains special constants and data types, module initialization and usage, and pseudo code providing the information about the module usage.

Figure 11. Snapshot of First Part of C Interface Section
Snapshot 1st C Interface Sect.gif

In the last section, theoretical background and mathematical derivations of the equations (if applicable) are provided to the user as shown in Figure 12. This section helps the user to understand the philosophy behind the module and allow the user to customize it properly.


Figure 12. Snapshot From the Theoretical Background Section (need equation)
Snapshot theo backgr sec prugi6.gif

DMC Library Optimization

There are several ways to optimize motor control systems for performance in terms of memory consumption and CPU cycles required to achieve the given task. TI suggests the following options to optimize the overall system performance:

When a function is called separately, the function call must call the code at the appropriate address, followed by a return statement when the function execution is completed. In addition, there is some overhead associated with setting up a stack frame. In the case of a small function, this call and return overhead may be significant, compared to the size of the function itself. In addition, when a function is inlined, the compiler can optimize the function in context of the calling code.

Another optimization is sometimes possible: to turn the function into a macro expansion. This allows the compiler to optimize further under certain circumstances and produces less code, and consumes fewer cycles to execute. The disadvantage of this method is the code size increase if multiple expanded macros are implemented. However, for single motor control, both size and cycle wise macro modules have superiority to earlier versions where the code size becomes comparable for dual motor operation. One must note that the number of instruction cycles is much lower in any case.

Unlike the DMC Library version in Legacy, the modules in controlSUITE are written in the form of macros for optimization purposes (refer to Optimizing Digital Motor Control Libraries, SPRAAK2, for more details at TI website). It is reported that the macro versions of the DMC library let the system run 2-3 times more efficient than non-optimized version in Legacy. The macros are defined in the header files. The user can open the respective header file and change the macro definition, if needed. In the macro definitions, there should be a backslash ”\” at the end of each line as shown below which means that the code continues in the next line. Any character including invisible ones like “space” or “tab” after the backslash will cause compilation error. Therefore, make sure that the backslash is the last character in the line. In terms of code development, the macros are almost identical to C function, and the user can easily convert the macro definitions to inline C functions. As an example, the park transformation macro definition is shown below.

Figure 13. A Typical Module Declaration and Macro Definition
Typical Mod Declaration Macro Def.gif

Incremental Build Methodology

Irrespective of how much planning has gone into a system engineering project, the chances are that the final (or complete) system will not work the first time, usually some subtle (or not) target dependency or requirement has been overlooked. This is normal engineering, especially in the case of software development, and if not anticipated ahead of time, can become a frustrating and time consuming disaster.

To prevent this, TI’s DMC Library system software comes prepackaged 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 very quickly and without risk of losing configuration or run-time information related to previous build levels. This allows a customer 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 and the type of control strategy used. It is important to note that regardless of the number of build levels used in the reference system, this framework is provided by TI as guidance and becomes a common point of reference in cases where customer trouble shooting necessitates interaction with TI customer support engineers.

Incremental system build levels are supported by frameworks with various configurations of interconnected modules. Frameworks also provide invaluable skeletons for customers to modify or customize as required to suit their own target system requirements, forming an excellent starting point.

To better understand the philosophy and details of the incremental build approach, a typical motor control case, a permanent magnet synchronous motor, will be used to step through the various commissioning phases. The system shown in is the final build of a sensored PMSM project. The subsequent block diagrams (Figure 14 to Figure 17) show examples of typical steps used to get to a solidly working final system.

Check System Vital Signs—Build Level 1

Figure 14 shows the module configuration of build level 1. Although the first is the simplest build, it is perhaps the most important one since many system fundamentals can be validated here. Build 1 removes main external connections (power hardware, motor, feedback circuitry, etc.) and allows a customer to focus on:

Assuming the above check list is correct, some key system vital signs can now be validated:

Figure 14. Build Level I - Checking Vital Signs
Build 1 Check Vital Signs.gif

Open Loop Motor Operation—Build Level 2

In this level, the motor is connected to the inverter and the motor is run open loop. In this level, the items below will be verified:

Figure 15. Build Level II - Inverter Test and ADC Calibration
Build 2 Invrtr Test ADC Calibrate.gif

Closed Current Loop Operation—Build Level 3

Assuming the previous section is completed successfully, this section verifies the dq-axis current regulation performed by PID_REG3 modules, QEP drv and speed measurement modules.

Figure 16. Build Level III - Closed Current Loop Test
Build 3 Closed Current Loop Test.gif

Closed Speed Loop Operation—Build Level 4

In this level, the speed loop will be closed in addition to the current loops regulating stator current d-q components and use the actual rotor position. This section verifies the speed PID and FOC based on actual rotor position. The basic sensored, field-oriented control of PMSM motor implementation will be done once this step is completed successfully.

Figure 17. Build Level IV - Closed Speed Loop Test / FOC
Build 4 Closed Speed Loop Test FOC.gif

PI Tuning

PI tuning is often considered an art form, or perhaps magic.  Many customers use simulation tools to tune their compensation systems. These have varying levels of success and are highly dependent on the accuracy of the plant model.  But we find the implementations from VisSim and Mathworks to be a good start.  For manual tuning, a common procedure is offered in the documentation for the pid_grando module in controlSUITE's motor_lib


Tuning the controller

Default values for the controller coefficients are defined in the macro header file which apply unity gain through the
proportional path, and disable both integral and derivative paths. A suggested general technique for tuning the
controller is now described.

Steps 1-4 are based on tuning a transient produced either by a step load change or a set-point step change.


Step 1.

Ensure integral and derivative gains are set to zero. Ensure also the reference weighting coefficients (Kr &
Km) are set to one.

Step 2.

Gradually adjust proportional gain variable (Kp) while observing the step response to achieve optimum rise
time and overshoot compromise.

Step 3.

If necessary, gradually increase integral gain (Ki) to optimize the return of the steady state output to nominal.
This will probably be accompanied by an increase in overshoot and oscillation, so it may be necessary to slightly
decrease the Kp term again to find the best balance.

Step 4.

If the transient response exhibits excessive oscillation, this can sometimes be reduced by applying a small
amount of derivative gain. To do this, first ensure the coefficients c1 & c2 are set to one and zero respectively. Next,
slowly add a small amount of derivative gain (Kd). The controller will be very sensitive to this term and may become
unstable so be sure to start with a very small number.


Steps 5 & 6 only apply in the case of tuning a transient set-point. In the regulator case, or where the set-point is fixed
and tuning is conducted against changing load conditions, they are not useful.

Step 5.

Overshoot and oscillation following a set-point transient can sometimes be improved by lowering the
reference weighting in the proportional path. To do this, gradually reduce the Kr term from its nominal unity value to
optimize the transient. Note that this will change the loop sensitivity to the input reference, so the steady state
condition will change unless integral gain is used.

Step 6.

If derivative gain has been applied, transient response can often be improved by changing the reference
weighting, in the same way as step 6 except that in the derivative case steady state should not be affected. Slowly
reduce the Km variable from it’s nominal unity value to optimize overshoot and oscillation. Note that in many cases
optimal performance is achieved with a reference weight of zero in the derivative path, meaning that the differential
term acts on purely the output, with no contribution from the input reference.
The derivative path introduces a term which has a frequency dependent gain. At higher frequencies, this can cause
noise amplification in the loop which may degrade servo performance. If this is the case, it is possible to filter the
derivative term using a first order digital filter in the derivative path. Steps 7 & 8 describe the derivative filter.

Step 7.

Select a filter roll-off frequency in radians/second. Use this in conjunction with the system sample period (T)
to calculate the filter coefficients c1 & c2 (see equations 5 & 6).

Step 8.

Note that the c1 coefficient will change the derivative path gain, so adjust the value of Kd to compensate for
the filter gain. Repeat steps 5 & 6 to optimize derivative path gain.

PU System Model and Base Values

In electrical engineering, a per-unit system is the expression of system quantities as fractions of a defined base unit quantity. Calculations are simplified because quantities expressed as per-unit (between -1 and +1) are the same regardless of the voltage, current etc level. Advantages of using the pu system for motor control applications include:

Conversion of per-unit quantities to volts, ohms, or amperes requires knowledge of the base that the per-unit quantities were referenced to. In the TI DMC systems, the base values are selected as the maximum measurable quantity of the peak of phase voltage, current etc. by the ADC. This is directly related to the current and voltage sensing circuits and the voltage dividers used to down-scale the actual voltage or current quantities to ADC input voltage range, which is typically 3 to 3.3V. Later, the measured voltage by ADCs will be converted to put quantity in the code. The calculation of the pu values can be formulated as:

Equation.gif

The selection of the base quantities is relative and can be any appropriate value as long as it is consistent within the whole system. For instance, assuming that the peak of the maximum measurable phase current is 20A on a DMC kit, the base current value can be selected as 20 where ±1pu represents ±20A in the code.

Example code prugi6.gif

Similarly, the base voltage can be selected as the peak of maximum measurable phase voltage in the system. Assuming that the dc bus voltage is 400V, base voltage is selected as 400V/√3.

DMC Systems: Legacy VS controlSUITE

There are basically two separate TI DMC systems offering similar solutions for motor control with minor differences. These differences can be summarized as:

The DMC projects in the Legacy and ControlSUITE are given in the table below:

http://www.ti.com/c2000dmc#dmc


Table 4. Projects in controlSUITE and Legacy

Motor Type Description Legacy
controlSUITE
3-ph ACI Sensored – Tacho i/p Scalar Control / SVPWM 281x 280x
2803x
3-ph ACI Sensored – Tacho or Encoder Field Oriented Control / SVPWM 281x 280x
2803x
3-ph ACI Sensorless – Direct Flux Estimator Field Oriented Control / SVPWM 281x 280x
2803x 2833x
3-ph PMSM Sensored – Incremental Encoder Field Oriented Control / SVPWM 281x 280x
2803x
3-ph PMSM Sensorless – Sliding Mode Observer Field Oriented Control / SVPWM 281x 280x
2803x 2833x
3-ph PMSM Sensored – Incremental Encoder Position Control / SVPWM 281x 280x
2803x
3-ph PMSM Sensored – Resolver Field Oriented Control / SVPWM 281x 280x
TBD
3-ph BLDC Sensored – Hall Effect Sensors Trapezoidal Control 281x 280x
2803x
3-ph BLDC Sensorless – BEMF Sensing Trapezoidal Control 281x 280x
2803x
3-ph BLDC Sensorless – Sinusoidal Control Field Oriented Control / SVPWM
-
2803x
Brushed DC Sensored – QEP Position and speed control
281x 280x
Q410
Stepper Motor Sensorless – Discrete Angle Est. Position and Speed Control
280x
Q410


More About controlSUITE

controlSUITE™ is the content and content management tool for C2000™ development. It includes a comprehensive suite of software that significantly decreases development time and accommodates different experience levels and programming preferences. It is also a one-stop shop for everything needed for C2000 system development.

controlSUITE’s main features include:

Figure 18. controlSUITE Desktop Graphical Navigation Tools
ControlSUITE Navigation Tools.gif

System Level DMC Documentation Support

In addition to the DMC Library documents detailed in the previous sections, all C2000 motor control projects are supported by a rich set of collateral to shorten the development time. These documents basically provide information about the motor type used in the project, control theory (e.g. FOC, trapezoidal control) system overview, hardware configuration, incremental build levels, hardware components, GUI related documents etc.

Quickstart Guide and Graphical User Interface (GUI)

In controlSUITE™, an open source graphical user interface is designed for sensorless HVDMC projects so that the users can visually and quickly evaluate the DMC kit and software without having to learn and configure the underlying project software or install CCS. Note that the GUI is not a development environment but intended for demonstration purposes only. The GUI supports all three kinds of motors (ACI, PMSM, and BLDC). The HVDMC kit ships with both a Piccolo™ F28035 and a Delfino™ F28335 controlCARD. Only the F28035 card is pre-flashed with the code that enables interface to this GUI. The flashed code is optimized for running sensorless FOC on ACI and PMSM motor and sensorless trapezoidal control on a BLDC motor that are available from the TI website. Note that the performance of the motor with the flashed image is not a metric of quality of control and performance levels achievable using the TI DMC library. The GUI allows the user to select the motor type, visually inspect some waveforms (e.g., current, voltage, back-emf , etc.), numerically watch bus voltage, estimated speed, set the reference speed, and change the graph update rate and graph scale. A snapshot of GUI is shown in Figure 19.

Figure 19. Graphical User Interface for Motor Control
GUI Motor Control.gif

The GUI exe file, flash image, and related files can be found in Desktop -Kits -Folders -Example GUI, or at the direct path of:

C:\ti\controlSUITE\development_kits\HVMotorCtrl+PfcKit_v1.3\~GUI

DMC System User Guides

The system user guide is the most critical document explaining the system overview, applied theory, hardware configuration, and incremental build levels. All motor control projects have a user's guide which includes:

These can be found in controlSUITE Desktop -Kits -Documentation or directly:

C:\ti\controlSUITE\development_kits\HVMotorCtrl+PfcKit_v1.3\HVPM_Sensored\~Docs

Or for Legacy at:

C:\tidcs\DMC\c28\v32x\sys\pmsm3_1_280x\doc

Hardware Guide and How to Run Guides

The hardware guide describes the target kit contents and hardware details, and explains the functions and locations of jumpers and connectors present on the board. This document supersedes all the documents available for the kit. The items discussed in this document include:

The “How to Run” guide explains the steps needed to run the target kit with the software supplied through controlSUITE. The list of document content is given below:

Both of the documents can be found in controlSUITE or directly:

C:\ti\controlSUITE\development_kits\HVMotorCtrl+PfcKit_v1.3\~Docs

Hardware Development Package

In controlSUITE, a hardware development package is prepared for each hardware platform including:

This package helps the users to build their own boards using TI design and layout. Found in controlSUITE Desktop -Kits -Folders or directly:

C:\ti\controlSUITE\development_kits\HVMotorCtrl+PfcKit_v1.3\~HVMotorCtrl+PFC-HWdevPkg

Key CCS Features for DMC Developers

Code Composer Studio (CCSudio) is the integrated development environment for TI’s micro-controllers and application processors. CCS includes a suite of tools used to develop and debug embedded applications. It includes compilers for each of TI's device families, source code editor, project build environment, real-time debugger, profiler, simulators and many other features. A link for a free download of CCSv4 is included in controlSUITE Desktop.

Figure 20. Code Composer Studio Interface
Code Composer Studio Interface-1.gif

Software Flow

As mentioned, the DMC Systems are highly modular, allowing for re-use and re-targeting. The trade off is that the modularity can initially be confusing as instead of a single C file, there are many separate files and functions being called. Let’s look at this by continuing to examine the High Voltage Kit Sensorless PMSM project. Explore the folder through controlSUITE Desktop-Kits-Kit Folder or directly:

C:\ti\controlSUITE\development_kits\HVMotorCtrl+PfcKit_v1.3\HVPM_Sensorless

[PROJECT_NAME]-SETTINGS.H

This header file defines global settings for the project, including Incremental build level, system clock frequency, ISR frequency, and motor parameter settings.

[PROJECT_NAME]-DEVINIT_[F28XXX].C

Initializes the device and the GPIO mux options (fixed function pins like ADC are already initialized by default). The DevInit file disables the watchdog timer, sets the clock/PLL, initializes the PIE, and then configures each GPIO to its own pin function. The DevInit file is target specific and is different based on the pin-out of the specific device.

[PROJECT_NAME].H

This is the header file which lists all of the DMCLibrary components that will be used in the project. There is a section for the device independent MATH blocks as well as the device dependent DRIVERS. When creating your own project you can directly use the MATH blocks as they exist in the DMCLib controlSUITE path C:\ti\controlSUITE\libs\app_libs\motor_control\math_blocks but it is recommended that you place the DRIVERS inside your specific project as they will need to be customized to your specific implementation. For controlSUITE the first DRIVER implementations were done for the High Voltage Kit, so those projects also point to the controlSUITE path, but you will notice for subsequent kits -like the Low Voltage versions -the drivers were brought into the specific project and modified as needed.

These DRIVER blocks additionally use files located in the controlSUITE\device_support orcontrolSUITE\development_kits\~SupportFiles for setting peripheral configuration.

[PROJECT_NAME].C

Let’s examine the main source file for this project: HVPM_Sensorless.c

The first statements include five header files.

  1. PeripheralHeaderIncludes.h: LOCATION: C:\ti\controlSUITE\development_kits\~SupportFiles\F2803x_headers PeripheralHeaderIncludes.h is a device specific header file that is chosen based on the include paths chosen in CCS. This header file is responsible for adding the correct set of F28xxx header files needed by the target and defining several target specific constants.
  2. IQmathLib.h: LOCATION: C:\ti\controlSUITE\libs\math\IQmathIQmathLib.h is the math library discussed in Section 2.1 of this document
  3. HVPM_Sensorless.h:Discussed in Section 3.3
  4. HVPM_Sensorless-Settings.h:Discussed in Section 3.3
  5. math.h: LOCATION: C:\Program Files\Texas Instruments\ccsv4\tools\compiler\C2000 Code Generation Tools 5.2.7\include Math.h header file is the standard math and trigonometric functions supported by the Code Generation tools.

Lines 26 through 108:

Includes function definitions for system initialization, state machine initialization, and variable definitions.


Lines 109 through 157:

Instance and define the project variable names for any of the DMCLib blocks that will be used in the project.

We now enter into the main program execution which can be summarized as follows:

Main

  1. Set-up three CPU timers for A, B, C state machine tasking
    • Tasking could consist of
      • Communications – A program may need to transmit data externally via a peripheral such as the CAN, SPI, or SCI
      • Variable Conversion/Scaling – Many variables used in a system are not completely obvious in what they translate to in real world units. This may happen for many reasons including the 0-3V range of the ADC as well as the way data is stored in various peripheral registers. The user may instead want to view these variables in real world units so that they can be sent externally to a data logger or so the program is easier to use.
      • Project specific events such as updating coefficients or enabling/disabling an output
  2. Initialize DMCLib modules that require initialization
  3. ISR/PIE servicing
  4. Enter idle / background loop
    • A Tasks (@1ms)
      • A1—Not used in this project
      • A2—Not used in this project
      • A3—Not used in this project
    • B Tasks (@5ms)
      • B1—Toggle GPIO-00
      • B2—Not used in this project
      • B3—Not used in this project
    • C Tasks (@50ms)
      • C1—Toggle GPIO-34
      • C2—Not used in this project
      • C3—Not used in this project

ISR (@ ISR frequency rate)

  1. Verify ISR Ticker
  2. If “BUILDLEVEL= X“ [setting in HVPWM_Sensorless-Settings.h] </nowiki>
    • CONNECT together inputs/outputs of software blocks
    • CALL each macro function
  3. Refresh Interrupt

Hardware Tools

TI currently offers two different hardware platforms for developing digital motor control applications, with several more planned. These tools provide a great way to learn and experiment with digital control of high and low voltage motors and to use PFC to increase efficiency of operation.

High Voltage Motor Control and PFC Developer's Kit

The High Voltage Motor Control and PFC Developer's Kit provides an easy, open-source way to evaluate the C28x microcontrollers and TI analog in a high voltage environment. A single 28x MCU controls the power factor correction (PFC) stage and the motor control stage. The PFC takes a line level AC input (~110 to ~240VAC) and outputs up to 750 watts of power, regulated by closed loop control. The motor driver stage can be driven from either the PFC or from a separate power stage and accepts up to 350V and outputs up to 1.5 kilowatts of power. The motor driver stage can drive the three most common types of brushless motors, AC induction, brushless DC, and permanent magnet synchronous motors. The kit has all the features to implement sensored and sensorless control of each motor type. The software and hardware for the kit is completely open source.

The kit has the following key features:

The Hardware Developer’s Package is available and includes schematics, bill of materials, Gerber files, etc.

Figure 21. High Voltage DMC Board
High Voltage DMC Board.gif


Figure 22. High Voltage DMC Board Block Diagram
High voltage dmc bbc prugi6.gif

Low Voltage Motor Control and PFC Developer's Kit

The Low Voltage Motor Control and PFC Developer's Kit provides a safe way to learn and experiment with digital control of low voltage motors and the use of PFC to increase efficiency of operation. The kit provides direct access to all of the enhancements and features of the 28x architecture, and also enables developers to determine quickly 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, higher power efficiency, control of multiple motors, and a various other options. In this way, developers can architect systems specifically optimized for their application constraints and requirements.

The low voltage kit has the following key features:


Figure 23. Low Voltage DMC Board
Low voltage dmc board prugi6.gif
Figure 24. Low Voltage DMC Board Block Diagram
Low voltage dmc bbd prugi6.gif



Low Voltage Three Phase BLDC/PMSM Kits (DRV83x + MCU controlCARD)

DRV8312-C2-KIT & Upcoming DRV8332-C2-KIT

Ships with controlCARD (C2 = C2000 Piccolo F28035), demonstrates BLDC Trapezoidal (Sensored and Sensorless) and Sensorless FOC.

Kits include Isolated USB-JTAG, Isolated UART, Isolated SPI, and Isolated CAN.

All documenation, source, GUIs, BOM, Gerbers, etc. available through www.ti.com/controlsuite


Upcoming DRV8301HC-C2-KIT (60A FETs)

Ships with controlCARD (C2 = C2000 Piccolo F28035), demonstrates new Sensorless Trapezoidal Control and Sensorless FOC.

E2e.jpg For technical support on the C2000 please post your questions on The C2000 Forum. Please post only comments about the article TMS320C2000 Motor Control Primer here.
Hyperlink blue.png Links
ARM Microcontroller MCU ARM Processor Digital Media Processor Digital Signal Processing Microcontroller MCU Multi Core Processor
Ultra Low Power DSP 8 bit Microcontroller MCU 16 bit Microcontroller MCU 32 bit Microcontroller MCU

Leave a Comment

Comments

Comments on TMS320C2000 Motor Control Primer


A0207979 said ...

The TMS320F2833x 176-pin LPFP Reference Design - DSP incorrectly shows the TPS767D301 pin 19 as 2SENSE. The LDO datasheet shows this as a no connect. Can you correct to reduce customer confusion http://e2e.ti.com/support/power_management/linear_regulators/f/321/t/149148.aspx

--A0207979 13:25, 27 November 2011 (CST)

Personal tools
Namespaces
Variants
Actions
Navigation
Print/export
Toolbox