HOME :: JOB LISTINGS :: ARCHIVES :: MEDIA KIT :: SUBSCRIBE


Model-Based Design Shortens Development Time of Motor Control Applications

by Arun Mulpur, Ph.D. and Zijad Galijasevic, Ph.D., The MathWorks, Inc.

Introduction

Sophisticated motor controllers are being used in an increasingly wide range of applications to provide more complex and accurate motion control, reduce energy consumption, and deliver many other benefits. These controllers are often based on 16- and 32-bit digital signal controllers (DSCs) that provide some application libraries but still require tools and methods for developing and implementing advanced motor and motion control algorithms and integrating various control functions and peripherals. Development time and expense is increased by the fact that errors in design and integration are usually not detected until code is run on actual hardware.

Model-Based Design can address these challenges by enabling a hierarchical design process in which the entire design is initially defined at a conceptual level and detail is added as necessary to deliver the needed functionality. The model is used to define specifications, evaluate design and system performance, automatically generate code, perform hardware-in-the-loop testing, and create a software-based test harness for testing production hardware. This approach can substantially reduce development time by rapidly leading to complete and functional proof-of-concept designs and enabling rapid design iterations and parameter optimization through a unified design, simulation, and test environment.

Model-Based Design of Embedded Control Systems

The use of Model-Based Design for motor control applications has been aided by the introduction of blocksets that include pre-configured blocks to handle all elements of vector control systems, such as Park and Clarke transforms, PWMs, PI loops, speed estimators, flux estimators, and others 1. These new tools enable designers to quickly build a graphical model using pre-built blocks representing primitives and advanced algorithms, incorporating their own C-code only when required. All of the integration between the various blocks and peripherals is carried out automatically. These new tools have received customer acceptance for critical engineering projects, as well as industry recognition 2. Figure 1 illustrates the Model-Based Design flow for implementing an embedded motor controller. The representative software tools are indicated for each phase.

Figure 1. Model-Based Design: Flow and representative tools.

Model-Based Design enables engineers to build scripts to depict typical operating scenarios that simulate the operation of the controller in software. Engineers can quickly modify the model and observe the performance change, enabling improved design performance through rapid iterations. The key element of this approach is flexibility in evaluating a new design without having to make a major investment in hardware prototyping. For example, engineers can run the controller model on a simulated real-time platform, controlling a model that simulates the performance of the motor. Or, they can generate the code and run it on the actual hardware and use it to control a real motor or a real-time simulation of the motor.

Model-Based Design – Sample Example

The rest of the article will explain detail how a simple DC motor control system design was developed using Simulink®, a leading platform from The MathWorks for multi-domain simulation and Model-Based Design. Figure 2 shows the model with expanded views of subsystems for speed correction and speed measurement.

Figure 2. Simulink model of a DC motor controller.

A PID block controls the duty cycle of a PWM block, which in turn controls the voltage delivered to the motor. The quadrature-encoder-pulse (QEP) block accepts quadrature pulse output of an optical encoder connected to the motor armature. The QEP block then calculates the position of the armature and the speed of rotation. The output from the QEP is a digital velocity signal that is utilized by the PID controller block to control the duty cycle of the PWM. It is important to note that the speed measurement, PID and several other blocks generate hand-written assembly code that is optimized for the TI DSP used in this example.

Reliable Control Design through Simulation

Model-Based Design makes it possible to run simulations and evaluate results at any time in the development process without the need for hardware. This makes it possible to evaluate the performance of a wide range of designs in a very short period of time and at a very low cost in the early phases of the development. In the sample application discussed in this paper, for example, the engineer might develop a simple software model of an electric motor and control it with the early iteration of the control systems. The engineer could easily quantify control system performance, for example, the amount of time required to respond to a speed change command. The design could be quickly changed, by adjusting PID parameters, and the effect on performance observed immediately. Figure 3 shows a model used for determining parameters and evaluating performance of PID block.

Figure 3. Simulink model for evaluating the PID controller

The initial PID parameters generated the results shown in Figure 4 (left). The plots represent the desired speed, PWM duty cycle and actual speed, respectively. The plots show that the controller response is not optimized due to a large overshoot and prolonged oscillations. Through iterative modifications, the parameters of the PID block are adjusted to produce better response. These results are shown in Figure 4 (right).

Figure 4. Initial response of the PID controller (left) and improved performance through iterative parameter modifications (right).

As mentioned earlier, switching from floating-point to fixed-point implementation in traditional design approach is difficult, time-consuming, and prone to errors. To simplify and streamline this process, DSP vendors may provide processor-specific fixed-point libraries. For example, the C28x IQmath library from Texas Instruments is shown in Figure 5.

Figure 5. Texas Instruments C28x
IQmath Library

These processor-specific libraries provide optimized execution speed and efficient utilization of memory especially for computationally intensive real-time applications. These specialized libraries achieve execution speeds considerably faster than equivalent code written in standard C language, making it possible to significantly shorten application development time related to code optimization. Model-Based Design facilitates the use of such libraries further by offering them in a block form. Perhaps even more importantly, Model-Based Design can simulate such libraries bit-true on the host PC by matching the on-DSP implementation up to the least significant bit (LSB).

Once the control system design behaves properly in simulation, the engineer can automatically generate C-code and run the design on an embedded hardware system. This means that designers can evaluate their hardware prototype in real-time. In this example, the design was targeted to the Texas Instruments TMS320F2812 DSP and the Code Composer Studio IDE.

