Board 55 Work in Progress Design and Implementation of An Advanced Electric Drive Laboratory Using A Commercial Microcontroller and A Matlab Embedded Coder
Board 55 Work in Progress Design and Implementation of An Advanced Electric Drive Laboratory Using A Commercial Microcontroller and A Matlab Embedded Coder
Jae-Do Park received his Ph.D. degree from the Pennsylvania State University, University Park, in 2007.
Park is currently an Assistant Professor of electrical engineering at the University of Colorado, Denver.
He is interested in various energy and power system research and education areas, including electric ma-
chines and drives, energy storage and harvesting systems, renewable energy sources, and grid-interactive
distributed generation systems. Prior to his arrival at the University of Colorado, Denver, Park worked for
Pentadyne Power Corporation in California as Manager of Software and Controls, where he took charge
of control algorithm design and software development for the high-speed flywheel energy storage sys-
tem. He also worked at the R&D Center of LG Industrial Systems, Korea, where he developed induction
machine drive systems as a Research Engineer.
American
c Society for Engineering Education, 2019
Work in Progress: Design and Implementation of an Advanced Electric
Drive Laboratory using a Commercial Microcontroller and a
MATLAB Embedded Coder
Abstract
This paper presents a design for an advanced instructional electric drives laboratory using
commercial Texas Instruments (TI) C2000 microcontroller and MATLAB-based Embedded
Coder toolbox. The main objective of this project is to familiarize students with real-time
implementation of advanced electric machine drive concepts such as field-oriented vector control
by programming high-performance industrial microcontrollers. Hands-on experience with
electric drives is also provided through the operation and control of machines. This laboratory
course, designed to follow the advanced lecture course on electric drives, aims to improve
students’ understanding of theory. Experiments, hardware and instruments for the proposed
laboratory course are discussed.
Introduction
In the past, due to the convenience of their torque and speed control, DC machines were used
most widely for adjustable speed applications. However, with the development of vector control,
also known as field-oriented control (FOC), AC machines driven by variable-voltage
variable-frequency (VVVF) inverters have become the norm 1,2,3 . AC machines, especially
induction machines, are inexpensive and more rugged than their DC counterparts. This shift from
DC to AC machines has continued due to the advancement of power electronics devices as well.
With FOC techniques, an induction machine can be modeled like a separately excited DC
machine through a series of transformations, so that DC machine-like control techniques can be
applied to obtain good transient performance. Recently, efforts have been made to implement
DSP-based electric machine and drive laboratories 4,5 , but the required software and equipment
have been unaffordable.
While TI provides software solutions to drive various machines via hardware, it is still
challenging for students to understand the complicated interlinking of modules with many
features and functions, typically in C language. However, today’s students are familiar with
writing MATLAB code and developing Simulink models for their courses. Graphical
representation of Simulink programming is easier to learn and more intuitive. Furthermore,
MATLAB has developed Embedded Coder, a toolbox that can translate MATLAB code and
Boost +48 VDC
Inverter
Transformers Power Supply
Fault,
ePWM sense
Simulink models into C and C++ for embedded microcontrollers. In this context, Simulink is
used to design and model complex machine control algorithms and translate them into C code
using the Embedded Coder toolbox.
This paper presents the design and implementation of an advanced electric drive laboratory using
a commercial microcontroller development kit and MATLAB Embedded Coder, including
hardware components, laboratory equipment setup, experiment sessions, and prototype test
results. The laboratory is designed for graduate and advanced undergraduate students with
moderate programming skills. Although it has not yet been offered, we expect 10-15 students in
this course.
Hardware Design
The hardware design for the proposed laboratory focused on cost-effectiveness and reliability, as
well as establishing a setup that is both realistic and safe. The design aims to place all equipment
(i.e., power supplies, inverter, microcontroller, transformers and machine) on the same platform,
so students can perform experimental tasks without the need for any modifications. The complete
system and a functional diagram of the setup appear in Figures 1 and 2, respectively.
TI provides real-time control microcontroller units (MCUs) that use a 32-bit 28x-core to provide
advanced digital signal processing in industrial system applications. In this work, an eZdsp
120 VAC
input
Analog
Inputs
Induction +24 VDC TMS320F28335 Digital
Machine outputs
JTAG
Encoder
RS 232 and CAN connectors
TMS320F28335 microcontroller DSP starter kit (DSK) was selected to perform the experiment
sessions. It features 150 MHz operating speed, on-chip 32-bit floating-point unit, 68 kbytes
on-chip RAM, 512 kbytes on-chip flash memory, 12-bit analog-to-digital converter (ADC) with
16 input channels, enhanced pulse-width modulation (ePWM) channels, RS-232 connector with
line driver, multiple expansion connectors for analog input/output (I/0) pins, and an on-board
JTAG emulation connector. Furthermore, the DSK has an enhanced quadrature encoder (eQEP)
module, intended to acquire position, direction, and speed information from rotating machines for
high-performance motion control applications.
The hardware setup also includes a custom voltage source inverter (VSI) that uses a 48 VDC
supply and 3.3V ePWM digital signals from the microcontroller to generate up to 24 VAC peak
output. The ePWM digital signals drive the six MOSFET devices using an IRS2336 integrated
gate driver. Three high-voltage discharge capacitors are placed before the AC output stage of the
VSI, which maintains solid DC input voltage. Furthermore, the VSI has one voltage sensor for
DC voltage and three current sensors that feed the microcontroller’s ADC channels.
To accommodate the microcontroller and its associated modules (ADC, ePWM, and eQEP), a
custom motherboard powered by a 24 VDC supply was developed. To implement user control
interfaces for speed, run/stop, and rotational direction, it has additional control inputs –
potentiometer, toggle and pushbutton switches, respectively. The bill of materials is listed in
Table 1.
Description Part number Manufacturer Quantity Price($)
Table 1: Bill of materials for one experimental setup. It should be noted that the price could vary
according to the purchasing quantity and time.
3. Step-Up Transformers
The maximum peak output voltage generated using VSI is half of the DC input voltage, which is
24 VAC. Since the machine requires 230 VAC, three single-phase 1:10 transformers are used to
step up the voltage level for each phase. Additionally, the transformers provide galvanic isolation
to the machine.
4. DC Power Supplies
In this laboratory, two AC-DC switching power supplies (48 and 24 VDC) are used to power the
VSI and motherboard. Both power supplies use 1, 60Hz, 100-240VAC input and connect to a
120VAC power socket through a switch, so that power can be cut when needed.
TI has a software program called Code Composer Studio (CCS) [6], an integrated development
environment (IDE) tool for their processors and controllers. The software includes a suite of
tools, such as optimizing C/C++ compiler, source code editor, project build environment,
debugger, and many other features that are used to develop and debug embedded applications;
however, users are required to develop complex C/C++ code. Alternatively, MATLAB Embedded
Coder – along with support packages for TI microcontrollers – generates C and C++ code from
Simulink models and MATLAB functions and sends it to CCS, where a real-time executable is
generated and downloaded to the target hardware. Figure 3 illustrates the MATLAB TI embedded
software design flow. Furthermore, a Simulink model is shown in Figure 4, and the C code
generated by the Embedded Coder appears in the Appendix.
A computer with pre-installed firmware development packages is provided to each student, as
well as generic industrial instruments like the digital multimeter and oscilloscope.
Generate C code
Simulink Model +
+ Compile and link
Matlab + eZdsp
Embedded Coder Download TMS320F28335
+
TI MCU
Support package
Debug
Figure 3: MATLAB embedded coder with TI support package software design flow.
6. Safety Aspects
Safety and protection measures will be taken at all times while students are performing
experiments. Motor connections are pre-soldered and completely insulated to avoid
short-circuiting. The hardware setup is covered with a transparent polycarbonate panel to avoid
accidental contact. Fully insulated quick connect crimp terminal connectors are used for all wiring
for added safety. All electrical connections ensure good contact, and no copper is exposed.
Figure 4: V/F closed-loop experiment session implementation in simulink.
Experiments
The proposed advanced electric drives laboratory comprises five experiment sessions, briefly
discussed here. Each session requires students to build a model in MATLAB/Simulink using the
equations provided at the start of the session. Then the code is debugged and deployed to the
target microcontroller using the MATLAB Embedded Coder. Troubleshooting is done as needed.
Students are provided with step-by-step procedures and exercises to meet learning objectives. At
the end of each chapter, students are asked to solve problems using components of the example
model. Each student submits an analysis of the results they obtained from the model and their
measurements for the tasks.
To apply the vector control algorithm, machine parameters should be identified for setting of
gains, reference and feed-forwarding values of regulators. Locally sensed values, introduced in 6 ,
are utilized to estimate machine parameters in this session. According to this theory, students are
asked to implement a particular machine operating condition using the microcontroller and
inverter so that the parameters can be estimated. For example, the stator transient inductance
(σLs ) is estimated by turning on the top switch of a-phase only in the VSI for a time duration of t,
so that the peak a-phase current is around a rated value. Using the sensed values of VSI voltage
and current, σLs can easily be determined. This step is repeated 3-5 times to find the average
value of estimated σLs .
The objective of this experiment session is to implement and test the Volts-per-Hertz (V/F)
control in open- and closed-loop modes. An overall block diagram implementing a closed-loop
V/F induction machine drive appears in Figure 5. The measured frequency (Fr ) obtained from the
DC supply
voltage
ePWMAH
ePWMAL
Fr * Ferr Fslip* F* V* ePWMBH Voltage
P PI
ωr* ePWM ePWMBL Source IM
120 Regulator
ePWMCH Inverter
Slip V/Hz ePWMCL
limiter profile
A
P eQEP B
Fr 120 ωr I
Encoder
DC supply
voltage
V/Hz ePWMAH
profile ePWMAL
Fr* Fsync V* ePWMBH Voltage
P
ωr* ePWM ePWMBL Source IM
120
ePWMCH Inverter
ePWMCL
eQEP module is compared with a reference frequency value (Fr∗ ) to generate an error (Ferr )
value. Using a PI regulator and a feed-forward signal, the reference value of frequency (F ∗ ) is
generated, which is then used to calculate the voltage reference value (V ∗ ) by looking up a preset
V/F profile. Finally, the ePWM module in the MCU is programmed to generate the PWM gating
signals to the VSI, which generates the 3-φ AC voltage. The test is conducted for different ωr∗ ; to
observe the V ∗ trend.
3. Slip Compensation
The objective of this experiment session is to implement and test the slip compensation control
technique, in which the slip speed (ωslip ) and slip frequency (Fslip ) are estimated using voltage
(Vdc ) and current (Idc ) measurements sensed from VSI. The estimated Fslip is then added with the
frequency reference (Fr∗ ) to obtain the machine synchronous speed (Fsync ). Voltage reference
value (V ∗ ) is calculated by looking up the V/F profile and applying the same approach as used in
Session 2 for generating 3-φ AC voltage. The overall block diagram implementing a slip
compensation technique appears in Figure 6.
DC supply
Idref Vdref Vαref voltage
PI Vabc*
Inverse Inverse
Clarke ePWMAH
Park
Vqref Trans. Vβref Trans. ePWMAL
PI
Iqref ePWMBH Voltage
ePWM ePWMBL Source IM
Id Inverter
Park ePWMCH
Iq
Trans. ePWMCL
Vα
Phase voltage Vdc
θr Vβ Vdc_sensed
construction
Flux ADC Ia_sensed
Estimator Iα Ia
Clarke Ib_sensed
Iβ Ib
Trans.
TMS320F28335 * Reference variable
Idref Iqref
Id Iq
(a) (b)
Figure 8: Rotor-flux oriented vector control experimental results. (a) shows the response of id
current for a step change in idref current. (b) shows the response of iq current for a step change in
iqref current.
Topics covered in this session include the implementation of Clarke and Park transformations to
convert the phase currents (Ia and Ib ) in abc reference frame to dq currents (Id and Iq ) in rotating
dq reference frame. A flux estimator block is modelled to estimate rotor position using the
voltages (Vα and Vβ ) and currents (Iα and Iβ ) in stationary αβ reference frame. Two current
regulators are designed to regulate Id and Iq , respectively, to a set reference value Idref and
Iqref .
The output of PI regulators (Vdref and Vqref ) is then utilized to obtain Vαref and Vβref by applying
an inverse Park transformation, which are then used as a source to generate PWM gating signals.
The overall block diagram and experimental results of current control implementation are shown
in Figures 7 and 8, respectively. As can be seen, the currents Id and Iq respond for a step change
in reference currents Idref and Iqref without steady-state error. Gain tuning and anti-windup can
be included as additional modules.
DC supply
Idref Vdref Vαref voltage
PI Vabc*
Inverse Inverse
ePWMAH
Park Clarke
Vqref Trans. Vβref Trans. ePWMAL
PI PI
ωr* Iqref ePWMBH Voltage
ePWM ePWMBL Source IM
ωr Id
ePWMCH Inverter
Iq Park
Trans. ePWMCL
θr Vα
Phase voltage Vdc
λα Vβ Vdc_sensed
construction
Speed λβ Flux ADC Ia_sensed
Estimator Estimator Iα Ia
Iα Clarke Ib_sensed
Iβ Ib
Iβ Trans.
TMS320F28335 * Reference variable
ωr*
ωr
Figure 10: Sensorless speed control experimental results showing the induction machine speed
(ωr ) response for a step change in the reference speed (ωr∗ ).
In this final experiment session, a speed control without the encoder is implemented. To estimate
machine speed, a speed estimator block is modeled by utilizing the information obtained from the
flux estimator model. The overall block diagram and experimental result of speed control
implementation are shown in Figures 9 and 10, respectively. As can be seen, the induction
machine speed (ωr ) responds well for a step change in the reference speed (ωr∗ ).
This paper presents a design for the instructional advanced electric drives laboratory and its
implementation . Off-the-shelf TI microcontroller DSK and industrial components were utilized
for their cost-effectiveness and reliability as well as the hands-on experience they offer with
induction machine drive systems, up-to-date tools, and embedded programming. For future work,
widely used serial communication interface (SCI), controller area network (CAN) bus and serial
peripheral interface (SPI) can be considered for improved user interface and peripheral
expansion.
References
[1] S. A. Shirsavar, B. A. Potter, and I. M. L. Ridge. Three-phase machines and drives-equipment for a
laboratory-based course. IEEE Transactions on Education, 49(3):383–388, Aug 2006. ISSN 0018-9359. doi:
10.1109/TE.2006.879266.
[2] N. Mohan, W. P. Robbins, P. Imbertson, T. M. Undeland, R. C. Panaitescu, A. K. Jain, P. Jose, and T. Begalke.
Restructuring of first courses in power electronics and electric drives that integrates digital control. IEEE
Transactions on Power Electronics, 18(1):429–437, Jan 2003. ISSN 0885-8993. doi:
10.1109/TPEL.2002.807120.
[3] R. S. Balog, Z. Sorchini, J. W. Kimball, P. L. Chapman, and P. T. Krein. Modern laboratory-based education for
power electronics and electric machines. IEEE Transactions on Power Systems, 20(2):538–547, May 2005.
ISSN 0885-8950. doi: 10.1109/TPWRS.2005.846237.
[4] Shuhui Li. Laboratory restructuring and development for the course of electric machinery using software and
hardware it tools. age, 10:1, 2005.
[5] Razvan C Panaitescu, Ned Mohan, William Robbins, Philip Jose, Todd Begalke, C Henze, Tore Undeland, and
E Persson. An instructional laboratory for the revival of electric machines and drives courses. In Power
Electronics Specialists Conference, 2002. pesc 02. 2002 IEEE 33rd Annual, volume 2, pages 455–460. IEEE,
2002.
[6] Seung-Ki Sul. Control of Electric Machine Drive Systems. IEEE, 2011. ISBN 9780470876541. doi:
10.1002/9780470876541.app1.
Appendix:
C code sample generated by MATLAB embedded coder for V/F closed-loop implementation
1 #i n c l u d e ” V F C l o s e d l o o p E x p e r i m e n t . h ”
2 #i n c l u d e ” V F C l o s e d l o o p E x p e r i m e n t p r i v a t e . h ”
3
4 /∗ B l o c k s i g n a l s ( d e f a u l t s t o r a g e ) ∗/
5 B V F Closed loop Experiment T V F Closed loop Experiment B ;
6
7 /∗ Real −t i m e model ∗/
8 RT MODEL V F Closed loop Expe T V F C l o s e d l o o p E x p e r i m e n t M ;
9 RT MODEL V F Closed loop Expe T ∗ c o n s t V F C l o s e d l o o p E x p e r i m e n t M =
10 &V F C l o s e d l o o p E x p e r i m e n t M ;
11 s t a t i c void rate monotonic scheduler ( void ) ;
12 s t a t i c uint16 T a d c I n i t F l a g = 0;
13 /∗
14 ∗ S e t w h i c h s u b r a t e s need t o r u n t h i s b a s e s t e p ( b a s e r a t e a l w a y s r u n s ) .
15 ∗ T h i s f u n c t i o n must be c a l l e d p r i o r t o c a l l i n g t h e model s t e p f u n c t i o n
16 ∗ i n o r d e r t o ” remember ” w h i c h r a t e s need t o r u n t h i s b a s e s t e p . The
17 ∗ b u f f e r i n g of events allows f o r overlapping preemption .
18 ∗/
19 void V F Closed loop Experiment SetEventsForThisBaseStep ( boolean T ∗ eventFlags
)
20 {
21 /∗ Task r u n s when i t s c o u n t e r i s z e r o , computed v i a rtm Step Tas k macro ∗/
22 e v e n t F l a g s [ 1 ] = ( ( b o o l e a n T ) rtmS tep Task ( V F C l o s e d l o o p E x p e r i m e n t M , 1 ) ) ;
23 }
24 /∗
25 ∗ This f u n c t i o n updates a c t i v e t a s k f l a g f o r each s u b r a t e
26 ∗ and r a t e t r a n s i t i o n f l a g s f o r t a s k s t h a t e x c h a n g e d a t a .
27 ∗ The f u n c t i o n a s s u m e s r a t e −m o n o t o n i c m u l t i t a s k i n g s c h e d u l e r .
28 ∗ The f u n c t i o n must be c a l l e d a t model b a s e r a t e s o t h a t
29 ∗ t h e g e n e r a t e d code s e l f −manages a l l i t s s u b r a t e s and r a t e
30 ∗ transition flags .
31 ∗/
32 s t a t i c void rate monotonic scheduler ( void )
33 {
34 /∗ Compute w h i c h s u b r a t e s r u n d u r i n g t h e n e x t b a s e t i m e s t e p . S u b r a t e s
35 ∗ a r e an i n t e g e r m u l t i p l e o f t h e b a s e r a t e c o u n t e r . T h e r e f o r e , t h e s u b t a s k
36 ∗ c o u n t e r i s r e s e t when i t r e a c h e s i t s l i m i t ( z e r o means r u n ) .
37 ∗/
38 ( V F C l o s e d l o o p E x p e r i m e n t M −>Timing . T a s k C o u n t e r s . TID [ 1 ] ) ++;
39 i f ( ( V F C l o s e d l o o p E x p e r i m e n t M −>Timing . T a s k C o u n t e r s . TID [ 1 ] ) > 9 ) { /∗ Sample
t i m e : [ 0 . 0 0 1 s , 0 . 0 s ] ∗/
40 V F C l o s e d l o o p E x p e r i m e n t M −>Timing . T a s k C o u n t e r s . TID [ 1 ] = 0 ;
41 }
42 }
43
44 /∗ Model s t e p f u n c t i o n f o r TID0 ∗/
45 v o i d V F C l o s e d l o o p E x p e r i m e n t s t e p 0 ( v o i d ) /∗ Sample t i m e : [ 0 . 0 0 0 1 s , 0 . 0 s ] ∗/
46 {
47 { /∗ Sample t i m e : [ 0 . 0 0 0 1 s , 0 . 0 s ] ∗/
48 rate monotonic scheduler () ;
49 }
50