Mattia Rossi, Introduction To Microcontroller Programming For Power Electronics Control Applications - Coding With MATLAB and Simulink
Mattia Rossi, Introduction To Microcontroller Programming For Power Electronics Control Applications - Coding With MATLAB and Simulink
Microcontroller
Programming for
Power Electronics
Control Applications
Introduction to
Microcontroller
Programming for
Power Electronics
Control Applications
Coding with MATLAB® and
Simulink®
Mattia Rossi
Nicola Toscani
Marco Mauri
Francesco Castelli Dezza
MATLAB® is a trademark of The MathWorks, Inc. and is used with permission. The MathWorks
does not warrant the accuracy of the text or exercises in this book. This book’s use or discussion of
MATLAB® software or related products does not constitute endorsement or sponsorship by The
MathWorks of a particular pedagogical approach or particular use of the MATLAB® software.
Reasonable efforts have been made to publish reliable data and information, but the author and
publisher cannot assume responsibility for the validity of all materials or the consequences of their use.
The authors and publishers have attempted to trace the copyright holders of all material reproduced in
this publication and apologize to copyright holders if permission to publish in this form has not been
obtained. If any copyright material has not been acknowledged please write and let us know so we may
rectify in any future reprint.
Except as permitted under U.S. Copyright Law, no part of this book may be reprinted, reproduced,
transmitted, or utilized in any form by any electronic, mechanical, or other means, now known or
hereafter invented, including photocopying, microfilming, and recording, or in any information
storage or retrieval system, without written permission from the publishers.
For permission to photocopy or use material electronically from this work, access www.copyright.com
or contact the Copyright Clearance Center, Inc. (CCC), 222 Rosewood Drive, Danvers, MA 01923,
978-750-8400. For works that are not available on CCC please contact mpkbookspermissions@tandf.
co.uk
Trademark notice: Product or corporate names may be trademarks or registered trademarks, and are
used only for identification and explanation without intent to infringe.
Library of Congress Cataloging‑in‑Publication Data
DOI: 10.1201/9781003196938
Typeset in LM Roman
by KnowledgeWorks Global Ltd.
Foreword xiii
Preface xvii
Acknowledgments xix
Biographies xxi
I Embedded Development:
Hardware Kits and Coding 13
2 Automatic Code Generation through MATLAB® 15
2.1 Model-Based Design and Rapid Prototyping . . . . . . . . . 16
2.2 Workflow for Automatic Code Generation . . . . . . . . . . . 18
2.3 Generate Code for C2000™ Microcontrollers . . . . . . . . . 22
2.4 TI C2000™ Processors Block-set . . . . . . . . . . . . . . . . 24
vii
viii Contents
4 Software Installation 39
4.1 TI Support Packages:
Code Composer™ Studio and ControlSUITE™ . . . . . . . . 39
4.2 MATLAB® Support Package:
Embedded Coder for Texas Instruments C2000 Processors . 41
4.3 Installation Procedure . . . . . . . . . . . . . . . . . . . . . . 41
8 Basic Settings:
Serial Communication COM and Hardware Target 101
8.1 Virtual Serial Communication through COM port . . . . . . 101
Bibliography 423
Index 427
Foreword
xiii
xiv Foreword
Most people go about their day blissfully unaware of the electric motors that
are spinning the world around us. We wake up staring upwards at a ceiling
fan, silently rotating in a circle. We jump into our car and rely on up to
40 motors—pumps, fans, locks, and lifts—to get us to our destination. We
power up our laptop computers and hear the soft whine of fans working to
keep the electronics cool. Motors are everywhere because they are one of the
main ways that an electronic circuit can interact with the real world, i.e. a
power electronic-based system. They are “lectromechanical, turning analog
and digital signals into real and visible mechanical motion. It is estimated
that electric motors consume 45 percent of the total worldwide electricity—
this is a stunning statistic! As we look to reducing energy consumption and
enabling a greener future, electric motors present a huge potential for efficiency
improvements.
Few engineering students are aware of the impact of electric motors on
the world around them, and even less are versed in the design and control of
motor systems. This is a problem! We need engineers growing in competency
in this field to create better and more efficient motor drive systems.
Motor drive and control is an incredibly multidisciplinary field. Real-time
digital processing is implemented in microcontrollers to be the “brain” behind
the motor system; controlling speed, power, and efficiency from the digital
domain. A wealth of analog components from power management (voltage
regulators & gate drivers) and signal chain (amplifiers & sensors) interface
the microcontroller to the motor through a power converter while providing
sensing, safe operation, and support for the system. Texas Instruments has
over 25 years of experience in the field of real-time control and also provides
a comprehensive analog portfolio covering every block of the motor drive and
control system.
This book presents very practical and important lessons to engineers and
engineering students alike on the topics of motor drive and control, covering
not only general concepts but details on how to create a motor drive system.
It provides an excellent resource to encourage the next generation of engineers
to grow and develop skills in the area of electric motors and power electronics,
introducing them the tools they need to make an impact on the world.
Politecnico di Milano is an outstanding academic partner, and the focus
of the Electrical Machines, Drives and Power Electronics Research Group on
cutting-edge power electronic-based technologies helps shape quality engineer-
ing minds. We wish the best of success to this publication and to the continued
collaboration between industry and academia.
Can you write the 100 million lines of code that are needed to build an average
modern car? The answer is pretty obvious: of course you can, it’s just a matter
of time. And how would you compare the complexity of this problem to writing
the 4501 lines of assembly code needed to build the first version of UNIX in
1971? While both tasks appear to be at a similar level of dauntlessness, the half
century separating them has witnessed the emergence of high-level languages
that enable programmers to address highly complex problems on their own
while reusing the legacy of their peers.
At MathWorks Inc., we relentlessly work on providing the best high-level
programming tools to automate the implementation of your ideas into embed-
ded systems. Simulink allows you to design and simulate complex algorithms
that you can translate into thousands of lines of embedded code with a click
of a button via our code generation technology.
The book Introduction to Microcontroller Programming for Power Elec-
tronics Control Applications will teach you how to use these modern techniques
to create control algorithms for systems involving complex physics. The re-
markable work of Mattia Rossi, Nicola Toscani, Marco Mauri and Francesco
Castelli Dezza from Politecnico di Milano, Italy, clearly explains deep concepts
to the reader in the field of embedded programming for power electronics ap-
plications using Model-Based Design.
The copyrighted material included in this book is reprinted with permission of The
MathWorks, Inc.
xvi Foreword
While the shift to digital is now largely dominating the industry of mo-
tor control, this revolution is just starting for power conversion applications.
The material in this book provides state of art techniques to train the many
engineers that the world needs tomorrow in a field that is at the core of the
indispensable transition to clean energy.
In recent conversations with Mattia and Nicola, while they politely thanked
us for our help, it was clear to us that the quality and the amount of effort
in this book deserved much more thanking from our side. With this foreword,
we extend all our gratitude to this outstanding contribution to accelerating
the pace of engineering and science, our core mission.
Power electronics-based systems are the key enabling technology to meet most
of the future sustainable challenges from grid to motor applications.
Standard textbooks and courses about power electronics and electrical ma-
chines deal with analysis in continuous-time, averaged modeling of switched-
mode power converters, and continuous-time control theory. Nevertheless, real
control algorithms and management functions around power converters are
implemented digitally, thus, extending the field of fundamentals studies to
discrete-time modeling and digital control concepts specific to power electron-
ics. The necessary background is achieved by combining specific textbooks
and courses from both power electronics and digital control theory. However,
students who approach the design of digitally controlled power converters for
the first time may not fully understand and successfully practice for a targeted
problem due to such fragmented references.
In this book, we attempt to fill this gap by treating the fundamental as-
pects of digital control implementation for power electronics based systems
in a systematic and rigorous manner. Our objectives are to put the reader
in the position to understand, analyze, model, design, and implement digital
feedback loops around power converters, from system-level transfer function
formulations to understand which coding tool may be used when working
with microcontroller (MCU or µC) platforms. In particular, the latter be-
longs to Texas Instruments™ C2000™ family, which is specifically designed
for real-time closed loop control such as power supplies, industrial drives,
and solar inverters applications. The Simulink® environment is able to au-
tomatically generate ANSI/ISO C/C++ code tailored for specific embedded
targets through a model-based workflow. Given the settings which enable a
background usage of the Code Composer™ Studio IDE, a Simulink® scheme
can be directly compiled and executed on C2000™ MCUs. Such automated
build and execution procedure speed up the control algorithms implementa-
tion, thus, the code generation of software interfaces and MCU peripherals
(e.g. ADC, digital I/O, PWM), which can be tested with execution profiling.
This makes the reader working in a rapid prototyping manner.
This book is oriented to graduate students of electrical and automation
and control engineering pursuing a curriculum in power electronics and drives.
Moreover, it aims to be a reference for engineers and researchers who seek to
expand on the expertize in design-oriented knowledge for the aforementioned
applications. It is assumed that the reader is well acquainted with funda-
mentals of electrical machines and power converters, along with associated
xvii
xviii Preface
Most of the projects shown in this book have been funded by the Department
of Mechanical Engineering of Politecnico di Milano, Italy, with the particular
contribution of its Laboratory of Electrical Drives and Power Electronics.
Special thanks goes to the university rector Prof. Ferrucio Resta and the
department director Prof. Marco Bocciolone for their support to this initiative.
We are grateful to our graduate students Marco Gerosa, Matteo Scandella,
Andrea Polastri, Matteo Sposito, and Luca Grittini for the precious work
in supporting the hardware development, the boards testing and the many
suggestions they made. We also thank all the Ph.D. students and researchers
who contributed to this book. In particular, Dr. Khaled ElShawarby and Dr.
Alberto Bolzoni, who were supporting the project from day zero.
The authors would like to specially thank Prof. Petros Karamanakos from
Tampere University, Finland, and Prof. Ralph Kennel from Technical Univer-
sity Munich, Germany, for their guidance, long discussions and availability to
share their high expertize in this field.
We are grateful to Nora Konopka and CRC Press LLC from Taylor and Fran-
cis Group for publishing this book. Special thanks goes to Prachi Mishra for
her guidance and support.
xix
Biographies
xxi
xxii Biographies
DOI: 10.1201/9781003196938-1 1
2 Advances in Firmware Design for Power Electronics Control Platforms
CPU
A/D
CONVERTER RAM
PROGRAM
CLOCK
MEMORY
MCU
1 From the customer’s point of view the “best” microcontroller is the one which matches
Since this book focuses on electrical power conversion case studies, from
now on the text refers to MCU platforms targeted to power electronics-based
applications. Even if this last statement reduces the candidate list, there still
are several suitable solutions available on the market which share a common
goal of being compact and versatile. Since the definition of a criterion to cat-
egorize each board would not be practical (i.e., there might be even deep
technology differences), it is recommended to follow a system-level approach
like the one presented here:
1. Consider all the components and peripherals that are necessary to
run all of the required features. If the board lacks any of them, it is
important to identify some supported expansions to include them.
2. Consider the supported programming languages and the level of
competence of the final user. Moreover, investigate if any automatic
code generation procedure is available as well as the quality of the
documentation at disposal for the adopted board. Indeed, commu-
nity and support are factors of great importance since they are the
primary resources when designing a project.
3. Evaluate costs versus adopted components for the considered spe-
cific application: is it worth paying for them?
• CPU and clock speed: these two values affect the overall performance of
the board. Namely, how fast it can perform computations. It should be noted
that clock speed comparisons between CPUs coming from different families
may not lead to meaningful considerations. Other factors, such as instruction
cycles, instruction sets, and pipeline depth, also affect MCU performances.
• RAM: the size of this memory affects the number of tasks that can be run
simultaneously. It also impacts how fast data can be processed, as swapping
it from RAM to nonvolatile storage incurs large performance overheads.
• Graphical processing unit (GPU): it allows development board to run
video output (e.g., VGA/HDMI). High-performance GPUs are needed while
processing video/images with the development board.
• Data memory: it affects the size of programs, operating systems, and gen-
erated/downloaded data that can be stored on development boards.
• General purpose input/output pins: these pins are used to connect
external components to the development board in use. Hence, more pins
typically means more possible simultaneous connections. These pins are
usually assigned specific functionalities by the manufacturer being compli-
ant with some standards, such as integrated circuit (I2C), serial peripheral
Selecting a Development Board 5
• Translation
Programs written in Binary code does not need any translation as this lan-
guage is a machine code already. Namely, the hardware is capable of un-
derstanding them without any translation. Instead, Assembly codes need
an Assembler to translate programs to their equivalent counterpart in Ma-
chine Code. High-level languages are always translated by compilers or in-
terpreters. Some of them required both compilers and interpreters to get the
Object/Binary file.
• Support
Low-level languages have less support than high-level ones. There may be
lower number of communities for low-level languages than for high-level ones.
applications in the fields of motor control, digital power supplies, lighting, re-
newable energy, and smart grids. This family is made up of several subfamilies,
from which it is worth mentioning:
In particular, the C28xx chips are from low to high performance MCU.
Piccolo™ (which main features and applications are summarized in Figure 1.3)
and Delfino™ are the families for low and high performance microcontrollers,
respectively. Their main characteristics are reported here in the following:
1. Piccolo™
•MCU with floating-point unit;
•CPU frequency: from 40 to 120 MHz;
•Core: 1xC28x;
•Memory:
from 60 kbit up to 512 kbit flash;
from 12 kbit up to 100 kbit SRAM;
•Main peripherals: ADC, PWM, QEP, DMA, SPI, UART, I2C,
CAN, USB.
2. Delfino™
•MCU with floating-point unit;
•CPU frequency: from 100 to 200 MHz;
•Core: from 1xC28x up to 2xC28x + 2xCLA + ARM Cortex-
M4;
•Memory:
from 512 kB up to 1.5 MB flash;
from 68 kB up to 338 kB SRAM;
•Main peripherals: ADC, PWM, QEP, DMA, SPI, UART, I2C,
CAN, EMIF.
In particular, the following families of C28xx MCUs (which are also available
as LaunchPad™ development kits) are supported with a dedicated library
available in Matlab® Simulink® : F2802x Piccolo™ , F2803x Piccolo™ , F2805x
Piccolo™ , F2807x Piccolo™ , F2806x Piccolo™ , F2837xS Delfino™ , F2837xD
Delfino™ , F28004x, F2823x Delfino™ , F28M3x.
From Chapter 2 on, this book refers to a specific model of development board,
that is Texas Instruments™ LaunchXL F28069M Piccolo™ , which is shown in
Scheme of a Power Electronics Control Problem 9
Figure 1.4. The reason behind this choice is its low-cost, low-power, and simple
development environment of the board. Moreover, it has both a 256 kbit flash
memory and a 96 kbit RAM. Finally, the community and project support for
this device is relatively sparse compared to other boards. TI offers several plug-
in expansion boards to expand the capabilities of the F28069M LaunchPad™
Piccolo™ .
• Reference: the controller must act to let the system follow a reference
signal. The latter can be both internally generated on the MCU or provided
as an external signal.
• Processing: this relates to the control logic implemented on the MCU.
The control structure is the main part of the scheme, since it is aimed at
generating the desired output based on the error between the reference and
the feedback signals. This stage may also comprise scaling routines.
Note that, the C2000™ MCU family includes several parts of this struc-
ture representing a complex ecosystem. Its main features are summarized in
Figure 1.6.
Figure 1.7 Traction converter and motor control for an efficient conversion DC
to AC to drive an electric motor [9].
Embedded Development:
Hardware Kits and Coding
2
Automatic Code Generation through
MATLAB®
Any time engineers design digital controls for power electronic-based applica-
tions, there are many good reasons to perform modeling and simulation:
• Test system behavior an possible variations, e.g., in the topology, power
supply, load.
• Test different passive (e.g. resistors, capacitors, inductors) and active (e.g.
semiconductor technology) elements to find suitable components.
• Test if the feedback control algorithms are able to meet the currents/volt-
ages/speeds regulation requirements.
Then, move to the coding stage aimed to embedded implementation for a
specific target. MathWorks® provides tools which bring the simulation stage
together with the implementation one, creating a powerful ecosystem which
allow to speed up the workflow from idea to practice.
In this book, the concepts of rapid prototyping and digital control tech-
niques for power electronics-based systems are explained by programming
a TI C2000™ based MCU platform through the MathWorks® MATLAB®
and Simulink® frameworks. Both MATLAB® and Simulink® are commonly
used for the analysis, design, simulation and optimization of models, includ-
ing power electronic circuits. For the latter, the Simscape™ Power Systems1
toolbox allows to model all the parts of power networks and to take into
account the realistic behavior of each component. Moreover, MathWorks®
along with various MCU manufacturers, such as Texas Instruments® , devel-
oped several Simulink® toolboxes aimed at automatically generating C/C++
targeted code for a specific CPU. Such toolboxes work together with the
IDE of the microcontoller supplier, i.e., TI Code Composer™ Studio in this
case.
1 Simscape™ toolbox enables a quick creation of models of physical systems within the
DOI: 10.1201/9781003196938-2 15
16 Automatic Code Generation through MATLAB®
system and the specific environment in which it operates. This model cap-
tures the accumulated knowledge about the control unit (e.g. considering
the peripheral of the targeted MCU). The engineers generate code auto-
matically from the model of the control algorithms for firmware testing and
verification. Then, they download the generated code onto production hard-
ware (e.g., MCU) for testing in an real hardware.
As this example shows, Model-Based Design uses the same elements as tradi-
tional development workflows, but with two key differences:
• A system model is at the heart of development, from requirements capture
through design, implementation, and testing;
• It requires to follow this modeling approach to enable the automated rou-
tines, e.g., automatic code generation.
The workflow reported in Figure 2.1 can be specified for power electronic-
based applications, as shown in Figure 2.2.
18 Automatic Code Generation through MATLAB®
• Refine and verify the functional operations of control system design with
the exploited hardware by rapidly iterating between algorithm design and
prototyping;
• Continuously explore and test new ideas using a flexible, scalable platform;
validate whether a component can adequately control the physical system
in real time;
• Evaluate system performance, investigate scenarios and hardware interac-
tions that are complex, expensive, or dangerous to perform with production
hardware (i.e. before laying out hardware, coding production software);
• Test hardware cutting the development time from idea to practice, to avoid
costly design flaws by detecting errors early when they are still cost-effective
to correct.
y ∗ (k)
Reference + e (k) PI u (k) PWM u (t) Power v (t) Electrical
− controller modulator electronics system
y (k) y (t)
Sensor
Power Systems library. In both cases, the system receives an actuating vari-
able/signal u(t) and it returns an output variable/signal y(t). Supposing to
design a closed-loop control, e.g., a PI-based current control, the regulator
processes the error y ∗ (t) − y(t) and it returns the control input u(t). The
whole control scheme is reported in Figure 2.3.
Due to the switching nature of power converters (i.e., discrete on-off behav-
ior), a modulation stage such as pulse width modulation (PWM), translates
the control input u∗ (t) into the actuating signal u(t) by a suitable switch-
ing pattern of the power converter. In this framework, the controller has to
be implemented into the processor of the MCU which cannot handle con-
tinuous signals. Thus, the control algorithm must be discretized. Namely, its
input/output signals are sampled at discrete time instances, i.e., u(k) and
y(k), while the discrete controller form is derived from the continuous-time
one through a discretization method. These latter aspects are deeply discussed
in Part II of this book.
The overall control implementation process can be summarized in three
main steps:
1. The Simulink® file is used to test and to optimize the controller
through simulation before its deployment on the selected hardware2 ;
2. Once the control design is ready, the control input and output are
substituted by the related MCU peripherals which are given in
Simulink® as block-set. According to the peripheral requirements,
it may be necessary to edit the data type of the signals;
3. Finally, the overall scheme (controller + I/O block-sets) can be
deployed on the MCU, i.e., translated into binary code and uploaded
into the MCU. The whole procedure is summarized in Figure 2.4.
This model translation is not simple since it involves several hidden steps.
Simulink® converts the model to a C programming code through MathWorks®
2 Given that the converter behavior is assumed to be faster than the load dynamics,
it is common practice to design the controller without taking the converter dynamics into
account
20 Automatic Code Generation through MATLAB®
Specifcations
I m pro v e m e nts
s
Simulation Bug
Firmware
Design of the
execution
control logic
E rrors
Discretization
Firmware
Automatic Deploy
Peripheral setting
code generation to hardware
Data type setting
Embedded Coder® . Then, the executable C code is fed to the IDE Code Com-
poser Studio™ in which it is:
1. Sequentially compiled to assembly language exploiting the Texas
Instruments libraries;
2. Assembled (e.g., ASM source code);
3. Lik-edited;
4. Downloaded on the TI C2000™ MCU flash memory.
Figure 2.5 shows such steps with a flowchart.
Benefits
The key advantage of such rapid prototyping technique is a seamless integra-
tion capability over multiple processors. This can be achieved by just replacing
Simulink®
Embedded
Coder
C-code
Download
Hardware
the processor specific block-set, making the necessary changes in their config-
uration rather than rewriting or rebuilding the whole model. This is valid not
only for hardware made by the same manufacturer, but by different producers
as well. Hence, designers do not have to worry about the compatibility of the
code. To validate changes made on the controller, it is enough to run the simu-
lation model first and, then, to verify that no errors are generated. Hence, this
approach is naturally oriented to research and development activities (i.e., for
academic and industries).
Drawbacks
It is important to underline how such procedure may imply performance bot-
tlenecks. Skipping the effort of low-level coding may limit the computational
efficiency of the generated code. The resulting C/C++ code is numerically
equivalent to the previously validated algorithms in Simulink® , but these lat-
ter has to be prepared for code generation, e.g., introducing implementation
considerations needed for low-level C code and using functions for code gen-
eration support.
To clarify such concept, the code generation of a simple MATLAB® func-
tion which multiplies two inputs is investigated here in the following:
Given two scalar inputs, the automatically generated C code maps clearly
back to the MATLAB® environment, as shown above.
Nevertheless, as any MATLAB® algorithms intended for code generation,
implementation constraints due to the differences between the two program-
ming languages must be considered. These mainly include:
Given the purpose of this book, the last two points require particular at-
tention. The polymorphism can give a single line of MATLAB® code different
meanings depending on the inputs. For example, the function shown previ-
ously could mean scalar multiplication, dot product, or matrix multiplication.
In fact, the inputs could be of different data types (logical, integer, floating-
point, fixed-point) or either real or complex numbers. If two matrices are
multiplied, the automatic procedure produce many lines of C code, even with
3 for-loops, as shown here in the following:
void Prod ( const double a [12] ,
const double b [20] ,
double c [15])
{
int i0 ; int i1 ; int i2 ;
for ( i0 = 0; i0 <3; i0 ++)
{
for ( i1 = 0; i1 <5; i1 ++)
{
c [ i0 + 3 * i1 ] = 0.0;
for ( i2 = 0; i2 <4; i2 ++)
{
c [ i0 + 3 * i1 ] =...
... a [ i0 + 3 * i2 ] * b [ i2 + ( i1 << 2)];
}
}
}
}
Thus, this piece of code looks quite different from that one reported before.
For further information on this topic, the reader is referenced to [5].
Figure 2.6 The Embedded Coder® Support Package for Texas Instruments™
C2000™ Processors Simulink® library.
the Library Browser, click on the icon in the simulation bar of the
coding simplification is useless. Part III shows in detail how to set the most
exploited blocks in power electronics control problems. They can be used to-
gether with the standard Simulink® blocks, generating complete control algo-
rithms and real-time interfaces. An example of the given workflow is denoted in
Figure 2.7.
3
Texas Instruments™ Development Kit
1 JTAG emulators are the “umbilical cord” between PC software tools and DSP boards.
It is a common hardware interface that provides the computer with a way to communicate
directly with the chips on a board. It was originally developed by a consortium, the Joint
(European) Test Access Group, in the mid-80s to address the increasing difficulty of testing
printed circuit boards (PCBs).
2 UART stands for Universal Asynchronous Receiver/Transmitter. It is not a commu-
DOI: 10.1201/9781003196938-3 27
28 Texas Instruments™ Development Kit
Figure 3.1 LaunchPad™ F28069 Piccolo™ board: main characteristics [12], top
and bottom view.
3.1.1 Features
The LaunchPad™ F28069M Piccolo™ allows applications to easily migrate to
lower cost devices. As a matter of fact, this board shows the features reported
here in the following and in Figure 3.3:
Figure 3.2 The C2000 MCU uses the C28x core as the main processing unit.
This is a 32-bit floating point (single precision) core with dedicated instruc-
tions tailored to real-time control applications. Complementing the C28x core
is a Control Law Accelerator (CLA) a 32-bit floating point co-processor capa-
ble of independent code execution increasing the system bandwidth versus a
C28x core alone. There are both dual and single core implementations across
the C2000 MCU family of devices [15].
Figure 3.3 Overview of the main components and parts of the LAUNCHXL
F28069M [11].
+3V3
+3V3 +5V
PWR 41 PWR 61
1
2
1
2
ANA 42 GND 62 PWR 1 PWR 21
FAULTn 43 J7.3 Vdc 63 ADCINB7 ANA 2 ADCINA6 GND 22
OCTWn 44 J7.4 V_A2 64 ADCINB4 FAULTn 3 J1.3 Vdc 23 ADCINA7
45 GPIO20 V_B2 65 ADCINA5 OCTWn 4 J1.4 V_A1 24 ADCINB1
ANA 46 V_C2 66 ADCINB5 GPIO 5 GPIO12 V_B1 25 ADCINA2
2SPI_CLK 47 GPIO14 I_A2 67 ADCINA3 ANA 6 ADCINB6 V_C1 26 ADCINB2
48 GPIO21 I_B2 68 ADCINB3 1SPI_CLK 7 GPIO18 I_A1 27 ADCINA0
SCL 49 GPIO23 I_C2 69 ADCINA4 GPIO 8 GPIO22 I_B1 28 ADCINB0
SDA 50 GPIO54 70 9 GPIO33 I_C1 29 ADCINA1
10 GPIO32 30
J5 J7 GND J1 J3
GND
2PWM_AH 80 GPIO6 GND 60 1PWM_AH 40 GPIO0 GND 20
2PWM_AL 79 GPIO7 2SPI_CS 59 GPIO27 1PWM_AL 39 GPIO1 1SPI_CS 19 GPIO19
2PWM_BH 78 GPIO8 GPIO 58 GPIO26 1PWM_BH 38 GPIO2 GPIO 18 GPIO44
2PWM_BL 77 GPIO9 57 1PWM_BL 37 GPIO3 17
2PWM_CH 76 GPIO10 RESET 56 RESET# 1PWM_CH 36 GPIO4 RESET 16 RESET#
2PWM_CL 75 GPIO11 2SPI_SI 55 GPIO24 1PWM_CL 35 GPIO5 1SPI_SI 15 GPIO16
74 2SPI_SO 54 GPIO25 GPIO 34 GPIO13 1SPI_SO 14 GPIO17
73 2EN_GATE 53 GPIO52 33 1EN_GATE 13 GPIO50
PWM_DAC 72 DAC3 2DC_CAL 52 GPIO53 PWM_DAC 32 DAC1 1DC_CAL 12 GPIO51
PWM_DAC 71 DAC4 51 GPIO56 PWM_DAC 31 DAC2 11 GPIO55
J8 J6 J4 J2
GND GND
Figure 3.5 Correspondence between pin and GPIO channels for the
LaunchPad™ F28069M [16].
Figure 3.7 Connection between the LAUNCHXL F28069M and a host PC.
Jumper Function
JP6 ON / USB/UART: GPIO15-58; FAULT/OCTW: GPIO28-29;
JP7 OFF J7.3-J7.4: Hi-Z
JP6 OFF / USB/UART: GPIO15-58; FAULT/OCTW: GPIO28-29;
JP7 OFF J7.3-J7.4: Hi-Z
JP6 OFF / USB/UART: GPIO28-29; J1.3-J1.4 – Hi-Z; J7.3-J7.4 –
JP7 ON GPIO15-58
JP6 ON / USB/UART Disabled; J1.3-J1.4 – GPIO28-29; J7.3-J7.4
JP7 ON – GPIO15-58
TI C2000™ LaunchPad™ : F28069M Piccolo 33
(a) (b)
(a) (b)
Figure 3.9 The Motor Drive BoosterPack BOOSTXL-DRV8301 (a) and other
BoosterPack boards stacked one over the other [12].
users may either want to perform an emulation boot or a boot to flash if they
are running the application standalone. The three switches reported in S1 (see
Figures 3.8 (b) and Table 3.3) which allow users to easily configure the pins
that the boot ROM checks before the start-up of the board.
Remark: in digital circuits, a high impedance (or Hi-Z) output is not
driven to any defined logic level by the output circuit. The signal is neither
driven to a logical high nor low level; this third condition leads to the descrip-
tion “tri-stated”. Such a signal can be seen as an open circuit or “floating”.
3.3 V power supply from the USB connection (see Table 3.1). Figures 3.9 (b)
and 3.10 show how to plug the converter BoosterPack on the LaunchXL-
F28069M board, i.e., it is connected to pins in rows from J1 to J4 (the
reader shuld refer to Figures 3.9 (b) and 3.5 for the pinout of the adopted
LaunchPad™ ).
Figure 3.11 Block scheme of the interactions between a LaunchPad™ and the
BOOSTXL-DRV8301 aimed to a motor control application [14].
36 Texas Instruments™ Development Kit
Remark: all the examples proposed in this book refer to the hardware pre-
sented in this chapter. It must be said that Texas Instruments™ started
the production of a new LaunchPad™ F280049C and new BoosterPacks
BOOSTXL-DRV8320RS, BOOSTXL-DRV8323RS, which will be available
along with the LaunchPad™ F28069M and BOOSTXL-DRV8301 on the mar-
ket. Even if a new hardware will imply differences in the settings of the pro-
gramming environment as well as some modifications in the pinout of the
adopted boards, the proposed design approach/workflow of closed-loop con-
trol strategies for power electronic applications is still valid. The reader is ref-
erenced to [7] for checking the compatibility between LaunchPads and Boost-
erPacks and [31] to verify the Embedded Coder support of the adopted MCU
board from Simulink® blockset.
4
Software Installation
DOI: 10.1201/9781003196938-4 39
40 Software Installation
(a) (b)
Figure 4.3 ControlSUITE™ overview: device drivers, APIs, utilities and li-
braries are used to build technology examples and system frameworks [22].
MATLAB Support Packages 41
Figure 4.4 Embedded Coder Support Package for Texas Instruments C2000
Processors available in the Add-Ons menu of Matlab® .
• Click on the lower part of the Add-Ons icon in the home bar of
(a) (b)
Figure 4.5 Example of MATLAB® windows that appear during the installa-
tion: (a) shows the processor family selection windows (only the required TI
Piccolo F2806x is selected), while (b) reports the needed third party softwares.
In this latter, all of them have been installed already.
Remark
Check if the Instrument Control Toolbox™ is installed on the adopted
MATLAB® release. This toolbox is needed to set Serial Communication be-
tween the LaunchPad™ and the host PC during the execution of the firmware.
More information on serial communication are reported in Chapter 8.
Potential Errors
For MATLAB® releases earlier than the 2019b (like the 2015b one) in
which Code Composer™ Studio v5 is used, it may be required to run
checkEnvSetup() tool to complete/adjust the installation:
To this aim, the following path should be checked by typing checkEnvSetup
(’ccsv5’,’f28069’,’setup’) in the MATLAB® prompt:
Checking CCSv5 (Code Composer Studio) version
Required version: 5.0 or later
• Required for : Code Generation
Your Version : 5.5.0
### Setting environment variable “TI_DIR” to “C:\ti\ccsv5”
It is important to note that this procedure could be also used to check the
correct installation of Code Composer Studio™ for other Matlab® releases up
to the 2018b one. For newer versions, this function has been removed.
Part II
DOI: 10.1201/9781003196938-4 49
50 Introduction
Interestingly, many real control systems are designed without any considera-
tion of these two points. For example, even for complex systems with many
inputs and outputs, it may be possible to design workable control systems
using only heuristic tuning (i.e., involving steps 1, 4 5, 6, 7, 12, and 13). How-
ever, in this case a suitable control structure may not be known at the outset,
and there is a need for systematic tools and insights to assist the designer at
least with steps 4, 5, and 6, based on step 2 and 3. This book aims to provide
guidelines for steps 12 and 13, for which the control structure design has to
deal with microcontroller implementations.
Simply stated, “even the best control system cannot make a Ferrari out of
a Volkswagen.” Therefore, the process of control system design should in some
cases also include a step 0, which involves the design of the system equipment
itself. Regarding the purpose of the book, this means to deal with the power
electronics design in term of sizing passive components, consider magnetic and
saturation effects, evaluate power losses and heat exchange and many more
aspects.
Both control and power electronics engineers have to remember that the
idea of looking at hardware/system equipment and control system design as
an integrated whole is not a novel approach, as it is clear from the following
quote taken from [44]:
The objective of a closed-loop control system is to make the output y(t) behave
in a desired way by manipulating the input u(t). This “desired way” is defined
by a proper formulation of the control problem, which could refer to:
• Command-tracking: u(t) is manipulated to keep the output close to a
given reference input (set point) y ∗ (t).
• Disturbance rejection: u(t) is manipulated to counteract the effect of
disturbances;
The evolution in time of u(t) is given by the controller type and its design,
which relates to the control target. Note that the controller should be selected
according to the system to be controlled. Starting from the physics of the cir-
cuits models, i.e., based on equivalent electrical ports, the following sections
denote that both electrical machines and power conversion systems may be
described as linear or linearized models. Hence, linear controllers represent
the easiest control candidate. Furthermore, the mathematical description of
such electrical dynamics refers to multi-input multi-output (MIMO) models.
Nevertheless, this manuscript shows how the control configuration/architec-
ture may lead to translate a MIMO model into a combination of single-input
single-output (SISO) models. This is possible by taking into accounts feed-
forward terms. For SISO linear models (like those treated in this book), a
proportional–integral–derivative controller (PID) results in control loop feed-
back mechanisms widely used in industrial power electronics-based systems
and a variety of other applications requiring continuously modulated control.
A PID controller continuously calculates an error value e(t) as the difference
between the set point y ∗ (t) and the measured variable y(t). Based on this
evaluation, the controller applies a correction based on proportional, integral,
and derivative actions. Note that, PID controllers are present in the industrial
fields since the early 1920s (automatic steering systems for ships).
In general, any closed-loop control scheme for SISO models can be repre-
sented by the block diagram shown in Figure 5.1.
DOI: 10.1201/9781003196938-5 51
52 Designing a Closed-Loop Control System
Measurement
dx(t)
= Ax(t) + Bu(t) (5.1)
dt
y(t) = Cx(t) + Du(t) (5.2)
y(t) y(s)
G(s) = = = C(sI − A)−1 B. (5.6)
u(t) u(s)
Namely, G(s) is defined through the ratio between the Laplace transform
of the output y(s) and the Laplace transform of the input u(s). Note that,
the mapping t ← s holds. Thus, y(t)/u(t) = y(s)/u(s). This equality will
be considered in the definition of other transfer functions in the following.
Equation (5.6) directly links to Figure 5.1.
54 Designing a Closed-Loop Control System
u(s) kp (1 + sTi ) ki
R(s) = = (series) or R(s) = kp + (parallel)
e(s) sTi s
(5.8)
where kp , ki are the proportional and integral gains, respectively, while Ti
is the integration time defined as Ti = kp /ki .
Figure 5.2 Example of L (s) obtained through pole/zero cancellation and its
properties detailed through a Bode diagram.
Pole/Zero Cancellation
By considering (5.7), the open-loop transfer function can be computed as:
kp (1 + sTi ) 1/a
L(s) = (5.11)
sTi 1 + s (b/a)
If Ti = τG = b/a is imposed, the so called pole/zero cancellation is performed,
which is rather typical for first-order systems:
kp /a
L(s) = (5.12)
sTi
This transfer function behaves as a pure integrator as shown in Figure 5.2,
thus φm ∼
= 90°, and it has a cut-off frequency which is defined by the controller
parameters
(if Ti = b/a)
kp /a kp kp /b
,1 → ωc = = (5.13)
(if Ti = kp /ki )
sTi
s=jωc aTi ki /a
In practice, L(s) and F (s) are subjected to the same time constant, which
can be denoted as τF . Having an explicit form, kp and ki can be computed
as functions of ωc . For instance, by considering ωc = kp /b → kp = ωc b from
(5.13), kp may be replaced in the expression of Ti = kp /ki = ωc b/ki , which is
equivalent to Ti = b/a = ωc b/ki , which leads to ki = ωc a. Finally:
k p = ωc b ki = ωc a (5.14)
How to use the explicit forms: assume that y(t) is required to follow a
step-wise reference y ∗ (t) within a specific settling time Ta,F . For instance, the
Design a PI Controller in Continuous-Time Domain 57
requirement might be Ta,F Ta,G , i.e., to speed up the open loop dynam-
ics by adopting a (closed) control loop. Since the final (closed-loop) settling
time is defined as Ta,F = 5τF , τF = Ta,F /5 can be computed, which repre-
sents the dominant time constant (i.e., associated to the dominant pole) of
F (s). Therefore, by choosing the cut off frequency ωc as ωc = 1/τF in rad/s,
and considering the other time-invariant parameters, all the ingredients are
available to derive kp , ki by substitution.
Generalized approach
The pole/zero cancellation is particularly suitable for 1st order linear systems.
If the system is higher-order, a different procedure should be adopted. In
general, the following formulas can be exploited:
where each parameter is function of the cut-off frequency ωc and the phase
margin φm . Of course, by using the same hypothesis on Ti for the zero pole/-
cancellation, the same results shown in (5.14) can be derived. Note that
much flexibility on the performance of the system is achieved compared to
the pole/zero tuning
Mathematical Proof
A generalized open loop transfer function cuts the 0 dB axis at ωc with phase
margin φm . In this point, its frequency response can be evaluated as:
ki 1
kp − j = [ cos (φm − π − arg (G(jωc ))) + ...
ωc |G(jωc )|
ki 1
kp − j = ... + jsin (φm − π − arg (G(jωc ))) ] (5.21)
ωc |G(jωc )|
By computing the real and imaginary parts of the previous equation, kp and ki
are obtained as reported earlier. All the angles must be considered in radians.
p
MATLAB® interface: pidTuner() and pidtune()
A third alternative for PI tuning is to use control design tools from Simulink® ,
e.g., pidTuner() and pidtune() from Control System Toolbox™ . In partic-
ular, pidTuner() allows to work with a user friendly tool (with a graphic
user interface as well) for simple step-response-based identification of a pro-
cess model, fast PID controller tuning and effective quality evaluation of the
control in the MATLAB® framework.
Regarding the control design, either time-domain or frequency-domain
approaches can be chosen. As an example, the MATLAB® commands
pidTuner(sys) or pidTuner(sys,PI) launch the user interface which allows
to design a desired controller for the system sys under investigation, which
in our case relates to G(s). The properties of the tuned controller can be sim-
ply and visually judged by the PID Tuner window using a simulation of the
closed-loop step response. Indeed, this tool displays the plot of the simulated
control response and the time behavior of the manipulated variable. It is easy
to compare several step responses generated with different values of kp and
ki , set points, disturbances and constraints on the manipulated variable.
pidtune(sys,’PI’,bandwidth,opt);
with
opt=pidtuneOptions(’PhaseMargin’,phase_margin);
The result is a structure called pid which contains the kp and ki coefficients
as field of this new variable type.
Note that booth approaches use the generalized formulas presented in the
previous section. In particular, the pidTuner() interface use pidtune() as
sub-function to compute the controller parameters.
60 Designing a Closed-Loop Control System
z−1
G(z) = G s = (5.24)
Ts (αz + 1 − α)
where Ts is the sampling time and 0 ≤ α ≤ 1 defines the type of discretization.
Indeed, equation (5.24) refers to a generalization of a bilinear transformation
which could result in:
The trapezoid rule is also called Tustin’s method in digital control commu-
nity. The continuous-time transfer function G(s) shows a stable behavior when
the poles have negative real part. In discrete-time, this translates in a G(z)
with poles inside the unitary circle. The coefficient α influences such stability
because a different integration method results in a different mapping, with
different boundaries for the pole/zero locations. The three mappings are sum-
marized in Figure 5.4. However, it is possible to find a large number of other
Derive a PI Controller in Discrete-Time Domain 61
Forward Euler Backward Euler Tustin
Im Im Im
s z
s z s z
1 Re 1 Re 1 Re
• Forward Euler - if the discrete form is stable, also the continuous one is
stable too, but not vice versa;
• Backward Euler - if the continuous form is stable, also the discrete one is
stable too, but not vice versa;
• Trapezoid if the continuous form is stable, also the discrete one is stable too,
and vice-versa.
Note that the convergence region depends both on the integration method
itself and on the considered sampling time width as well. High Ts enlarges the
mapping areas. This might create a great amount of mapping distortion, even
leading to instability problem if the unitary circle is violated.
Another important property of the z-domain lies in the fact that the quan-
tity z −1 is equivalent to a unitary delay in the discrete time domain. This cor-
respondence allows to calculate the output of a generic regulator as function
of the inputs/output at the previous time steps.
In particular, Figure 5.5 shows how to interpret the described Back-
ward Euler integration method, where k denotes the discrete-time steps. This
method is adopted in the following sections.
For an exhaustive explanation of the z-transform theory, the reader is
referred to [2].
2 In multi-step methods, several points are used to evaluate the output at each time
step. These ones are characterized by a higher accuracy as the number of steps increases,
but they imply a big number of variables to be managed by the microcontroller, i.e., high
computational burden.
62 Designing a Closed-Loop Control System
• Represent the closed loop system as shown in Figure 5.6 (a) or (b).
Derive a PI Controller in Discrete-Time Domain 63
(a)
(b)
Figure 5.6 Example of discrete closed-loop control system (a) and discrete
controller (b). The scheme reported in (b) includes analog to digital (A/D)
and digital to analog (D/A) converters as interfaces between the hardware
and the real system.
Even if Figure 5.6 (a) and (b) includes the same controller R(z), they
differ on how the rest of the scheme is defined. In particular, Figure 5.6 (a)
considers a discrete transfer function G(z), which is then used to compute L(z)
and F (z) as reported in equations (5.25) and (5.26). Differently, in Figure 5.6
(b) the discretized controller is interfacing the system model in continuous-
time domain, i.e., G(s), through analog to digital (A/D) and digital to analog
(D/A) converters operating at the sampling time Ts used for the discretization.
In Simulink® , the operations of both converters can be mimicked with Rate
Transition blocks.
In any case, both methods starts from the results of the design in
continuous-time domain, i.e., based on G(s) via s.
As a reminder, note that G(z) may be directly derived by discretizing (5.1)
and (5.2), thus, deriving discrete-time differential equations such as
0 0
x(k + 1) = A x(k) + B u(k) (5.27)
0
y(k) = C x(k) (5.28)
0 0 0
The new matrices A , B and C have to be computed according to one of
the previously described discretization method.
6
Design Example: PI-Based Current Control of
an RL Load
In order to apply the design rules presented in the previous chapter and to
show how to tailor them to a power electronics-based control problem (as
a complete exercise), a simple RL (ohmic-inductive) load circuit fed by a
controllable voltage source is considered as a case study (see Figure 6.1).
The system parameters and the desired characteristics of the controller are
reported here in the following:
• Data:
R = 25 mΩ and L = 100 mH → τG = L/R = 4 s, thus, Ta,G = 5τG = 20 s
• Objectives: reference tracking
y ∗ (t ≥ 1 s) = 3 A and Ta,F = 1 s, thus, τF = Ta,F /5 = 0.2 s
The aim of this exercise is to design a current control loop, i.e., to control the
current flowing into the winding i(t) according to a given step-wise reference
i∗ (t), by using a PI controller while achieving a final settling time of Ta,F = 1 s.
In particular, the reference changes from 0 A to 3 A (i.e., Yss = 3) at t = 1 s,
holding this value until the end of the simulation.
According to Figure 6.1, v(t) is the voltage of a variable voltage source (e.g.,
a controllable DC voltage supply), while R and L are the circuit parameters.
Applying the Kirchhoff’s voltage law, it follows that:
di(t)
v(t) − Ri(t) − L =0 (6.1)
dt
R
RL load
y (t) e (t) Current u (t) y (t)
controller G (s) +
+ u (t) L
− −
x (t)
(a) (b)
DOI: 10.1201/9781003196938-6 65
66 Design Example: PI-Based Current Control of an RL Load
which is a differential equation describing a 1st order linear system. The volt-
age v(t) is the controllable variable, i.e., u(t) = v(t), which allows to in-
crease/decrease the current flow according to the system parameters. Hence,
such current control is based on the manipulation of the input voltage. By
considering x(t) = i(t) and y(t) = x(t), the state-space representation shown
in equations (5.1) and (5.2) is achieved considering A = −R/L, B = 1/L, and
C = 1.
Then, the transfer function of the continuous-time linear system is defined
as follows:
Given R(s) of the same kind as that one reported in equation (5.8), the open-
loop transfer function is:
1 kp = ωc L = 0.50 Ω
Ta,F
Ta,F → τF = → ωc = = 5 rad/s →
5 τF ki = ωc R = 0.125 Ω/s
(6.4)
Therefore, the computed kp and ki parameters ensure the command-tracking
performances and, given L(s) as a minimum phase system (mps), the phase
margin φm is about 90° (i.e., high robustness). It must be noted that kp and
ki have precise unit values, which in this case are Ω and Ω/s, respectively. The
resulting closed-loop transfer function is:
L(s) 1 1 1
F (s) = = = = (6.5)
1 + L(s) 1 + sTi 1 + s (L/R) 1 + s (kp /ki )
At this point of the design procedure, all the characteristics of F (s) are known.
The next step is to numerically simulate the system.
1 Note that Simulink® supports both floating-point and fixed-point computations, as well
Figure 6.2 Relationship between system dynamics and time step [32].
thermal, and other physical aspects for modeling and simulating applica-
tions such as electromechanical actuation, drives, smart grids, and renew-
able energy systems. This book mainly refers to blocks from the Simscape™
Electrical™ Specialized Power Systems library, which can be found by clicking
in the Simulink® library browser: Simscape → Electrical → Specialized Power
Systems. For further information, the reader is referred to the MathWorks®
website [30].
Using both standard blocks or Simscape™ components, analog (passive
or active) and digital components can be modeled and simulated to validate
the design of closed-loop control algorithms as well as the supervisory logic
through real-time simulations.
system behavior, the simulation will run fast. Assuming that the same system
has to be installed in a real harsh environment (e.g., the power train of an
electric vehicle) which is sensitive to temperature variations, the model should
include a detailed power electronics switching behavior, effects of temperature
on electrical efficiency, as well as the nonlinear model of the inductor, resulting
to be mathematically more complex than before. As a result, the simulation
will run really slow.
Before performing real-time simulations, the very first task is the initial-
ization of all the needed parameters. In this book, this procedure is done using
MATLAB® code by creating a script/source file (.m or m-file) that is called in
Simulink® from the Model Properties → InitFcn callback (the .m file is exe-
cuted every time the Simulink® model is running) or as PostLoadFcn callback
(the .m file is executed only once). Nevertheless, the .m file could be even ex-
ecuted manually, thus, without creating such automatic routine in Simulink® .
• The controller is implemented using the standard block PID Controller from
the library Continuous;
• The RL load is emulated through a transfer function (tf), i.e., a stan-
dard block, or building an equivalent circuit with blocks available in the
Simscape™ library. Thus, the user has the possibility to select which one of
the two modeling strategies should be included in simulation and then run
it.
The full scheme is shown in Figure 6.4. The possibility to switch between
the two load emulations is ensured by the manual switch Sw2 which is a stan-
dard block from the Simulink® library. Every double-click done on the block
changes its connection. Note that Figure 6.4 includes a further stage enabled
through Sw1, which can add a saturation block (standard block) to bound
the actuation signal u(t). This will be discussed in details later in Section 6.2
referring to the windup effects. Thus, it is anticipated in Figure 6.4 just for
(a) (b)
Continuous
Current Measurement
i
+
-
+
v(t) RL
y(t)
[yr] Goto
no saturation
s
-
discrete PI controller From
reference step
y*(t)
[yr]
e(t) e(k) u(k) u(t) y(t)
y*(t) PI(z)
y(t) Sw1 Sw2
saturation y(t)
m(t) [e]
e(t)
[u]
u(t)
G(s) [m]
[e] [u] [m] m(t)
using transfer function sat
Figure 6.4 Simulink® scheme of a current control for an RL load using both
standard and Simscape™ blocks. Rate Transition blocks are inserted to mimic
the behavior of the A/D and D/A converters (see Figure 5.6 (b)).
where num and den are matrices that contain the coefficients of the numera-
tor and denominator ordered in descending powers of s with order n and m,
respectively. For SISO systems (as in this example), these scalar coefficients
have to be entered as vectors: numerator coefficients: [1] → num(1) = 1
with n = 1; denominator coefficients: [L R] → den(1)s = L s, den(2) = R
with m = 2; zero initial condition.
(a) (b)
line) with Ta,F ≈ 0.6 s; 2.97 A for ≈ 1% (black dotted line) with Ta,F ≈ 1 s.
Therefore, the definition of the settling time in terms of accuracy is necessary
to classify the performances of the systems and to compare them, e.g., the
comparison among two systems must refer to the same degree of accuracy to
understand which behaves better. From now, the proposed procedure refers to
the design guidelines reported in Chapter 5, in which ≈ 1% is suggested as
reference accuracy, thus, entering in the region [(1 − 0.01)Yss (1 + 0.01)Yss ],
where Ta = 4 ÷ 5τ holds. It results that Ta,F = 1 s < Ta,G = 20 s and
τF = Ta,F /5 = 0.2 s < τG = 2 s, so the closed-loop control system is going to
be ten times faster than the open-loop one.
The effectiveness to achieve the desired steady-state value Yss can be ver-
ified via the final value theorem. Since the Laplace transform of a step-wise
signal in time-domain is µs /s, where µs is the amplitude value (i.e., 3 A), by
multiplying F (s) = y(s)/y ∗ (s) with µs /s it results Yss = F (s)µs /s. Namely:
µs µs
lim sYss = lim sF (s) = lim = µs = 3 A (6.7)
s→0 s→0 s s→0 1 + sTi
Note that the results holds for every considered value of Ti , that is, for every
design choice.
Based on Figure 6.5 (b), the command-tracking performances are achieved
thanks to the sudden change of the input voltage u(t) = v(t) at t = 1 s. In
particular, the error e(t) and the control variable u(t) are following a decay
which is equal (but mirrored) with respect to y(t), as shown in Figure 6.5 (a).
At steady-state, e(t) = 0 while u(t) 6= 0 since the system changed its operating
point and a certain voltage is necessary to assure the required current flow.2
This is still a consequence of the Kirchhoff’s law, where at steady-state the
current derivative can be neglected while computing the voltage value,3 that
is:
di(t)
v(t) − Ri(t) − L =0 → Uss = Vss = RIss = RYss = 0.075 V (6.8)
dt
Given the aforementioned parameters and performances, the designed PI con-
troller achieves all the specifications.
After this first design, the controller parameters are modified to evaluate
the potential issues due to a wrong design. Two scenarios are considered and
the performances of the new controllers are compared to the previous one (the
correctly designed one). The plots shown in Figure 6.6 reports the behaviors
of all the design controllers.
2 Note that a voltage drop is always present among the inductor (and its internal series
(a) (b)
More specifically, the two new controller are designed such that:
1. Integral action is removed, i.e., ki = 0.
It is worth noting that a simple P controller keeps a permanent
offset at steady-state. The kp action contributes to quickly increase
the voltage only, bringing the output close to the current reference.
The distance between y (t) and y ∗ (t) depends on the value of kp .
In case of a P controller, no pole/zero cancellation is possible. The
open-loop and closed-loop transfer functions simply result:
1 kp
L(s) = kp F (s) = (6.9)
R + sL kp + R + sL
Then, the cutoff frequency can be computed by imposing
|L(s)|s=jωc = 1. It can be easily proved that this equality leads
q
to ωc = kp2 − R2 /L. If the considered bandwidth is again ωc =
5 rad/s, the resulting kp is obviously different. Moreover, the ap-
plication of the final value theorem on the controlled system leads
to:
µs kp µs kp µs
lim sF (s) = lim = (6.10)
s→0 s s→0 kp + R + sL kp + R
where the result is kp -dependent. An increase in kp might improve
the reference tracking, while the offset persists since it could be
zeroed only if kp → ∞. This also implies that a lower voltage effort
u(t) than before might be used to keep a (wrong) steady-state value
i(t).
2. kp is kept equal to that one of the previous controller, while ki is
chosen ten time larger, i.e., 10 × ki .
Derive an Anti-Windup PI Controller Scheme 77
Saturation RL load
y (t) e (t) Current u (t) m (t) y (t)
G (s)
+ controller
−
(a)
1.5
0.5
-0.5
-1 -0.5 0 0.5 1 1.5 2 2.5 3
(b)
Figure 6.7 Closed-loop control scheme with saturated actuation (a) and ex-
ample of saturated output (b).
where m(t) is the actuation variable. Since the control variable is a voltage
level, umin and umax are minimum and maximum allowed voltages that the
DC power supply can output, that is, vmin and vmax . For this case study, a
(fictitious) unidirectional DC power supply which is able to provide a vari-
able voltage from umin = 0 V to umax = 0.5 V is assumed to be available. If
these limitations are introduced in the proposed model as reported in equation
(6.11), the closed-loop scheme changes as shown in Figure 6.7 (a). The satu-
ration block receives umin as input and it outputs umax . There is a Simulink®
block that can mimic this behavior among the standard ones under the name
saturation. From now on, a discrimination is introduced between:
• u(t), that is, the control variable returned by R(s) as results of the control
design (i.e., output of the PI controller);
• m(t), that is, the actuation variable seen by the RL load, where m(t) could
saturate depending on the value assumed by u(t).
From the controller perspective, note that the previous design of R(s) does
not include any information regarding the saturation of u(t).
Indeed, Figure 6.8 (a) reports the transient response of the previous control
scheme without saturation (blue dotted line), the related command-tracking
Derive an Anti-Windup PI Controller Scheme 79
4.5
3.5
2.5
1.5
0.5
(a) (b)
performances and the evolution of the same system including saturation effects
(blue solid line). For this latter, the output y(t) takes long to reach the steady-
state condition due to the windup effect of the integrator, which also generates
an overshoot.
Moving to Figure 6.8 (b), since R(s) operates regardless any saturation
limit, the voltage is required to be u(t) = 1.5 V at time instance t = 1 s to
bring y(t) closer to y ∗ (t) = Yss = 3 A. However, the DC power supply is able
to feed only m(t) = umax = 0.5 V. Thus, the system is fed by this maximum
voltage value. At the following time instant, the output y(t) do not increase as
expected due to a lower actuation. This limitation implies a larger error e(t)
compared to the unsaturated case, which shows an higher y(t) due to an higher
actuation signal (which has a peak value exactly equal to u(t)). The effects of
this saturation on u(t) and y(t) are more clear as long as u(t) returns below
umax , which enables the system to re-enter into the linear region. Nevertheless,
the effects due to the presence of a large error are still present. Thus, even if
m(t) = u(t), the system requires a long time to reach the steady state and it
shows an overshoot as well.
This is a well-known problem which has a really practical explanation.
More specifically, the windup effect is mainly due to the integrator part of the
PI controller, which for u(t) > umax keeps integrating the tracking error e(t)
producing m(t) 6= u(t). When m(t) = u(t), the controller re-enters into the
linear region behavior. This means to wait for the integrator discharge (also
called integral discharge time or de-saturation time), which depends on the
integration area defined by the unsaturated u(t) (yellow area in Figure 6.8
(b)).
This effect is particularly clear in Figure 6.9, which includes a further
simulation of a system with a stricter voltage limitation, i.e., umax = 0.3 V.
The larger the integrating area, the longer and the stronger the windup
effect. So, the case with saturation set at 0.3 V implies a longer windup and
80 Design Example: PI-Based Current Control of an RL Load
(a) (b)
Figure 6.9 Comparison between different transient responses and the related
windup effects.
a quite larger settling time Ta,F , keeping = 1%. To mitigate the windup
problem, the controller must be augmented according to one of the many anti-
windup schemes available in the literature. In this book, the back-calculation
principles are considered, which lead the compensation schemes reported in
Figure 6.10.
By exploiting the block schemes theory, it can be proven that the diagrams
reported in Figure 6.10 (a) and (b) are equivalent, creating both an anti-
windup compensation. The back-calculation method uses a feedback loop to
discharge the integrator when the controller hits specified saturation limits,
avoiding to enter in nonlinear operations. The back-calculation coefficient kaw
is computed as kaw = 1/Ti = ki /kp . This time, constant Ti determines how
quickly the integrator of the PI controller is reset by the anti-windup loop.
The regulator reported in Figure 6.10 (a) is subjected to the continuous-time
equations reported here in the following:
if
umin umin ≥ p(t)< umax
u(t) = sat (p(t)) kp e(t) + 1
1+sTi u(t) if umin < p(t) < umax (6.12)
umax if umin <p(t) ≥ umax
where p(t) is an auxiliary variable used to keep the notation short. Therefore,
the key aspects of an anti-windup scheme can be summarized as:
• No effect when the actuator is not saturating, i.e., within the linear region
controllers with and without anti-windup scheme behave the same;
• Just one additional parameter kaw = 1/Ti is required;
• If the saturation limits are not clearly specified, a mathematical model of
the actuator should be used.
Derive an Anti-Windup PI Controller Scheme 81
Current regulator
e (t) u (t)
kp
+
+
1
1 + sTi
(a)
Current regulator
kp
+
e (t) 1 u (t)
ki
+ s +
+
− +
kaw
(b)
Both schemes reported in Figure 6.10 share the idea to include the satu-
ration limits as thresholds inside a suitable saturation model. This latter may
be just implemented by looking at the data sheet of the DC power supply
or derived by using some identification techniques, especially in case where
those limits are uncertain. Note that, in this case, it is quite easy to define the
saturation limit. However, this is not always the case, e.g., accurate describe
magnetizing phenomena or skin effects are not always available.
(a) (b)
Note that the controller design has been started in continuous-time toward
discrete-time domain. This is necessary to meet the working principle of em-
bedded platforms, i.e., systems with discrete nature. Nowadays, this technol-
ogy represents the main industrial standard for power electronic-based appli-
cations (and many more) instead of using the more historical analog control
systems. Their difference is shown in Figure 6.12 which consider a closed-loop
voltage control scheme.
The proposed discrete-time domain approach led to a Simulink® -based
scheme suitable for the automatic code generation features. More details on
this topic are reported in the upcoming chapters.
7
Manipulate the Variables Format: Data Types
The main objective of this book is to empower the reader with the ability to
work and coding with standard MCU. As already discussed in the previous
sections, due the discrete/digital nature of embedded systems, tuning and sim-
ulations of power electronic setups are carried out in the discrete-time domain.
Nevertheless, real implementations of control algorithms could not be possible
without considering even the hardware structure of a MCU. Clock frequency,
maximum sampling time, memory storage, peripherals resolution, computa-
tional capabilities are just some examples of hardware-based requirements and
specifications. In particular, the computational capability of a MCU is defined
by the nature of the variable which may be involved in the computations and
the type of operations they are asked to perform. The underlying concept is
also called data-type analysis.
Fixed point: fixed point format exploits the two’s complement represen-
tation to allow the computations between rational numbers. The positive and
negative extreme values differ by one least-significant bit (LSB). Keeping a
32 bit word length, the bit format is:
SI
|{z} .f f f f f f f f f f f f f f f f f f f f f f f f f f f f f f (7.1)
| {z }
2 bit integer 30 bit quotient(fraction)
which is also called 2Q.30 (or just IQ30), where the 30 “f ” represent the
number to the right of the radix point.
Instead, the two remaining bits on the left side of the radix point represent
the integer part of the number. Namely “S” is the sign bit, where 0 is allocated
for positive numbers and 1 for negative ones, and one single bit “I”. Hence,
the maximum positive value of the integer part of such numbers is decimal
DOI: 10.1201/9781003196938-7 85
86 Manipulate the Variables Format: Data Types
“1” (i.e., integer bits S = 0, I = 1) and the minimum decimal value is “−2”
(i.e., integer bits S = 1, I = 0).
Floating point: The bit format for floating-point numbers is
S eeeeeeee
| {z } .f| f f f f f f f f f f{z
ffffffffffff (7.2)
}
8 bit exponent 23 bit quotient(fraction)
Example
As an example, Figure 7.2 shows how the value x = 0.15625 is represented in
floating point format. Namely, x is split in terms of bits as follows:
Table 7.1 Comparison of 32 bit floating and fixed point representations: ranges
and resolutions.
±2 (255−127)
(1 − 2 −23
)ˇ (2 − 2−30 ) ˇ
Max. decimal
value 3.4028 · 1038 1.9999999991
Min. decimal ±1.1755 · 10−38 −2.000000000
value
• Sign: S = b31 = 0
(−1)S = (−1)0 = +1 ∈ {−1, +1}
P7
• Exponent: e = (b30 b29 . . . b23 )2 = i=0 b23+i 2 = 124 ∈ {1, . . . , 28 − 1 −
+i
1} = {1, . . . , 254}
• 2(e−127) = 2124−127 = 2−3 ∈ {2−126 , . . . , 2127 }
P23
• Fraction: 1.b22 b21 . . . b0 = 1 + i=1 b23−i 2 = 1 + 1 × 2 = 1.25 ∈ {1, 1 +
−i −2
2 , . . . , 2 − 2 } ⊂ 1; 2 − 2
−23 −23 −23
⊂ [1; 2)
Thus:
To the aim of providing a better understanding of the floating and fixed point
representations, they are compared in Table 7.1.
The floating point format range is much wider than the fixed point one, but
this advantage comes with the penalty of a less favorable relative resolution,
for which the eight bits used for the exponent are not available for resolution.
For both floating and fixed point formats, the radix point can be moved
to any location within the 32-bit word to manage the trade off between range
and resolution.
88 Manipulate the Variables Format: Data Types
Bits Usage
63 Sign (0 =positive, 1 =negative)
62 to 52 exponent, biased by 1023
51 to 0 Fraction f of the number 1.f
Remark
A signed 32-bit integer variable has a maximum value of 231 −1 = 2147483647,
whereas a 32-bit base-2, floating-point variable can reach numbers up to
(2 − 2−23 ) × 2127 ≈ 3.402823 × 1038 .
It is important to note that all integers with six or fewer significant digits
as well as any number that can be written as 2n (with n ∈ [−126, 127]) can
be converted into floating-point values without any loss of precision.
Bits Usage
31 Sign (0 =positive, 1 =negative)
30 to 23 exponent, biased by 127
22 to 0 Fraction f of the number 1.f
Double Precision
Since the default numeric type for MATLAB® is double, any double-precision
number can be declared with a simple assignment statement:
x = 25.783;
The function whos shows the information associated with variable x, that is
a 1-by-1 array of type double which is stored in 8 bytes, as reported in the
following:
>> whos x
Name Size Bytes Class Attributes
x 1x1 8 double
Instead, the function isfloat can be used just to verify that x is a floating-
point number. This function returns logical 1 (true) if the input is a floating-
point number and logical 0 (false) otherwise.
90 Manipulate the Variables Format: Data Types
>> isfloat(x)
ans=
logical
1
Other numeric data, characters or strings, and logical data can be converted
to double precision using the function double(). The example reported here
in the following converts a signed integer number to double-precision floating
point one:
Single Precision
Conversion functions are needed in MATLAB® to create floating point single-
precision variables starting from the default data type:
x = single(25.783);
The whos() function can be used to store the characteristics (i.e., name, size,
bytes, class, attributes, as shown previously) of variable x in a structure. For
example, the bytes field allows to verify that single variables require 4 bytes
only:
xAttrib = whos(’x’);
>> xAttrib.bytes
ans=
4
Instead, functions double() and single() can convert other numeric data,
characters or strings, and logical data to single precision variables. The ex-
ample reported here in the following converts a signed integer number to
single-precision floating point one:
Example
Given Ib = 20 A as base value and Nbit = 6 bit, translate the current value
into scaled integers considering i(t) = 17.5 A and 10.2 A.
I Nbit 17.5 6
#i6 = 2 = 2 = 56 (7.7)
Ib 20
10.2 6
#i6 = 2 = 32.64 ≈ 32 (7.8)
20
Note that the data conversion is not exact in the second case. Thus, an ap-
proximation error is introduced. Such error is inversely proportional to the
selected number of bits for Nbit .
Regarding the value adopted for Nbit , it is possible to determine the maximum
and the minimum numbers that can be represented. Thus, for Nbit = 6 bit:
• Sum: in the worst case scenario, where both addends assume the maximum
allowed value, it follows that 4095 + 4095 = 8190 < 32767 → no overflow.
• Product: this operation behaves differently with respect to the sum. To
the aim of providing a better understanding to the reader, an example is
exploited starting directly from p.u. representation:
xa = 3.56790
→ xc = xa · xb = 4.54490 (7.10)
xb = 1.27383
Example
A value of 0.375 is consider. Knowing that 0.375 = (1.1)2 × 2−2 , the exponent
is −2 and in the biased form it is 127 + (−2) = 125 = 0111 1101. The fraction
is 1 by looking at the right part of binary sequence 1.1 (1 = b22 ). Finally, the
resulting single representation of the real number 0.375 is:
Summary
Computational efforts required by the design of firmware running on an em-
bedded platform is dependent on the type of required operations and by the
nature of the variable involved in such calculations. Due to the reduced avail-
ability of computational power, it is a best practice to avoid the introduction
of complex numerical structures like float or double in the code. The best
96 Manipulate the Variables Format: Data Types
Real-Time Control in
Power Electronics:
Peripherals Settings
Introduction
DOI: 10.1201/9781003196938-7 99
8
Basic Settings: Serial Communication COM
and Hardware Target
1 Baud rate refers to the number of signal or symbol changes that occur per second.
To obtain the actual Bit/Rate the formula is: BitRate = BaudRate × nBit where nBit is
the number of bit required to represent that symbol.
(a) (b)
Figure 8.1 Device Manager window (a) and port properties window for
XDS100 Class Auxiliary Port (b).
The virtual COMx is not only used for communication (data exchange)
purposes, but as programming interface too, i.e., letting the JTAG2 Debug
Flow. Indeed, many C2000 MCU boards have a JTAG emulator implemented
on-board and they do not require an external one. Unless there is an appli-
cation requirement, TI suggests using the onboard emulator for development
purposes. The XDS100 and the XDS110 are two target emulators that are
found on TI C2000 Evaluation Modules. For completeness, note that those
emulators are physically connected to:
For the JTAG emulator to communicate the PC, the driver files need to be
installed. Their installation typically occurs co-incident to the installation of
2 The use of JTAG in embedded systems aims to development, debugging, and testing.
JTAG uses a 5-pin implementation in most systems: TDI (Test Data In), TDO (Test Data
Out), TCK (Test Clock), TMS (Test Mode Select), TRSTn (Test Reset).
Virtual Serial Communication through COM port 103
Code Composer Studio. To check that the drivers are successfully installed, it
is enough to connect the PC to the JTAG emulator and power it up.
Remark
The Target Configuration File (.ccxml) contains the information necessary
to connect the PC to target device and the JTAG emulator being used. To
view the current target configurations, select Target Configurations under the
“View” tab in CCS.
9
Simulink® Configuration
Every time a blank Simulink® project is opened, the following steps must be
implemented/verified to assure a correct automatic C-code generation and
firmware deployment on the target microcontroller:
onboard the LaunchPad™ . Otherwise, the code is temporarily stored in the RAM memory
of the board not allowing any stand alone executions.
Simulink® Environments: Firmware vs Testing 107
9.1.1 Overview
The Simulink® environment is used both to design the control system firmware
and to test it giving inputs from the host PC to the microcontroller. In order
to differentiate better the code running inside the MCU from the simulation
test code, two different .slx files are built:
1. Firmware.slx: this is the Programming Environment for the
MCU, where the internal algorithm is built. It defines the pro-
grammable logic that the input/output peripheral has to follow
(see Figure 9.3 (a)). It is mainly subejct to the samplig time Ts . By
means of automatic code generation, this Simulink® file is translated
into executable implementation through the following steps:
(a)
(b)
• To run the simulation file testing.slx, click on the Run button on the
Simulation bar.
MCUs and Real-Time Control with Simulink® 109
program the platform through the JTAG cable. The latter will be also used
as a virtual serial port to exchange data and provide touting actions. More
complex exercises requires the effective presence of both converter and load
stages in addition to custom interface boards.
An example of complex control system is provided in Figure 9.6. Here in
the following, the required hardware will be detailed at the beginning of every
exercise.
Figure 9.6 Example of a motor control test bench based on the LaunchPad™
F28069M Piccolo™ programmed by the host PC (see Appendix B).
10
Serial Communication Interface (SCI)
Peripheral
the interfaces of the communicating endpoints are not continuously synchronized by a com-
mon clock signal. Instead of a common synchronization signal, the data stream contains
synchronization information in form of start and stop signals before and after each unit of
transmission.
2 Full-duplex communication is adopted in point-to-point systems and it means that
unreadable values. Hence, the transmission rate (both baud rate and sampling
time) should be set considering the computational load given by the firmware.
• Both external pins can be used as GPIO if they are not used for SCI, thanks
to a suitable arrangement of jumpers JP6 and JP7 (see Table 3.2).
• The baud rate is programmable up to 64000 different rates. However,
115 200 baud/s is the standard value adopted in all the exercises reported in
this manuscript.
Firmware Environment: Send and Receive Data through Serial Communication 113
which ones are represented by one significant condition, usually a positive voltage, while
zeros are represented by some other significant condition, usually a negative voltage, with
no other neutral or rest condition.
114 Serial Communication Interface (SCI) Peripheral
C28x C28x
Data Data
Figure 10.2 SCI Receive (SCI RCV) and Transmit (SCI XMT) blocks to for
programming C2806x processors.
Block Parameters:
• SCI Module
This label sets the SCI module which is adopted for communication. For the
LaunchPad™ F28069M it can be A or B.
Remark: this setting should match with the Serial Send block channel
selected in the Testing Environment (i.e., added inside the testing.slx file,
see Section 10.3.2).
• Additional Package Header
This field specifies the data located before the received data package. It gen-
erally indicates the start of data. The additional package header must be an
ASCII value. A string or number (0–255) can be used. Single quotes around
strings must be entered in this field, but the quotes are not received or in-
cluded in the total byte count. To specify a null value (no package header),
enter two single quotes alone ”. Additional package headers specified here
must match with that one entered in the Serial Send block placed in the
testing.slx file (see Section 10.3.2).
• Additional Package Terminator
This field specifies the data located at the end of the received data package.
It generally indicates the end of data. The additional package terminator
must be an ASCII value. A string or number (0–255) can be used. Single
quotes around strings must be entered in this field, but the quotes are not
received nor included in the total byte count. To specify a null value (no
package terminator), enter two single quotes alone ”. Additional package
terminators specified here must match with that one entered in the Serial
Send block placed in the testing.slx file (see Section 10.3.2).
Firmware Environment: Send and Receive Data through Serial Communication 115
• Data Type
This option specifies the data type of the output data. Available options are
int8, uint8, int16, uint16, int32, uint32 and single.
• Data Length
This value specifies the size of data that the block should receive at each
time step. Numbers greater than 1 indicate that arrays are transferred. The
data length must match the input data length, which is sent through the
Serial Send block in the testing.slx file (see Section 10.3.2).
• Initial Output
This parameters sets the output default value from the SCI Receive block.
This value is used, for example, if a connection time-out occurs and the
Action taken when connection timeout field is set to Output the
last received value, but nothing has been received yet.
• Action taken when connection times out
This label allows to specify the output in case a connection time-out occurs.
If Output the last received value is selected, the outputs return the last
received value. If no value is received, the SCI Receive block outputs return
the Initial output value. If Output custom value is selected, the custom
value is set through the parameter Output value when connection times
out.
• Output value when connection times out
Parameter that sets the output time-out custom value.
• Sample Time
This field specifies the sample time Ts in seconds for input sampling of the
block. To inherit sample time and to execute this block asynchronously, set
it equal to −1.
• Output receiving status
By enabling this feature, a status block providing the status of the serial
communication is created.
• Enable Receive FIFO interrupts
If this option is selected, an interrupt is posted when the FIFO is filled with
a specified amount of data, allowing the subsystem to perform any action.
For example, the C28x Hardware Interrupt block can be used for triggering
the SCI Receive block to read the data as soon as it is received. If the option
is not selected, the SCI Receive block is in polling mode and it checks the
FIFO for data. If any data is present, the block reads and outputs it. If data
is not present and blocking mode is enabled, the block waits until data is
available. In non-blocking mode, the block goes on with the execution of the
algorithm without waiting for any received data.
116 Serial Communication Interface (SCI) Peripheral
Figure 10.3 Examples of Rate Transition and Data Type Conversion blocks
connected to a SCI Transmit block.
Block Parameters:
The block parameters of C2806x SCI Transmit are less than C2806x SCI
Receive, but with the same meaning. In particular they are: SCI Module,
Additional Package Header, Additional Package Terminator, Enable transmit
FIFO interrupts, Transmit FIFO interrupt level. See the previous section for
further details.
Remarks
The transmission rate as well as the trasnmitted data format/length are not
internally set by this SCI blocks. These have to be (hardly) fixed through spe-
cific Simulink® blocks, such as Rate Transition and Data Type Conversion,
according to the firmware execution. This is summarized in Figure 10.3, which
shows a couple of possible arrangements related to data exchange required in
the following exercises. Note that, multiple data/variables can be sent exploit-
ing Mux blocks (data is organized in [1 n] arrays). Double-precision floating
point data is not recommended due to its large size. This is particularly critical
when more than one variable have to be transmitted/received.
Finally, note that no COM port is specified in SCI RCV or XMT, since those
blocks are translated into code which is downloaded directly on the hardware
board.
Testing Environment: Send/Receive Data through Serial Communication 117
COM5
115200 Data COM5 COM5 Data
8,none,1
Figure 10.4 Serial Configuration, Send, and Receive blocks for setting serial
communications between the testing.slx file and the LaunchPad™ F28069M.
Block Parameters:
• Communication Port
This setting specifies which available COMx port is exploited for serial com-
munication. This choice must match with the COM port number selected in
the Serial Send and Serial Receive block as well as with the VCP generated
in the PC Device Manager.
• Baud rate
This option allows to set the rate at which signals are transmitted for the
serial interface. The default value is 9600 baud/s. This number should match
the one specified in the Model Configuration Parameter window.
• Data bits
This label specifies the number of bits of a single chunk of data (i.e., baud)
that are transmitted over the serial interface. The default value is 8 and
other available values are 5, 6, and 7.
• Parity
This field allows to specify the desired check of parity bits in the data bits
118 Serial Communication Interface (SCI) Peripheral
transmitted through serial port. This is set to none by default. The other
available choices are:
– Even: parity bit is set equal to 0 if the number of ones in a data set
of bits is even;
– Odd: parity bit is set equal to 1 if the number of ones in a data set of
bits is odd;
– Mark: parity bit is always set equal to 1;
– Space: parity bit is always set equal to 0.
• Stop bits
This option specifies the number of bits used to indicate the end of the chunk
of data. The selected number of data bits impacts on this parameters since
it determines the choices available for the stop bits. If data bits is set equal
to 6, 7 or 8, then, the default value is 1 and the other choice at disposal is
2. Otherwise, the only available number is 1.5.
• Byte order
This label sets the byte order. If byte order is LittleEndian (default value),
then the instrument stores the least significant byte in the first memory
address. Conversely, if byte order is set to BigEndian, the most significant
byte is placed first in memory and the least significant one last.
• Flow control
This field specifies the process of managing the rate of data transmission on
the serial port. Flow control can be set to none or hardware, depending if
the user wants to have no flow control or to let the hardware determine it.
• Timeout
This setting specifies the amount of time that the model waits for the data
during each simulation time step. The default value is 10 s.
Block Parameters:
• Communication Port
This field allows to specify an available COM port. This choice must match
with the COM port number selected in the Serial Configuration block (see
Section 10.3.1).
Testing Environment: Send/Receive Data through Serial Communication 119
• Header
This label specifies additional data placed at the beginning of the infor-
mation frame to be transmitted before sending it through serial port. By
default, <none> or no header is specified. The header entered here must
match with that one chosen in the SCI Receive block in the firmware.slx file
(see Section 10.2.1).
• Terminator
This label specifies the additional data placed at the end of the information
frame to be transmitted after sending it over the serial port. By default,
<none> or no terminator is specified. The terminator entered here must
match with that one chosen in the SCI Receive block in the firmware.slx file
(see Section 10.2.1).
• Enable blocking mode
This flag allows simulation halting while sending data. Namely, the Serial
Send do not send any other data until a signal is received. This option
is selected by default. It is cleared in case it is not desired to have write
operations that should pause the simulation.
Remark:
A Data Type Conversion block should be connected before the Serial Transmit
block to avoid the transfer of any double-precision floating point data. The
setting of this additional block should match the data type selected in the
option panel of the SCI Receive block in the Firmware Environment (see
Section 10.2.1).
Block Parameters:
Some parameters of Serial Receive block are the same as those reported in the
previous Section, i.e., Communication Port, Header, Terminator. The other
parameters are:
• Data Size
Through this label, it is possible to specify the size of the transmitted data.
Both 1-D vectors and matrices are accepted, e.g., [1 1] corresponds to a
scalar value, while [1 3] corresponds to an array of size 3.
120 Serial Communication Interface (SCI) Peripheral
• Data Type
This label specifies the type of the received signal (i.e., int8, uint8, int16,
uint16, int32, uint32 and single). This setting should be coherent with the
corresponding one specified in the Data Type Conversion block connected
to the SCI XMT block in the firmware environment (see Section 10.2.2).
It is important to note that the board F28069M can handle single-precision
floating-point numbers, but this choice implies an heavier transmission and
computational load. Hence, this kind of transmission likely overloads the
communication buffer. To avoid this problem, int8/uint8 or int16/uint16
data types are preferable in case many signals have to be transferred.
• Action when data is unavailable
This option can be set choosing among one of the following actions: Output
last received value, Output custom value or Error. It is very similar
to the setting reported in Section 10.2.1, i.e., Action taken when connection
times out for firmware environment (see Section 10.2.1).
• Custom value
This parameter is enabled only if Action when data is unavailable is
set on Output custom value. It specifies a value to output when no data
is received. The default value is 0.
• Block sample time
This setting specifies the sample time of Serial Receive during simulation.
Namely, it indicates the rate at which the block is executed during simula-
tion. This value must be specified in seconds.
Remarks
Firmware and Testing Environments have common features: while both SCI
RCV/Serial Receive blocks must specify Sample Time and Data Type, SCI
Transmit and Serial Send do not have these options available and they must
be checked and possibly adapted to be synchronized with other blocks by
employing the Data Type Conversion block, the Rate Transmission block,
and Mux block in case of multiple data transmission.
• Fixed Step-Size - ∆t
Regarding the firmware environment, every firmware.slx relies in a discrete
framework. Thus, the book case studies will focus on Simulink® schemes
which adopt a fixed-step solver option with a discrete solver such as ODE4
(Runge-Kutta) and a fixed-step size Ts , i.e., ∆t = Ts .
In the simulation environment (i.e.,testing.slx), the simulation starts at t = 0
and ends at t = Tend . The simulation time step Tsim may be fixed or vary
122 Serial Communication Interface (SCI) Peripheral
Figure 10.5 Connection between the F28069M LaunchPad™ board and a host
PC.
during each run according to the selected solver options in Simulink® , i.e.,
discrete- or variable-step size, respectively. Since the firmware is designed
in a discrete-time domain, the same is done for the testing environment,
e.g., keeping ∆t = Tsim = Ts or ∆t = Ts /10 (to increase the visualiza-
tion resolution). Note that, every time the enabling blocking mode option
is enabled in the Serial Send block, the simulation environment waits for
the data acquisition before increasing the Simulation Time by one step (i.e.,
ti+1 = ti +∆t), resulting in simulation times which are totally different from
the real time. Namely, the more the testing environment receives data, the
longer the simulation will take to run.
Example 1
serial port COMx. SCI module A is used. Thus, the right jumper configuration
should be realized on the board (see Table 3.2).
Firmware Environment
c28069_internalSin_F.slx (solver: fixed step - ODE4, step size: Ts = 100 µs)
Open a new blank Simulink® project and configure the environment as shown
in Chapter 9. Then:
• Place a SCI Transmit block in the file and double click on it to modify its
parameters:
• Insert a Sin Wave block to generate the internal signal. Double click on it:
Data
sine
By double clicking on the manual switch icon, the input signal can be changed
to the pulse generator. This block works analogously to the sine-wave one,
thus, its explanation is not repeated here.
Be careful: the sine-wave can be edited any time by acting on the parameters
of the Sin Wave block. To make these changes effective on the board, the
translation in C-code and the deploy to hardware must be repeated every
time. The same holds for the Pulse generator block.
Testing Environment
c28069_internalSin_T.slx (solver: fixed step - ODE4, step size: Tsim = Ts )
COM14
115200 COM14 Data
8,none,1 out
Note that the data type sent from the board to the PC is single. Thus, single
is set as data type in the Serial Receive parameters without any need for ad-
ditional data conversion. The resulting sine-wave can be visualized through a
Scope block. Finally, connect these blocks as shown in Figure 10.7. In particu-
lar, this scheme can also include a Dashboard Scope with signal associated
to the output of the Serial Receive. This is a simple way to dynamically vi-
sualize signals over time. This approach is suggested for the next exercises
included in the book which requires SCI as debugging tool. For simplicity rea-
sons, Dashboard Scopes will be included in the testing environments, but not
126 Serial Communication Interface (SCI) Peripheral
0.6
1
0.5
0.8
0.4
0.6 0.3
0.4 0.2
0.1
0.2
0
0
-0.1
5 10 15 20 5 10 15 20
(a) (b)
Figure 10.8 Data read from the SCI A when the internal signal is generated
by Sine Wave (a) and Pulse Generator (b) blocks.
reported in any figure. Moreover, the Testing Environment does not need to
deploy code to target. Indeed, this file should be run only as standard simu-
lations to start sending data through the serial port. In order to continuously
run the simulation, the stop time is set equal to inf (i.e., infinity). It is impor-
tant to note that the serial configuration is the “main” block which sets the
parameters of the COMx communication, possibly overwriting previous set-
tings edited in the PC device manager. The results of this exercise are shown
in Figure 10.8.
Example 2
In this example, the F28069M LaunchPad™ board must be able both to read
an external command and send it back through the virtual serial COMx port.
SCI A module is used. Thus, the right jumper configuration should be realized
on the board (see Table 3.2).
Firmware Environment
c28069_externalSin_F.slx (solver: fixed step - ODE4, step size: Ts = 100 µs)
Open a new blank Simulink® project and configure the environment as shown
in Chapter 9. Then:
• Open the Model Configuration Parameters window and use the same
settings adopted in Example 1.
Examples on Serial Communication 127
SCI A Rx SCI A Tx
C28x C28x
Data Data
• Place a SCI Transmit block in the file and and use the same settings
adopted in Example 1. The Rate Transition block is set with an Output
port sample time equal to 0.01 s.
• Insert a SCI Receive block in the file and double click on it to modify its
parameters as follows:
• Add a gain block and set its value equal to 2. Moreover, set the output data
type as single in the Signal Attributes tab.
Testing Environment
c28069_externalSin_T.slx (solver: fixed step - ODE4, step size: Tsim = Ts )
• Open the Model Configuration Parameters window and use the same
settings adopted in Example 1;
• Place a Serial Configuration block and use the same settings adopted in
Example 1;
• Insert a Serial Send block. Double click on it:
128 Serial Communication Interface (SCI) Peripheral
COM14
Data COM14 115200 COM14 Data
8,none,1
sine1
• Add a Serial Receive block and use the same settings adopted for Exam-
ple 1;
• The external signal is generated by a Sin Wave block with the same pa-
rameters set in Example 1
1.5
0.5
10 11 12 13 14 15 16 17 18 19 20
1.2
0.8
0.6
0.4
10 10.05 10.1 10.15 10.2 10.25 10.3 10.35 10.4 10.45 10.5
than the former. Hence, this computational delay is mainly due to the serial
communication. This is detailed by a zoom view reported in the lower side of
Figure 10.11, allowing to visualize TRX .
11
GPIO Peripheral—Digital Input/Output
In particular, the pins of the analog port are connected to the channels of
the analog-to-digital converter peripheral ADCA0-7 and ADCB0-7. Further
details on this peripheral are reported in the next Chapter.
These pins can be operated as digital I/O (referred to as GPIO) or con-
nected to one up to three I/O peripheral signals via the GPxMUXn registers.
If digital I/O mode is selected, the pin “direction” (i.e., input or output) is
configured via the GPxDIR registers. It is also possible also to qualify the
input signals to remove unwanted noise via the GPxQSELn, GPACTRL, and
GPBCTRL registers. Note that most of the pins are re-configurable (i.e., they
are associated to many registers). However, Simulink® provides a limited ac-
cess to them. Indeed, only some of them can be edited through the dedicated
block library. For a more flexible customization of the code, the reader is
suggested to use Code Composer Studio™ .
Every time a reconfiguration of the I/O pins is needed, it is suggested to
follow these steps:
1. Organize a pin-out table.
2. Enable or disable internal pull-up resistors.
To enable or disable the internal pullup resistors, write to the re-
spective bits in the GPIO pullup disable (GPAPUD and GPBPUD)
registers. For pins that can operate as ePWM output pins, the in-
ternal pullup resistors are disabled by default. All the other GPIO-
capable pins have the pull-up resistor enabled by default. The AIOx
pins do not have internal pull-up resistors. It must be noted that
the pin register access in its full extent is available only through
Code Composer Studio™ .
3. Select input qualification.
In case a pin is used as an input, it may be needed to specify its input
qualification. This information should be set in the GPACTRL, GP-
BCTRL, GPAQSEL1, GPAQSEL2, GPBQSEL1, and GPBQSEL2
registers. By default, all the input signals are synchronized by
SYSCLKOUT.
4. Select pin function.
Configure the GPxMUXn or AIOMUXn registers such that each pin
to be re-configured is connected to one of the available peripheral.
By default, all GPIO-capable pins are configured at reset as general
purpose input pins.
5. For digital general purpose I/O, select direction of the pin.
Every time the pin is configured as a GPIO, the direction of the pin
should be specified as either input or output in the GPADIR, GPB-
DIR, or AIODIR registers. By default, all GPIO pins are inputs. To
change the pin from input to output, first load the output latch with
the value to be driven by writing the appropriate value to the GPx-
CLEAR, GPxSET, or GPxTOGGLE (or AIOCLEAR, AIOSET, or
Firmware Environment: GPIO Peripherals 133
C2806x
GPIOx
GPIO DI
Block Parameters:
• GPIO Group
GPIO signals are organized into groups. This setting allows the selection of
the group of pins to view or configure. Changing group, different pins can
134 GPIO Peripheral—Digital Input/Output
C2806x
GPIOx
GPIO DO
– Voltage inputs between 0 and 1.3 V lead to LOW output values, i.e.,
logic 0;
– Voltage inputs over 1.5 V lead to HIGH output values, i.e., logic 1;
– Voltage inputs in the range [1.3, 1.5] V lead to random output values,
i.e., logic 0 and 1.
Remark
Since voltage inputs in the range [1.3, 1.5] V lead to random logic states, it is
recommended to keep Vpin quite far from the high/low voltage threshold.
Every digital output GPIO has a toggle option that inverts the output
signal on the pin. The main settings of this block are reported here in the
following. One parameter is not explained since it is used to set the same
function described for the C2806x GPIO Digital Input block.
Block Parameters:
• GPIO Group
• Regular- and Toggle mode
For each selected pin, regular- (default) or toggle mode can be selected to
drive the GPIO signal. In regular mode, true inputs pull the GPIO pin high.
False ones ground the pin. In toggle mode, true values switch the pin output
level continuously. Thus, a true input switches the output voltage from high
to low and vice-versa. Instead, if the input is set to false, the pin output
level is unaffected. Namely, the last logic value is kept constant as long as
the the input is kept equal to 0.
Remark
The switching frequency in toggle mode is limited by the 20 MHz rate of the
pin buffers. Regardless of the input data type, every time a numerical signal
is applied to a GPIO in regular-mode, this value is interpreted as:
The led turn on/off is the “hello world” for micro-controller progrmming. This
simple exercise is essential to understand the electrical characteristics of the
microcontroller in use. The schematics of the LaunchXL F28069M board as
well as its pin-out can be found in the corresponding User’s guide [16]. From
this file, it can be noted that this board includes two programmable leds
which are physically connected to two digital pins: a blue (GPIO39) and red
(GPIO34) one. An initialization script can be used to load some constants,
e.g., in Model Properites/Callbacks/InitFcn.
136 GPIO Peripheral—Digital Input/Output
3.3 V
C2806x
GPIOx
GPIO DO R
led blue GPIO39
(a) (b)
Firmware Environment
c28069_ledB_F.slx (solver: fixed step - ODE4, step size: Ts = 100 µs)
Open a new blank Simulink® project and configure the environment as shown
in Chapter 9. Then:
• Open the Model Configuration Parameters window and use the same
settings adopted for Example 1 in Section 10.5;
• Insert a Digital Output (GPIO DO) block and double-click on it:
Figure 11.4 Example of GPIO39 output voltage over time in toggle mode.
Remark
The input value of GPIO39 can be edited by changing the value of the constant
block. The translation in C-code and the deploy to hardware must be repeated
at each modification of this value.
Example 2
In this exercise, the discrete time Delay block is exploited to set a certain
delay of Nd time steps for the driving signal of one led. The time delay in
seconds is computed as Nd Tsig , where Tsig = 1000Ts and Ts is the fixed step
size of the solver.
In order to make the leds blink, the toggle mode must be enabled in the
GPIO DO block parameters window. The interleaved blinking is achieved by
selecting an odd time delay (e.g., Nd = 1 which imply one step delay)
Firmware Environment
c28069_ledBR_F.slx (solver: fixed step - ODE4, step size: Ts = 100 µs)
Open a new blank Simulink® project and configure the environment as shown
in Chapter 9. Then:
• Open the Model Configuration Parameters window and use the same
settings adopted for Example 1 in Section 10.5; the constant block value
must be equal to 1 in order to use the toogle mode.
• Insert a Digital Output (GPIO DO) block and double click on it:
led red
C2806x
GPIOx
GPIO DO
C2806x
Z-1 GPIOx
GPIO DO
led blue
(a) (b)
• Insert a new Digital Output (GPIO DO) block and double-click on it:
The blinking speed depends on the sample time Tsig set in the constant
block.
• Insert a Delay block (it can be found in the Discrete library) and:
• Insert two Data Type Conversion blocks to feed the two GPIO DO blocks
with uint16 or uint8 data.
Finally, connect these blocks as shown in Figure 11.5 (a). The blinking
effect would be directly visible on the board as reported in Figure 11.5 (b).
Example 3
Build a firmware which is able to drive the GPIO channels to turn the
leds on/off by reading an external command signal through serial port
Examples with GPIO blocks 139
For this exercise, two Simulink® files must be created. One is needed to pro-
gram the MCU board and another one to test it by sending data through
COM port. SCI module A is used for communication purposes. Thus, a suit-
able jumper configuration should be realized on the board (see Table 3.2).
Firmware Environment
c28069_SCIledBR_F.slx (solver: fixed step - ODE4, step size: Ts = 100 µs)
Open a new blank Simulink® project and configure the environment as shown
in Chapter 9. Then:
• Open the Model Configuration Parameters window and use the same
settings adopted for Example 1 in Section 10.5.
• Insert two Digital Output (GPIO DO) blocks and double-click to set:
• Place an Add and a Constant block to invert the signals fed into GPIOs.
Set the signs of the add block equal to −+ and the constant block sample
time equal to 0.1 s. This arrangement is such that every time GPIO34 turns
on, then, GPIO39 turns off and vice-versa.
In this case, the input of the SCI module is uint8. Thus, an input signal
bounded between [0, 1] is converted into a integer ranging in [0, 255].
A sample time equal to 0.1 s (meaning a working frequency of 10 Hz) is set
for the serial communication to ensure good data transfer. The serial com-
munication was tested by the authors up to 5 kHz. However, this is not its
upper limit, which depends by the firmware optimization. Finally, connect the
aforementioned blocks as shown in Figure 11.6 (a).
140 GPIO Peripheral—Digital Input/Output
led red
C28x C2806x
Data GPIOx
GPIOx
GPIO DO
led blue
(a) (b)
Testing Environment
c28069_SCIledBR_T.slx (solver: fixed step - ODE4, step size: Tsim = Ts )
• Open the Model Configuration Parameters window and use the same
settings adopted for Example 1 in Section 10.5.
• Place a Serial Configuration block and use the same settings adopted for
Example 1 in Section 10.5.
• Insert a Serial Send block and use the same settings adopted for Example
2 in Section 10.5.
COM10
Data COM10 115200
8,none,1
Example 4
If the led turn on/off is the “hello world” for microcontroller programming,
the realization of a pulse-width-modulation (PWM) technique is the “hello
world” for power electronics applications. In this example, a PWM logic is
built from scratches using basic Simulink® elements. The Embedded Coder
Support Package for Texas Instruments C2000 Processors library includes
optimized PWM peripherals, but they are not used in this exercise. Indeed,
this example is aimed at providing the reader more insight into the logic
behind this modulation technique before to move in built-in peripherals.
The external command transferred thorugh COM port represents the mod-
ulation signal which is compared to a triangular carrier. The result of this op-
eration is a train of pulses which drives the blinking of the blue led (GPIO39).
Firmware Environment
c28069_SCIledBpwm_F.slx (solver: fixed step - ODE4, step size: Ts = 100 µs)
Open a new blank Simulink® project and configure the environment as shown
in Chapter 9. Then:
• Open the Model Configuration Parameters window and use the same
settings adopted for Example 1 in Section 10.5.
• Insert a SCI Receive block and double-click on it:
• Place a Rate Transition block and set its sample time equal to TTX =
0.001 s and a Data Type Conversion block set as single before sending
the data via SCI XMT.
• Place another Rate Transition block and set its sample time equal to
Ts = 0.001 s. Namely, this block is to be placed aftera SCI RCV and all the
computations done after it are executed every Ts .
• Add a Digital Output (GPIO DO) block and double-click on it:
Data
SCI A Rx
SCI XMT
C28x
mod C2806x
Data
GPIOx
SCI RCV
GPIO DO
led blue
K Ts
z-1
carrier
discrete continuous
0.8
0.6
0.4
0.2
0 0.05 0.1 0.15 0.2 0.25 0.3 0.35 0.4 0.45 0.5
0.8
0.6
0.4
0.2
0 0.05 0.1 0.15 0.2 0.25 0.3 0.35 0.4 0.45 0.5
0 0.05 0.1 0.15 0.2 0.25 0.3 0.35 0.4 0.45 0.5
Figure 11.9 Resulting signals for a PWM logic which implements a carrier
built up with continuous-time blocks.
where y(k) is the output of the block, u(k) is the input of the block,
k is the time step index, K is the gain of the integrator and y0 is
the initial condition. The parameters of the block are set as follows:
0.8
0.6
0.4
0.2
0 0.05 0.1 0.15 0.2 0.25 0.3 0.35 0.4 0.45 0.5
0.8
0.6
0.4
0.2
0 0.05 0.1 0.15 0.2 0.25 0.3 0.35 0.4 0.45 0.5
0 0.05 0.1 0.15 0.2 0.25 0.3 0.35 0.4 0.45 0.5
Figure 11.10 Resulting signals for a PWM logic which implements a carrier
built up with a discrete-time integrator.
COM14
Data COM14 115200 COM14 Data
8,none,1
Testing Environment
c28069_SCIledBpwm_T.slx (solver: fixed step - ODE4, step size: Tsim = Ts )
Finally, connect all these blocks as shown in Figure 11.11. The waveforms
that should be visualized in the scope are the those reported in the bottom
plots of Figure 11.9 and 11.10 for the continuous and discontinuous carriers,
respectively.
12
Analog to Digital Converter Peripheral
In this Chapter, the working principles and the main configuration of ana-
log to digital converter (ADC) peripherals mounted on TI boards are briefly
outlined. ADCs are fundamental elements to sample analog external signals
and convert them into digital data to be processed by the MCU. In particular,
the ADC peripherals installed on the F28069M LaunchPad™ board has 12-bit
resolution (part SAR, part pipelined) with input pins operating in the range
0÷3.3V and it able to work up to 3.46 MSPS. Since ADC peripherals includes
many analog and digital circuits besides the analog-to-digital converter core,
it is common to refer to them as ADC modules. The analog circuits include
the front-end analog multiplexers (MUXs), sample-and-hold (S&H) circuits,
the conversion core, voltage regulators, and other analog supporting circuits.
Digital circuits include programmable conversions, interface to analog circuits
and to device peripheral bus. Moreover, ADCs work at full system clock with-
out the need of any prescaler.
The ADC core contains a single 12-bit converter fed by two sample-and-
hold circuits (A and B). The S&Hs can sample both simultaneously and se-
quentially, and they are fed by up to 16 analog input channels (8 for S&H A
and 8 for S&H B). The reader is reference to Figure 3.5 for more details on
the pinout of the board. The ADC blocks available in Simulink® allow to set
all the ADC modules options.
0
Dn−1
S u (t)
u (t) n-bit ..
Analog to Digital .
C Converter D1
D0
at least the time required for the digitizalization, which is performed by the
ADC. This process is sketched in Figure 12.1.
Figure 12.2 Block scheme showing the working principles of the ADC periph-
eral [19].
1 Recyclic ADCs use the same module for both fine and coarse conversions of analog
signals.
2 SAR stands for successive approximation register. In this implementation, the signal
is temporarily stored in a register and coded so that its most significant bit is equal to 1.
Then, each bit of this code is compared with a reference voltage and converted step-by-step
in the final digital signal.
3 This implementation foresees the conversion through p stages. Each of them converts
n bit at a time. This operation leads to some delays in the output since the converted signal
is not available until all the stages complete the conversion. Then, the resulting signal is
coded over np bit.
152 Analog to Digital Converter Peripheral
• Trigger source;
• Channel;
• Acquisition prescale window.
sources into a smaller set. The PIE block can support up to 96 peripheral interrupts.
154 Analog to Digital Converter Peripheral
C2802x/03x/05x/06x C2802x/03x/05x/06x
A0 A0/B0
ADC ADC
(a) (b)
Figure 12.3 C2806x ADC block in two different configurations: (a) single sam-
pling mode and (b) simultaneous sampling mode.
– Software;
– CPU0/1/2_XINT0/1/2n;
– XINT2_XINT2SOC.
XINT2SOC external pin should be specified inside the Configuration
Parameters window, Hardware Implementation, Target hardware re-
sources menu, ADC. This operation defines the GPIO channel con-
nected to a pin that triggers the start of conversion;
– ePWM1-8 _ADCSOCA/ePWM1-8 _ADCSOCB.
• Sample Time
This parameter specifies the time interval elapsed between two consecutive
samples, e.g., Ts .
• Data Type
This drop-down menu specifies the data type of the digital output data.
The available options are double, single, int8, uint8, int16, uint16, int32,
and uint32.
Firmware Environment
c28069_ADCledBpwm_F.slx (solver: fixed step-ODE4, step size: Ts = 100 µs)
Open a new blank Simulink® project and configure the environment as shown
in Chapter 9. Then:
• Open the Model Configuration Parameters window and use the same
settings adopted for Example 1 in Section 10.5.
• Insert a GPIO DO block and build the same PWM logic used in Chapter
11 by following the steps reported in Example 4 in Section 11.3.
• The ADC block can be found in the C2806x subset of the library Embedded
Coder Support Package for Texas Instruments C2000 Processors. Insert it
in the scheme ans set its parameters as follows:
Example with ADC block 157
3.3 V 4000
3500
3000
potentiometer
2500
2000
R
1500
vp (t) 1000
500
ADCA3 0
(PIN67) 0 5 10 15 20 25 30 35 40 45
(a) (b)
• Insert a Data Type Conversion block set to int16 to deal with positive
signal only.
• Place a Gain block for scaling the digitalized signal within the interval [0, 1].
This is fundamental because a 12-bit reading returns a value in a range from
0 (0 V) to 212 − 1 = 4095 (3.3 V, see Figure 12.5 (b)). Hence, set the gain
as 1/(212 − 1) or, to be more conservative, as 1/212 . In this last case, the
representation range is not fully exploited.
• Insert a SCI transmit block to send the values returned by ADCA3 and the
output of the PWM logic to the host PC via SCI A. the reader is suggested
to use the same settings adopted in Chapter 11, i.e., single data type and
transmission rating equal to 0.01 s.
158 Analog to Digital Converter Peripheral
carrier
led blue
GPIO DO
ADC
GPIOx
mod
A3
C2806x
C2802x/03x/05x/06x
SCI XMT
potentiometer
Data
C28x
SCI A TX
The remaining part of the scheme directly refers to Example 4 in Section 11.3.
Inside the ADC block, the sample time is set equal to TADC = 0.001 s 6= Ts .
In this exercise, the ADC reading does not represent a critical task in terms of
timing, i.e., such peripheral is not synchronized with any other one. Therefore,
the timing has been relaxed, i.e., TADC > Ts , to reduce the computational load
on the processor. However, this is not always the case, and most of the time
the ADC peripheral has to be synchronized with a particular signal as well as
using Ts is necessary to improve plot resolution.
Note that Rate Transition blocks are placed to run the signal comparison
every Ts . A continuous-time block is used to create the triangular carrier,
resulting in a switching frequency of fsw = fc = 20 Hz. This allow the reader
to recognize the different led blinking during operation. The resulting scheme
is reported in Figure 12.6.
The linear potentiometers mounted on the extPot3 board are connected to
the 3.3 V supply, which is directly available on the LaunchXL F28069M board.
A full rotation of a potentiometer leads to a voltage span from 0 V to 3.3 V or
vice-versa, depending on the direction of rotation. The resulting modulation
signal acquired by the ADC can be sent to the PC and visualized, as shown in
Figure 12.7. Since the ADC peripheral has a 12 bit resolution, the output range
is between 0 and 4095. This bit value can be nicely represented by unit16
data type, which allows numbers between 0 and 65535. Note that, in the ADC
settings does not exist a 12-bit data type, thus, 16-bit representation is the
right choice to avoid data cast. Regarding global definitions, an initialization
script an be created in Model Properites/Callbacks/InitFcn or in a separate
m-file. An example of such script is reported here below:
0.8
0.6
0.4
0.2
5.75 5.8 5.85 5.9 5.95 6 6.05 6.1 6.15 6.2 6.25
0.8
0.6
0.4
0.2
5.75 5.8 5.85 5.9 5.95 6 6.05 6.1 6.15 6.2 6.25
5.75 5.8 5.85 5.9 5.95 6 6.05 6.1 6.15 6.2 6.25
Testing Environment
c28069_ADCledBpwm_T.slx (solver: fixed step - ODE4, step size: Tsim = Ts )
• Open the Model Configuration Parameters window and use the same
settings adopted for Example 1 in Section 10.5.
• Place a Serial Configuration block and use the same settings adopted for
Example 1 in Section 10.5.
buzzer
C2806x
GPIOx
GPIO DO
(a) (b)
Figure 12.9 Block arrangement for driving GPIO8 (a) and detail of extPot3
board showing the buzzer (b).
Synchronization between ADC modules 161
Example
This exercise is an extension of the previous one. Two ADC modules are
exploited, ADCINA3 and ADCINB5. The main settings to create a master-
slave chain configuration between ADC modules is presented.
Firmware Environment
c28069_ADCsync_F.slx (solver: fixed step - ODE4, step size: Ts = 100 µs)
Modify the previous example by duplicating the ADC block and updating
the settings as follows:
ADC1 settings:
• Select ADCINA3 as Conversion channel in the Input Channels tab.
Then, go back in the SOC Trigger tab.
• Sampling mode: Single sampling mode;
• SOC trigger number: SOC0;
• SOCx acqusition window: 7;
• SOCx trigger source: CPU0_TINT0n or Software;
• ADC will trigger SOCx: No ADCINT;
• Sample time: TADC = 0.001 s;
• Data type: uint16;
• Flag Post interrupt at EOC trigger;
• Interrupt selection: ADCINT1;
• Flag ADCINT1 continous mode (optional);
162 Analog to Digital Converter Peripheral
potentiometer2
C2802x/03x/05x/06x SCI A TX
B5 C28x
ADC Data
ADC2 settings:
• Select ADCINB5 as Conversion channel in the Input Channels tab.
Then, go back in the SOC Trigger tab.
• SOC trigger number: SOC1;
• ADC will trigger SOCx: ADCINT1;
• Unflag Post interrupt at EOC trigger;
• Keep the other settings equal to those specified for ADC1.
In this case, ADC1 (ADCINA3) is the master that creates an interrupt sig-
nal ADCINT1 at its EOC. This signal is used to trigger the SOC of ADC2
(ADCINB5), which behave as slave.
Note that if only one ADC module is used, the EOC flag is not strictly
necessary since no other modules requires such trigger; this also explain the
settings reported in Section 12.4. The new scheme is shown in Figure 12.10.
Remark
Every ADC block exploits one SOC in single sample mode or two of
them in simultaneous sample mode. It is forbidden to use the same SOC
instance for different ADCs.
13
Pulse Width Modulator Peripheral
comparator
1 S1
v " x
+ − 0 S1 , S4
vc
S2
x
S2 , S3
10
0 0.002 0.004 0.006 0.008 0.01 0.012 0.014 0.016 0.018 0.02
• Small motors often requires low power consumption and the use of (dis-
continuous) PWM signals allows to efficiently control a power converter
by reducing the power losses in the switches (both due to conduction and
switching) compared to other kind of linear controller.1 Indeed, the switch-
ing devices foresees two states only: short and open circuit.
• The motor dynamics (which can be modeled as an RL circuit and a con-
trolled voltage source, that is, the back-emf) act as a low pass filter. Hence,
undesired high-order harmonics resulting from the PWM implementation
might be rejected by the machine itself without the need for additional filter,
being mostly sensitive to low frequency components such as the fundamental
one.
1 An old alternative was a simple circuit in which the current flow was linearly controlled
• A trip condition which can force either high, low, or high-impedance state
logic levels at PWM outputs.
• All events of the module can trigger both CPU interrupts and ADC SOC
signals.
168 Pulse Width Modulator Peripheral
Figure 13.5 Counting modes available in the adopted MCU board. From left
to right they are: up/down, up and down count.
– Do nothing;
– Clear the pin low;
– Set the pin high;
– Toggle the pin based independently on count-up and count-down time-
base match events.
It is important to note that zero and period actions are fixed in time, whereas
Compare A and B actions are movable in time by programming their cor-
responding registers. These actions are configured independently for each
output using shadowed registers.
Generation of PWM signals 171
– Zero;
– Period;
– Zero or period;
– The up- or down-count match of Compare A, B, C, or D registers.
PWMfrequency PWMfrequency
up-down TBCLK
4 4
count
3 3 3 3
2 2 2 2
1 1 1 1
0 0
up up
TBCTRdir down down
TBPRD
TBCTR=
TBPRD
TBCTR=0
PWMfrequency PWMfrequency
TBCLK
up-count 4 4
3 3
2 2
1 1
0 0
Comparator
b (k) 2 [0 TBPRD]
m CMPA ePWMxA
>
ePWMxB
Carrier
ePWMx peripheral
90 MHz
PWMcounter_period = = 4500
20 kHz
Note that the value of TBCTRdir follows from the reasoning reported for
the symmetrical carrier.
PWMfrequency PWMfrequency
4 4
3 3 3 3
CMPA=3
2 2 2 2
CMPA=2
1 1 1 1
0 0
up up
TBCTRdir down down
TBCTR=
CMPA
ePWMxB
PWMfrequency PWMfrequency
4 4
3 3 3 3
CMPA=3
2 2 2 2
CMPA=2
1 1 1 1
0 0
ePWMxA
FED RED
ePWMxA
FED
ePWMxA
RED
ePWMxA
AHC
ePWMxB
AHC
Figure 13.10 Counter compare operation for ePWMxA and ePWMxB with
dead bands in the correspondence of both RED and FED.
of the system, i.e., a delay is always present even if dead-time equals zero at the firmware
level.
Generation of PWM signals 177
implementation, the dead time should be defined in clock cycles (i.e., as mul-
tiples of TBCLK). In this case, it is easier to refer to dead band which is used
to define the time interval that separates the transition edges of two signals:
output and complemented output.
In particular, dead times can be added in the correspondence of
1. Rising edges—defining a rising edge delay (RED);
2. Falling edges—defining a falling edge delay (FED);
3. Both rising (RED) and falling edges (FED).
By default, ePWMxA is used as signal source both for RED and FED. These
latter identifies dead bands since they are defined in clock cycles. Furthermore,
the choice of the dead time, thus, the length of the RED and FED dead
bands should consider the value assumed by PWMcounter_period . For instance,
assuming PWMcounter period = 2250, the sum RED+FED must allow switching
operations inside the switching period. Namely, each dead time is limited in
the range [0 1023], so that 1023 + 1023 = 2046 < 2250.
Referring to the 2L-VSC case, since ePWM1A is operated as master, the
dead band polarity can be configured as Active High Complementary (AHC)
to compute the ePW1B starting from ePW1A. Then, the resulting switching
pattern provided to the gate driver circuits are ePW1A AHC and ePW1B
AHC. By choosing equal values for RED and FED, the pattern keeps a cen-
tered symmetry. This is shown in Figure 13.10. However, this is not always
the case in power electronics applications.
The aforementioned features and working principles of this peripheral can
be summarized as shown in Figure 13.11. The reader should refer to the Sec-
tion reported here in the following for the details on the implementation of
these functions in Simulink® .
178 Pulse Width Modulator Peripheral
C2802x/03x/05x/06x
ePWM
In the following, given the target of this book, only the main settings useful
for power electronic-based applications are reported.
• Module
There are 12 different ePWM modules available: ePWM1-12. Each of them
has two outputs: ePWMxA and ePWMxB.
• Timer period units
This setting specifies whether the unit of TBPRD is specified in seconds or
directly in clock cycles (default choice). Note that, even if the timer period
unit is seconds, the software converts this value to an equivalent quantity
in clock cycles during the deploy to hardware. Therefore, it is suggested to
specify TBPRD in a clock cycles units (TBCLK) to reduce computations and
rounding errors. Regarding the F28069 LaunchPad™ board, it is important
to remind that fck = CPUfrequency = SYSCLKOUT = 90 MHz, that leads
to TBCLK = 11.1 ns.
Firmware Environment: ePWM Peripheral 179
– Counter equals to zero: the counter period refreshes when the value
of the counter is 0. Namely, the shadow register contents are transferred
to the active register TBCTR = 0;
– Immediate without using shadow: the counter period refreshes
immediately.
• Counting mode
Three different counting modes are feasible: Up, Down, and Up-Down; this
directly relates to the definition of TBPRD. More details are reported in
Section 13.3.
• Synchronization action
Every time different ePWM modules should work together, the source of
a phase offset can be specified to act on the time-base synchronization in-
put signal (EPWMxSYNCI), that is, a synchronization input signal from a
previous ePWM module through the SYNC input port. Possible choices are:
Figure 13.13 TBPHS role while synchronizing the counter: count down on
synchronization event [21].
• Time base clock (TBCLK) and High speed time base clock (HSP-
CLKDIV) prescaler dividers
The default prescaler value is 1. Nevertheless, a different value can be set
(i.e., additional prescaler) to reduce the size of the peripheral counters in
order to not exceed the range of values allowed by uint16 data type. This
especially happens for low carrier frequencies. As an example, considering
an up counting mode at fc = 1 Hz and CPUfrequency = 90 MHz, it follows
that:
CPUfrequency
TBPRD = PWMcounter_period = = 1 · 106 (13.3)
PWMfrequency
which cannot be realized with 16 bit data. Hence, a frequency di-
vider/prescaler is needed to adapt the representation range. The clock cycle
used as base time can be recomputed as:
1
TBCLK =
PWMfrequency · 65535
Now, it can be used to cast PWMcounter_period up to the maximum value
allowed by uint16 data type.
182 Pulse Width Modulator Peripheral
• Enable ePWMxA
This checkbox is needed to allow any change in all the options for controlling
the switch that corresponds to ePWMxA. By default, Enable ePWMxA is
ticked (whereas Enable ePWMxB is not).
• Action when counter = [· · · ]
The comparison between the input signal and the triangular carrier is de-
fined by the AQ settings. In particular, there are four compare registers:
CMPA, CMPB, CMPC, and CMPD, which are compared to TBCTR value
to generate appropriate events. The values of interest of the counter are:
ZERO, period (PRD), CMPA on up-count (CAU), CMPA on down-count
(CAD), CMPB ojn up-count (CBU) and CMPB on down-count (CBD). In
case of a 2L-VSC, CMPA is of particular interest. The reader is referred to
Section 13.3 for further details.
• Compare value reload condition
This drop-down menu determines if and when to reload the AQ operations.
The available choices are:
• CMPA units
This drop-down menu allows to specify the units used by the register which
is dedicated for the comparison. The available choice are:
• CMPA value
This field appears when Specify CMPA via is set on dialog. A constant
control signal is specified in this option in CMPA units.
• CMPA initial value
This field appears when Specify CMPA via is set on input port. This
label is intended to assign the initial value to CMPA, which is considered
by the ePWM block every time it starts counting. Then, the input signal
through WA port drives the modulation of the high switch.
• The same settings can be provided for CMPB such as CMPB units,
Specify CMPB via Input port (which creates a new port WB), CMPB
value and CMPB initial value.
Firmware Environment
c28069_PWMbasics_F.slx (solver: fixed step-ODE4, step size: Ts = 1/3 kHz)
Open a new blank Simulink® project and configure the environment as shown
in Chapter 9. Then:
• Open the Model Configuration Parameters window and use the same
settings adopted for Example 1 in Section 10.5.
– General (Tab)
∗ select module ePWM1;
∗ set Timer period units to Clock cycles (TBCLK);
∗ set Timer period equal to PWMcounter_period ;
∗ verify that Counting mode is set on Up-Down;
∗ leave the other default settings.
– ePWMA (Tab)
∗ tick Enable ePWM1A check-box;
∗ Action when counter=ZERO: do nothing;
∗ Action when counter=period (PRD): do nothing;
∗ Action when counter=CMPA on up-count (CAU): clear;
∗ Action when counter=CMPA on down-count (CAD): set;
∗ Action when counter=CMPB on up-count (CBU): do noth-
ing;
∗ Action when counter=CMPB on down-count (CBD): do
nothing;
∗ set in Compare value reload condition as Load on counter
equals to zero (CTR=zero);
∗ leave the other default settings.
– ePWMB (Tab)
∗ tick Inverted version of ePWMxB check-box. This option en-
ables the implementation of the complement of ePWM1A;
∗ leave the other default settings.
– Counter Compare (Tab)
∗ select clock cycles as CMPA units;
∗ select input port in Specify CMPA via;
∗ set CMPA initial value on 0;
∗ select Counter equals to zero in Reload for compare A register
(SHDWAMODE);
188 Pulse Width Modulator Peripheral
sin50Hz
WA
A3
ePWM
ADC
Figure 13.14 shows the complete scheme and its connections. In particular, the
ADC conversion chain from the ADCA3 reading up to the saturation block is
the same as that one reported in Section 12.4. Note that the rate transition is
used to reduce the discretization of the modulating signal, with the value of
m(k) being updated every Ts . It is common practice to set the sampling time
related to the controller, i.e., Ts , according to the chosen switching period
Ts = 1/PWM frequency or half of it Ts = 1/(2 · PWM frequency). If Ts =
1/PWM frequency is chosen, this imply a constant modulating signal over
Tc = 1/fc = 2 · TBPRD. Therefore, in the ePWMA tab, the Compare
value reload condition has to be set as Load on counter equals to zero
because a new CMPA value is evaluated at CTR=ZERO.
Example with ePWM block 189
15000
10000
5000
Figure 13.15 Measured signals at the pins 39 and 40 when the modulating
signal is a constant m(k) = 0.5.
All the system parameters have to be defined and initialized before the
firmware deploy through a separate MATLAB® .m file or included in Model
Properties/Main/InitFcn. An example of such script is reported here in the
following.
15000
10000
5000
0 0.002 0.004 0.006 0.008 0.01 0.012 0.014 0.016 0.018 0.02
0 0.002 0.004 0.006 0.008 0.01 0.012 0.014 0.016 0.018 0.02
0 0.002 0.004 0.006 0.008 0.01 0.012 0.014 0.016 0.018 0.02
Figure 13.16 Measured signals at pin 39 and 40 when the modulating signal
is a 50 Hz sine wave.
3 3 3
2 2 2
1 1 1
0 0 0
0 0.2 0.4 0.6 0.8 1 0 0.2 0.4 0.6 0.8 1 0 0.2 0.4 0.6 0.8 1
10-3 10-3 10-3
3 3 3
2 2 2
1 1 1
0 0 0
0 0.2 0.4 0.6 0.8 1 0 0.2 0.4 0.6 0.8 1 0 0.2 0.4 0.6 0.8 1
10-3 10-3 10-3
Figure 13.17 Measured signals at pin 39 and 40 when the modulating signal
comes from a potentiometer.
3 Sometimes, it may happens that minimum RED and/or FED are introduced by default
for safety reason, i.e., to avoid short-circuits, but this is not the case in this example.
192 Pulse Width Modulator Peripheral
(a) (b)
approximate modulating signal in a more accurate way. The cut off frequency
of the RC filter is constant because it is related to the physical components
mounted on the F28069M LaunchPad™ board. Therefore, the quality of the
filtered signal strongly depends on the choice of the switching frequency at
which the PWM logic operates. The LaunchXL F28069M board provides 4
DAC channels, which are connected to ePWM7A, ePWM7B, ePWM8A, and
ePWM8B. Their corresponding output voltages are connected to GPIO40,
GPIO41, GPIO42 and GPIO43, as shown in Figure 13.18 (b).
There are no dedicated Simulink® blocks for DAC peripheral since, at the
firmware level, the same ePWM settings still hold. Nevertheless, the correct
ePWM module must be selected.
lim C2802x/03x/05x/06x
WA
ePWM
Firmware Environment
c28069_sinDAC_F.slx (solver: fixed step - ODE4, step size: Ts = 100 µs)
Open a new blank Simulink® project and configure the environment as shown
in Chapter 9. Then:
• Open the Model Configuration Parameters window and use the same
settings adopted in Section 10.5, Example 1.
• Insert a Sine Wave block and double click on it:
1
f1 = = 10 Hz
ns · Tsig
0.8
0.6
0.4
0.2
Figure 13.20 Modulating signal and measured signal at pin 32, referred to
the ground of the board.
Example 2
lim1 C2802x/03x/05x/06x
WA
ePWM
ADCA7: J3 - pin23
DAC3: J8 - pin72
C2802x/03x/05x/06x
C2802x/03x/05x/06x
A7
WA
ADC Z-d
ePWM
Firmware Environment
c28069_sinDACinout_F.slx (solver: fixed step - ODE4, step size: Ts = 100 µs)
Make a copy of the Simulink® file from the previous exercise (Example 1)
keeping the same settings. Then:
• Copy and paste the previous ePWM block. Double-click on the new copy
and select module ePWM8. Leave all the other settings unchanged, thus,
only ePWM8A is enabled.
• Add an ADC block and use the same configurations as those adopted in
Section 12.4. Note that ADCA7 has to be selected, with sample time equal
to Ts . Use the same approach to process the data in terms of scaling (to
obtain a [0, 1] range) and data type (single).
• Keep the same data processing in terms of saturation, PWMcounter_period
scaling, rate transition (Ts ), and data type (int16).
• Insert a manual switch and a Delay block; set Sample time as Ts and
Delay length equal to 100.
0.8
0.6
0.4
0.2
Figure 13.22 Modulating signal and measured signals at pin 32 and 72, both
referred to the ground of the board.
(from DAC1), thus, returning rounded data. Moreover, also data type conver-
sion blocks are included in the processing. The cable connection from DAC1
to ADCA7 might introduce additional noise as well.
Regarding the computational delay, DAC3 is lagging DAC1, even if this
time delay is not fully recognizable from Figure 13.22. This can be somehow
expected since the data read/actuation is scheduled within TBCLK, while
the processing/computations occurs every Ts . Thus, the new data provided
by the ADC reading (i.e., board data in) is delayed with respect to the output
values (i.e., board data out). The processing effect can be emphasized by
manually adding a larger delay in the ADC conversion chain. The manual
switch inserted in the scheme (see Figure 13.21) allows to include a delay
block which is configured to add Td = 100Ts = 0.01 s to the computational
time at each step. This is evident in Figure 13.23, where DAC1 is still aligned
with the internally generated signal, while DAC3 is now delayed by Td (i.e.,
it is shifted to the right).
To make a comparison, this approach is also suitable to describe the effects
observed in Example 2 reported in Section 10.5, where the overall delay was
mainly due to serial communication sampling.
Remark
If the delay is too large, the workflow of the firmware might be corrupted in
terms of synchronization between input/output. As an example, given that
the internal sine-wave frequency is set equal to f1 = 10 Hz, if Td > 0.05 s
(i.e., greater than 1/2f1 ) the MCU starts to adapt the frequency of the sine-
wave approximated by DAC1 (which still operates at carrier frequency, fc =
10 kHz), resulting in lower values than f1 . As an example, running the previous
firmware with Td = 600Ts = 0.06 s, DAC1 returns a 5 Hz sine-wave. Hence, in
Synchronization between Multiple ePWM Modules 197
1
0.8
0.6
0.4
0.2
Figure 13.23 Modulating signal and measured signals at pin 32 and 72, both
referred to the ground of the board in presence of large latency Td = 0.01 s.
case of large delay, the PWM carrier frequency should be increased to obtain
more accurate outputs. Note that, no SOC synchronization between ADC and
ePWM/DAC has been introduced yet.
SyncIn
Phase reg EN
Φ=0� EPWMxA
EPWMxB
CTR = 0
CTR=CMPB
X
SyncOut
EPWM1SYNCI
GPIO
ePWM1 MUX
EPWM1SYNCO
SYNCI
eCAP1
EPWM2SYNCI
ePWM2
EPWM2SYNCO
EPWM3SYNCI
ePWM3
EPWM3SYNCO
EPWMxSYNCI
ePWMx
EPWMxSYNCO
Phase reg are explained to this aim. A time-base synchronization scheme con-
nects all the ePWM modules installed on a board. Each ePWM module has
a synchronization input (EPWMxSYNCI), also called SyncIn, and a synchro-
nization output (EPWMxSYNCO), also called SyncOut. The synchronization
input for the first instance (ePWM1) comes from an external pin. The synchro-
nization scheme for the remaining ePWM modules is shown in Figure 13.25.
Each ePWM module can be configured to use or ignore the synchronization
input/output. In the Simulink® environment, such feature can be configured
by acting on:
• Synchronization action (input)
This option allows to specify any possible delay between counters by setting
the reset value of ePWM modules. Actually, this quantity may be specified
through an input port with Set counter to phase value specified via
input port or via dialog with Set counter to phase value specified via
dialog (see Section 13.4.1). The latter setting generates two new parameter
fields: Counting direction after phase synchronization, which can be
set equal to Count up after sync or Count dwon after sync, and Phase
offset value (TBPHS) which has to be defined. This feature enables to
configure the selected direction of the time-base counter immediately after
a synchronization event, such as TBCTR=TBPHS.
• Synchronization output (SYNCO)
Figure 13.25 shows that the synchronization input of the second ePWM
Synchronization between Multiple ePWM Modules 199
Example
Firmware Environment
c28069_PWMsync_F.slx (solver: fixed step - ODE4, step size: Ts = 1/3 kHz)
Modify the Simulink® file adopted for the Example proposed in Section 13.5
as follows:
• Make two copies of the ePWM block in order to have three of them in the
scheme;
ePWM1 settings:
• General (Tab)
sin50Hz WA
A3 WA
ePWM
ADC
ePWM3
C2802x/03x/05x/06x
WA
ePWM
ePWM2 settings:
• General (Tab)
ePWM3 settings:
• General (Tab)
0 1 2 3 4 5 6 7 8
10-4
• Sample time: Ts ;
• Data type: uint16;
• Flag Post interrupt at EOC trigger (optional);
shunt current
actual curent
carrier signal
into a closed-loop control based on linear controllers. Indeed, these latter may
work poorly in presence of high ripple. Thus, averaging may be necessary.
As an example, a setup which comprise a control platform (LaunchXL
F28069M) and a converter (BOOSTXL-DRV8301) equipped with current sen-
sors is considered. In this particular case, phase current measurements are
provided by some low-side shunts (see Section 3.2). By using the previous
synchronization settings, ADCA0 starts the acquisition window when ePWM1
module equals CTR=PRD (an up-down counting mode is adopted). This SOC
event is chosen since it occurs in the correspondence of the theoretical mean
value of the current, avoiding to process any ripple inside the MCU. This result
is shown in Figure 13.29. Note that in presence of an highly distorted current,
this approach still limits the amount of noise processed in the closed-loop
scheme. Therefore, when an average measurements is required, the firmware
should be settled to follow this proposed approach (i.e., ePWM and ADC
synchronization).
Instead, for ePWM8A module the settings can be the same as those used in
Example 1. Both ePWM7A and ePWM8A still operate with a 10 kHz carrier.
Once those module are set, the ADC block can configured for ADCA7 channel
as follows:
• Select ADCINA7 as Conversion channel in the Input Channels tab.
Then, go back to the SOC Trigger tab:
• Sampling mode: Single sampling mode;
• SOC trigger number: SOC0;
• At the beginning of Ts , when the PWM counter value equals the PWM
counter period (TBCR=TBPRD), the ePWM peripheral (which is center-
aligned in this case, that is, up-down counting mode) triggers the start-of-
conversion (SOC) event for the ADC module;
• The ADC module converts the sampled analog signal into digital counts and
triggers the end-of-conversion (EOC) event;
• The EOC triggers the ADC interrupt for the controller, which reads the
phase current value;
• Assuming that any other reference value is already provided, the controller
starts performing the required operations necessary to the computation of
the modulating signal for the ePWM module. The number as well as the
complexity of these operations define the length of this execution window;
• When the controller execution is done, the resulting modulating signal is
sent to the ePWM input and hold on until the end of the Ts .
14
Encoder Peripheral
The enhanced quadrature encoder pulse (eQEP) modules are used for direct
interface with linear or rotary encoders to get position, direction and speed
information from the rotating parts of a system. Typically, they are used for
measuring the speed or the position of rotors in electrical machines driven by
power electronics. Thus, this peripheral is used for closing speed or position
control loops. This Chapter provides some insight in the working principles of
this peripheral and of optical rotary encoders.
Figure 14.1 Generic structure of an optical rotary encoder disk and corre-
sponding channel signals [20].
(a)
(b)
disk rotates, the two optical sensors generate square waves signals that are
shifted by 90° out of phase from each other.
For the F28069M LaunchPad™ Piccolo™ board, these waveforms are called
QEPA (or simply A) and QEPB (or simply B) signals, while the index signal
QEPI (or simply I). QEPA and QEPB channels in quadrature (i.e., quadra-
ture encoders) means that when the incremental encoder is moving at a
constant speed, the duty cycle of each pulse is 50% (i.e., the waveform is a
square wave) realizing the 90° phase difference between A and B. Typically,
the clockwise direction is defined as the QEPA channel going positive before
the QEPB channel, as shown in Figure 14.2. Unlike absolute encoders, an
incremental encoder is not able to indicate absolute position. Indeed, it only
reports variations in position and the direction of the motion for every angular
change.
In general, direct coupled encoders (i.e., mounted on the rotor shaft be-
fore a gearbox) make one revolution for each complete rotation of the motor.
Therefore, the frequency of the digital signal coming from the QEPA and
QEPB outputs varies proportionally with the motor speed; high frequencies
indicate high speeds, whereas low frequencies mean slow speeds. The resolu-
tion of an incremental encoder refers to the precision of the produced posi-
tion information. In the case of rotary encoders, resolution is specified as the
number of pulses per revolution (ppr) or cycles/counts per revolution (cpr).
The ppr determines the number of pulses that can be counted on each signal
(QEPA and/or QEPB) in each complete revolution. Nevertheless, quadra-
ture encoders are able to increase their effective resolution by combining the
Hardware Details 209
+5V +5V
R13 1K
R29 1K
R48 1K
R49 1K
R50 1K
R51 1K
A 1 EQEP1A 1 EQEP2A
B 2 EQEP1B 2 EQEP2B
I 3 EQEP1I 3 EQEP2I
0.001u
0.001u
0.001u
0.001u
0.001u
0.001u
PWR 4 4
GND 5 5
C50
C51
C52
C53
C54
C55
QEP_A QEP_B
GND GND
even with an oscilloscope; the open collector output has no voltage when there is no pull-up
resistor.
Speed Computation 211
enough to detect every A/B state change before the following variation occurs.
Upon detecting a state change, the position counts xp (k) is incremented or
decremented based on whether A leads or lags B. This is typically done by
storing a copy of the previous A/B state and, upon state change, compare the
current and previous A/B states to determine movement direction.
Therefore, signals QEPA and QEPB are both processed for computing
angular speeds. Nevertheless, regarding the implementation, estimating the
speed from a digital position sensor is a cost-effective strategy in motor control.
Hence, two different first order approximations for the speed computation may
be written starting from the position counter xp (k), namely:
• Standard approach:
xp (k) − xp (k − 1) ∆x(k)
ω(k) ≈ = (14.2)
Tw Tw
where ω(k) is the speed computed at time step k, xp (k) and xp (k − 1)
are the position counters at time step k and k − 1 respectively, Tw is the
acquisition time window, which is the inverse of speed calculation rate (and is
known in advance). This approach is based on the fact that the encoder count
(position) is read once at the beginning of each acquisition time period, and
the width of each pulse is a function of the motor speed and the resolution
of the sensor.
However, this method has an inherent accuracy limit directly related to the
ratio between the resolution of the position sensor and the acquisition time
period Tw that has to be chosen.
As an example, considering the LPD3806-600BM-G5-24C encoder, a 600 ppr
quadrature encoder results in 2400 cpr which implies a resolution of
1
res = 360° = 0.15° (14.3)
cpr
|{z}
1
revolution
Considering a speed calculation rate of 400 Hz, thus, Tw = 1/400 = 2.5 ms,
it follows that:
round revolution 1
ωmin = or = 60 = 10 rpm (14.4)
min min cpr · Tw
| {z }
revolution
sec
Assuming that this motor has to measure the angular frequency of a mo-
tor, which rated speed is 2000 rpm, ωmin represents the 10 rpm/2000 rpm ≈
0.42% of this quantity. While this resolution may be satisfactory from mod-
erate to high speeds, it would behave poorly at very slow rotations. Indeed,
the estimated speed would erroneously be zero much of the time for pulsa-
tions lower than 10 rpm. Note that, by varying Tw , different minimum speed
can be computed, e.g., for Tw = 1/1e3 = 1 ms it results ωmin = 25 rpm.
Firmware Environment: eQEP Peripheral 213
C28x
qposcnt
eQEP
where tp (k) and tp (k − 1) are the time instant at time step k and k − 1
in which a channel A/B present a rising edge, while X is the position step,
that is, one. Equation (14.5) provides a more accurate approach at low
speed rather than (14.2). Such approach computes the speed by measuring
the elapsed time between consecutive edges. An acquisition window is not
present, while the encoder interface is required to work with a high sampling
time in order to detect rising edges even at high speed. Indeed, this approach
leads to better results at low speeds while suffering every time the motor
spins at such speed for which the sensor makes the time interval ∆tp small,
difficult to measure and greatly influenced by the timer resolution. Therefore,
considerable speed estimation errors can be introduced.
For motor control applications characterized by large speed ranges, these two
approaches can be combined by using (14.5) at low speed while switching to
(14.2) every time the motor speed overcomes a specified threshold.
This drop down menu allows to select which module is in use. The adopted
board has two modules only, i.e., eQEP1 and eQEP2.
• Position counter mode
Depending on the structure of the encoder, there are four ways in which the
device and the peripheral can be interfaced:
• Positive rotation
This option allows to select the convention for positive speed, i.e., clockwise
or anti-clockwise, depending on how the encoder is mechanically coupled
with a motor.
• Sample Time
This setting specifies how often the position counter is read. In case of the
standard speed computation approach, Equation (14.2), this refer to Tw
acquisition time period.
0 is set by defualt. There are different options for Position counter reset
mode, e.g., Reset on the maximum position.
• Output capture timer: this option enables the block to output the cap-
ture timer value in clock cycles stored inside the quadrature capture timer
(QCTMR) register, in the correspondence of the last quadrature signal. Port
qctmr is generated;
• Output capture period timer: this option enables the block to output
the capture period timer value (in clock cycles) stored in the quadrature
capture period (QCPRD) register, that is, the time elapsed between two
consecutive quadrature signals (i.e., positions). This value can be used for
speed computation purposes.
eQEPx output and used to compute a frequency or period from which speed
can be calculated. This exercise is carried out by considering a LPD3806-
600BM-G5-24C incremental rotary encoder, aiming to implement the stan-
dard computation approach by using Equation (14.2).
Firmware Environment
c28069_encoder_F.slx (solver: fixed step-ODE4, step size: Ts = 100 µs)
Open a new blank Simulink® project and configure the environment as shown
in Chapter 9. Edit an initialization script, e.g., in Model Properites/Callback-
s/InitFcn. Then:
– General (Tab)
∗ select module eQEP2;
∗ set Position counter mode to Quadrature-count;
∗ set Positive rotation equal to Clockwise;
∗ set Sample time equal to Tw ;
∗ leave the other default settings.
• Insert a Delay block with Sample time equal to Tw and Delay length
equal to 1 (i.e., one step delay).
• Insert an Add block followed by a Data type conversion block set to
single. This process the difference between xp (k) and xp (k − 1) which is
then multiplied by a Gain block set to 60/(cpr · Tw ). The result is in rpm,
which can be translated in rad/s by multiplying this quantity by π/30.
Example with eQEP block 217
C2806x
C28x GPIOx
qposcnt GPIO DO
w
led red
eQEP Z-1
encoder
• Insert a GPIO block with the related data type as reported in Chapter 11
(red led is connected to GPIO34);
The whole Simulink® scheme is shown in Figure 14.7. Every time the position
signals QEP2A e QEP2B are sampled (discrete time signals), the pulses (or
pulse edges) are detected and counted by the encoder interface. The MCU has
read access to the interface and the eQEP module returns directly the position
counter through qposcnt. The latter is then used to compute the speed by
taking the actual position count xp (k), i.e., qposcnt(k), and the previous one
xp (k − 1), i.e., qposcnt(k-1), within a specific acquisition period Tw . This is
realized by using an add and delay block, with sample time Tw . The result is
then multiplied by 60/(cpr·Tw ). Considering a speed calculation rate of 400 Hz,
it follows Tw = 1/400 = 2.5 ms. Note that, the sample time Ts is related to the
switching period of the modulator, e.g. Ts = Tsw = 1/fsw = 1/10e3 = 100 µs.
Hence, it follows Tw = 25 · Ts , which underline that Tw is (quite) often a
multiple of Ts to keep an hierarchical scheduling of firmware executions.
A coefficient equal to 60 is used since 1/(cpr · Tw ) is expressed as counts
per unit time (e.g., counts per second), while, in practice, it may be necessary
to translate the speed in units such as revolutions per minute (rpm). Such
scaling factor takes into account the relationship between counts and desired
distance units, as well as the ratio between the sampling period and desired
time units. The other coefficient depends on the fact that LPD3806-600BM-
G5-24C encoder produces 2400 counts per revolution (cpr). The speed is finally
multiplied by another scaling factor, i.e., π/30, to move from rpm to rad/s.
Given the encoder connection on eQEP2 as shown in Figure 14.5, the firmware
can be tested by manually rotating the encoder shaft. The qposcnt value is
connected to the red led (GPIO34) to visualize the pulse frequency changes
Figure 14.8 QEP2A (pin 54) and QEP2B (pin 55) waveforms, measured
through an oscilloscope for slow rotational speeds.
218 Encoder Peripheral
Figure 14.9 Detailed QEP2A (pin 54) and QEP2B (pin 55) waveforms in case
of slow and fast rotation scenarios.
Figure 14.10 QEP2A (pin 54) and QEP2B (pin 55) waveforms in case a fast
transition from slow to high rotational speed is considered.
.
2 Both cables and encoder interface circuits (even considering the voltage regulator)
Real-Time Control in
Power Electronics:
Applications
15
Open Loop Control of a Permanent Magnet
DC Motor
After a brief overview of the main peripherals and their main settings for the
F28069M LaunchPad™ Piccolo™ board, the reader is guided in this part of
the book where some experimental open- and close-loop implementations are
described step-by-step. Starting from simple examples with DC motors and
custom RL(C) loads, the reader will be shown how to solve all the proposed
control problems starting from the preliminary Simulink® simulations, then
going through the design of the PI controller and finally implementing the re-
quired control loops. In particular, this Chapter shows some examples of open-
loop control algorithms for DC Motors using the Simulink® blocks introduced
in the previous Sections coming from the Embedded Coder Support Package for
Texas Instruments C2000 Processors library. The objective is to drive a two-
pole permanent magnet DC (PMDC) motor through a BOOSTXL-DRV8301
converter connected to the LaunchXL F28069M board. The DRV8301 boost-
erpack presents three independent MOSFET-based switching legs. It is worth
noting that the actuation of a PMDC motor does not require the use of all of
them (i.e., due to its DC nature). However, the converter legs can be physi-
cally connected to create some specific topologies. In particular, two conversion
stage configurations are investigated:
• Half-Bridge (also known as Two-Quadrants converter);
• Full-Bridge (also known as H-Bridge or Four-Quadrants converter).
Both stages aim to convert a fixed input DC voltage, VDC , to a variable/con-
trolled output DC voltage, which is provided at the PMDC terminals. Such
DC-DC converters are also called choppers.
The reader is referred to Section 3.2 for all the details on BOOSTXL-
DRV8301 board. Since the three legs of the converter are independent, it
is possible to realize the two aforementioned configurations by changing the
physical connections between the motor and the power converter. Then, the
related ePWM modules must be enabled.
It is important to note that every time the converter is mounted on the
microcontroller board, it is preferable to feed both of them through the power
supply only. Indeed, jumpers JP1 and JP2 should be removed (further details
are reported in Section 3.1.3) to isolate the USB port. In this case, the USB
connection is used to deploy of the firmware and for the serial communication
between the LaunchPad™ and the PC only. Moreover, it should be remem-
bered that the BOOSTXL-DRV8301 converter must be supplied with a DC
voltage which is VDC > 6 V, to allow the proper working of the boosterpack
regardless of the state of the jumpers JP1 and JP2. The reader is referred to
the rated voltage limits of the converter reported in Section 3.2.
Now, the LaunchPad™ F28069M board connected to the BOOSTXL-
DRV8301 converter are programmed to drive the PMDC motor in open loop
by manipulating the duty cycle d(t). Both the possible converter configura-
tions are considered. This is achieved by using one of linear potentiometers
mounted on the extPot3 custom board. As shown in Section 12.4, the rotation
of the potentiometer changes an internal resistance, i.e., varying the ratio of a
voltage divider. The resulting voltage value is read by the ADC peripheral that
converts it into a digital value. By using a proper scaling (like those presented
in Chapter 13), this latter can be used as a modulating signal for the ePWM
peripheral. Depending on the chosen topology, one or two ePMW modules
are operated in up-down counting mode at fsw = PWMfrequency = 20 kHz.
Reminding that for the F28069M board fck = CPUfrequency = 90 MHz, it
follows:
CPUfrequency
TBPRD = PWMcounter−period = = 2250 (15.1)
2 · PWMfrequency
ia (t) La Ra
va (t) e (t)
coils with the external power supply through brushes. A coil of wire with a
current running through it generates an electromagnetic field aligned with
the center of the coil. Direction and magnitude of the magnetic field produced
by the coil can be changed with the direction and magnitude of the current
flowing through it.
Focusing on the system to control, the equivalent circuit of the PMDC
motor is shown in Figure 15.1 and its electrical and mechanical equations are:
dia (t)
La =va (t) − Ra ia (t) − e (t) (15.2)
dt
dΩ(t)
J =me (t) − ml (t) − βΩ(t) (15.3)
dt
where La is the armature inductance, Ra is the armature resistance, ia (t)
is the armature current (i.e., the current flowing through the winding of the
motor), va (t) is the armature voltage (i.e., the voltage applied to the terminals
of the machine), e is the back electromotive force (back-emf) induced on the
armature winding, J is the equivalent moment of inertia of the machine, β
is the rolling friction coefficient, Ω(t) is the mechanical speed of the rotor,
me (t) is the torque generated by the motor and ml (t) is load torque that may
be applied to the electrical machine. In DC machines, both electromagnetic
torque me (t) and back-emf e(t) depend on the magnetic flux linked with the
armature windings ψae and the related constants kT and ke , respectively. As
the name says, the main feature of PMDC machines is the presence of perma-
nent magnets (PM) on the stator to provide the magnetic field against which
the rotor field interacts to produce torque.1 The use of PMs is convenient
in small motors to eliminate the power consumption of the field windings,
thus, increasing their efficiency. Moreover, large PMs are costly and difficult
to assemble; this favors wound fields for large machines. To minimize overall
weight and size, small PMDC motors may use high energy magnets made by
peculiar alloys, e.g., with rare earth materials such as neodymium-iron-boron
or samarium-cobalt.
The PMs create a constant flux density B (if no field weakening tech-
nique is applied) and, accordingly, a constant excitation flux which is defined
1 Therefore, the PMs replace the excitation circuit installed in separately excited DC
Figure 15.2 First magnetization curve of two PMs (no hysteresis is represented
here) and internal structure of the PMDC motor used in this exercise.
PM (ψPM = ψae (t)), see Figure 15.2. This is the case for all the examples
reported in this book which use PMDC motor. Moreover, kT and ke can be ap-
proximately considered equal, assuming that the energy conversion is almost
perfect. Thus, a new constant K can be defined as K = ψPM kT = ψPM ke .
Therefore, the electrical torque and the back emf can be computed as:
with me (t) which is function of ia (t) only. The voltage va (t) is a controllable
variable, i.e., u(t) , which allows to increase/decrease the current flowing into
the PMDC motor (according to the system parameters). Assuming that ml (t)
is a controllable disturbance related to the characteristic of the mechanical
load, the vector of the inputs is u(t) = [va (t) ml (t)]T . As shown in Chapter
5, by considering2 x(t) = [Ω(t) ia (t)]T and y(t) = x(t), the equations (15.2)-
(15.5) can be summarized by the following state-space representation:
dx(t)
= Ax(t) + Bu(t) (15.6)
dt
y(t) = Cx(t) (15.7)
ml (t)
−
va (t) 1 ia (t) me (t) 1
(t)
K
+ Ra + sLa + + sJ
−
e(t)
K
2L-VSC
=
VDC PMDC
= motor
S(k)
d (k)
modulator
physics.
Half-Bridge Configuration 227
1A ia (t) La Ra
VDC +
−
va (t) e (t)
1B
%% power supply
Vdc = 10;
%% carrier frequency definition
fsw = 20e3;
Tsw = 1/fsw;
%% sampling time definition
Ts = 50e-6;
%% step-size definition
Tsim = Tsw/400;
%% motor parameters
Ra = 0.5290;
La = 8.6507e-4;
K = 0.0232;
B = 1.8026e-4;
J = 3.559e-6;
The simulation time step Tsim is small enough to approximate the switching
behavior and high frequency effects that occurs in the scheme well, i.e., get-
ting the simulation closer to the practice. The reference subsystem includes
several kind of inputs to operate the system differently. Focusing on the PWM
stage, the duty cycle d(k) is compared to a triangular carrier at fc = 20 kHz,
generating a switching pattern S(k). This is done in the MCU by using the
ePWM modules. The gate signals of the 2L-VSC topology are S(k) = S1 (k)
for 1A and S2 (k) = not(S1 (k)) for 1B , which are applied to the switch through
the gate drivers. Therefore, the operation of these switches together with the
given switching pattern creates a pulsed output voltage waveform, i.e., the
Half-Bridge Configuration 229
Continuous
s1A
D
PMDC w
1A i
modA
TL m
S
modA
reference dc
m
carA s1A
A+ A-
s1B
s1B
carA
D
+
1B v va
-
S
Figure 15.6 Simulink® scheme to simulate the open-loop dynamics of the
PMDC motor driven in half-bridge configuration included in HBsimDC.slx.
armature voltage va (k). This is the reason why the average value of this latter
va,avg (k) is considered in Equation (15.12). Indeed the actual voltage va (k) is
computed as
va (k) = S(k)VDC (15.13)
which is discontinuous and bounded within two voltage levels, i.e., [0, VDC ].
Considering the ramp waveform ranging from 0 to 1 as reference signal, d(k)
reaches 1 in 0.3 ms after which such value is hold. The effects of the reference
increase are reflected into the switching pattern of 1A and 1B , which is aimed
to make the average armature voltage Va (k) increasing by enlarging the pulse
width of va (k). This is evident in Figure 15.7. This latter also shows that the
speed Ω(k) is increasing almost quadratically. In can be noted that the same
occurs for the current ia (k) and the torque me (k), but the switching effects
are more evident (see the dashed line interval reported in Figure 15.7). Indeed,
the inertia J limits these abrupt variations on Ω(k).
A longer simulation with trapezoidal duty cycle d(k) is then considered, as
shown in Figure 15.8. The carrier waveform is dropped out to improve the plot
readability. A longer simulation allows to analyze the steady-state interval for
each of the considered quantities. In particular, Figure 15.8 shows how fast
is the current ia (k) reaction to the voltage increase. Its dynamic is related to
La . When va,avg (k) reaches the first steady-state point, the current ia (k) is
at its peak value and, after that, it starts decreasing due to the presence of
e(k) (the motor is spinning) and Ra . The speed Ω(k) requires, as expected,
a longer time to reach the steady-state due to the mechanical inertia J. It is
fundamental to remind that the considered system is running in open-loop.
Thus, no forcing action to adjust the dynamics of the motor is applied.
230 Open Loop Control of a Permanent Magnet DC Motor
Figure 15.7 Open-loop dynamics of the PMDC motor with a ramp reference
signal and Half-Bridge converter.
Half-Bridge Configuration 231
12
10
300
200
100
0
0 0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09
0.12
0.1
0.08
0.06
0.04
0.02
0
0 0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09
Figure 15.8 Analysis of steady-state and transient intervals for the open-loop
dynamics of the PMDC motor.
Firmware Environment
c28069_openDC_hbF.slx (solver: fixed step - ODE4, step size: Ts = 50 µs)
Open a new blank Simulink® project and configure the environment as shown
in Chapter 9. Then:
• Open the Model Configuration Parameters window and use the same
settings adopted for the Example 1 in Section 10.5.
• Add a GPIO block. Remember that the BOOSTXL-DRV8301 is enabled
by settling GPIO50 high (see Section 3.2). Namely, the GPIO peripheral
is driven by a Constant block with value 1 and sample time Ts .
• Insert an ADC block to read the potentiometer mounted on the extPot3
custom board; double click on it:
– Select ADCINB5 as Conversion channel in the Input Channels
tab. The, go back to the SOC Trigger tab:
– Sampling mode: Single sampling mode;
– SOC trigger number: SOC0;
– SOCx acqusition window: 7;
– SOCx trigger source: CPU0_TINT0n or Software;
– ADC will trigger SOCx: No ADCINT;
– Sample time: TADC = 0.001 s;
– Data type: uint16;
Half-Bridge Configuration 233
GND
rotating
legA
ADCINB5
DC link
• Place a Gain block for scaling the digitalized signal within [0, 1]. This is
fundamental because a 12-bit reading returns a value in a range from 0
(0 V) up to 212 − 1 = 4095 (3.3 V). Hence, set the gain as 1/(212 − 1) or, to
be more conservative, as 1/212 , even if it, in this last case, the representation
range is not fully exploited.4
• Insert an ePWM block and use the same settings reported in Section 13.5:
– Select ePWM1 module with TBPRD related to fc = 20 kHz, i.e.,
PWMcounter−period = 2250;
– Remember to unflag Enable ePWM1B and tick Inverted version of
ePWMxA. This option allows to drive 1B as the complement of 1A ;
– Keep all the other settings as reported in Section 13.5.
• Add another gain block to normalize the modulation signal over the peak
value of the carrier signal PWMcounter−period . Include a data type conver-
sion set to int16 to represent the duty cycle within a 16-bit base.
4 Alternatively, this operation can be carried out by using an arithmetic shift of 12 bit,
which is the preferable choice in microcontrollers. Indeed, this kind of operation is quicker
than multiplications or divisions with this hardware. In particular, the right shift means
division (see Section 7.3).
234 Open Loop Control of a Permanent Magnet DC Motor
DRV enable
C2806x
GPIOx
potentiometer B5 GPIO DO
C2802x/03x/05x/06x
C2802x/03x/05x/06x
B5
WA
ADC
ePWM
A
pulses
1A 2A
e (t)
+ ia (t) La Ra
VDC
−
va (t)
1B 2B
Similarly to Section 15.4, the simulation time step Tsim is set small. Moreover,
the reference subsystem includes different kind of inputs to operate the system
differently. A unipolar or bipolar voltage switching approaches can be selected
by acting on the manual switch, which sets the carrier phase-shift (carB)
processed by the modulator stage related to leg B.
Moreover, the actuation of the two legs (i.e., two duty cycles for two mod-
ulation stages) is done by manipulating one modulation signal d(k) only, from
which the gating signals of the four switches are generated. Such switching
pattern derivations (that is, how to compute the duty cycles) can be done by
using different strategies. Therefore, before going into the implementation de-
tails, the following sections provide the descriptions of the different converter
operations.
The two legs should be synchronously operated to control the current flow
iA (k) of the motor and regulate its rotation as well. Thus, dA (k) and dB (k)
236 Open Loop Control of a Permanent Magnet DC Motor
Continuous
s1A s2A
modA
modB
D
reference w
s1A 1A PMDC 2A
carA i
s1B
S
TL m
carA
modB m
dc
modB
s1B A+ A- s2B
carB s2A
D
s2B
+
-
unipolar carB 1B 2B
carB
v
S
S
bipolar va
carB
-5
-10
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
10-4
10
10
in Figure 15.16 (where the carrier waveforms are dropped out to improve the
plot readability). In particular, the benefits in terms of lower current ripple in
ia (k) is evident.
The unipolar voltage switching reduces the magnitude of the harmonic
components of va (k) and ia (k), which means lower ripple and harmonic dis-
tortion, while keeping the converter switching frequency fsw constant. This
goal is achieved by displacing vA (k) and vB (k), so that the effective switch-
ing frequency in va (k) is 2fsw and, consequently, in ia (k) as well. In standard
240 Open Loop Control of a Permanent Magnet DC Motor
Therefore, the RMS value of va (k) is varying in time, ranging between 0 and
VDC , as shown in Figures 15.15 and 15.16.
In conclusion, this solution has the following advantages and disadvantages:
Advantages
• Better harmonic content compared both to the Half-Bridge and Full-Bridge
bipolar voltage switching configurations;
• One control signal is needed leading to three voltage levels (−VDC , 0, +VDC ).
Full-Bridge Configuration 241
Disadvantages
• The RMS value of the armature voltage varies in time.
Even in this case, one modulating signal is still enough to fully operate the
system. Thus, the relationship between d(k) = dA (k) (i.e., potentiometer ro-
tation) and the motor speed is the same as for the unipolar voltage switching.
The main peculiarity of this solution, compared with the previous case, is
that in a bipolar voltage switching approach the output of leg A, vA (k), is
equal and opposite to the output of leg B, vB (k). This condition is carried out
by complementing the behavior of ePWM1 and ePWM2 modules. Given the
equivalent circuit reported in Figure 15.12, the diagonally opposite switches
1A , 2B and 1B , 2A are turned on or off at the same time. This logic leads to
an armature voltage va switching between two levels: −VDC and +VDC , which
is the reason beyond the name bipolar.
In terms of implementation, only one ePWM module may be used to realize
such approach theoretically speaking. For instance, if ePWM1 is settled to
provide S1 (k) and S2 (k) (i.e., driving 1A , 1B ) at pins 40 and 39 respectively,
it would be enough to physically connect S3 (k) to pin 39 and S4 (k) to pin 40
to control leg B.
On the other hand, the proposed implementation foresees to use two mod-
ulator stages (ePWM1/2). The bipolar voltage switching is achieved by using
modulators operating with different triangular carriers. The latter would be
in opposition (counter-phase) to each other. For instances, if the phase shift of
the ePWM1 carrier is set equal to 0◦ (or 90◦ ), then the one of ePWM2 should
be set equal to 180◦ (or −90◦ ), which is equivalent to have an inverted/mir-
rored carrier. Since the carrier is internally created by the ePWM blocks, the
phase shift is introduced through a specific parameter setting.
Figure 15.18 shows an example of bipolar voltage switching operation.
In particular, the same positive ramp profile adopted for the unipolar case
is applied to d(k) = dA (k) and complemented for dB (k). At the beginning,
d(k) = 0 → dA (k) = 0, dB (k) = 1 leading to vA (k) = −VDC . Nevertheless,
at the following time steps, Figure 15.18 shows how the zero voltage level is
absent from va (k), leading to a switching between −VDC and VDC to regulate
the average voltage. The resulting behavior of the output voltages vA (k) and
vB (k) (which are always positive) are shown in Figure 15.19.
Comparing Figure 15.14 and 15.18, it is evident that the bipolar voltage
switching returns an higher current and voltage harmonic distortion with re-
spect to the unipolar one. The latter benefit of the cancellation of the all the
242 Open Loop Control of a Permanent Magnet DC Motor
-5
-10
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
10-4
10
10
odd harmonics of fsw for va (k) and, consequently, ia (k), which is not the case
for the bipolar case. This can be proved and clarified by Figure 15.20, which
compares the harmonic spectra of the armature voltages va (k) when a fixed
Figure 15.20 Spectra (truncated at the 5th harmonic) of the armature voltages
obtained in unipolar and bipolar voltage switching operator. In both cases,
the converter operates at the same fsw .
244 Open Loop Control of a Permanent Magnet DC Motor
duty cycle d(k) = 0.2 (i.e., in steady-state conditions) is applied for the unipo-
lar and bipolar operations, respectively. The spectra are computed through a
discrete fast Fourier transform (DFFT) considering 800 periods. The converter
legs are operated at the same fsw in both cases. This comparison shows how
the unipolar approach is able to operate the system at an effective switching
frequency of 2fsw , leading to a lower current distortion.
Similarly to Section 15.5.2, a long simulation and a trapezoidal duty cy-
cle d(k) are considered for the bipolar operation. The results are shown in
Full-Bridge Configuration 245
Figure 15.21, where the carrier waveforms are dropped out to improve the
plot readability. A larger ripple on ia (k) is particularly evident in comparison
to Figure 15.16.
Regarding the RMS value of the armature voltage, va (k) is now a bipolar
pulse function. Inside one sampling period Ts (where the on time is defined
as t1 , see Figure 15.22), va (t) = VDC for 0 ≤ t < t1 , while va (t) = −VDC
for t1 ≤ t < Ts . By replacing such values in the general equation (15.19), it
follows:
v
Zt1 ZTs
u
u1
r r
t1 t1
u
2
va,RMS = t VDC + (−VDC ) dt = VDC
2 + VDC 1 − = VDC
Ts Ts Ts
0 t1
(15.23)
Therefore, the RMS value of va (k) in case of bipolar voltage switching is always
constant and equal to VDC independently from the duty cycle, as shown in
Figure 15.19 and 15.16. As an example, it can be assumed to include a lighting
device in the drive system. Light emissions are sensitive to the RMS value of
the supply voltage (this is true for LEDs, incandescent and fluorescent lights).
By connecting a lighting device in parallel to the PMDC motor terminal, the
motor control is unaffected and this device is continuously emitting light. Car
mirrors typically use this idea to regulate the position of the mirrors through
small motors, while turning on/off the integrated light indicators by directly
connecting, e.g., LEDs, to the motor terminals.5 In conclusion, the bipolar
solution shows the following advantages and disadvantages:
Advantages
• One modulation signal needed leading to two voltage levels (+VDC , −VDC );
• RMS value of the armature voltage is constant.
Disadvantages
• Higher voltage and current harmonic distortion compared to unipolar case.
5 This approach is used to reduce the number of elements aimed to the electronic circuit.
246 Open Loop Control of a Permanent Magnet DC Motor
legB
rotating
legA
ADCINB5
DC link
Open a new blank Simulink® project and configure the environment as shown
in Chapter 9. Then:
• Open the Model Configuration Parameters window and use the same
settings adopted for the Example 1 in Section 10.5.
• Insert an ADC block to read the potentiometer and set it as shown in
the previous Section 15.4.1. Indeed, the potentiometer reading is the same.
Hence, add Data Type Conversion blocks to manipulate the signal (i.e.,
int16 and single). Place a Gain block set to 1/212 to scale the digitalized
signal within [0, 1].
• Insert two ePWM blocks; use the settings reported in Section 13.5:
Full-Bridge Configuration 247
B
C2802x/03x/05x/06x
db
WA
ePWM
potentiometer B5
A
C2802x/03x/05x/06x
C2802x/03x/05x/06x
B5 d da
WA
ADC
ePWM
pulses
Take the previous Simulink® project about the unipolar voltage switching
There, the PWM actuation must be modified. In particular, the ePWM pe-
ripherals of the TI LaunchXL F28069M Piccolo™ allow swap features be-
tween ePWMxA and ePWMxB. By selecting swap the ePWMA and eP-
WMB outputs, the computed ePWMxA output signal is redirect/provided
at the ePWMxB output terminal, and vice-versa. For the bipolar approach,
this feature allows to simplify the PWM actuation since the duty cycles
are set dA (k) = dB (k). Two modulation stages are considered, ePWM1
(which provides S1 (k), S2 (k)) and ePWM2 (which provides S3 (k), S4 (k)),
both fed with the same modulating signal. If ePWM2 is swap-enabled, then
ePWM2A=S3 (k) and ePWM2B=S3 (k). Thus, if ePWM1 has standard set-
tings, it follows that S1 (k) = S4 (k) and S2 (k) = S3 (k). This latter correspond
to the bipolar voltage switching principle and it is exactly equivalent to make
ePWM2 operating with a triangular carrier shifted by 180° with respect to
ePWM1 and having dB (k) = (1 − dA (k)).
Therefore, the previous scheme has to be updated as follows:
• Remove the dB (k) derivation, keeping one duty cycle only, i.e., dA (k) =
dB (k), by deleting the constant and the add block.
• Use the same settings adopted in the unipolar case for module ePWM1:
TBPRD corresponds to fc = 20 kHz, i.e., PWMcounterperiod = 2250.
• Keep the same settings for ePWM2 apart from the following:
– Thick enable swap module A and B at the bottom of the General tab.
• Keep the rest of the scheme set as before.
Full-Bridge Configuration 249
B
C2802x/03x/05x/06x
WA
ePWM
potentiometer B5
da=db A
C2802x/03x/05x/06x
C2802x/03x/05x/06x
B5 d
WA
ADC
ePWM
pulses
In order to close a control loop with the LaunchPad™ F28069M board, dif-
ferent measurements have to be managed and processed. Current, voltage
and speed sensors (e.g., encoders or hall effect sensors) are widely adopted
in electrical drive applications. These devices are usually placed at the power
converter terminals or mechanically coupled with the load. The resulting mea-
surements are fed into the MCU through ADC or GPIO channels. This section
focuses on how to manage current measurements.
For instance, the TI™ BOOSTXL-DRV8301 converter has both voltage
and current sensors on-board. In particular, this board includes a low-side
shunt current sensor, which is a resistor placed below the low side MOSFET
(e.g., 1B ) of each leg. A differential operational amplifier (op-amp) takes the
differential voltage across the resistor as input, which varies depending to the
current flow, to compute a filtered voltage value scaled for the peripheral in-
puts (i.e., ranging in [0, 3.3] V). The corresponding equivalent circuit is shown
in Figure 16.1 (a). It is worth noting that shunt resistors provide an indirect
current measurements since, actually, a voltage drop across them is measured.
The main advantage of low-side sensing is the simple implementation.
Moreover, being on the low side of the load, the common-mode voltage at
the shunt is approximately zero; therefore, the robustness of the amplifiers is
not an important factor. However, this solution comes at the cost of ground
variations and it foresees a resistance between in the path to ground. Indeed,
this resistance removes the ability to detect faults in the load if it is shorted
to ground. Moreover, the op-amp circuit present several gains, which can be
activated by acting on dedicated registers to adjust its output according to
the magnitude of the measurement, as shown in Figure 16.1 (b). Hereafter, to
simplify the notation, the terms op-amp or amplification stage directly refer
to the differential structure shown in Figure 16.1 (b).
In order to design a firmware able to manage a current feedbacks, an
accurate ADC conversion chain must be built taking into account the tol-
erances of the components mounted on sensoring circuits mounted on the
BOOSTXL-DRV8301 converter as well as the ADC peripheral resolution of
the LaunchPad™ F28069M board. In practice, this means to set some gains
that allow a proper calibration of the conversion chain. To this aim, the fol-
lowing sections propose and compare two approaches: a theoretical and an
experimental calibration targeted on the available hardware.
leg 1
1A
dc-dc
1B
vcc
v1
amplifcation
RSH vSH
stage
(a) (b)
Figure 16.1 Equivalent circuit of (a) low-side shunt resistor and op-amp circuit
for leg 1 and a (b) detailed view of the op-amp differential structure and
selectable gains through switches S1 − S4. In this last schematic vSO = vsh
[14].
vSO (k) = vref − 10(vSN (k) − vSP (k)) = vref − 10RSH i (k) (16.2)
| {z }
RSH i(t)
3.5
2.5
1.5
0.5
-0.5
provided at the ADC peripheral inputs are inside a [0.25, 3.05] V range. This
means that the amplification circuit has a safety margin for current manage-
ment, since the magnitude of the current can be theoretically pushed up to
±16.5 A. This last range allows to exploit the all the possible voltage values,
that is, [0, 3.3] V. Namely:
vmax − vref mV
gi = 10RSH = = 0.1 Ω = 100 (16.5)
imax A
Then, vSO is processed and scaled over the 12 bit ADC peripheral through a
quantization process, which can by accounted for by the gain:
vmax 3.3 mV
gv = = ≈ 0.81 (16.6)
212 − 1 4095 bit
0 − 4096 bit
i (t) ±1.65 V
gi + vSO (t) vSO (k) ADC bit
vSO (k)
S&H + ±2048 bit i (k)
+ gv−1 gadc
vref 0 − 3.3 V −
bit
2 vref
2
ADC peripheral
Figure 16.3 ADC conversion chain for current measurement through the
BOOSTXL-DRV8301 converter board.
The same process can be used to compute all the other current values.
Remark: it is convenient to synchronize the conversion procedure of the ADC
peripheral with the ePWM module as reported in Section 13.9.
Ra
Ia
Va e (t) = 0
This test can be carried out driving the PMDC motor in open-loop with
a converter in half-bridge configuration (see the equivalent circuit in Figure
15.5). The power supply is set to VDC ≈ 10 V with current limitation at 2 A.
Differently from the exercises reported in Chapter 15, the duty cycle is now
constant and internally settled into the MCU instead of using a potentimeter.
This is aimed to have a constant and stable voltage supplied at the motor
terminal, which implies a constant current absorption as well. Hence, the duty
cycle is set to d = 0.2 so that Va ≈ 2 V at armature windings. It follows that:
Va 2V
Ia = = ≈ 3.33 A (16.10)
Ra 0.6 Ω
Since the motor size is small and the applied voltage low, the rotor can be
hand locked with the help of a clamp, as reported in Figure 16.5. A simple
test is to measure the motor current at steady-state with an ADC peripheral
and visualize it through the Serial Port (e.g., SCIA). If the conversion chain is
correctly set, using gv and gadc , the result should be close to the value reported
in equation (16.10). Regarding the MCU programming, it is suggested to start
from the firmware developed in Section 15.4.1.
Firmware Environment
c28069_lockedDC_F.slx (solver: fixed step - ODE4, step size Ts = 50 µs)
• Insert a Constant equal to 2048 (as int16) and an Add block with list of
signs +− to remove the offset at the ADC output.
• Add a data type conversion block set to double (or single) for safer
mathematical computations. See see Chapter 7 for reference.
• Insert a Gain block set on gadc = 8 mA/bit to map the ADC reading over
a range of values in Ampere.
• Add a data type conversion block set to single combined with a Rate
Transition block with sample time TSCI = 0.01 s to prepare the data ex-
change.
• Insert a Mux block to send two inputs via the SCI Transmit block.
• Insert a SCI Transmit block and set it as shown in Section 10.5 (i.e.,
SCIA).
• Place a pulse generator block and double click on it:
– Set pulse type on Sample based;
– Insert an Amplitude equal to 0.2;
– Choose a period of 250 samples;
– Type a pulse width of 125 samples;
– Insert a sample time of 0.01 s.
The duty cycle is now a train of pulses with amplitude 0.2. This block
is included to limit the steady-state condition. Indeed, even if the current
is low, being related to the voltage input (which is 2 V while the rated
value for this motor is 24 V), the temperatire of the armature windings may
rise too much. The latter may lead to significant variations in the windings
resistance, thus, affecting the measurement. Hence, the pulse generator block
prevents overheating.
Locked Rotor Test 257
ePWM1A: J4 - pin40
C2802x/03x/05x/06x
WA
ePWM
shunt
C2802x/03x/05x/06x C28x
vSO_bit
A0 Data
i SCI XMT
ADC
offset
• Add a data type conversion block set to single combined with a Rate
Transition block (TSCI = 0.01 s), to prepare the output data of the pulse
generator. Connect it to the Mux block
• For the ePWM settings the reader is referred to Section 15.4.1 (fc = 20 kHz)
The arrangement of these blocks is shown in Figure 16.6. Since fc =
fsw holds, the sampling time for the current is Ts = Tsw = 50 µs. A
up-down couting mode is used with a TBPRD = PWMcounter−period =
CPUfrequency /2 · PWMfrequency = 2250. An initialization script either in Model
Properites/Callbacks/InitFcn or as a separate m-file should be edited to
set the system parameters. The latter approach is used in this exercise
(lockDC_init.m) and the code is reported here in the following:
%% F28069M clock
CPU_frequency = 90e6;
%% carrier frequency definition
PWM_frequency = 20e3;
Tsw = 1/PWM_frequency
%% TBPRD (counting mode) definition
PWM_counterperiod = CPU_frequency/(2*PWM_frequency)
%% sampling time definition
Ts = Tsw;
%% ADC theoretical gain
g_adc = 33/4095;
Testing Environment
c28069_lockedDC_T (solver: fixed step - ODE4, step size Tsim = 100 µs)
Open a blank Simulink® project and set the Model Configuration Pa-
rameters as reported in Section 10.5. Then:
• insert a Serial Configuration block and set it as reported in Section 10.5.
258 Low-Side Shunt Current Sensing
COM10
115200 COM10 Data d
8,none,1 i
iavg
Figure 16.8 Comparison between the current measured through the low-side
shunt resistor and the expected steady state values. Those current levels were
evaluated thorough a current probe.
nA
dc-dc
nB
VS1 + vcc
−
IS2
amplifcation
RSH vSH
stage
Figure 16.9 Equivalent circuit of the test setup for the characterization of the
current sensor for the generic leg n, where n = 1, 2 or 3.
1 This is not always the case and a characterization even for negative currents is recom-
A0 Data
Firmware Environment
c28069_offset_F.slx (solver: fixed step - ODE4, step size: Ts = 50 µs)
Testing Environment
c28069_offset_T (solver: fixed step - ODE4, step size: Tsim = 100 µs)
Build a new testing environment simplifying the previous one. Indeed, only
one signal is sent trough SCI:
• Keep the Serial Configuration and the Serial Receive blocks. Change
the data size back to [1 1].
• Use a Scope or a Display block to visualize the current reading translated
in a bits.
• Delete or comment out the remaining blocks.
262 Low-Side Shunt Current Sensing
COM10
115200 COM10 Data
8,none,1 bit
• Optional: a Mean block could be added to filter the noise, which may be
present in the bit reading. Use the settings presented in the previous exercise
for this block.
Arrange these blocks as reported in Figure 16.11.
By feeding only the dc-link with a given voltage (e.g., VDC = 10 V) without
connecting the second power supply (i.e., no forced current flow), the SCIA
returns the bit value of vSH
bit
corresponding to zero current. Theoretically, this
value should be 2048 for 12 bit ADC. However, due to the components toler-
ance, the resulting value is vSH
bit
= 2067 in this case. The latter value is strictly
related to the hardware. Therefore, every reader performing such test will find
(slightly) different results. The new bit value is used to compensate the bias
highlighted in Figure 16.8.
2200
if (k) bit
vSO (k) 2160
0A 2067
240 mA 2097
2140
shunt
C2802x/03x/05x/06x vSO_bit
C28x
A0
Data
ADC
SCI XMT
offset exp.
3.5
2.5
1.5
0.5
-0.5
d(k) are read via the SCIA, they are both affected by the same delay. This
latter can be reduced by using a faster sampling rate (in this case 0.01 s should
be reduced) until the MCU capabilities are reached. For instance, if a current
probe is able to measure a transient with a classical exponential waveform, the
serial communication tend to approximate it to a step-wise signal as a con-
sequence of the lack of samples. Figure 16.15 also shows an offset in iosc (k).
This is a consequence of the connection between the LaunchXL F28069M
board and the BOOSXL - DRV8301 converter. Indeed, the MCU is powered
by the power supply connected to the dc-link, requiring a minimum current
absorption. It can be noted that the same locked-rotor test can be performed
considering a H-bridge configuration.
Be careful: integer numbers are used to perform the sum aimed to re-
move the offset. Therefore, int16 is chosen as ADC output
data type to allow computations involving negative values.
As seen previously, it is always possible to use (directly)
single or double numbers to increase accuracy.
17
Current Control of an RL Load
1A 1A 2A
L i (t)
+ L + iL (t) L R
VDC VDC
− −
vL (t) vL (t) vR (t)
vR (t) R
1B 1B 2B
(a) (b)
Figure 17.2 Equivalent circuits of the test setups involving the RL load driven
by A DC/DC converter in Half-Bridge (a) and Full-Bridge (b) configurations.
where the constant value iL0 refers to initial condition of the current for the
considered equivalent circuit (i.e., the steady state value before the operation
of the switch u(t − 1)), while iL∞ is the steady state value resulting from the
270 Current Control of an RL Load
L R iL (t) L R
iL (t)
(a) (b)
Figure 17.3 Equivalent circuits used for studying the transients caused by a
switching operation in an RL circuit. The switches can cause (a) zero or (b)
full voltage on the load.
application of u(t) and ideally kept over an infinitely long time interval. This
latter equals Yss defined in Chapter 6. Note that, in open-loop situation, iL∞
(or Yss ) is reached after a time interval which is dependent on the natural
dynamics of the circuit, that is the time constant τ = L/R. For instance, for a
step-wise supply voltage, e.g., varying from 0 up to VDC , the evolution of the
current in time domain can be described by settling a zero initial condition
iL0 = 0 and iL∞ = VDC /R, which are the solutions of the circuits reported in
Figure 17.3. These results lead to:
VDC −t R VDC VDC t
iL (t) = − e L + = 1 − e− τ (17.3)
R R R
Considering x(t) = i(t) and y(t) = x(t), both a state-space representation and
system transfer functions can be derived based on the solution proposed in
Chapter 6. Then, a PI controller R(s) = kp + ki /s is used to close the loop
and designed with pole/zero cancellation method. Here in the following the
system G(s) and open loop L(s) transfer functions are simply recalled:
i(t) y(s) 1/R i(t) kp /R
G(s) = = = L(s) = = R(s)G(s) = (17.4)
v(t) u(s) 1 + sτG e(t) sTi
where L(s) is computed by setting Ti = ki /kp = L/R. Alternatively, G(s) can
be computed considering the equivalent impedance Z (s) = R + sL.
As previously mentioned, the modeling can consider the parasitic resis-
tance of the inductor, which is summed up to the load resistor. An equivalent
resistance Req = 6.95 Ω is obtained. The uncontrolled system is characterized
by a small time constant τG = L/R = 124 µs, which leads to a settling time of
Ta,G = 619 µs. For a better visualization of the result, the designed controller
is slowing down the natural response by choosing Ta,F = 2.67 × Ta,G = 1.7 ms.
This choice implies τF = Ta,F /5 = 333 µs and a controller bandwidth equal
to ωc = 1/τF = 3000 rad/s. The values of kp and ki are explicitly determined
as:
kp = ωc L = 2.58 Ω (17.5)
ki = ωc R = 20 850 Ω/s (17.6)
System Simulations 271
i∗ (t) =
+ current u (t) 1 d (t) S (t) v (t) ũ (t) 1 i (t)
controller modulator AVG
− VDC = R + sL
2L-VSC
Figure 17.4 Closed-loop current control scheme including the inner loop for
the converter actuation and its relationship with the average modeling.
theory,1 leading to compute key parameters and figures of merit, e.g., kp and
ki . Even if the controller parameters are necessary, the firmware architecture
aimed to close a loop has to cope with the driving elements of the converter
stage (modulator, scaling and protections) and the sensing stage as well (in-
cluding measurements and sampling). Getting closer to the system physical
behavior, Chapter 13 and 15 show how to include the converter topology and
the ePWM peripheral working principle (which generates the switch positions)
into the simulation environment. In particular, the actuation variable is the
modulating signal d(t), which is directly a duty cycle when referring to dc
quantities.2 Even though the controller design should be based on a linear av-
erage model, the controller output u(t) must be related to d(t) and the switch
positions S(t). This is detailed in the scheme reported in Figure 17.4. Based
on the controller design and voltage limits (i.e., umax = VDC ), the manipu-
lated variable for a 2L-VSC is defined within u(t) ∈ [0, VDC ]. This last interval
divided by VDC becomes the duty cycle range of variation d(t) ∈ [0, 1]. This
is the input of the modulator operating at carrier frequency fc = fsw for each
converter leg, which operates according to the switching pattern S(t) ∈ [0, 1]
(see Section 13.1). Therefore, S(t) defines how long the dc-link voltage VDC
is applied to the load inside the time interval Tsw . The voltage v(t) is then a
squared waveform approximated by v(t) = S(t)VDC . The average value of v(t)
over Tsw is u b(t), which is u(t) ≈ ub(t), see Figure 17.4. Such approximation
becomes more and more accurate as fsw increases. In practice, the current i(t)
is affected by a ripple which is influenced by fsw and the resulting closed-loop
dynamic. However, the ripple should not be included (or at least limited) in the
feedback path used to compute the current error, otherwise the controller is
not able to reach a zero error at steady-state, i.e. a proper command-tracking
1 Linear control theory deals with systems governed by linear differential equations.
%% power supply
Vdc = 15;
%% carrier frequency definition
fsw = 10e3;
Tsw = 1/fsw;
%% sampling time definition
Ts = Tsw;
%% step-size definition
Tsim = Tsw/400;
%% load parameters
R = 6.95;
L = 860e-6;
computational delay
s1A enable
D
il
S
i
+
- +
s1B
D
+ v
v
-
Continuous
%% controller design
tauG = L/R;
TaG = 5*tauG;
wc = 3000;
TaF = 5/wc;
kp = wc*L;
ki = wc*R;
The equivalent circuit shown in Figure 17.2 (a) is then created in Simulink®
shown in Figure 17.5. This scheme is included in the file:
The simulation time step Tsim is particularly small to well approximate the
switching behavior of current i(k) and voltage v(k). The reference subsys-
tem includes different kinds of input signals to operate the system in several
working conditions.
Considering the PWM stage, the duty cycle d(k) is compared to a tri-
angular carrier at fc = 10 kHz, generating a switching pattern S(k). This is
realized on the MCU by using the ePWM modules. Since the gate signals of
the 2L-VSC topology are S(k) = S1 (k) for 1A and S2 (k) = not(S1 (k)) for
1B , the instantaneous output voltage v(k) is a pulsed waveform that can be
computes as:
va (k) = S(k)VDC (17.8)
Half-Bridge Configuration 275
which is discontinuous and bounded within two voltage values, i.e., 0 and VDC .
The aim of this exercise is to design a current control loop, i.e., to control the
current i(k) flowing into the load based on a step-wise reference i∗ (k) by using
a PI controller while achieving a settling time of Ta,F = 1.7 ms (see Section
17.2). To check these performances, a step-wise current reference i∗ (k) ranging
from 0 A to 1.5 A (i.e., Yss = 1.5) at 0.5 ms is applied.
Figure 17.6 shows the current flowing into the load y(k) = i(k) (blue line),
which is correctly following the step-wise reference y ∗ (k) = i∗ (k) (red dotted
line). The current dynamic follows an exponential behavior as described by
Equation (17.3). Based on the design guidelines reported in Chapter 5, a
≈ 1% is considered as reference accuracy. Thus, the transient is completed
once the current enters in the region [(1 − 0.01)Yss (1 + 0.01)Yss ], where
Ta ≈ 5τ holds. Indeed, it results that Ta,F = 1.7 ms, so the closed-loop control
276 Current Control of an RL Load
di(t) RIss
v(t)−Ri(t)−L = 0 → Vss = Dss VDC = RIss → Dss = (17.9)
dt VDC
which results in Dss = 0.7. This value is reached approximately within the
settling time Ta,F .
Focusing now on power supplies, they are limited by upper and lower
bounds, which represent static non-linearity. Hence, the control variable
u(k) is bounded by the energy flow capabilities of a power supply. For this
case study, a unidirectional DC source is considered, which works between
umin = 0 V and umax = VDC = 15 V. An anti-windup PI controller based on
the back-calculation method is considered. The coefficient kaw is computed as
kaw = 1/Ti = ki /kp to define how quickly the integrator of the PI controller
is reset by the anti-windup loop. As reported in Section 6.2, the anti-windup
parameters should be defined inside the PID block. In particular, Limit out-
put must be selected and the saturation limits umin and umax have to be
specified. Then, select back-calculation in the Anti-windup method menu and
specify the Back-calculation coefficient Kb equal to kaw . The verification of
the settling time is just the first step of a closed-loop system evaluation. Simu-
lations should provide an useful insight into the system operations, including
as many implementation aspects as possible. The synchronization between
ADC and ePWM modules to obtain an average current measurement is an
example of how important it is to choose the specific sampling time to avoid
issues related to peripheral and task scheduling early during the design stage.
This directly reflects on the calculation and actuation updates that the con-
troller should provide, i.e., integrate MCU scheduling and peripherals in power
electronics-based applications, as discussed in Section 13.10. To this purpose,
an embedded closed-loop control scheme (with MCU target) involving current
reading (ADC module), 2L-PWM acutation (ePWM module) and a PI-based
controller which use the ADC reading to compute the duty cycle for the ePWM
is subjected to a sequential events execution.
Half-Bridge Configuration 277
• The EOC triggers the ADC interrupt for the controller, which reads the
phase current value;
• Given the PI structure, the controller processes the current error to compute
the modulating signal for the ePWM module. The number as well as the
complexity of these mathematical operations define the execution window
length require by the controller to have a data ready. This time interval is
expected to be sufficiently lower than Ts ;
278 Current Control of an RL Load
modA
Z-400
modA y*
s1A reference Z-1
1 1
carA y e u
il PI(z) Z-1
2 >0 2 u
3
SOC
(a) (b)
Figure 17.8 Detailed view of (a) the modulator subsystem and (b) the equiv-
alent representation of the triggered subsystem for the current controller (see
Figure 17.5).
• The resulting duty cycle is held until the end of the sampling interval and it
is sent to the adopted ePWM module. Therefore, even if the updated duty
cycle value is ready before the end of Ts , the actuation happens only at
the reload of the ePWM peripheral. During the remaining time in-between,
the MCU is assigned to other tasks (e.g., communication) or enters in sleep
mode.
Therefore, the controller adopted in the Simulink® simulation is expected to
be consistent with such event sequence. To this end, the scheme reported in
Figure 17.5 includes a modulator subsystem, in which a trigger is generated
every time the carrier equals 1. Namely, a simulated SOC signal is created.
The implementation is achieved by using a Relational Operator block which
returns one when the carrier is greater than 0.99 or zero otherwise, i.e., a
boolean squarewave is obtained. A detailed scheme of this subsystem is shown
in Figure 17.8 (a). The SOC signal is used as trigger source for a triggered
subsystem4 which realizes a current controller synchronized with the carrier
peaks.
Assuming to adopt the previously mentioned step-wise current reference
i∗ (k), both a Pulse Generator block (sample based, with gain A = 1.5, number
of samples ns = 120, pulse width 50 %, phase delay = 5, and sample time Ts )
and a square-wave of period 120Ts = 12 ms can be used. Focusing on the first
rising edge after the step shown in the top plot of Figure 17.9, the current
reference varies at the zero value of the triangular carrier. Since the ADC
SOC trigger is generated at the carrier peak, i∗ (k) is delayed by Ts /2, thus,
generating a current error at the controller input. This delay can be included
through a Delay block, where the sample time is set equal to Ts /2 and the delay
length is 1. The resulting reference current is called i∗ctrl (k). This is detailed
in the second plot of Figure 17.9 . Even if i(k) shows a superimposed ripple,
4 A triggered subsystem is a conditionally executed atomic subsystem that runs each
time the trigger signal assume one of the selected triggering condition, i.e., rising, falling,
rising-falling trigger type. For more information see https://www.mathworks.com/help/s
imulink/ug/triggered-subsystems.html.
Half-Bridge Configuration 279
Figure 17.9 Example of MCU scheduling and latency between sensing and
actuation.
the center-aligned carrier ensures an ADC SOC which allows to measure the
average value of the current, which is hold until the next SOC, i.e., for the
hwole sampling period Ts . The resulting measured current is called ictrl (k).
The subscript ctrl refers to the quantity that are processed by the controller,
which is expected to read the current error ictrl,err (k) = i∗ctrl (k) − ictrl (k) and
compute the resulting duty cycle d(k). It can be noted that, the controller
starts processing ictrl,err (k) and the related computations at the ADC EOC.
The time interval between ADC SOC and EOC is small but not zero, i.e.,
280 Current Control of an RL Load
both ictrl,err (k) and d(k) data values are not evaluated strictly simultaneously
with the carrier peak (at TBPRD). In Figure 17.9, the time interval between
SOC and EOC is not visible due to the limited figure resolution, but it is still
present. Even if the controller computations are relatively easy to perform,
providing a value for d(k) before the end of the switching period Ts = Tsw , the
controller has to wait the next reload PWM action to feed the resulting duty
cycle value at the ePWM input. This happens when CTR=zero. Therefore,
another Delay block, with sample time Ts /2 and data length 1, is included at
the controller output to synchronize the actuation with the zero value of the
carrier. This event sequence is fulfilled by the implementation of the current
controller as a triggered subsystem. To understand better its behavior, the
involved blocks are showed in Figure 17.8 (b), which is used to analyze the
controller scheduling only at simulation level.
Given the aforementioned parameters and performances, the designed PI
controller meets all the specifications.
Firmware Environment
c28069_RLcontrol_hbF.slx (solver: fixed step - ODE4, step size: Ts =
Tsw /2 = 50 µs)
Half-Bridge Configuration 281
extRL(C)
used in RL mode
R=6.8 no C L=860 µH
GND
VCC
legA
enable
(ADCB3)
DC link
Open a new blank Simulink® project and configure the environment as shown
in Section 9. Remember that the BOOSTXL-DRV8301 is enabled by settling
GPIO50 high (see Section 3.2).
• Insert an ePWM block and use the same settings reported in Section 13.5:
– Select ePWM1 module with TBPRD related to fc = 10 kHz, i.e.,
PWMcounter−period = 4500;
– Remember to unflag Enable ePWM1B and tick Inverted version of
ePWMxA. This option allows to drive 1B as the complement of 1A ;
– Keep all the other settings as reported in Section 13.5.
• Add a gain block to normalize the modulation signal over the peak value of
the carrier signal PWMcounter−period . Include a data type conversion set
on int16 to represent the duty cycle within a 16-bit base.
For up-down counting mode, the measurement of an average current i(k)
is feasible thanks to the ePWM module which sends a synchronization sig-
nal that triggers the SOC of an ADC module when the carrier equals
TBCTR=TBPRD, as shown previously. To this aim, the following settings
are summarized here below:
• In the Event Trigger (Tab) of ePWM1
– Select Enable ADC start of conversion for module A;
282 Current Control of an RL Load
measures the current only when S2 (k) = 1 only, that occurs at every switching period when
d(k) < 1.
Half-Bridge Configuration 283
[iref]
A
Z-1
y* C2802x/03x/05x/06x
pulses PI(z) u
[i] WA
y
ePWM
en
C2806x
enable [ref] GPIOx
>= 0.5
C2802x/03x/05x/06x
GPIO DO
B3
C28x
ADC
Data
C2802x/03x/05x/06x [ref]
SCI XMT
A0
ADC
shunt A [i]
offset exp
means to feed the integral part (integrator) of the controller with an infinite
value. So, even if the closed-loop system is well designed, this issue could make
the control not operating, e.g., I/O freezing or even entering in fault mode
(nFault) condition, causing the controller action to be not suitable for the
load.
To avoid this issue, the PID controller block has an external reset that
can be selected/activated in the Initialization tab, as described above. By en-
abling this feature, an additional input port is created which allows to specify
the trigger condition that causes the block to reset the integrator to initial
conditions, e.g., Source: internal - Integrator: 0. By default, the output of the
integrator is set to initial conditions when the scheme/code is initialized, while
it is not during the simulation/firmware execution. When the trigger occurs,
i.e., sending a signal to the External reset port, the integral part of the PI
controller is reset on a rising-, falling-edge, or level of such signal. The port
icon indicates the selected trigger type. For this exercise, an external reset on
the rising-edge is chosen.
In order to manually manage the activation of the PI controller, the exter-
nal reset (rising) is connected to a potentiometer (ADCINB3/pin68). Without
moving the latter, the control algorithm is forced not to provide any actuation
signal. To do that:
• Add an ADC block and select ADCINB3 as Conversion channel in the
Input Channels tab. Then, go back in the SOC Trigger tab:
– Sampling mode: Single sampling mode;
– SOC trigger number: SOC1;
– SOCx acqusition window: 7;
– SOCx trigger source: Software;
– ADC will trigger SOCx: No ADCINT;
– Sample time: Tsig = 0.0011,s;
– Data type: uint16.
• Add a Data Type Conversion block set to int16 (since positive signal
only are used) and the 12-bit scaling to move from a range (0 V) up to
212 − 1 = 4095 (3.3 V) to [0, 1].
Figure 17.12 Closed-loop dynamics measured from the F28069M board pins
through an oscilloscope (Half-Bridge configuration).
• To visually evaluate the pulsed reference i∗ (k), the Pulse Generator can be
connected to a GPIO block (e.g., GPIO7) with a proper scaling of 1/1.5
to normalize the signal in a [0, 1] range. This allow to visualize through an
oscilloscope the reference signal ranging in [0, 3.3] V at pin 79.
Optional: the firmware could be also prepared to a debug through the serial
COM. In this case:
• Add Data Type Conversion and Rate Transition (e.g., TT X = 0.01 s)
blocks to prepare the data exchange via SCI Transmit block. Figure 17.11
shows how those blocks should be connected. See Section 10.5 or Chapter
16 for further details.
• In this case, even a Testing Environment must be arranged.
Figure 17.12 reports the closed-loop behavior of the system obtained by exe-
cuting the given firmware. The system dynamics are validated through an os-
cilloscope. In particular, the current i(k) is measured by using a current probe,
while the converter output voltage v(k) and the gating signals S1 (k), S2 (k)
(considered as voltage levels at the related pins) are measured by voltage
probes. These latter are also used to check the current reference available at
pin 79.
286 Current Control of an RL Load
As done in simulation, the analysis of Figure 17.12 starts from the eval-
uation of the command tracking performances. The resulting i(k) (blue line)
is following the internally generated i∗ (k) (red line), which is re-scaled from
3.3 V on the actual reference value in Ampere. The settling time is slightly
larger than 1.7 ms. This is due to the presence of a delay in the converter
actuation. Indeed, both the gating signals of 1A, 1B switches and the volt-
age v(k) are operating late compared to the dynamics shown in Figure 17.6.
Moreover, this delay also implies a (small) overshoot in i(k) that modifies the
shape of the current response. The current ripple is ∆iL ≈ 540 mA. Thus, it is
slightly larger than that one computed in simulation, but it is still compara-
ble. This value is influenced by the inductor parameters as well as the probe
accuracy. For instance, the series-resistance R` might be lower than the value
reported in the datasheet. The Pulse generator which provides the internal
reference i∗ (k) is synchronized with the zero value of the triangular carrier.
Nevertheless, such synchronization is not as strict as other tasks, e.g., counter
comparison in ePWM, which is based on hard synchronization (hard-sync)
event through interrupts. Therefore, it might happen that the rising edge of
the step-wise i∗ (k) is not perfectly synchronized with the ADC SOC (i.e.,
carrier peak). This effect can be simulated by using the Simulink® scheme in
Half-Bridge Configuration 287
Remark: the same study and implementation can be repeated for a Full-
Bridge configuration of the converter, which requires two ePWM modules,
e.g., ePWM1 and ePWM2. The same procedure is suggested, that is to start
from simulation first and, then move to implementation. Moreover, the con-
siderations on the processing delay are still valid. The ripple on the current
changes depending on the adopted strategy for the converter operation, that
is, unipolar or bipolar voltage switching. For more information see Chapter
15.
current ripple ∆IL . At steady state, an increase of four times in the inductance,
L = 3.44 mH results in a quite relevant current ripple reduction, i.e., ∆IL =
259 mA. As a matter of fact, given the same steady-state value for the current
(i.e., average value), the continuous-time domain current waveform and, thus,
the ripple can be computed considering the integral:
1 t2
Z
i(t) = iL (t) = vL (t) dt (17.11)
L t1
u (t) +
L
−
x (t)
(a) (b)
reaction, which is now not possible due to a greater energy stored in four
inductors (insted of one), that implies an higher electrical inertia. Despite the
different settling time, the command tracking is still guaranteed.
On the other hand, decreasing R, e.g., moving to R = 3.48 Ω, while keeping
the reference inductance value does not have any impact on ∆Il . Due to
this low resistance, the current rapidly increase enlarging the overshoot if the
same control action applied in the reference case (i.e., designed considering a
larger R) is provided. This imply a faster dynamic, thus, a smaller settling
time, while the command tracking is still guaranteed. However, the current
overshoot might be dangerous for the system, which now have to sustain an
higher current and possible overheating.
Both cases are simple but effective test which could represent practical
scenarios that may lead to components degradation or load revamp.
Remark: the same effects caused by variations of load parameters are valid for
the Full-Bridge configuration, both for unipolar and bipolar voltage switching.
This Chapter requires the same hardware adopted in Chapter 17, as shown
in Figure 18.1 and 17.1. Half-Bridge configuration is used as converter stage
topology. The corresponding equivalent circuit is shown in Figure 18.2. The
latter shows that the system to be controlled is a resistive load R connected to
a LC filter which smooth the discontinuous voltage supplied by the two-level
converter leg. The DC link voltage is again provided by a power supply set to
VDC = 15 V, with the output current limited to 2 A. It can be noted that the
extRL(C) board is designed to sustain up to 4 A.
There is no unique control paradigm that solves this power electronic-based
control problem [40]. Only one among the classical DC-DC converter control
approaches is presented in this book. Namely, the so called voltage-mode con-
trol is outlined together with its related embedded implementation. The ex-
tRL(C) board has a voltage sensing stage connected in parallel to the resistive
load, allowing to measure vo (k). This voltage is scaled by a voltage divider in
a [0, 3.3] V range, so that it can be directly read by an ADC peripheral.
Differently from Chapter 17, the relationship among duty cycle d(k), out-
put voltage of the converter vA (k) and its averaged value are described by
using the general state-space averaging method. In particular, the control pro-
posed in Chapter 17 is a current-mode control, which considers the output volt-
age v(k) as the controlled variable. Thus, there is no need to specify the duty
cycle in the derivation of the system transfer functions both in continuous- or
discrete-time domain. For a voltage-mode control, the duty cycle is required to
Required Hardware 295
1A
L, C and R values can
be changed on-the-fy
L iL (t)
VDC +
−
vL (t)
v (t)
C vo (t) Ro
1B
ic (t)
io (t)
Figure 18.2 Equivalent circuit of the test setup involving the RLC load, which
is connected to a bidirectional step-down DC-DC converter.
Steady-State Analysis
Assuming that the capacitor C is sufficiently large to keep vo (t) = Vo , which
implies ic (t) = dvc (t)/dt = 0, the average value of the output quantities at
steady-state2 are:
1 "An engineer who deals with power electronics applications has to know the basics
of power electronics design in order to figure out system physical limits, later used as
information for the control structure" Prof. Ralph Kennel and Prof. Jose Rodriguez.
2 In order to keep a simple notation, the subscript
ss is omitted from variable definitions.
Guidelines for the Hardware Design of a RLC Load 297
Vo
Io = IL = = 882.4 mA (18.1)
Ro
Po = Ro Io2 = 5.3 W (18.2)
Figure 18.3 Waveforms of the load voltage, inductor current and position of
switch 1A for a step-down DC/DC converter. The area highlighted in light blue
is the charge ∆Q that is stored (and, then, released) on the capacitor in Tsw /2.
The dotted lines refer to average values, e.g. Io = ∆iL /2 = DTsw VDC /(2L)
∆iL Tsw
Cmin = = 62.5 µF → C ≥ Cmin (18.10)
8∆vo
A first selection proposal is a commercial electrolytic capacitor with C =
100 µF. Considering the specific current ripples resulting from the implementa-
tion with the selected inductor, the resulting voltage ripples can be computed
through equation (18.9), that is:
∆iL(on) Tsw
∆vo(on) = = 51.6 mV (18.11)
8C
∆iL(off) Tsw
∆vo(off) = = 51.2 mV (18.12)
8C
Nevertheless, the effects of the ESR on the voltage ripple should be verified.
Indeed, the presence of a resistance Rc implies a further voltage drop in the
capacitor branch, that leads to vo (t) = vc (t) + Rc ic (t). In terms of variations,
it becomes:
∆vo = ∆vc + Rc ∆iL (18.13)
The ripple ∆vc can be computed similarly to ∆vo from equation (18.9) through
a geometric approach. The ∆vc waveform equals ∆vo except for a different
300 Voltage Control of an RLC load
L R` ∆iL C Rc ∆vo D
860 µH 150 mΩ ≈ 412 mA 100 µF 66 mΩ ≈ 52 mV 0.4
veo ∗ (t) =
+ voltage de(t) S (t) v (t) veo (t)
controller modulator RLC load
− =
single leg
The basic idea is to focus only on small AC signals (small signal control
theory), linearizing the system around a steady-state DC operating point.
The step-down DC-DC converter topology shown in Figure 18.2 is consid-
ered. A voltage-mode control scheme based on the state-space average mod-
eling method can be represented as reported in Figure 18.4. All time domain
variables can be represented by a steady-state DC value plus a small AC per-
turbation, e.g., vo (t) = Vo + veo (t). The goal of this approach is to compute
the small signal transfer function Gp (s) = veo (s)/d(s)
e in the continuous-time
domain by using the Laplace operator. In particular, Gp (s) describes in a
condensed manner the dynamics of the modulator, power converter and RLC
load stage. The variables veo (s) and d(s)
e are the small perturbations in the
output voltage vo (t) and in the duty cycle d(t) around their steady state DC
operating values Vo and D, respectively.
Then, a state vector x(t) = [iL (t) vc (t)]T is considered, which includes
the current flowing in the inductor L and the voltage measured across the
capacitor C, as well as the switch position vector S(t) = [S1 (t) S2 (t)]T . This
latter defines the converter output voltage value v(t). The general procedure
can be outlined through the following steps:
where terms containing products of veo (t) and d(t)e are neglected
since they are second order terms. To simplify the notation, matrices
A = A1 D +A2 (1 − D), B = B1 D and C = C1 D +C2 (1 − D) are
defined. The steady-state contributions shown in equation (18.18)
and (18.19) can be computed by setting all the AC perturbation
terms and their time derivatives equal to zero. It follows:
AX + BVDC = 0 (18.20)
CX − Vo = 0 (18.21)
This operation leads to compute the steady-state voltage transfer
function, which can be seen as a DC gain:
Vo
= −CA−1 B (18.22)
VDC
By removing the steady-state contributions from equations (18.18)
and (18.19), a small AC perturbation description is finally achieved.
dex(t)
= Aex(t) + [(A1 − A2 ) X + B1 VDC ] d(t)
e (18.23)
dt
veo (t) = C x
e(t) + [(C1 − C2 ) X] d(t)
e (18.24)
General State-Space Average Modeling Method 303
veo (s) −1
Gp (s) = = C (sI − A) BVDC =
d(s)
e
1
s+
Ro Rc CRc
= VDC =
L (Ro + Rc ) C (Ro (R` + Rc ) + Rc R` ) + L Ro + R`
s +s
2
+
LC (Ro + Rc ) LC (Ro + Rc )
| {z }
oscillating response
ωo2 s + ωz
= VDC (18.27)
ωz s2 + 2ξωo s + ωo2
| {z }
The highlighted term of Gp (s) includes a 2nd order denominator which models
resonating effects. Therefore, the intrinsic behavior of a LC filter increases the
model complexity. In particular, its oscillating response is identified by the
resonance frequency ωo (which is associated to the poles), the anti-resonance
frequency ωz (which is associated to the zeros), and the damping coefficient
ξ. Based on equation (18.27), they are defined as
s
Ro + R` C (Ro (R` + Rc ) + Rc R` ) + L 1
ωo = ξ= ωz =
LC (Ro + Rc ) 2ωo (LC (Ro + Rc )) CRc
(18.28)
Figure 18.5 (a) shows the Bode plot of Gp (s) considering the numerical
values reported in Table 18.2. The transfer function presents a fixed gain
(about 23 dB) and a almost zero phase shift at frequency below ωo ≈
3431 rad/s. Beyond the resonance frequency ωo , |Gp (s)| is decreasing with
a −40 dB/dec slope, whereas the phase approaches −180°. Beyond the anti-
resonance frequency ωz ≈ 151.521 × 103 rad/s, the absolute value decreases
with a −20 dB/dec slope and the phase starts rising toward −90°. The damp-
ing coefficient is ξ ≈ 0.249, keeping the resonance peak limited below 30 dB.
From equation (18.28) it is evident how important R` and Rc are to increase
the damping factor.
As shown in Figure 18.4, a PI controller R(s) = kp + ki /s is used to close
the voltage loop. From now on the hat m e is omitted. The open-loop transfer
function is defined as:
vo (t) 1 + sTi ω2 s + ωz
L(s) = = R(s)Gp (s) = kp VDC o 2 (18.29)
e(t) sTi ωz s + 2ξωo s + ωo2
Since Gp (s) is a second order transfer function, a simple pole-zero cancellation
is not straightforward in this case. The explanation and analysis of the tuning
techniques for this kind of systems are out of the scope of this book. Never-
theless, a first set of tuning parameters can be found using the MATLAB®
General State-Space Average Modeling Method 305
(a) (b)
Figure 18.5 Bode diagrams of (a) Gp (s) and (b) comparison between Gp (s),
L(s) and F (s) transfer functions for the designed controller. The amplitude
of the overshoot strongly depends on the damping coefficient ξ.
where the units of the gains are defined to be consistent with L(s). The re-
sulting bode diagrams are shown in Figure 18.5(b).
The control variable is u(t) = d(t). However, the dc voltage VDC = 15 V
provided by the power supply is considered an upper bound. This is set as
regulator saturation by limiting the control variable u(t) in a range [0 1].
SOC
reload
dmax
PWM
u s1A
y*
reference Z-1
current controller u modulator s1B
(syncronized with PWM)
vo debug SOC
y
computational delay
s1A enable
D
>= tR
S il
io
i circuit
+ i
- + +
- breaker
+
s1B
-
i
ic
g
+
+ +
v v v vo
- -
+ vc
v
S
Continuous
e.g., ePWM1. Hence, the switch 1A is driven by the signal S1 (k) and 1B
by S2 (k), operating in a complementary way. The RLC load is connected
between the central point of leg A and ground. The average output voltage of
the converter leg is function of the duty cycle d(k) (or dA (k)):
where the variables are already considered in the discrete-time domain k, i.e.,
moving the simulation toward the implementation. The voltage VDC is set
by the power supply, while d (k) ∈ [0, 1]. Considering the PWM stage, the
duty cycle d(k) is compared to a triangular carrier at fc = 10 kHz, which
generates a switching pattern S(k). This is realized on the MCU board by
using ePWM modules. Since the gate signals of the 2-level topology are S(k) =
S1 (k) and S2 (k) = not(S1 (k)), the instantaneous output voltage v(k) is a
pulsed waveform that can be computes as:
which is discontinuous and bounded within 0 and VDC . This result allows to
analyze the different states in the state-space average model.
As already mentioned, the system is characterized by the parameters re-
ported in Tables 18.1 and 18.2. The control coefficients are defined in the
previous Section. These parameters can be initialized in Model Properites/-
Callbacks/InitFcn or in a separate m-file as shown here in the following:
308 Voltage Control of an RLC load
%% power supply
Vdc = 15;
%% carrier frequency definition
fsw = 10e3;
Tsw = 1/fsw;
%% sampling time definition
Ts = Tsw;
%% step-size definition
Tsim = Tsw/400;
%% load parameters
Ro = 6.8;
L = 860e-6;
Rl = 150e-3;
C = 100e-6;
Rc = 66e-3;
imax = 2;
%% controller (pidTuner)
%% wc = 555 - phiM=90
kp = 0.0047;
ki = 33.35;
The simulation time step Tsim is particularly small to well approximate the
switching behavior of currents iL (k), ic (k), io (k) and voltages v(k), vc (t),
vo (k). The reference subsystem includes different kinds of input signals to
operate the system in several working conditions.
The time constants τG and Ta,G were estimated by analyzing the bode
diagram of Gp (s). Nevertheless, it is recommended to analyze the open-loop
behavior of the system in simulation to verify both Ta,G and the resonance ef-
fects on the variables. A constant duty cycle d(k) = D = 0.4 is directly applied
avoiding any control, as shown in Figure 18.6. Based on the previous steady-
state analysis, the output voltage is computed as vo (k) = Vo = DVDC = 6 V.
The resulting open-loop dynamics are reported in Figure 18.7. Both vo (k)
and iL (k) shows oscillating responses influenced by the forcing action pro-
vided by D 6= 0 and the resonance excitation at ωo . The peaks are attenuated
thanks due to the damping ξ, as reported in equation (18.28). In particular,
the steady state value Vo differs from the predicted one due to the voltage
drop determined across the inductor, which is due to R` . Indeed, reminding
Half-Bridge Configuration 309
that this is a open loop test, the duty cycle d(k) cannot be dynamically ad-
justed to compensate such voltage error, leading to Vo,open ≈ 5.718 V < 6 V.
As a consequence, at steady-state, Io,open ≈ 865 mA < Io = 882.4 mA. Even
the current ripple ∆ iL,open slightly differs from the predicted one too. The
output current io (k) presents a filtered dynamic compared to iL (k). However,
the latter has a fast dynamic which exceed the limit imax = 2 A. Similarly,
the output voltage overshoot Sv% can be analytically identified through the
coefficients reported in equation (18.28):
− √ πξ 2
Sv%
Sv% = 100e 1−ξ
≈ 44.63% → vo,pk = Vo 1 + ≈ 8.68 V
100
(18.34)
The peak value vo,pk is in-line with the results provided in Figure 18.7. The
settling time can be estimated as:
5
Ta,G,open = = 6 ms > Ta,G (18.35)
ξωo
which is larger than the one computed through the bode plot. As already
detailed, this behavior is due to the energy-related effects of the resonance,
which influences the time decay of the voltage waveform.
Moreover, the scheme shown in Figure 18.6 allows to test load variations.
At time instances tR (which is a parameter to be initialized), the circuit
breaker subsystem connects the second resistor Ro , which lead to an equiv-
alent resistance Req = Ro /2 = 3.4 Ω < Ro . Setting tR = 8 ms, Figure 18.7
shows how the system reacts to such perturbation. Since Req < Ro , both iL (k)
and io (k) are higher than before. Based on Section 18.2, it follows:
Vo
Io(Req ) = = 1.76 A > Io,open
(Req )
≈ 1.69 A > Io,open (18.36)
Req
310 Voltage Control of an RLC load
Table 18.4 Steady-state values of the currents and voltages in open loop sim-
ulations.
(R ) (R )
Vo,open Io,open ∆ iL,open ∆ vo,open eq
Vo,open eq
Io,open
5.87 V 865 mA ≈ 420 mA ≈ 52 mV 5.75 V 1.69 A
(R )
Consequently, the new steady state value of Vo,open eq
is lower than the one
before load variation due to the increase in the load current, which, in turns,
causes a larger voltage drop in the inductor and in the load resistance. The
steady-state values of the open-loop dynamics are summarized in Table 18.4.
The aim of this exercise is to design a voltage-mode control loop. Namely,
this means to control and stabilize the output voltage vo (k) measured across
the load Ro (which is effectively the output variable y(k)) based on a specific
reference vo∗ (k) (lower than VDC ) by using a PI controller while achieving a
settling time Ta,F = 9 ms (see Section 18.3.1). To check these performances,
a step-wise voltage reference vo∗ (k) jumping from 0 up to 6 V (i.e., Yss = 6) at
0.5 ms is applied.
Figure 18.8 shows the output voltage y(k) = vo (k) (blue line), which is
correctly following the step-wise reference y ∗ (k) = vo∗ (k) (red dotted line).
The current flowing in the inductor iL (k) is subjected to a more oscillating
dynamic than vo (k), but always below the upper bound imax = 2 A. The
resulting waveforms of vo (k) and iL (k) follow an exponential behavior with
oscillations superimposed on them, which is a typical case in second order
systems.
Based on the design guidelines reported in Chapter 5, ≈ 1% is considered
as reference accuracy. Thus, the transient is completed once the voltage en-
ters in the region [(1 − 0.01)Yss (1 + 0.01)Yss ], where Ta ≈ 5τ holds. Indeed,
it results that Ta,F = 9 ms, so the closed-loop control system is behaving as
expected. The steady-state value Yss can be verified by applying the concepts
reported in Sections 18.2 and 18.3. Furthermore, the closed-loop dynamics
lead to a voltage ripple ∆vo ≈ 56 mV and current ripple ∆iL ≈ 423 mA,
which are consistent with the predicted values (see Section 18.2 to check the
requirements). The effects of the step variation in the reference are reflected
into the switching patterns of 1A and 1B , which are aimed to make the av-
erage voltage vavg (k) increase by enlarging the pulse width of v(k). This is
evident from Figure 18.9, which shows a portion of the voltage transient to
relate current and voltage dynamics to the switch positions and modulation
behavior. The command-tracking performances are achieved thanks to the
regulation of u(k) = d(k) which effectively approximates vavg (k). In particu-
lar, the load current io (k) is filtered thanks to the capacitor, which absorbs all
the high-frequency components. Indeed, ic (k) shows the same ripple of iL (k).
Note that the control variable u(k) (i.e., duty cycle dynamic) is indirectly
bounded by the energy flow capabilities of a power supply, which is a static
non-linearity. For this case study, a unidirectional DC source operating within
Half-Bridge Configuration 311
Figure 18.9 Detailed view of the closed-loop dynamics, which relates the cur-
rent/voltage dynamics to the switch positions and modulation behavior.
• The ADC module converts the sampled analog signal into digital counts and
triggers the end-of-conversion (EOC) event;
• The EOC triggers the ADC interrupt for the controller, which reads the
output voltage value (sample);
• Given the PI structure, the controller processes the voltage error to compute
Half-Bridge Configuration 313
the modulating signal for the ePWM module. The computation interval
required to obtain d(k) is expected to be sufficiently lower than Ts ;
• The resulting duty cycle is held until the end of the sampling interval and it
is sent to the adopted ePWM module. As already explained, the actuation
happens at the reload of the ePWM peripheral.
Therefore, the controller adopted in the Simulink® simulation is consistent
with such event sequence. Indeed, the scheme reported in Figure 18.6 use the
same approach adopted for the current control of an RL load (Section 17.4).
In particular, a trigger signal SOC (i.e., a boolean square-wave) is gener-
ated inside the modulator subsystem every time the carrier equals 1. The SOC
is used as trigger source for a triggered subsystem which realizes a voltage
controller synchronized with the carrier peaks. A voltage reference vo (k) in-
ternally generated by a Pulse Generator block is considered (sample based,
with gain A = 6, number of samples ns = 500, pulse width 50 %, phase delay
= 5, and sample time Ts ). This is a square-wave of period 500Ts = 25 ms. The
Pulse Generator block is synchronous with the zero value of the triangular
carrier. Since the ADC SOC trigger is generated at the carrier peak, vo∗ (k) is
delayed by Ts /2 to provide a correct voltage error at the controller input.6 The
resulting reference voltage is called vo,ctrl
∗
(k), where the subscript ctrl refers
to the quantity that are processed by the controller. Hence, the processed
voltage is called vo,ctrl (k). Even if the controller computations return a value
for d(k) before the end of Ts = Tsw , the controller has to wait the next reload
PWM action to feed d(k) to the ePWM input (this happens when CTR=zero).
Therefore, another Delay block (sample time Ts /2 and data length 1) is in-
cluded at the controller output to synchronize the actuation with the zero
value of the carrier. The whole event sequence is denoted in Figure 18.9.
As did for the open-loop test, the closed-loop dynamics are also evaluated
in presence of load variations. Figure 18.10 shows how the system reacts to
such perturbation occurring at tR = 8 ms.
Immediately after the operation of the switch, the inductor current iL (k)
cannot instantaneously increase since it is a state variable. Thus, the load
current io (k) increase (due to the lower resistance) is supplied by the capacitor,
which starts to discharge. Then, iL (k) starts to increase too. The capacitor
goes on discharging until the new steady-state value for io (k) is reached. This
current compensation is evident in Figure 18.10. In addition, it can be noted
that the output voltage quickly stabilizes around vo (k) = vo∗ (k) after the
transient.
Considering the achieved aforementioned performances, the designed PI
controller meets all the specifications.
For the sake of completeness, the close-loop dynamics can be compared
with those provided by a faster controller. Therefore, Ta,F = 3.6 ms which
6 This delay can be included through a Delay block, where the sample time is set equal
Figure 18.11 Comparison of the closed-loop dynamics for two different control
design. The fastest one is denoted by subscript f .
CPUfrequency
TBPRD = PWMcounter−period = = 4500 (18.37)
2 · PWMfrequency
Firmware Environment
c28069_RLCcontrolSD_F.slx (solver: fixed step - ODE4, step size: Ts =
Tsw /2 = 50 µs)
Open a new blank Simulink® project and configure the environment as shown
316 Voltage Control of an RLC load
Vo(mcu)
GND
extRL(C)
used in RLC mode
R=6.8 C=100 µF L=860 µH
GND
VCC
legA
enable
(ADCB3)
DC link
Vo(mcu)
Rlo
vo,mcu (k) = vo (k) if vo (k) = 6 V → vo,mcu (k) ≈ 375 mV
Rup + Rlo
(18.38)
Similarly, 15V → vo,mcu (k) ≈ 937.5 mV, thus, a limited portion of the
[0, 3.3] V voltage range is used. This implies that the voltage conversion
chain is characterized by the following gain:
3.3 Rup + Rlo
gv,adc = (18.39)
4095 Rlo
As done for the low-side shunt (Chapter 16), the voltage sensor should be
318 Voltage Control of an RLC load
[ref]
A
Z-1
dmax C2802x/03x/05x/06x
pulses
PI(z) u
[vo] WA
y
en ePWM
C2806x
ADC C28x
C2802x/03x/05x/06x [i] [ref] Data
A5
[vo]
ADC
ADCA5 pin65
offset exp
• Copy the ePWM block, select ePWM8 (which is connected to DAC3 in J8,
pin 72), keep the other settings. Connect this block in parallel to the other
ePWM (i.e., connect d(k) just after the Data type conversion block). Hence,
d(k) can be observed by connecting a voltage probe to pin 72.
Figure 18.14 reports the closed-loop behavior of the system obtained by exe-
cuting the firmware and observing the current and voltages of interest through
an oscilloscope. In particular, voltages vo (k) and vo∗ (k) are measured by using
voltage probes (with vo∗ (k) scaled on GPIO7), while the currents iL (k) and
io (k) are measured with current probes. In case DAC3 is used to check d(k),
another voltage probe connected to pin 72 is needed.
As done in simulation, the analysis of Figure 18.14 starts from the evalu-
ation of the command tracking performances. The resulting vo (k) (blue line)
320 Voltage Control of an RLC load
Figure 18.14 Closed-loop dynamics measured from the F28069M board pins
through an oscilloscope.
is following the internally generated vo∗ (k) (red line), which is re-scaled from
3.3 V on the actual reference value in Volt. The settling time is similar to the
expected one Ta,F = 9 ms even if both voltage and current dynamics looks
smoother (i.e., reduced oscillating responses) during transient. Besides the
probe accuracy, this effect is mainly due to the parasitic resistances RL and
Rc , which differ from the theoretical ones. In particular, Rc is a great mat-
ter of concern since even a slightly increase has a significant impact on the
damping coefficient ξ, while the settling time Ta,F is almost unaffected.
Consequently, the current ripple is ∆iL ≈ 382 mA, which is lower than the
value predicted in simulation. The voltage ripple is ∆vo ≈ 100 mV, which is
larger than the value predicted in simulation. However, both ∆iL and ∆vo are
compliant with the requirements. This last discrepancy could be a consequence
of a more noisy environment. The Pulse generator which provides the internal
reference vo∗ (k) is synchronized with the zero value of the triangular carrier
(TBPRD=0). Nevertheless, such synchronization is not as strict as other tasks,
e.g., counter comparison in ePWM, which is based on hard synchronization
(hard-sync) event through interrupts. Therefore, it might happen that the
rising edge of the step-wise vo∗ (k) is not perfectly synchronized with the ADC
SOC (i.e., carrier peak). By adding a fixed shift of Ts /2, vo,ctrl
∗
(k) is coincident
with ADC SOC, thus, sampling a value of vo,ctrl (k) = 6 V. This is the same
∗
Half-Bridge Configuration 321
processing obtained for the RL load, thus, the reader is referred to the detailed
description reported in Section 17.4.1. Based on this part, the overall interval
between the the rising edge of vo∗ (k) and the start of the system dynamics7
(i.e., when vo (k) and iL (k) start to increase due to v(k) 6= 0) reaches 2Ts in
a worst case scenario. Figure 18.15 also shows the duty cycle reading through
DAC3. The signal read at pin 72 (gray dotted line) needs to be additionally
averaged to obtain d(k) (red line). This can be easily done via software by
using an average function or a digital filter.
As did in simulation, the closed-loop dynamics are also evaluated in case of
variations in the resistance value. This is performed by manually moving the
switch S3 mounted on the extRL(C) board after the system reaches a steady-
state value. The operation changes the resistance down to Req = Ro /2. Figure
18.15 shows how the system reacts to such perturbation. The current compen-
sation behaves as explained in the previous Section. In particular, it is shown
that the inductor current iL (k) does not increase instantaneously. Thus, the
variation in the load current io (k) is compensated by the capacitor through its
branch current ic (k). The d(k) signal is also visible. Both transients and am-
plitudes are consistent with simulations, validating the stability of the voltage
loop to vo (k) = vo∗ (k) even in case of load variations.
Remark: as already reported in Section 18.2 and 18.3, the parasitic resis-
tances RL and Rc strongly impact on the damping coefficient ξ. The value of
this parameter might be also influenced by snubbers resistors and non-zero
impedance of the power supply. Moreover, resistance of the wires and/or the
traces of PCBs may impact on ξ too, leading to higher system losses too.
Figure 19.1 DecMot Hardware Kit rearranged for implementations with one
PMDC motor only connected to a DC-DC converter (see connection scheme
in Figure 19.15). The reader is referenced to Appendix B for further details
on this setup.
Basically, the setups used in this chapter adopt the same hardware described in
Chapter 15. The same recommendations shown there are still valid. Namely,
jumpers JP1 and JP2 should be removed to isolate the USB/JTAG port.
Moreover, keep in mind that the BOOSTXL-DRV8301 converter requires a
dc-link voltage VDC > 6 V to properly work, otherwise the nFAULT is returned
(regardless of the state of the jumpers JP1 and JP2). The reader is referred
to the converter details reported in Section 3.2.
In the proposed control schemes, the low-side shunt-resistors are used as
current sensor to close the inner current loop (their characterization explained
in Chapter 16), whereas the rotary encoder provides the feedback for the
speed loop (see Chapter 14 for all details on this device and on the eQEP
peripherals).
328 Cascade Speed Control of a Permanent Magnet DC Motor
2 No flux weakening can be performed. Thus, the motor speed can not reach values above
For the single motor configuration, the load torque refers to external causes
such as additional friction or mechanical load coupled to the PMDC motor.
If the configuration does not foresee the application of any load torque, then
ml (t) = 0. For the B2B configuration, the load torque is separately managed.
Therefore, equation (15.4) is subject to the current control loop implemented
for the braking motor. Considering this latter connected to the leg B of the
converter, it follows
ml (t) = KiB (t) (19.1)
where iB (t) is the current flowing in the armature circuit of the braking motor,
whereas ml (t) is the variable load torque.
The state-space representation is derived considering u(t) = [va (t) ml (t)]T ,
x(t) = [Ω(t) ia (t)]T and y(t) = x(t). Therefore, the resulting equations in
matrix notation are those reported in (15.9) and (15.10), that are:
d
Ω(t) −β/J K/J Ω(t) −1/J
= + va (t)
dt ia (t) −K/La −Ra /La ia (t) 0
1 0
Ω(t) Ω(t)
=
ia (t) 0 1 ia (t)
where the state-space matrices are defined as follows:
0
−β/J K/J −1/J
A= B= C = I2
−K/La −Ra /La 0 −1/La
It is important to note that all the parameters of the considered motors (Ra ,
La , J, β, K) must be estimated through some identification procedures such
as the locked rotor test (see Chapter 16) and by observing the open loop
mechanical dynamics. These calculations are necessary (and they must be
performed as fist task) to follow the controller design procedures presented in
the previous chapters. Since the two system configuration are different (i.e.,
three different motors and two couple of boards and converters are involved),
the results of the identification tests will be provided in the following sections
for each case.
Finally, the transfer functions Gi (s) and GΩ (s), which refer to the electrical
and mechanical behavior of the motor, respectively, are derived based on the
motor equations in the time domain, as shown in equation (15.11):
ia (t) 1 Ω(t) 1
Gi (s) = = GΩ (s) = =
va (t) Ra + sLa me (t) β + sJ
The PMDC motor in single configuration and the traction motor in B2B
330 Cascade Speed Control of a Permanent Magnet DC Motor
Ω ∗ (t)
+ speed m∗e (t) 1 i∗a (t)
+ current u∗a (t)
− controller K + va∗ (t) power PMDC
− controller
− stage motor
e(t)
2L-VSC +
modulator
K
ia (t)
Ω(t)
Figure 19.3 Block scheme for a cascade speed control of a PMDC motor with
back-emf compensation. This strategy is valid both for Half- or Full-Bridge
configurations.
eb(t) = KΩ
b or eb(t) = K
bΩb (19.2)
Cascade Control Architecture and Design 331
voltage va∗ (t), which represents the modulating signal to be processed by the
modulator stage for generating the PWM signals. This stage is included into
the power stage block (not drawn explicitly for the sake of brevity) shown in
Figure 19.3, which includes a 2L-VSC (i.e., the DC-DC converter) and the
PWM modulator.
The back-emf compensation provides an important contribution, since it
represents and additional voltage term (on condition that the dc-link is able
to provide the required power). It should be clear that the feed-forward term
achieve an effective decoupling only at steady-state, while the cross-coupling
persists during transients. Nevertheless, the importance of such compensation
term depends on the machine design. Indeed, if the PMDC motor is of small
size and low voltage rating, e(t) can be neglected (i.e., no compensation). On
the other hand, even the load torque ml (t) can be estimated and then compen-
sated. However, for the simulation analysis, ml (t) is considered a controllable
disturbance, thus, manipulating its instantaneous value. It can be noted that
the current controller is of the same kind of that one designed in Chapter 17,
i.e., it is based on an RL circuit (see Gi (s) in (15.11)). In addition, a combined
design of both speed and current control loops is needed to ensure that the
mechanical dynamic is satisfactory.
Given the feed-forward action, the system is suitable to be controlled with
a cascade scheme. This becomes quite evident if the power stage (i.e., DC-
DC converter + modulator) and the PMDC motor shown in Figure 19.3 are
substituted with the equivalent linear average representation of the motor
dynamics shown in Figure 15.3. This require to approximate va∗ (t) with va (t)
(see Section 17.3.1).
In particular, it is important to remind that this architecture has to fulfill
cascade constraints in terms of bandwidth between the nested loops, i.e., aim-
ing to decouple the electrical and mechanical dynamics. The outer (speed)
loop must be consistently slower than the inner (current) one. This means
that, from the outer loop point of view, a current reference i∗a (t) sent as input
of the current loop is immediately provided as output ia (t) = i∗a (t), i.e., allow-
ing to approximate the inner closed-loop transfer function as a unitary gain.
This requirement translates in a constraint on the bandwidths. Indeed, this
behavior is guaranteed by imposing a cut-off frequency for the inner current
controller at least ten times smaller than the outer speed one.
ωΩ ≤ ωΩ /10 or τGΩ ≥ 10τGi (19.3)
where ωi and ωΩ are the bandwidths of the current and speed controller,
respectively. If equation (19.3) is satisfied, the two controllers can be designed
332 Cascade Speed Control of a Permanent Magnet DC Motor
separately, i.e., each one is tuned based on its specific transfer function. This
means that the control action of the speed controller is not influenced by the
dynamics of the inner loop, since the current regulator is much faster than
the outer one.
The PI-based speed controller is defined as RΩ (s) = kp,Ω + ki,Ω /s and
the current one as Ri (s) = kp,i + ki,i /s, where the integrator time constants
are Ti,Ω = kp,Ω /ki,Ω and Ti,i = kp,i /ki,i , respectively. By imposing equation
(19.3), RΩ (s) would be designed based on GΩ (s) only, while Ri (s) based on
Gi (s). It is worth noting that this simplifies the controllers design. Indeed,
since both GΩ (s) and Gi (s) are 1st order transfer functions, RΩ (s) and Ri (s)
can be explicitly designed using the pole/zero cancellation (i.e., still within
linear control theory) as shown in Chapter 5. This leads to the following open-
loop transfer functions:
i(t) kp,i /Ra
Li (s) = = Ri (s)Gi (s) = (19.4)
ei (t) sTi,i
Ω(t) kp,Ω /β
LΩ (s) = = RΩ (s)GΩ (s) = (19.5)
eΩ (t) sTi,Ω
where Ti,Ω = J/β and Ti,i = La /Ra . The open loop transfer functions behave
as a pure integrators (φm ≈ 90◦ ) and their cut off frequencies ωc,Ω , ωc,i
depends explicitly on the system parameters. As shown in Chapter 5, it follows
that:
characteristics taken from the converter data-sheet, e.g., Ron and Rd , are set
into the Simulink® blocks as shown in Chapters 15, 17 and 18. The two-level
Full-Bridge configuration is obtained by rearranging these blocks based on the
equivalent circuit and Simulink® scheme reported in Section 15.5. The switches
are driven by a PWM modulator with a carrier frequency fsw = 30 kHz. The
PMDC motor is modeled through the DC Machine block which can imple-
ment both a wound-field and permanent magnet DC machine by selecting the
motor model in the Field type frame. The armature circuit (A+, A-) consists
in an inductor La and resistor Ra connected in series with the back-emf. In the
permanent magnet DC machine, there is no field current creating the excita-
tion flux, which is established by the magnets. Thus, ke and kT are constant as
expected. It is important to underline that Torque constant has to be selected
in the Specify frame. The DC Machine block already include a lumped (first-
order) mechanical model based on the inertia J, the viscous friction coefficient
β (or Bm ), and, as a further option, the Coulomb friction torque (which is not
used here, i.e., = 0). The load torque ml (t) can be provided as an external
input by selecting Torque TL in the Mechanical input frame. By selecting −1
as sample time, this block uses the largest integration step-size allowed by the
Powergui block. This latter is essential to manage the numerical integration
of the Simscape™ elements, as explained in Section 6.1.2.
%% power supply
Vdc = 10;
%% carrier frequency definition
fsw = 30e3;
Tsw = 1/fsw;
%% sampling time definition
Ts = Tsw;
%% step-size definition
Tsim = Tsw/400;
%% motor parameters
Ra = 0.529;
La = 8.651e-4;
K = 0.0232;
B = 9.013e-5;
J = 7.118e-6;
%% current controller
tauGc = La/Ra;
TaGc = 5*tauGc;
TaI = TaGc/10;
wcI = 5/TaI;
kpI = wcI*La;
kiI = wcI*Ra;
%% speed controller
tauGm = J/B;
TaGm = 5*tauGm;
wcW = wcI/100;
TaW = 5/wcW;
kpW = wcW*J;
kiW = wcW*B;
%% encoder settings
Tw = 5*Ts;
cpr = 2400;
minRPM = 1/(cpr*Tw)*60;
minRAD = minRPM*pi/30;
%% MRAS settings
Tsm = 5*Ts;
kpMR = kpI;
kiMR = kiI;
west
Z-1 computational delay
w
enable
s1A s2A
load
torque
g
D
w
ia
S
S
TL m
me
dc
s1B A+ A- s2B
g
D
+
-
v
S
S
va
+
-
+
-
Continuous
v
vA vB
6115 rad/s. The values of kp,i and ki,i are explicitly determined as:
Discrete-time PI controllers RΩ (z) and Ri (z) are derived based on these con-
siderations. The sampling time of the controller is set equal to Ts = Tsw =
1/fsw , using Forward Euler as integration method. Getting closer to the MCU
implementation, the system variables are referred to the discrete-time domain.
The equivalent circuit shown in Figure 15.12 is then realized in Simulink® in-
cluding the control scheme discussed previously (see Figure 19.3), as reported
in Figure 19.4. This scheme is available in the file:
Full-Bridge Configuration 337
SOC
ei
reference
ew i*
iref
wref
1 m* i*
w* cut PI(z) PI(z)
noise u
e 3 1
2 uC
ww ia da
w d
mref i
e
d(k) is discontinous
d due to ctrl
i
Discrete west
1 PI(z) 2
u y va
0.0008s+1 f Adaptive ia est.
model west
wm
Figure 19.5 Detailed view of the cascade controller subsystem (see Figure
19.4). The top part of the scheme reports the two nested control loops realized
based to the scheme shown in Figure 19.3, whereas the bottom shows a possible
realization of the MRAS observer.
Similarly to the previous chapters, the simulation time step Tsim is set quite
small. Moreover, the reference subsystem includes different kinds of inputs
to operate the system differently.
The actuation of the two legs (i.e., two duty cycles for two modulator
stages) is done by manipulating one modulation signal d(k) only, from which
the gating signals of the four switches are generated. This duty cycle comes
from a processing done on the desired reference armature voltage va∗ (t), which
has to be divided by VDC provided by the power supply, i.e., 10 V in this case.
A detailed description of the unipolar voltage switching operation is reported
in Section 15.5.2. However, it is of great importance to recall that the PMDC
motor is subjected to the difference of the leg voltages vA and vB , which is
defined as:
va (k) = vA (k) − vB (k)
The adopted working operation foresees that the duty-cycles of the two legs
dA and dB are linked as follows:
dB (k) = 1 − dA (k)
on the desired direction of rotation (that is, on the value of the duty cycle,
as shown in Section 15.5.2). Indeed, it must be remembered that Full-Bridge
converters allow to run DC motors in both clockwise and anti-clockwise di-
rections of rotations without modifying the physical connections of the setup.
Speed and current feedbacks are taken from the measurement port of the DC
machine block. The aim of this exercise is to design a cascade control strategy.
Full-Bridge Configuration 339
Namely, this means to control and stabilize the motor speed Ω ∗ (k) despite
the presence of a load torque, while achieving a settling time Ta,FΩ = 81.8 ms.
To check these performances, a step-wise speed reference Ω ∗ (k) jumping from
−100 rad/s up to 100 rad/s is applied. Figure 19.6 shows the closed-loop dy-
namics of the cascade speed control of a single PMDC motor for a step of
100 rad/s in the reference speed. Both speed Ω(k), torque me (k) and, conse-
quently, armature current ia (k) are correctly following their related references.
It can be noted that the settling times are respected both for the current and
the speed, being ≈ 818 µs and ≈ 82 ms, respectively. The current control loop
is quite fast compared to the speed control loop. The references m∗e (k) and
i∗a (k) are almost coincident with the actual variables me (k) and ia (k), while
the transient of Ω(k) is visible. It follows an exponential behavior. Current
and torque responses are scaled by the factor K. Due to the different system
parameters and controller settings, the plots reported in Figure 19.6 show
that the current behavior is pretty different with respect to those reported in
Chapters 15 and 17.
Since the reference Ω ∗ (k) consists in a positive speed only (i.e., clockwise
rotating direction), the voltage is varying between 0 and VDC . At the time
instance in which the speed reference changes from 0 to 100 rad/s , the current
ia (k) grows up quickly, starting the rotation of the motor shaft. Therefore, the
back-emf starts acting on the armature circuit after less than 1 ms. Then, the
current drops down to values close to 0.5 A thanks to the Ri (z) controller.
The current peak (which translates in torque peak as well) is due to a sudden
variation in the duty cycles d(k) = dA (k) and dB (k), after which they both
approach the related steady-state values. A pulse in the average and RMS
value (which is always greater than zero) of the armature voltage va (k) are
measured as well.
It can be noted that both speed and the current ripples, ∆Ω and ∆ia , are
quite small, as a consequence of the unipolar voltage switching operation.
After the steady state is reached, a load torque ml (k) = 0.02 N m is ap-
plied to the motor to test the robustness of the cascade control scheme. The
load torque is defined into the subsystem load torque (see Figure 19.4).
The command-tracking performances are quite different from the disturbance-
rejection ones, with the latter characterized by a longer time constant. Indeed,
in order to compensate the additional load torque applied to the system, the
cascade control requires a time interval which is larger than the settling time
Ta,Ω . This effect can be changed by setting a higher bandwidth ωc,Ω . It must
be noted that the control effort to compensate ml (k) is quite small, since the
duty cycles and the armature voltage are slightly higher compared to their val-
ues before the load torque transients. Besides the verification of the settling
time of the closed-loop system, the choice of the sampling time to avoid is-
sues related to peripheral and task scheduling, e.g., controller calculation and
actuation updates, is investigated as discussed in Section 13.10 and 17.4. To
this purpose, the elements involved in the closed-loop control scheme loaded
into the MCU, i.e., current reading (ADC module), encoder reading (eQEP),
340 Cascade Speed Control of a Permanent Magnet DC Motor
Figure 19.8 Part II of Figure 19.7. Analysis of the MCU scheduling and latency
within a sampling period. Due to the different bandwidth between the loops,
the command-tracking performances of the speed and the related speed error
are slowly changing compared to the current dynamics and the related error.
The duty cycles actuation happens at every PWM reload action.
3 If necessary, the subsystem cut noise can be used to bring the speed error equal to
120 120
100 100
80 80
60 60
40 40
20 20
0 0
0 0.01 0.02 0.03 0.04 0.05 0.06 0.07 0 0.01 0.02 0.03 0.04 0.05 0.06 0.07
2 2
1.5 1.5
1 1
0.5 0.5
0 0
0 0.01 0.02 0.03 0.04 0.05 0.06 0.07 0 0.01 0.02 0.03 0.04 0.05 0.06 0.07
(a) (b)
Figure 19.10 Comparison closed-loop dynamics (in terms of speed and arma-
ture current transients) for (a) Tw = 5Ts and (b) Tw = 200Ts
.
presence of a rotary encoder. By considering the standard approach proposed
in Section 14.4 it follows that:
xp (k) − xp (k − 1) ∆x(k)
Ω(k) ≈ = (19.12)
Tw Tw
where Ω(k) is the speed computed at time step k, xp (k) and xp (k − 1) are
the position counters at time step k and k−1 respectively, Tw is the acquisition
time window, which is the inverse of speed calculation rate. The value of Tw is
of paramount importance since it is directly related to the speed computation:
round revolution 1
Ωmin = or = 60 (19.13)
min min cpr · T
| {z w}
revolution
sec
the acquisition time Tw , Figure 19.10 (a) and (b) compare the closed-loop dy-
namics in terms of speed and current transients for Tw = 5Ts and Tw = 200Ts ,
respectively. It is quite evident from Figure 19.10(b) that large values of Tw
creates a discontinuous behavior even in a fast control loop like the current
one. From now on, Tw = 5Ts is set, which leads to Ωmin = 15.71 rad/s.
Remark: in case the cascade control loop is required to operate within par-
ticularly low speed (e.g., even lower than the Ωmin ) it is better to change the
speed computation approach, as described in 14.4. Moreover, by decreasing the
bandwidth ωc,Ω the acquisition time might be increased without introducing
too much delay in the control loop.
Adaptive ŷ (t)
model
x̂ (t)
Figure 19.11 Block scheme showing the working principle of a generic MRAS
observer.
dia (t)
va (t) = La + Ra ia (t) + KΩ(t) (19.14)
dt
This expression is used to predict the deviation of the current at time
instant t (reference model). Thus, ia (t) can be computed by solving this dif-
ferential equation. In view of an implementation on MCUs, the adaptive model
is discretized considering a forward Euler method:
Figure 19.12 Detailed view of the adaptive model subsystem (see Figure 19.5).
∆ia Tsm K
=− (19.17)
∆Ω La
This equality suggests that an increase in the speed causes a drop in the
armature current. Indeed, inverting the signs before the PI regulator leads to
the following scenarios:
Besides the accuracy of the system parameters, the stability of the proposed
observer is related to Tsm . Similarly to the encoder trade-off between sensing
accuracy and latency, the MRAS observer has to be designed to well ap-
proximate the speed measurements (i.e., a small Tsm to increase the iterative
refinements). However, if the speed controller is relatively slow and the actual
speed value does not need to be update every Ts , the discretization time can be
set as Tsm = 5Ts as for the encoder. This is helpful to reduce the computations
which has to be scheduled within Ts (which may enlarge the overall execution
time), while keeping the synchronization between computations since Tsm is
a multiple of Ts . Therefore this would be the preferable choice.
Since the Adaptive Model is based on the armature current dynamic, the
kp,M R and ki,M R parameters of the the PI controller can be set equal to those
computed for the current control loop, i.e., kp,M R = kp,i and ki,M R = ki,i .
These value define the expected time of convergence of the estimated value
Ω̂(k). As previously said, this approach is suitable for both Half- and Full-
Bridge configurations (i.e., feasible for single-motor and B2B test cases). The
only difference would be in the definition of the armature voltage, which is
related to the specific adopted topology. The MRAS observer is assumed to
be used in the Full-Bridge configuration scheme adopted to drive the single
PMDC motor. The armature voltage is va (k) = (2da (k) − 1)VDC , as shown in
wm ia_est
2 1
1
Va
Single Motor Configuration 347
˝Gi (ms) Ra (
) La (mH)
1.635 0.529 0.865
Va = Ra Ia + KΩ (19.18)
thanks to the virtual COM port, even if some delay is introduced. However,
it is assumed to be sufficiently low not to compromise the characterization of
mechanical transient, which is typically much slower than the electrical one.
To this purpose, a firmware exploiting the same block chain shown in Section
14.6 for speed measurement is built. The blocks presented in Section 16 for
running the motor in open loop are included as well. Indeed, this time the
rotor is not locked any more. If some delay issues arise, the DAC peripherals
can be used for data acquisition.
The mechanical dynamics is related to the following equation:
dΩ(k)
me (k) − ml (k) = βΩ(k) + J (19.20)
dt
The friction coefficient and the inertia of the motor can be computed
similarly to the electrical parameters. Indeed, β can be evaluated at steady
state without applying any load torque ml (k) on the shaft, whereas the inertia
needs a measurement of the mechanical dynamic. Therefore, the motor can
be still supplied with VDC = 10 V with a train of pulses with duty-cycle equal
to, e.g., d(k) = 0.2. Then, the electromagnetic torque can be computed as:
Firmware Environment
c28069_DCchar_hbF.slx (solver: fixed step - ODE4, step size: Ts = 50 µs)
This firmware is obtained by joining the schemes realized in Section 14.6 and
16.2 (fsw can be set equal to 20 kHz or 30 kHz). Indeed, the motor is supplied
with a d(k) = 0.2 pulse duty cycle once again and the speed measurement
through the encoder is still valid: this signal is processed so that the angular
speed in rad/s is obtained. In addition, the GPIO block is replaced with a SCI
Transmit block set as reported in Section 10.5. A Rate Transition block with
sample time equal to 0.01 s is added and the Data Type Conversion block is
set on single values. Finally, the resulting Simulink® scheme is shown in Figure
350 Cascade Speed Control of a Permanent Magnet DC Motor
encoder
eQEP
SCI XMT
qposcnt Z-1 w
Data
C28x
C28x
ePWM
WA
C2802x/03x/05x/06x
ePWM1A: J4 - pin40
CPUfrequency
TBPRD = PWMcounter−period = = 1500 (19.22)
2 · PWMfrequency
Firmware Environment
c28069_DCcontrol_fbF_uni (solver: fixed step - ODE4, step size: Ts =
1/2fsw = 16.7 µs)
Open a new blank Simulink® project and configure the environment as shown
ePWM1A: J4 - pin40
C2802x/03x/05x/06x
WA
ePWM
C28x
Single Motor Configuration 351
rotating
legA
legB
encoder cable
enable
DC link (ADCB3)
Figure 19.15 Connections of the DecMot Hardware Kit with the LaunchPad
F28069M through the BOOSTXL-DRV8301 converter and the extPot3 board.
A Full-Bridge configuration is realized and the encoder wires are interfaced
with module 2 of the eQEP peripheral.
• Add a Gain block to normalize the speed controller output (which varies
in the [−Kia,max , Kia,max ] range) through a scaling factor 1/K. Then, the
signal spans a [−ia,max , ia,max ] range, becoming a reference current. De-
pending on the value of kaw , dynamics close to the upper/lower bounds are
damped by the back-calculation strategy.
• Add a Gain block to normalize the current controller output (which varies
in the [0, VDC ] range) trough a scaling factor 1/VDC . Then, the signal spans
a [0, 1] range, being consistent with the definition of d(k) = dA (k) (and,
then, dB (k) is computed).
• Add a Pulse Generator (sample based) block to create the reference Ω ∗ (k).
Set the amplitude equal to A = 200, number of samples ns = 60000, pulse
width 30000 samples, phase delay 0, and sample time Ts . It is equivalent to
have a square-wave Ω ∗ (k) of period 60000Ts = 2 s with Ton = 1 s. It can be
noted that Ω∗ (k) is synchronized with the zero value of the triangular carrier
CTR=0. Then, a Add and a Constant blocks are placed to bias Ω ∗ (k) and
to generate a reference signal ranging from [−100, 100] rad/s.
• Add a Gain set on K, a constant block, a Manual Switch and an Add block
to allow the inclusion of the back-emf compensation in the control scheme.
• Regarding the speed measurement, add an eQEP block and build the related
conversion chain to process qposcnt in order to get Ω(k); the reader is
referred to Chapter 14, Section 16.3 and to the file c28069_DCchar_hbF.slx.
It can be noted that these eQEP blocks are scheduled through the sample
time Tw . To this purpose, it must be noted that Tw must be set large enough
to provide a good approximation of the measured speed. Indeed, a too low
value fo Tw may badly compute the speed value within the acquisition time,
while a too large Tw introduces further actuation delay that may lead the
controllers to saturate. As previously explained, a trade-off must be found.
IN this implementation, Tw = 5Ts is considered.
Arrange these aforementioned blocks as shown in Figure 19.16. In order to
manually manage the activation of the PI controller, the external reset (rising)
is connected to a potentiometer (ADCINB3/pin68). Without moving it, the
control algorithm is forced not to provide any actuation signal. To this aim:
• Add an ADC block and select ADCINB3 as Conversion channel in the
Input Channels tab. Then, go back in the SOC Trigger tab:
– Sampling mode: Single sampling mode;
– SOC trigger number: SOC1;
– SOCx acqusition window: 7;
354
C2806x
pot unipolar
[ref] GPIOx
C2802x/03x/05x/06x scaling
current test GPIO DO
A3
B
ADC C2802x/03x/05x/06x
db
speed ctrl WA
C28x
C28x w [w]
qposcnt Z-1 Data
w Discrete
1 [ia] SCI XMT
eQEP u y
0.009s+1 wf
encoder
speed estimator (MRAS)
[w]
[da]
[ia] DAC1: J4 - pin31
Continuous
1 west C2802x/03x/05x/06x
u y va
0.0008s+1 f Adaptive ia est. PI(z)
model [w] unipolar
wm WA
scaling
d(k) is discontinous
due to ctrl [en] ePWM
%% F28069M clock
CPU_frequency = 90e6;
%% carrier frequency definition
PWM_frequency = 30e3;
%% TBPRD (counting mode) definition
PWM_counterperiod = CPU_frequency/(2*PWM_frequency);
%% sampling time definition
Ts = 1/PWM_frequency ;
%% ADC theoretical gain
g_adc = (530e-3)/62;
Similarly, the measured speed can be sent to an other channel of the DAC
peripheral:
• Copy the previous ePWM block, select ePWM7 (which is connected to
DAC1 in J4, pin 31), and keep the other settings. Copy and paste the Gain
block set on PWM_Counter_Period and the data type conversion set on
int16. The measured speed is first scaled through a 1/400 gain and, then, it is
biased by constant which can be defined by the reader depending on specific
needs. For instance, a 0.65 bias cause a speed variation up to 100 rad s/400+
0.65 → 0.9 × 3.3 = 3 V. This might be not satisfactory in presence of a speed
overshoot, because the DAC saturates at 3.3 V. Hence, a more conservative
choice could be to use a bias of 0.45. It must be remembered that this
value is application dependent. Finally, Ω(k) can be observed through an
oscilloscope by connecting a voltage probe to pin 31.
Figure 19.17 reports the closed-loop behavior of the cascade speed control
scheme obtained by executing the firmware and observing the speed Ω(k),
the armature current ia (k) and the duty cycle applied on leg 1 d(k) = dA (k)
through an oscilloscope. In particular, Ω(k) and d(k) were measured with
voltage probes connected to DAC1 and DAC3, respectively, while ia (k) was
acquired through a current probe.
As done in simulation, Figure 19.17 shows the command tracking perfor-
mances of the controlled system in terms of speed and current dynamics. The
resulting Ω(k) (blue line) is following the reference signal Ω ∗ (k) (red line). It
must be noted that those two signals are expressed in a 0 − 3.3 V range. In
particular, the speed lies in a shorter 0 − 3 V interval thanks to the 0.65 bias
in the DAC1 processing. This is aimed to still have voltage margin to detect
358 Cascade Speed Control of a Permanent Magnet DC Motor
line). This can be easily done via software by using an average function or a
digital filter. Despite this processing, d(k) still show spikes in the correspon-
dence of the step variations of the reference signals, being consistent with the
behavior observed in simulation. Indeed, this is a consequence of the sudden
control action provided by the PI-based current controller.
The steady-state values of Ω(k), ia (k) and d(k) are in line with the final
value theorem, as shown in Chapter 5.
Furthermore, in analogy with simulations, the robustness of the closed-
loop dynamics are evaluated in case a load torque is applied to the shaft.
This can be carefully performed by simply hand-locking the rotor, as shown
in Figure 19.18. This operation is equivalent to applying a variable an not-
a-priori known ml (k) on the rotor shaft. Figure 19.19 shows how the system
reacts to such variable perturbation. As expected, the disturbance rejection
performances differ from the command-tracking ones, with the former being
much slower. In particular, the first plot shows that Ω(k) tends to decrease
when the hand is holding the shaft, while the current ia (k) increases, trying
to compensate ml (k). Even if slow, the load disturbance is rejected by the
cascade architecture until Ω(k) tracks Ω ∗ (k) again.
Nevertheless, the rotor accelerates when ml (k) is removed, producing a
rebound effect. This behavior is due to the large rising of ia (k) during ml (k) 6=
0, which has to rapidly decrease when ml (k) = 0 producing an acceleration in
the rotor speed. The latter is, then, compensated by reducing d(k). However,
it requires some time as a consequence of the slow dynamic of the speed loop.
It must be noted that the scaling of Ω ∗ (k) and Ω(k) for the GPIO7 and
DAC1 reading is different with respect to that one adopted Figure 19.17.
Indeed, in this case 100 rad/s correspond to ≈ 1.2 V to keep a sufficiently
large voltage margin to observe the speed overshoot without saturating the
peripheral.
Finally, Figure 19.20 reports a comparison of the closed-loop dynamics for
a speed loop which processes the speed measured by the encoder LPD3806-
600BM-G5-24C (blue line) and the one obtained by using an MRAS observer.
The measured curves are in accordance with the simulated results even if the
MRAS observer shows a larger latency in comparison to simulations. More-
over, the implemented MRAS do not include a low pass filter on the duty cycle
360 Cascade Speed Control of a Permanent Magnet DC Motor
d(k). Indeed, it is left up to the reader test possible behavioral differences due
to the inclusion of a filter.
1A 2A
VDC + iT iB
−
T B
1B 2B
Figure 19.21 Equivalent circuit of the test setup involving the two PMDC
motors in back-to-back configuration.
(a) (b)
Figure 19.22 Mechanical and electrical port conventions for the test setup
involving the two PMDC motors in back-to-back configuration: (a) no me-
chanical coupling (both machines spin their shaft in the same direction when
operated as motors) and (b) with mechanical coupling (the braking motor
works as a generator).
where the labels T and B stand for traction and braking, respectively. It is
quite evident that the traction motor is related to the current ia (k) (from leg
A) and the braking motor to ib (from leg B). From now on these two currents
are called ia (k) and ib (k). It must be noted that the proposed implementation
foresees that the two involved legs are independently controlled. Thus, the
braking motor may make the shaft rotate if activated before the traction one.
The model of this system now includes two electrical and one mechanical
equations, which describe the behavior of the coupled PMDC motors (rigid
shaft and coupling elements are assumed). In the continuous-time domain, it
follows that:
dia (t)
La = va (t) − Ra ia (t) − KΩ(t) (19.24)
dt
dib (t)
Lb = vb (t) − Rb ib (t) − KΩ(t) (19.25)
dt
dΩ(t)
Jeq = me,a (t) − me,b (t) − βeq Ω(t) (19.26)
dt
where Jeq and βeq are the equivalent inertia and friction coefficient associated
to the whole system (i.e., the two PMDC motors and the mechanical joint),
whereas me,b (t) and me,a (t) correspond to me (t), ml (t) (see equation (15.3)
and Figure 19.22), respectively. Moreover, it can be noted that the subscripts
a and b now denote the two motors for all the system parameters. Given the
sample time Ts and an integration method, the B2B model and the related
variable can be discretized.
Discrete-time PI controllers RΩ (z) and Ri (z) are derived based on these con-
siderations. The sampling time of the controller is set equal to Ts = Tsw =
1/fsw , using Forward Euler as integration method.
CPUfrequency
TBPRD = PWMcounter−period = = 1500
2 · PWMfrequency
as already seen for the control of the single PMDC motor. Moreover, the
sampling time is Ts = Tsw = 1/PWMfrequency . Once again, reference speed
can be internally generated in the firmware or externally provided both using
the available potentiometers on the extPot3 board or through COM port
(e.g., SCIA). The analog solution is adopted to add versatility to the control
scheme in the proposed solution. However, the reference braking torque is
obtain by varying a second potentiometer on the extPot3 board. The required
Back-to-Back (B2B) Configuration 365
legA
load
torque
enable
DC link (ADCB3)
Figure 19.23 Connections of the B2B-PMDC Hardware Kit with the Launch-
Pad F28069M through the BOOSTXL-DRV8301 converter and the extPot3
board. A Half-Bridge configuration is realized for each motor and the encoder
wires are interfaced with module 2 of the eQEP peripheral.
Firmware Environment
c28069_B2Bcontrol_hbF (solver: fixed step - ODE4, step size: Ts = 1/fsw )
Open a new blank Simulink® project and configure the environment as shown
in Section 9. Remember that the BOOSTXL-DRV8301 is enabled by settling
GPIO50 high (see Section 3.2). This firmware can be realized starting from
the file c28069_DCcontrol_fbF_uni built previously. Indeed, this implemen-
tation requires a speed and a current loop for the traction motor, as well
as speed and current measurements. Moreover, the braking motor requires
the same current control scheme adopted previously and a MRAS observer
is needed to test sensorless runs of the code. The control (and actuation)
enable is managed again through the potentiometer connected to ADCB3,
whereas DAC modules can be used for measuring speed and duty cycle with
an oscilloscope. Therefore, it is suggested to copy and paste the whole scheme
included in c28069_DCcontrol_fbF_uni in this new blank project and, then,
to slightly modify the ePWM blocks and the processing of the modulating
signals in order to move from a Full-Bridge to an Half-Bridge configuration.
Indeed, referring to the previous file:
366 Cascade Speed Control of a Permanent Magnet DC Motor
• Modify the generation of the speed reference. As a matter of fact, the back-
to-back setup is allowed to spin the shaft in one direction only. Therefore,
remove the Constant and the Add blocks and set the amplitude of the Pulse
Generator equal to 100. Therefore, the system tracks a speed reference rang-
ing from 0 up to 100 rad/s.
• Modify the ADC block for the current measurement by allowing the Simul-
taneous sampling of channels A0 and B0, i.e., the modules connected to the
onboard shunts on legs 1 and 2, respectively. To this aim, set the SOC trigger
number equal to SOC0-SOC1 and modify the same entry in the ADC block
for enabling the PI blocks (channel B3) setting it equal to SOC4. Indeed,
multiple SOC trigger numbers are not allowed. It can be noted that this
strategy is preferred to the use of two separated ADCs since it requires less
use of embedded resources.
• Add a Mux block to split the measurement for the currents on both legs.
Then, copy and paste the same conversion chain adopted for channel A0. It
is important to modify the offset and the gain based on the identification
process for the second leg.
• Copy and paste the current control loop from the traction motor. It must be
remembered that the two current PI controllers share the same parameters.
Then, move the gain block set equal to PWM_Counter_Period, the Data
Type Conversion block set on int16 and the ePWM2 close to this second
control loop for the braking motor. The reference braking torque is generated
through the potentiometer connected to channel B5 of the ADC peripheral.
Set the parameters of this block as follows:
– Select ADCINB5 as Conversion channel in the Input Channels
tab. Then, go back in the SOC Trigger tab;
– Sampling mode: Single sampling mode;
– SOC trigger number: SOC3;
– SOCx acquisition window: 7;
– SOCx trigger source: Software;
– ADC will trigger SOCx: No ADCINT;
– Sample time: 0.001;
– Data type: uint16.
Then, use a Data Type Conversion block set on int16 and a Gain block with
parameter 1/212 to re-scale the reading of the ADC channel into a [0, 1]
range. After that, this signal is translated into a braking torque through a
Gain block set on -maxBr, that is, −0.05 N m. A redundant saturation block
can be used to limit the load torque up to this value.
• Leave all the other blocks unchanged.
Back-to-Back (B2B) Configuration 367
Remark: it must be noted that the overall firmware scheme is pretty large
and complex compared to the previous exercises. Hence, it may be possible to
saturate the computational resources of the MCU during the execution of the
firmware. To avoid this issue, some parts of the scheme which are not strictly
necessary for the execution can be commented. For example, the blocks im-
plementing the MRAS observer during the sensored control. Moreover, Data
Type Conversion blocks can be inserted and/or edited to reduce the process-
ing effort during computations as well as DAC blocks can be excluded from
the firmware.
%% F28069M clock
CPU_frequency = 90e6;
%% carrier frequency definition
PWM_frequency = 30e3;
Tsw = 1/PWM_frequency
%% TBPRD (counting mode) definition
PWM_counterperiod = CPU_frequency/(2*PWM_frequency)
%% sampling time definition
Ts = 1/PWM_frequency;
%% ADC theoretical gain
g_adcA = 4.65/550;
g_adcB = 4.65/450;
%% maximum braking torque definition
maxBr = 0.05;
%% encoder sample time definition
Tw = Ts*5;
were the parameters of the two motors and of the controllers are not reported
for the sake of brevity. It can be noted that the encoder acquisition window
is set to Tw = 5Ts . However, the same consideration reported previously on
this parameter are still valid and a new trade-off value can be determined if
necessary. As done for all the implementations proposed in this book, Figure
19.25 shows the command tracking performances of the controlled system.
The resulting Ω(k) (blue line) is following the reference signal Ω ∗ (k) (red
line). It must be noted that those two signals are expressed in a [0, 3.3 V]
range as consequence of the measurement performed via GPIO7 and DAC1,
368
C2802x/03x/05x/06x
[wref] C2806x
A3
speed ctrl [wref] unipolar GPIOx
ADC scaling
Traction Motor m* current ctrl GPIO DO
[w] PI(z) [da]
pulses ia* A
u
PI(z) C2802x/03x/05x/06x
[ia]
enable ia
en WA
C2802x/03x/05x/06x
en ePWM
B3 >= 0.5
e
DAC3: J8 - pin1
ADC [en]
[w] C2802x/03x/05x/06x
WA
C2802x/03x/05x/06x [ia]
[ia] ePWM
Discrete [ib]
A0/B0 1
u y
0.0009s+1 iaf [w]
ADC
shunt A ib
ib [ib] [wref] C28x
Discrete ibf
1
u y
0.009s+1 [w] Data
C28x
SCI XMT
qposcnt
w
[w]
eQEP Z-1
encoder Discrete
1 [west]
u y
0.01s+1 wf
[da]
DAC1: J4 - pin31
[ia]
Discrete C2802x/03x/05x/06x
1
u y va PI(z) unipolar
0.0008s+1 f Adaptive ia est. [w] WA
model west scaling
wm
d(k) is discontinous ePWM
due to ctrl [en]
C2802x/03x/05x/06x
current ctrl B
ib* [wref] >= 0.2
B5 C2802x/03x/05x/06x
ib*
mb*
ADC PI(z) WA
[ib]
torque is limited to avoidexcessive stress ib
Braking Motor ePWM
on the traction motor and couplings
en
en
[en]
e
[w]
with respect to ia (k). The evolution in time of ml (k) depends on the dynam-
ical variation of the potentiometer connected to ADCB5. The plots show a
rejection to disturbances which is similar to that one observed in the single
PMDC motor implementation.
Part V
Real-Time Control in
Power Electronics: Load
Emulation
20
Debugging Tools and Firmware Profiling
In the previous chapters, firmware design has been described in a step-by step
manner, helping the reader to understand how to make an embedded control
scheme out of system simulations, which is consistent with linear control the-
ory. Nevertheless, there are a many debugging techniques that can be adopted
both to check possible mistakes or to verify the performances of the gener-
ated code. Among them, the processor-in the-loop (PIL) testing technique and
the external mode execution are adopted in this book and described in this
Chapter. Both approaches lead to test numerical equivalence between model
computations, produced code and expected behavior (predicted from simula-
tions). As the system is running, information on block states, inputs, outputs,
and time execution can be displayed within the Simulink® Editor. This allows
the designer to investigate specific problems and/or potential improvements
in blocks, parameters, or interconnections.
Simulink®
code generation
Figure 20.1 Block diagram showing the main steps to be carried out during
PIL simulations.
the considered control loop fits within the execution time available on the
embedded processor.
• Observe code coverage: PIL allows an evaluation of the automatically gen-
erated code.
• Perform code execution profiling: this testing technique is useful to identify
the most demanding operations inside the control loop.
Therefore, the PIL simulations are aimed to evaluate the performances of
a controller running on a target board before its implementation on a real
system. From the hardware point of view, a control platform such as the
LaunchPad™ F28069M board is required only. Instead, the load is still emu-
lated.
As an example, by considering the closed-loop speed control of a PMDC
motor as shown in Chapter 19, PIL simulations may be performed to gain
confidence and to check that the control algorithm performs as expected once
it is physically running on the MCU, without connecting the TI BOOSTXL-
DRV8301 BoosterPack or the DC machine as well. A block diagram showing
the main steps of this procedure is shown in Figure 20.1. In particular, a sim-
ulation environment is used to model and verify the behavior of a speed-loop
control for a DC motor. Basically, starting from the simulation environment
that represents the whole controlled system, the control task which have to
be executed in the MCU are selected (e.g., PI controllers and sensing path)
and translate in C-code. This latter is then downloaded into the MCU, while
the PMDC motor model is kept in the scheme, but it is emulated only (i.e.,
code is not generated for this part of the model, see Figure 20.2).
Through a communication channel, the Simulink® environment (on the
host PC) exchanges stimulus signals (e.g., test vectors) with the MCU board
for each sample interval of the simulation. Every time the target processor
Processor-in-the-loop with Simulink® 375
Figure 20.2 PIL workflow between the LaunchPad™ F28069M and the host
PC developed in Simulink® .
receives signals from Simulink® , it executes the on-board code for one sample
step. The results, e.g., a control action, are returned to the Simulink® scheme
through a communication channel. Then, one sample cycle of the simulation
is complete, and the process keeps repeating for the next sample interval. It
can be noted that in each sample period, PIL simulations do not run in real
time. Indeed, the Simulink® environment and the object code exchange I/O
data depending on the serial communication settings. Although the workflow
reported here in the following describes how the performances of a motor
control application are assessed using PIL testing, it is possible to general-
ize this procedure for any power electronic-based application, framework and
processor/MCU supported by the Simulink® environment.
%% motor data
Vdc = 10;
imax = 5;
Ra = 0.529;
La = 8.651e-4;
Kt = 0.0232;
B = 1.803e-4;
J = 3.56e-6;
%% modulation and sampling
fsw = 20e3;
Tsw = 1/fsw;
Ts = Tsw; or Ts = Tsw/2
Tsim = Ts/100;
%% current controller
tauGc = La/Ra;
TaGc = 5*tauGc;
TaI = TaGc/10;
wcI = 5/TaI;
kpI = wcI*La;
kiI = wcI*Ra;
%% speed controller
tauGm = J/B;
TaGm = 5*tauGm;
wcW = wcI/10;
TaW = 5/wcW;
kpW = wcW*J;
kiW = wcW*B;
w*
reference w* switch to PIL mechanical
w cascade electrical ml
w w va w
speed/current loops va w
ia ia me
ia ia
va ia me
e
Place your PIL
Block here
Considering the scheme shown in Figure 20.3, the control subsystem (which
includes both speed/current controllers and back-emf compensation) is the
object of the verification through PIL testing. Only this part of the Simulink®
scheme has to be implemented and run online into the LaunchPad™ F28069M
board.
To this aim, enable the settings for running PIL over Serial by typing the
instructions reported here below in the Command Window:
setpref(’MathWorks_Embedded_IDE_Link_PIL_Preferences’,’COMPort’,’COM10’);
setpref(’MathWorks_Embedded_IDE_Link_PIL_Preferences’,’BaudRate’,115200);
setpref(’MathWorks_Embedded_IDE_Link_PIL_Preferences’,’enableserial’,true);
where the user has to set the COM port which has been defined in the PC
device manager, e.g., COM10 in this example.
Then, right-click on the control subsystem and select C/C++
w*
reference w* switch to PIL mechanical
w cascade electrical ml
w w va
w
speed/current loops
ia ia me w
ia ia va
va ia me
w*
e
Place your PIL
w PILhere
Block va
ia
Figure 20.7 Closed-loop dynamics resulting from standard and PIL simula-
tions.
A load torque ml (k) is also applied to test the disturbance rejection and to
verify the robustness of the proposed control scheme. Both strategies return
the same dynamics, which are reported in Figure 20.7. It is possible to note
that the PIL simulations are subjected to a slower processing, since the com-
putations of the control action are performed on-board the MCU (serial com-
munication is required),1 while in standard simulations those are computed
through the host PC CPU. The PIL framework enables another widely used
1 Note that, from MATLAB® version 2019b it might be neccessary to specify the de-
sired behavior for denormal results for arithmetic operations. Denormal numbers are any
non-zero numbers whose magnitude is smaller than the smallest normalized floating-point
number. Some hardware targets as the LaunchPad™ F28069M board flush denormal results
from arithmetic operations to zero. You can set this behavior in Model Configuration
Parameters/Math and Data Types, then change the parameter Denormal Behavior to
Flush To Zero (FTZ) (instead of Gradual Underflow which is given by default).
380 Debugging Tools and Firmware Profiling
feature which is the profiling of the task execution time and function execu-
tion time of the real-time algorithm running on the MCU board. This tool
is named Profiler or Simulink® Profiling. The Profiler captures performance
data while the software is running the simulation, e.g., it identifies which
parts of a control algorithm require most time or most iterations to be com-
puted and executed. Such information is useful to evaluate the need for code
refinements and where to focus the optimization efforts in the algorithm. To
this end, profiling is particularly useful to analyze the pipelining in real-time
platform which may benefit of multi-core processors on the target hardware.
There are two ways to enable the Profiler:
• Open the Debug tab, select Performance Advisor/Simulink Profiler.
• Select Analysis/Performance Tools/Show Profiler Report
2 In particular, the Profiler measures the time required to execute each invocation of
these functions.
External Mode Execution with Simulink® 381
C2806x
GPIOx
GPIO DO
led blue
next model update. Depending on the firmware complexity, such data trans-
fer could be less critical than maintaining deterministic real-time updates at
the required sample interval (i.e., not a priori).
The serial communication between PC and board is automatically settled
without any block like Serial Send and SCI Receive. Hence, differently from
what is described in Part III, this time only one Simulink® file is needed both
for programming and debugging purposes, since the external mode automat-
ically manages the data flow through the virtual COM. Scopes and displays
can be inserted directly in the firmware scheme. It is important to note that
there is a maximum number of plots that can be used depending on the per-
formances and capabilities of both the serial communication and the host PC.
Indeed, code size and memory consumption are increased when the External
Mode is enabled.
Figure 20.9 Plot from the scope block in External Mode execution.
Target Hardware Resources, look for External mode. There, enter the se-
rial COM port set in the PC device manager, e.g., COM10 in this example.
Keep the other settings as they are.
• Coming back to the Simulink® editor, set the desired simulation time, e.g.,
20 s, and click on the monitor & tune icon to run external mode
execution.
These settings are necessary to program the MCU and to run the External
Mode execution for the supported MCU devices. Starting from MATLAB®
release R2018a, this procedure is easier due to the introduction of a specific
"TI Piccolo F28069M LaunchPad" target as Hardware board, which has de-
fault settings matching the LaunchPad™ SCI pins and oscillator frequency.3 In
previous releases, it was required to manually adjust the oscillator frequency
and the SCI pins to match the LaunchPad™ board layout. This settings al-
ready include a target buffer size which specifies how much memory should
be allocated to store signals for the external mode.4
In addition, some export settings for the variables of interest can be found
in external mode control panel, by clicking on the icon Control Panel .
Once the external model execution is launched, the model is built, compiled
and deployed in the platform. The simulation automatically starts and the
data values can be assessed through Scopes. In this case, the pulses used to
make the led blinking can be visualized as shown in Figure 20.9. An other im-
portant feature of the external mode is that constant blocks can be edited dur-
ing the execution, allowing several real-time verifications for different steady-
state working conditions.
Unfortunately, the external mode suffers from a communication bottle-
neck. It may happen that the data exchange via COM fails, causing an abrupt
stop of the Simulink® simulation. This scenario may be potentially dangerous,
3 In particular, it is possible to specify which GPIO channels are used for the External
Mode SCI connection. The corresponding pins cannot be used by other peripherals.
4 The number of words N
w required by the external mode can be computed as Nw =
Nsignals · 2 · (Nsamples + 1). In case more samples than those allowed by the memory alloca-
tion are required, Simulink® automatically truncates the scope traces every time Nsamples
points are plotted. It can be noted that cases of insufficient memory on the target result in
a build error.
External Mode Execution with Simulink® 383
since the MCU may keep executing the C-code with the last memorized state.
Based on Figure 20.9, it is particularly evident that the data samples are not
equally distributed everywhere. Extra samples may appear, implying that the
data exchange is affected by latencies. Therefore, this issue explains why this
kind of execution is suitable for debugging purposes, but it is recommended
to double check the results even with other evaluation tool.
Remark: it must be remembered that the XDS interface typically has two
serial interface channels, one for debugging and the other one for auxiliary
communication, including UART. If the External Mode connection to the
device is unsuccessful, a possible explanation is that the debug channel was
selected instead of the auxiliary communication channel during the COM port
setup.
21
Electric Propulsion Case Studies
This last Chapter proposes two realistic cases study that deal with electric
propulsion on vehicles. No solution is reported in the following pages, since
the aim of those two exercises is to leave the reader free to organize the control
logic to check its understanding on the topics and concepts explained in the
previous Sections. Since those two exercises involve a tramway vehicle and
an electric car, no actual implementation on hardware is feasible for both
of them. However, the reader is invited to perform PIL simulations to test
the performance of the designed control strategy. The first case study deals
with a DC motor control. The reader is referred to Chapter 19 for all the
details of this control. Instead, the electric car involved in the second exercise
is controlled through an AC brushless drive. Such strategy is not explained
in the previous chapters of this book. However, this second exercise reports
some guidelines on how to deal with a synchronous motor and how to simplify
its modeling. Then, the control logic of such machines is not so different with
respect to that one adopted for PMDC motors.
Figure 21.2 Plots of the slope and speed profile of the track.
Table 21.1 Track profile for the tramway “Carrelli 1928.” The vehicle starts
from 0 speed and it stops at the end of the track.
1 In the reality, tramway vehicles go forward in coasting mode once they reach a steady
state speed. For the sake of simplicity, in this exercise it is possible to assume that the
traction torque is always applied on the motor to follow the speed profile with no error.
388 Electric Propulsion Case Studies
mtot = mT + mP NP = 25.4 t
Ptot = 4Pr = 84 kW
d
vr, m/s = ρ Ωr, rad/s = 6.07 m/s
2
La = τa Ra = 3.86 mH
Le = τe Re = 1.2 H
Mechanical parameters
1. Equivalent inertia of the vehicle seen on the motor shaft:
2
vr, m/s
Jeq = mtot = 90.62 kg m2
Ωr2
2. Friction coefficient2 :
mfr,r
β= = 0.81 N m s
Ωr
2 it can be assumed that the friction torque acting on the whole vehicle can be computed
• Efficiency η = 0.95;
• Stator resistance Rs = 0.1 Ω;
• Stator inductance Ls = 0.8 mΩ;
• Nominal speed Ωr = 400 rad/s;
• Pole pairs p = 2;
• Permanent-magnet flux φPM = 0.5 Wb.
Giulietta Quadrifoglio Verde. Please, note that such electric car is does not exist and,
therefore, it is not available on the market.
Electric Racing Car 391
(a)
(b)
Figure 21.4 Speed profile of the car running on the Varano circuit (also
available in Ex_E_car.mat file, variable: speed_kmh) (a) and correspond-
ing equivalent braking torque applied on the motor shaft before the gearbox
(also available in Ex_E_car.mat file, variable: T_braking) (b).
va = Rs ia + pφa
vb = Rs ib + pφb
vc = Rs ic + pφc
φa = Lss (θm )ia + Mss (θm )ib + Mss (θm − 32 π)ic + φPM (θm )
φb = Mss (θm )ia + Lss (θm − 23 π)ib + Mss (θm + 23 π)ic + φPM (θm − 23 π)
φc = Mss (θm − 23 π)ia + Mss (θm + 23 π)ib + Lss (θm + 23 π)ic + φPM (θm + 23 π)
where p is the derivative operator, i.e., d/dt, Rs is the phase resistance, va,b,c
are the voltages applied on each phase of the motor, ia,b,c are the currents
flowing in each phase of the motor, φa,b,c stand for the magnetic flux linked
4 All the currents i
a, b, c, d, q , voltages va, b, c, d, q , fluxes φa, b, c, d, q , angles θm ,
speeds ωm and Ω, torque me and ml are in general function of time. In this paragraph,
this dependency on t is not made explicit for the sake of brevity.
Electric Racing Car 393
ea
Rs Lss
1A 2A 3A Mss ia
eb
Rs Lss
VDC + n
−
ib
ec
1B 2B 3B Rs Lss
N ic
with each winding of the motor, Lss is the phase inductance (equal for all the
windings), Mss is the mutual inductance (equal for all the magnetic couplings
between windings), φPM is the magnetic flux generated by the permanent
magnets and θm is the electrical position of the rotor. This angle differs from
the mechanical position of the rotor by a factor equal to np , that is the number
of pole pairs of the machine. Indeed, the periodicity of the electrical variables
is 1/np of the mechanical one. In addition, it is important to note that, in
general, all the phase voltages, currents, fluxes and the rotor position θm are
functions of time. The previous set of equations can be simplified reminding
that the motor adopted in this chapter is isotropic. Thus, the dependence of
the self and mutual inductances on the rotor position disappears. In addition,
the stator windings are connected in such a way that ia + ib + ic = 0 for every
considered time instant. Consequently, the new set of equations becomes:
va = Rs ia + pφa
vb = Rs ib + pφb
vc = Rs ic + pφc
φa = Ls ia + φPM (θm )
φb = Ls ib + φPM (θm − 23 π)
φc = Ls ic + φPM (θm + 23 π)
vd va
vq = T (θm ) vb
v0 vc
id ia
iq = T (θm ) ib
i0 ic
φd φa
φq = T (θm ) φb
φ0 φc
Then, it can be noted that this operation allows to define a number of new
reference frames, since angle θm can be chosen arbitrarily. For convenience,
a set of transformed axes which rotates synchronously with the rotor of the
machine under study is adopted commonly. In this way, all the AC electrical
variables appear as constants at steady state. Namely, the new transformed
electrical equations of a PMSM are:
vd = Rs id + pφd − np Ωφq
vq = Rs iq + pφq + np Ωφd
φd = Ls id + φPM
φq = Ls iq
where Ω is the mechanical speed of the rotor and the equations for the hom-
polar components of the voltage and the flux are not reported since they are
both nil. It can be noted that the electrical speed of the rotor and of all the
electrical variables can be defined as ωm = np Ω. Moreover, space vectors can
Electric Racing Car 395
From this compact notation, the term jnp Ωφs can be highlighted. This is
a motional term which is a consequence of the adoption of a moving reference
frame and it is responsible for the electromechanical conversion of the machine.
Moreover, combining the voltage and flux equations, the following dynamical
expressions can be obtained:
vd = Rs id + Ls pid − np ΩLs iq
vq = Rs iq + Ls piq + np ΩLs id + np ΩφPM
where np ΩLs iq and np ΩLs id are cross coupling terms between the two axis
and np ΩφPM = E is the back-emf expressed in the d-q reference frame. Finally,
the torque expression and the mechanical equation are presented. The first one
is obtained by setting an energy balance between the electrical and mechanical
part of the system. For isotropic machines, it holds that:
me = np φPM iq (21.5)
where me is the electrical torque generated by the PMSM. Instead, the dy-
namical equations of the mechanical part of the system is obtained from a
torque balance as follows:
Jeq pΩ + βΩ = me − ml (21.6)
where ml is the load torque applied in the shaft of the machine, Jeq is the
equivalent inertia of the PMSM and β is the friction coefficient.
np φPM np Ls 2L-VSC +
modulator
i∗d (t)
+ current u∗d (t)
+ vd∗ (t)
− controller
−
np Ls
ia (t)
iq (t)
ib (t)
id (t) T (θm )
ic (t)
Ω(t)
Figure 21.7 Block diagram of a generic PI based vector control for a PMSM.
and, consequently, for regulating the speed of the rotor, whereas the other one
is exploited to provide a variation in the magnetic field. For PMSM, this last
operation is done by generating currents in the stator windings that partially
demagnetize the magnetic field due to the magnets φPM . Carefulness must be
paid while demagnetizing real PMSM since too high current may compromise
the magnets.
Focusing on the realization of the vector control, the speed regulation is
implemented in an external loop and it is cascaded with the current control
acting on iq . Indeed, this current is responsible for torque variations (see
equation 21.5). The other current control acting on id can be considered as a
loop which acts in parallel to iq . A PI-based scheme of the vector control is
reported in Figure 21.7.
For Ω lower than the base speed irefd is set equal to 0. This choice allows
the quadrature current iq to reach the maximum sustainable current of the
machine imax . Above Ωb , the value of irefd is decreased (iref
d < 0) until it
reaches the value −φPM /Ls . Once this limit is reached, the d-axis current is
kept constant. On top of that, compensation terms should be added in the
control scheme based to the model of the machine previously shown.
Speed Controller
This PI controller is tuned based on the mechanical transfer function of the
PMSM. This latter is retrieved starting from equation 21.6, that relates the
mechanical speed with the electrical torque, and moving to the Laplace do-
main. The resulting transfer functions GΩ (s) reads as:
1
GΩ (s) = (21.7)
β + Jeq s
Electric Racing Car 397
kpΩ s + kiΩ 1
LΩ (s) = RΩ (s)GΩ (s) = (21.8)
s β + Jeq s
This transfer function shows two poles in zero. Therefore, in order to guar-
antee asymptotic stability, it is crucial to properly tune kpΩ and kiΩ . From the
study of L(s), both terms kpΩ can be directly linked to the bandwidth of the
controlled system ωΩ through the following equations:
Current Controllers
The tuning procedure of the current controllers is based on the same electri-
cal transfer function of the PMSM. Indeed, the transformed machine in the
Laplace domain, it can be noted that the resulting transfer function has the
same structure of that one adopted for the same control in a DC machine. As
a matter of fact, the cross-coupling terms and the back-emf can be dealt with
as if they were disturbances. Namely, for both d and q axes, it holds that the
electrical transfer function is:
1
Gi (s) = (21.11)
Rs + sLs
Therefore, the open loop transfer function reads as:
kpi s + kii 1
Li (s) = Ri (s)Gi (s) = (21.12)
s Rs + sLs
As for the Speed PI controller, a relationship between the gains of the
controller and the bandwidth of the system ωi can be written as:
kpi = Ls ωi (21.13)
kii = Rs ωi (21.14)
Due to the symmetry in the transformed machine, both the current con-
trollers can be tuned with the same parameters. In addition, it must be remem-
bered to select a value at least ten time larger with respect to ωΩ to fulfill the
cascade constraint for nested loops. Indeed, the speed loop is cascaded with
the current one, as shown in Figure 21.7.
398 Electric Propulsion Case Studies
Hint#3: acceleration
The motor can start from 0 speed and accelerate up to the initial speed of the
profile shown in Figure 21.4 (a) or an initial speed can be assigned.
Set suitable torque limits and separate the mechanical torque from the elec-
tromagnetic one.
Use the block Saturation Dynamic from library Discontinuities to imple-
ment the field weakening logic.
mtot = mT + mD = 1580 kg
2Pel
Irpeak = = 546.96 A
3Vpeak cos ϕ
Mechanical parameters
1. Equivalent inertia of the vehicle seen on the motor shaft:
2
Jeq = mtot (rρeq ) = 142.20 kg m2
#I12 · 3.1416 ∼
= #I12 · (21 + 2−1 + 2−3 + 2−6 + 2−11 )
Then, the shift properties can be exploited, making the calculation of the
product very fast. Since the shift operations have lower priority with respect
to the sum, parenthesis are required between the terms of the summation in
order to avoid errors:
#I12 · 3.1416 ∼
=(#I12 << 1) + (#I12 >> 1) + (#I12 >> 3)+
+ (#I12 >> 6) + (#I12 >> 11)
A.1.3 Multiplication
The multiplication between two variables in the same base can be written as:
#Abitbase · #Bbitbase
#Cbitbase = #(A · B)bitbase =
2bitbase
By expressing the constant division with the shift operator, it becomes:
A.1.4 Division
The division of two variables follows the same method introduced for the
multiplication and it can be expressed as:
#Abitbase 1
#Cbitbase = #(A/B)bitbase = · bitbase
#Bbitbase 2
The above expression is equivalent to:
#Abitbase << bitbase
#Cbitbase = #(A/B)bitbase =
#Bbitbase
The strategy to avoid overflow is to temporary move into 32 bit (long) vari-
able through left shifting, making the product computation, and then come
back to 16 bit integers. The corresponding C code is as follows:
. .
#x16 = (int) ((long)#xa,12 · #xb,12 ) 4 (A.1)
. .
The inclusion of an header file into the main program is performed by means
of the following piece of code placed at the beginning of the .c code:
#include filename.h
In order to have global visibility for both functions and variables set inside
any header file, it is necessary to define them as extern.
Macros are predefined pieces of code that are are substituted to the corre-
sponding invocation before code execution. In practice, a macro is a fragment
of code which has been given a name. Whenever the name is used, it is re-
placed by the contents of the macro. Macros are useful in order to speed up
the coding by avoiding multiple writing of the same pieces of code. Macros
can be invoked in the main .c file with a syntax similar to the one adopted
for the functions:
c = SUM(a,b) // -> c = (a + b)
404 Appendix A: Basics of C
Macros are also useful for simplifying the coding of multiplications between
a variable and a constant. Recalling the properties of the shift, as defined in
Section 7.3 and previously in this appendix, it is possible to express the mul-
tiplication of any variable by π with the following macro:
In this Appendix, the main characteristics of the custom expansion boards and
assembled kits targeted to the exercises proposed previously are illustrated.
As university initiative, the boards have been developed at the Laboratory
of Electrical Drives and Power Electronics, in the Department of Mechani-
cal Engineering of Politecnico di Milano, Italy, in collaboration with Würth
Elektronik™ Group and Texas Instruments™ Inc. The aim of this collabora-
tion is to provide to students ready-to-use test benches for the study of power
electronics-based applications. In particular, the developed boards and test
benches are:
• extPot3 board, which provides a direct manipulation of analog signals,
conversion chains, and buzzer;
• extRL(C) board, which is a configurable load equipped with output filter.
It is able to realize RL, RLC, R, L, LC topologies;
• RL(C) kit, which integrates the extRL(C) board with the LaunchPad™
F28069M and the BOOSTXL-DRV8301 BoosterPack boards;
• DecMot kit, which allows to test PMDC motors. An encoder sensor is
included as well as MCU interface for external power supply. Other kind of
motors can be installed and driven by the same hardware as well. Indeed,
the housing of this setup is suitable for two generic small motors;
• B2B-PMDC kit, which contains two coupled PMDC motors anchored on
an aluminum base plate, encoder sensor and MCU interface for external
power supply.
It is important to note that, according to the considered application, boards/k-
its need to be manually configured, e.g., topology settings, motor calibration
and cable connections should be edited.
Either custom expansion boards and assembled kits are open to users com-
munity. Project files can be shared and/or pre-assembled boards/kit can be
directly shipped. In case of interest, please contact:
- Mattia Rossi [email protected]
- Nicola Toscani [email protected]
- Francesco Castelli Dezza [email protected]
extPot3 Board
The extPot3 board (see Figure B.1) is a custom-made expansion board which
aims to drive three ADC channels of the LaunchPad™ F28069M board.
Namely, ADCA3, which is connected to pin 66, ADCB3 which is connected to
pin 67 and ADCB5 which is connected to pin 68. These channels are connected
to three 20 kΩ linear potentiometers (Pot1, Pot2 and Pot3), which are able to
generate analog signals in the range [0, 3.3] V at the ADC inputs. The extPot3
board can be directly mounted on top of the 40-pin plug-in module connector
(headers J5-J8) of the LaunchPad™ F28069M board. In addition, the board
includes a piezoelectric buzzer. This device can be driven by a generic GPIO
or by a ePMW, namely GPIO8 (which is connected to pin 78) and ePWM5B
(which is connected to pin 77). A bipolar transistor BJT NPN 25 V 0.5 A is
used as buzzer driver to decouple the driving signal from the actuation stage.
The extPot3 board mounts a six pins terminal header arranged to connect
hall-effect sensors through pull-up resistors. Starting from the left-hand side
of the board (front view of the board, see Figure B.1), the first three pins
corresponds to three phases for hall-effect sensor measurements, while the
other three to 3.3 V, GND, and 5 V supply, respectively. A SMD green led turns
on when the LaunchPad™ F28069M board is supplied with 3.3 V, verifying
the correct connection between boards (the 3.3V supply of the extPot3 are
taken from the MCU board).
As previously mentioned, the extPot3 board is connected to the
LaunchPad™ F28069M board through standard 40-pin plug-in module con-
nector. These pins remains accessible for debugging purpose or further connec-
tions. The maximum height of a BoosterPack is 1700 mil. This value becomes
1350 mil if there is no need for accessing header J5. Instead, there is no detailed
standard for the inner 20 pins (i.e., header J3 and J4). extPot3 board must
be attached with care to the LaunchXL F28069M one to ensure a successful
stacking with the various pins and to improve device lifetime as well.
extPot3 Board 407
All these pins can be used as GPIOs except VCC, GND, TEST, and RE-
SET. It can be noted that most of the LaunchPad™ F28069M board pins are
multiplexed for dual functionality. Thus, attention must be paid to check if
any of the ADC pin used by the extPot3 (which is physically connected to one
of the linear potetniometers) is reconfigured. Therefore, it is recommended to
keep the default pin mapping pins unless it does not restrict the firmware
design.
The Bill of Material of the extPot3 board is reported in the following table:
Key Features
• Manipulation of analog signals through linear potentiometers;
• Piezoelectric buzzer;
• Pins of LaunchPad™ F28069M board are still accessible;
• Suitable (i.e., without conflicts) for TI BOOSTXL-DRV8301 converter board
top mouting.
Test Points
Many test points are available to debug the LaunchXL F28069M board pins:
• TP1: connected to ENC A of QUEP_A;
• TP2: connected to ENC B of QUEP_A;
• TP3: connected to ENC I of QUEP_A;
• TP4: connected to 5 V of QUEP_A;
• TP5: connected to GND of QUEP_A;
408 Appendix B: Custom Expansion Boards and Hardware Kits
Jumpers
• J8: signal selector from GPIO or ePWM connected to the buzzer;
• ENABLE: to be connected to enable QEP_B functions when using TI
BOOSTXL-DRV8323RS converter board.
Connectors
• J6: hall-effect sensor terminal block.
current [A]
area mil2 = (B.1)
1c
b
k · temp.rise [◦C]
• Width computation:
area mil2
width [mil] = (B.2)
1.378 [mil/oz] · thickness [oz]
extRL(C) Board
The extRL(C) board (see Figure B.2) is an configurable load which is able
to combine different resistors R, inductors L and capacitors C, thus, allow-
ing to operate the system with several equivalent values of load resistance,
inductance and capacitance. This board is suitable for both operation in DC
or AC. The board includes dedicated current and voltage sensors as well as
an additional two-level converter leg with dedicated gate driver. The latter is
useful if no external converter board is used (e.g. the TI BOOSTXL-DRV8301
BoosterPack is not present).
The main feature of the extRL(C) load is the possibility to dynamically
change parameters values and load topology through three switches mounted
at PCB top and one at PCB bottom. Combining the extRL(C) with the TI
BOOSTXL-DRV8301 BoosterPack, the user is able to operate the system
with both Half or Full-Bridge DC-DC converter, with single-phase loads and
performing measurements comparison between the extRL(C) and BOOSTXL-
DRV8301 on-board sensors.
The details of the RLC load are reported here in the following:
• The available resistance values R are 6.8 Ω, 3.4 Ω and 0 Ω (no connected
resistors). Such value changes are made by acting on switch S1, which can:
– Put in parallel two 6.8 Ω resistors (decreasing the overall/equivalent
load resistance);
– Keep connected just one of the two 6.8 Ω resistors;
– Disconnect the passive load (switch S4 off is also required).
The adopted resistances are two Arcol HS50 Series Aluminum Housed Axial
Wire Wound Panel Mount Resistor, with nominal value 6.8 Ω±5% and rated
power 50 W.
• The available capacitance values C are 100 µF, 10 µF and 0 F (no connected
capacitor). Such value change is made by acting on switch S2, which can
connect one of the available capacitors at a time or by-pass the capacitor
stage (i.e., removing the C from the load). Electrolytic capacitors are used.
Their characteristics are reported here below:
– WCAP-ATET: Aluminum Electrolytic Capacitor, Radial, THT,
D8xH11.5mm, rated capacitance 10 µF ± 20%, rated voltage 100 V;
– WCAP-ATET: Aluminum Electrolytic Capacitor, Radial, THT,
D13xH25mm, rated capacitance 100 µF ± 20%, rated voltage 100 V.
• gating signals coming from the LaunchPad™ F28069M board, e.g., ePWM1A
and 1B. This option is called PWMext;
• gating signals provided by a timer blox monostable pulse generator inte-
grated circuit LTC6992 by Analog Devices (mounted on the PCB bottom).
This option is called PWMint.
Figure B.3 extRL(C) board features printed on the PCB top surface.
since those are the components heating the most in this load stage. The heat
sink ensures a sufficient temperature drop which allows to keep the extRL(C)
board on a (student) desk. The (non-scaled) voltage applied across the resis-
tance(s) is accessible from the screws placed on the top of the PCB.
A summary of the extRL(C) features is reported in the scheme printed on
the PCB top surface, which is shown in Figure B.3. The Bill of Material of
the extRL(C) Board is reported here in the following:
Key Features
• Different resistance, inductance, capacitance values can be set on-the-fly;
• Choose between internal or external switching stage;
• Choose between internal or external PWM signals generation when the in-
ternal Half-Bridge converter is used;
• Over-current and over-voltage protections;
• On-board high-accuracy current sensor;
Test Points
• PWM: internal pulse width modulation;
• Vext+: positive pole of external input voltage;
• Vext-: negative pole of external input voltage;
• Vo+: positive pole of output voltage;
• V-: negative pole of converter output voltage (before L);
• Vdc: positive pole of input voltage;
• V+: positive pole of converter output voltage (before L);
• GND: ground;
• 3v3: 3.3 V connected to output pin of linear (low-drop) voltage regulator;
• 5v: 5 V connected to output pin of FDSM fixed step down regulator module;
• GND: ground;
• bp: bypass OPA350EA;
• bp: bypass OPA350EA.
Jumpers
• PWM: selection from internal or external PWM generator circuit.
Connectors
• EXT: Half-Bridge/Full-Bridge external power supply;
• SUPPLY: Half-Bridge internal power supply;
• J2: microcontroller current connector;
• J3: microcontroller voltage connector;
• PWM_EXT: external PWM genertor connector;
• Vo+: positive pole of output voltage;
• V-: negative pole of output voltage.
RL(C) Hardware Kit 415
Figure B.4 Different views of the RL(C) kit and its connections.
Figure B.5 Closed-loop dynamics measured from the F28069M pins through
an oscilloscope (Full-Bridge operating with unipolar voltage switching).
• A mezzanine board to hold the MCU and manage the external power supply;
• One extRL(C) board.
This kit is a complete development test-bench for the energy management
of power topologies and passive loads. Digital power management and con-
trol capabilities provided by rapid prototyping allows the study and design of
adaptable high frequency switching power supplies, e.g. targeting both power
processing and EV on-board battery charge applications. This kit is mainly
built around the extRL(C) which was previously presented. All the afore-
mentioned features holds. The mezzanine card is a MCU housing based on a
custom made design. It can be even separately used as support for the MCU
board. The kit is designed to operate with 40 V 3 A input source at rated
conditions. Depending on the considered application target, those values can
be temporary exceeded. A usage example of this board is reported below.
Encoder Connection
The encoder LPD3806-600BM-G5-24C adopted for the exercise proposed in
this book (see Chapter 14) and in the DecMot kit see an encoder interface
made by open collector outputs with 20 Ω resistors for protection. This cir-
cuit draws around 30 mA. Since it can not source current, the open-collector
418 Appendix B: Custom Expansion Boards and Hardware Kits
+Vin +5 V +5 V
OUT
7805 4.7 kΩ 20 Ω
R4
D1 C1 C2
1 kΩ
C0
C5
3 The encoder case is connected to the chassis and not to circuit ground.
B2B-PMDC Hardware Kit 419
Figure B.7 Different views of the DecMot kit and its connections.
Figure B.8 Different views of the B2B-PMDC kit and its connections.
This kit can be modified by substituting a PMDC motor with a BLDC one,
resultign in the:
Figure B.9 Different views of the B2B-BLDC kit and its connections.
Politecnico di Milano
Department of Mechanical Engineering, via La Masa 1, Milan 20156, Italy
Electrical Machines, Drives, and Power Electronics Research Group
422 Appendix B: Custom Expansion Boards and Hardware Kits
423
424 Bibliography
[13] Texas Instruments. Motor Drive and Control Solutions. Technical Report
SLYB165I, Texas Instruments, 2017.
[14] Texas Instruments. DRV8301 Three-Phase Gate Driver With Dual Cur-
rent Shunt Amplifiers and Buck Regulator. Technical Report SLOS719F,
Texas Instruments, August 2011 (revised January 2016). Available at
https://www.ti.com/lit/ds/symlink/drv8301.pdf.
[33] Mathworks. Simulink for Developing Digital Control for Motors, Power
Converters, and Battery Systems. Technical report, MathWorks, 2020.
Available at https://www.mathworks.com/content/dam/mathworks/
brochure/speed-digital-control-motor-power-converters-syst
ems-simulink-handout.pdf.
[38] Mattia Rossi, Francesco Castelli Dezza, Marco Mauri, and Maria Pran-
dini. Explicit Computation of Indirect Hybrid MPC for Voltage Control
in Multilevel DC-DC Converters. In 2018 20th European Conference on
Power Electronics and Applications (EPE’18 ECCE Europe), pages P.1–
P.9, 2018.
[39] Mattia Rossi, Eyke Liegmann, Petros Karamanakos, Francesco Castelli
Dezza, and Ralph Kennel. Direct Model Predictive Power Control of a
Series-Connected Modular Rectifier. In 2019 IEEE International Sym-
posium on Predictive Control of Electrical Drives and Power Electronics
(PRECEDE), pages 1–6, 2019.
[40] Mattia Rossi, Luigi Piegari, Francesco Castelli Dezza, Marco Mauri, and
Maria S. Carmeli. Voltage Control Comparison for Low-Power DC-DC
Converters in EVs: PI and Explicit MPC. In IECON 2018 - 44th Annual
Conference of the IEEE Industrial Electronics Society, pages 5005–5011,
2018.
[41] Sigurd Skogestad and Ian Postlethwaite. Multivariate Feedback Control:
Analysis and Design. John Wiley & Sons, 2nd edition, November 2005.
[42] Stephen Umans. Fitzgerald & Kingsley’s Electric Machinery. McGraw-
Hill Education, 7th edition, 16 May 2013.
[43] Peter Vas. Sensorless Vector and Direct Torque Control. Oxford Univer-
sity Press, 1998.
[44] J. G. Ziegler and N.B. Nichols. Process lags in automatic control circuits.
Transactions of the A.S.M.E., 65(5):433–444, 1943.
Index
427
428 Index