Direct Path to Implementation through Automatic Code Generation

Real-Time Workshop® and Embedded Target for TI C2000 DSP from The MathWorks provide fixed- and floating-point code generation from Simulink for TI C2000 DSPs. The generated source code is then automatically placed into a Code Composer Studio project. In addition to device drivers and control algorithm, generated code contains a real-time scheduler, linker-command file and project-settings.

In this example, the target was connected to a real motor, using an evaluation board. Link for Code Composer Studio was also used to transfer data between Simulink and Code Composer Studio. Link for Code Computer Studio extends MATLAB®, The MathWorks core platform for technical computing to provide project load, run, and stop management; debug points; data manipulation; the hardware-in-the-loop simulation system; co-simulation support; and support for RTDX. This application takes control of Code Composer Studio during the testing and debugging process and allows for real-time exchange while the target application is running.

One of the steps in targeting the TI DSP is to change drivers to optimize the model for Texas Instruments Real Time Data Exchange (RTDX), which provides bi-directional communications between the host-side client and target application. Link for Code Composer Studio is used to facilitate RTDX communication between MATLAB and applications running on the target. In addition, the same product creates the Code Composer Studio project, sets compiler and linker options, builds, loads and runs the application.

On-Target Code Verification

Performing the optimization tasks described earlier using a traditional design process would require significant number of iterations, with each involving changing the control system algorithms and parameters, recompiling, and re-running the application. Model-Based Design makes it possible to perform design iterations in a matter of seconds on parameters that can be adjusted in real-time, and in minutes on other parameters.

For example, engineers can view the measurements of current and voltage on the real motor stator windings on the screen while at the same time looking at variables in the control systems, such as measurements of the same parameters. The ability to view and compare physical measurements with control system variables in real-time provides insight into the design that can dramatically reduce development time. Figure 6 illustrates real-time monitoring capability of a tool chain for Model-Based Design based on Simulink. Plots show data representing measured motor speed and duty-cycle of the generated PWM waveform. The data is brought back from the application running on the real hardware to MATLAB using RTDX. In this example, RTDX is also used for varying the desired speed of the motor in real-time.

Figure 6. Motor speed and PWM duty cycle for target speed of 2007 rpm

Adding Advanced Design Features

Additional control systems capabilities that might otherwise require weeks of coding can be added to the system design simply by dragging and dropping blocks from other block libraries. For example, designers of distributed control systems can add a block to provide CAN networking capabilities to the controller architecture, as shown in Figure 7.

Figure 7. Incorporating CAN messaging support into a motor controller design.

The logic operations needed for processing the received CAN messages and generating the resulting control decisions can be prototyped, simulated, and implemented through automatic code generation just like the rest of the controller design as shown in Figure 8.

Figure 8. CAN message processing logic

The networking capabilities of the controller can easily be simulated by using an add-on card that provides CAN support to the PC as shown in Figure 9.

Figure 9. Simulating CAN based controller network capabilities on desktop.

The same capability can be used for tuning model parameters and obtaining model data while the application representing the model is running on the actual DSP hardware.

Conclusion

Model-Based Design can assist in the development of increasingly sophisticated embedded motor controllers by providing an environment where simulations can be used to quickly evaluate the performance of alternate design concepts. Models can be automatically converted into efficient C-code for hardware-in-the-loop simulation. This approach makes it possible to deliver higher performance by evaluating a larger number of design alternatives while reducing engineering costs.

References

  • Wong, William. March 2004. Tool Speeds TI DSC Application Development. Electronic Design Online – Article ID#7663
  • EE Times ACE Ultimate Products of the Year. San Francisco, CA. March 10, 2005.
Click here for printable PDF
(By clicking on this link you agree to Embedded Technology Journal's Terms of Use for PDF files. PDF files are supplied for the private use of our readers. Republication, linking, and any other distribution of this PDF file without written permission from Techfocus Media, Inc. is strictly prohibited.)

by Arun Mulpur, Ph.D. and Zijad Galijasevic, Ph.D., The MathWorks, Inc.

August 8, 2006

 

About the authors:

Arun Mulpur has been with The MathWorks, Inc. (Natick, MA) since 2002, where he is currently Signal Processing Product Marketing Manager. From 1994 to 2002, he was with Visual Solutions, Inc. (Westford, MA), most recently as Director of Product Engineering.

He received the MS and PhD degrees from University of Massachusetts (Lowell, MA) in 1989 and 1994, and a BE degree from Osmania University, India in 1986, all in Electrical Engineering.

Dr. Mulpur has written many technical papers and articles, and presented at conferences on nonlinear control systems, nonlinear dynamics, signal processing, embedded systems, and hardware implementation and verification.

Zijad Galijasevic has been with The MathWorks, Inc. (Natick, MA) since 2001, where he is currently Principal Embedded DSP Engineer. He is currently involved in the development of tools for model-based design and deployment on Texas Instruments DSPs. Prior to joining The MathWorks, he worked for Texas A&M University as a research associate.

He received his PhD degree from Texas A&M University (College Station, TX) as well as MS and BS from the University of Sarajevo (Bosnia-Herzegovina), all in Electrical Engineering.

Dr. Galijasevic has published technical papers and presented at conferences on different topics ranging from the model-based design and embedded system deployment to intelligent computing in power system applications.

[back to top]

Comments on this article? Send them to comments@embeddedtechjournal.com

All material on this site copyright © 2006 techfocus media, inc. All rights reserved.
Embedded Technology Journal
Privacy Statement