Upload
tao-yang
View
806
Download
3
Embed Size (px)
Citation preview
CURRENT CONTROL OF PERMANENT MAGNET SYNCHRONOUS MOTORS USING DSP TECHNOLOGIES
by
TAO YANG B.E., Zhejiang University, China, 1998
A THESIS Submitted in partial fulfillment of the
requirements for the degree
MASTER OF SCIENCE
Department of Mechanical and Nuclear Engineering College of Engineering
KANSAS STATE UNIVERSITY Manhattan, Kansas
2004
Approved by:
Major Professor Dr. Dale E. Schinstock
ABSTRACT
This thesis investigates systematic design methods for DSP-based current control
of permanent magnet synchronous motors (PMSM). This includes systematic methods
for finding the gains of the motor current controller and methods for finding the
minimum controller update and pulse width modulation (PWM) frequencies.
In this thesis, two control structures are studied. One is vector current control,
where the controllers are applied in the rotor synchronous, dq0, frame; the other is sine
wave current control, where the controllers are applied in the stationary, abc, frame.
The proportional integral (PI) controller is a standard controller in the current
control of PMSM. Typical tuning methods for PI are reviewed. A system identification
method based on relay feedback is presented for tuning current control loops.
Linear quadratic (LQ) optimization is a time domain controller design method.
The idea of this approach is to select proper controller gains to minimize a performance
index. LQ design is repeated against plant parameters to develop empirical formulae for
specific controllers and plants. This thesis extends previous work in empirical
optimization to apply to a wider range of values in PI control of a 1st order plus time
delay system. It also originally presents a set of empirical optimization formulae for
integral control of a pure time delay system. For these two sets of empirical formulae, the
resulting system bandwidth is formulized originally. The phase margin and gain margin
of the resulting system are also presented.
The effects of digitization and PWM are considered in the systematic design
process. Combining such effects and LQ optimization empirical formulae, systematic
design methods are proposed to determine minimum values for digital update frequency
and PWM frequency according to desired bandwidth and the maximum operation speed.
These methods are the main contribution of this thesis.
i
TABLE OF CONTENTS
LIST OF FIGURES…………………………………………………….……………….iv
LIST OF TABLES………………………...…………………………..………………..vii
ACKNOWLEDGMENTS.……………………………………....……..………….…..viii
CHAPTER 1: INTRODUCTION AND BACKGROUND............................................ 1
1.1. BACKGROUND........................................................................................................... 1
1.2. INTRODUCTION.......................................................................................................... 3
CHAPTER 2: EXPERIMENTAL SYSTEM.................................................................. 6
2.1. OVERVIEW ................................................................................................................ 6
2.2. PMSM BRUSHLESS SERVOMOTOR AND DYNAMOTOR .............................................. 7
2.3. L180 DIGITAL SERVO DRIVE AMPLIFIER .................................................................. 8
2.4. DSP BOARD (MC8-DSP-ISA BOARD) ..................................................................... 9
2.5. POWIRTRAIN .......................................................................................................... 10
2.6. SHAFT POSITION SENSOR ........................................................................................ 11
2.7. ISOLATOR BOARD ................................................................................................... 12
2.8. CURRENT SENSOR BOARD....................................................................................... 12
2.9. POWER SUPPLY ....................................................................................................... 13
CHAPTER 3: PID CONTROL TUNING METHOD REVIEW AND SYSTEM
IDENTIFICATION BY RELAY FEEDBACK............................................................ 14
3.1. INTRODUCTION........................................................................................................ 14
3.2. ZIEGLER-NICHOLS (ZN) METHOD .......................................................................... 14
3.2.1. Open Loop ZN Tuning Method ....................................................................... 15
ii
3.2.2. Closed Loop ZN Tuning Method..................................................................... 17
3.3. RELAY FEEDBACK TUNING ..................................................................................... 19
3.3.1. Astrom-Hagglund Method .............................................................................. 19
3.3.2. Describing Function of a Relay ...................................................................... 20
3.3.3. Describing Function of Relay without Hysteresis .......................................... 21
3.3.4. Describing Function of a Relay with Hysteresis............................................. 22
3.3.5. Describing Function Analysis of a Relay in the Loop .................................... 24
3.3.6. Critical Point Identification............................................................................ 26
3.3.7. Parameter Identification via Relay Test for Specific Systems ........................ 27
CHAPTER 4: OPTIMAL DESIGN FOR PID CONTROLLERS VIA LQ
APPROACH.................................................................................................................... 30
4.1. INTRODUCTION TO LQ DESIGN ............................................................................... 30
4.2. PI/PID CONTROLLER DESIGN BY LQ APPROACH.................................................... 37
4.2.1. PI Controller for FOPTD ............................................................................... 37
4.2.2. PID Controller for the Second Order plus Time Delay System...................... 48
CHAPTER 5: PMSM CURRENT CONTROL ........................................................... 55
5.1. INTRODUCTION........................................................................................................ 55
5.2. VECTOR CURRENT CONTROL .................................................................................. 56
5.3. SINE WAVE CURRENT CONTROL............................................................................. 61
CHAPTER 6: DIGITAL IMPLEMENTATION AND SYSTEMATIC DESIGN OF
PMSM CURRENT CONTROL .................................................................................... 69
6.1. DIGITAL IMPLEMENTATION ARCHITECTURE FOR PMSM CURRENT CONTROL........ 69
iii
6.1.1. Sine Wave Current Control Structure............................................................. 70
6.1.2. Vector Current Control Structure................................................................... 76
6.2. EFFECTS OF DIGITIZATION AND PWM ON THE CURRENT CONTROL SYSTEM DESIGN
....................................................................................................................................... 79
6.3. SIMULATION MODELS ............................................................................................. 87
6.4. SYSTEMATIC DESIGN OF PMSM CURRENT CONTROL SYSTEM ............................... 89
6.4.1. Systematic Design of PMSM Vector Current Control .................................... 89
6.4.2. Systematic Design of PMSM Sine Wave Current Control .............................. 91
6.5. DESIGN EXAMPLES ................................................................................................. 93
6.5.1. Vector Current Control Design Example ....................................................... 93
6.5.2. Sine Wave Current Control Design Example ............................................... 105
6.6. AUTOMATIC TUNING............................................................................................. 114
CHAPTER 7: CONCLUSION..................................................................................... 118
REFERENCES:……......……………………………………………….……………..120
APPENDIX A: Current Control DSP Program Source Code …...….……………..124
APPENDIX B: LQ Design MATLAB Program Code ……….…...….……………..146
iv
LIST OF FIGURES
Figure 1-1: Typical Motion Control Structure.................................................................... 2
Figure 1-2: Three Phase Two-Level Inverter...................................................................... 4
Figure 2-1: Experimental System ....................................................................................... 7
Figure 2-2: The IRPT 1058 PowIRTrain within a Motor Control System....................... 11
Figure 3-1: Open Loop ZN Tuning Method ..................................................................... 16
Figure 3-2: Closed Loop ZN Tuning ................................................................................ 18
Figure 3-3: Relay Tuning Scheme .................................................................................... 19
Figure 3-4: Relay without Hysteresis ............................................................................... 22
Figure 3-5: Relay with Hysteresis..................................................................................... 23
Figure 3-6: Closed Loop System with Tuning Relay ....................................................... 24
Figure 3-7: Stability Analysis of Limit Cycle Operation with Relay ............................... 26
Figure 4-1: Plant with Compensator of Desired Structure................................................ 31
Figure 4-2: Proportional Gain of PI controller vs. NT Delay with ISE............................ 40
Figure 4-3: PI Integral Time Constant vs. NT Delay with ISE ........................................ 40
Figure 4-4: PI Proportional Gain vs. NT Delay with ISTE .............................................. 41
Figure 4-5: PI Integral Time Constant vs. NT Delay with ISTE...................................... 41
Figure 4-6: PI Proportional Gain vs. NT Delay with IST2E ............................................ 42
Figure 4-7: PI Integral Time Constant vs. NT Delay with IST2E.................................... 42
Figure 4-8: Gain Margin of ISE, ISTE, and IST2E Design .............................................. 47
Figure 4-9: Phase Margin of ISE, ISTE, and IST2E Design............................................. 47
Figure 4-10: Crossover Frequency of ISE, ISTE, and IST2E Design............................... 48
Figure 4-11: Integral Gain for ISE.................................................................................... 52
v
Figure 4-12: Integral Gain for ISTE ................................................................................. 52
Figure 4-13: Integral Gain for IST2E................................................................................ 53
Figure 4-14: Gain Margin for ISE, ISTE, and IST2E ....................................................... 53
Figure 4-15: Phase Margin for ISE, ISTE, and IST2E...................................................... 54
Figure 4-16: Crossover Frequency of ISE, ISTE, and IST2E ........................................... 54
Figure 5-1: Phasor Diagram.............................................................................................. 56
Figure 5-2: Simulation Scheme of Vector Current Control.............................................. 59
Figure 5-3: Simulation Result of Vector Current Control for Step Response .................. 60
Figure 5-4: Simulation Result of Vector Current Control for Sinusoidal Response ........ 60
Figure 5-5: Equivalent Phase Circuit ................................................................................ 63
Figure 5-6: Simulation Scheme of Sine Wave Current Control ....................................... 66
Figure 5-7: Simulation Result of Sine Wave Control for Step Response......................... 67
Figure 5-8: Simulation Result of Sine Wave Control for Sinusoidal Response ............... 68
Figure 6-1: System Schematic of Sine Wave Current Control ......................................... 70
Figure 6-2: Program Flow Chart of Sine Wave Current Control...................................... 75
Figure 6-3: Timing Chart of Sine Wave Current Control................................................. 76
Figure 6-4: System Schematic of Vector Current Control................................................ 76
Figure 6-5: Program Flow Chart of Vector Current Control ............................................ 78
Figure 6-6: Time Sequence of Current Sampling, Calculation and PWM Output ........... 81
Figure 6-7: Synchronous Reference Frame Quantities in the Stationary Reference Frame
................................................................................................................................... 82
Figure 6-8: Complex Vector Block Diagram of Vector Current Control ......................... 83
Figure 6-9: System Model of Vector Current Control (1) ................................................ 83
vi
Figure 6-10: System Model of Vector Current Control (2) .............................................. 84
Figure 6-11: Rotation of the Synchronous Reference Frame Corresponding to the Time
Delay ......................................................................................................................... 86
Figure 6-12 Phase Current Reference Generation with the Error Caused by Rotation .... 87
Figure 6-13: One Phase Current Control Loop in Sine Wave Current Control................ 87
Figure 6-14: First Level Vector Current Control Simulation Model................................ 88
Figure 6-15: First Level Sine Wave Current Control Simulation Model ......................... 88
Figure 6-16: Second Level Vector and Sine Wave Current Control Simulation Model .. 89
Figure 6-17: Vector Current Control PI Controller Design Model................................... 90
Figure 6-18: Eigenvalues for Different Speed .................................................................. 95
Figure 6-19: Simulation and Experimental Result at 0 rpm for Step Response ............... 97
Figure 6-20: Simulation and Experimental Result at 1000rpm for Step Response .......... 99
Figure 6-21: Simulation and Experimental Result at 2000 rpm for step response ......... 101
Figure 6-22: Simulation and Experimental Result at 3000rpm ...................................... 103
Figure 6-23: Simulation and Experimental Result at 0 rpm for Sine Wave Command . 105
Figure 6-24: Simulation and Experimental Result at 0 rpm for Step Response ............. 108
Figure 6-25: Simulation and Experimental Result at 1000 rpm for Step Response ....... 110
Figure 6-26: Simulation and Experimental Result at 2000rpm for Step Response ........ 111
Figure 6-27: Simulation and Experimental Result at 0 rpm for 100Hz Sine Wave
Command Response................................................................................................ 113
Figure 6-28: Relay Test Result ....................................................................................... 115
Figure 6-29: Step Responses for Different PI Controller Gain Settings......................... 117
vii
LIST OF TABLES
Table 2-1: Motor Specification........................................................................................... 8
Table 2-2: L180A-310A Drive Specification ..................................................................... 9
Table 3-1: Open Loop ZN Tuning Method....................................................................... 16
Table 3-2: Closed Loop Ziegler-Nichols Tuning.............................................................. 18
Table 4-1: LQ Tracker with Time Independent Performance Index [19]......................... 35
Table 4-2: LQ Tracker with Time Dependent Performance Index [19] ........................... 36
Table 4-3: Empirical Formula Coefficients Table (1) for PI Controllers ......................... 44
Table 4-4: Empirical Formula Coefficients Table (2) for PI Controllers ......................... 45
Table 4-5: Crossover Frequency Formula Coefficients for PI Controllers....................... 46
Table 4-6: Empirical Formula Coefficients Table for Integral Controllers...................... 51
Table 6-1: Inverter State Definitions ................................................................................ 72
Table 6-2: Inverter Switching Patterns ............................................................................. 73
Table 6-3: Auto Tuned PI Controller Gains ................................................................... 116
viii
ACKNOWLEDGMENTS
I am indebted to my advisor, Dr. Dale Schinstock, for the support and guidance
throughout the course of this work. I greatly appreciate his encouragement and patience.
I am also grateful to my committee members, Dr. Warren N. White and Dr. Shelli
K. Starrett, for their participation and advice.
I would like to thank my friends Scott Hammack, Mike Molt, and Michael
Trumble for their help in the past two and a half years.
This material is based upon work supported by the National Science Foundation's
Experimental Program to Stimulate Competitive Research (EPSCoR) program under
Grant No. 0091853. Any opinions, findings and conclusions or recommendations
expressed in this material are those of the author(s) and do not necessarily reflect the
views of the National Science Foundation (NSF).
1
Chapter 1: Introduction and Background
1.1. Background
In recent years, in the field of motion control, permanent magnet ac (PMAC)
machines have been widely used. PMAC machines can be separated into two major
classes according to the back EMF forms. The machines generating trapezoidal back
EMF are referred to as trapezoidal machines [1], and are also known as brushless dc
motors (BDCM) [2]. The machines generating sinusoidal back EMF are referred to as
sinusoidal machines [1], and are also known as the permanent magnet synchronous
motors (PMSM) [2].
In PMAC machines, the field windings are replaced by the permanent magnets,
which make it unnecessary to provide the magnetizing current to the rotor in the power
range of fractional Hp to 30kW, and the motor can operate with higher efficiency than an
induction motor. Slips and brushes are no longer needed which conduct direct current to
the field windings in the traditional synchronous machines, increasing the system
reliability. The use of the permanents magnet can also reduce the motor weight and
result in higher power density (kW/kg).
In motion control applications with PMAC machines, the control structures share
some characteristics. In order to implement the speed or position control, the multi loop
structure is commonly used. Figure 1-1 shows a typical multi loop control system with
PMAC machines.
2
Figure 1-1: Typical Motion Control Structure
The current control loop is used to minimize the machine and inverter
nonlinearity, and move the electrical dynamics to high frequency. It should control the
stator flux position according to the rotor position measured by an angle position sensor
such as a resolver. Generally the electric torque is closely related to the current in PMAC
machines. The current reference to the current loop can directly map the desired torque if
the current control loop is good.
The speed control loop is used to cancel unknown variation in the load torque,
correct the current control loop imperfections and the variation of torque to current ratio.
The position control will correct the position error, and get the desired position trajectory.
In some specific applications, there is only one of the two outer loops outside the
current control loop in the system. For example, in a position control system, the speed
loop can be absent, and if only speed control is desired, the position control will not be
necessary. In some digital implementations of the control system, since the analog speed
may be not available and the derivative calculation is not desirable in the digital control,
only position control loop appears outside the current control loop. Speed control can be
achieved via the position control loop by calculating the position trajectory in real time
Speed Controller
Position Controller
PMAC
Current Controller
ddt
rω
rθ
*rθ rθ∆
+− +
−*rω
rω∆
*I
Angle PositionSensor
3
with desired speed.
1.2. Introduction Currently most PMAC machines use voltage source inverter topologies.
Combined with the current control loop, this kind of configuration yields a current-
regulated voltage source inverter [1]. Physically the current control system for PMSM
and BDCM can share a similar structure. A typical configuration is shown in Figure 1-2.
This configuration is a two-stage configuration with the rectifier in the system and it can
perform ac-dc-ac conversion. In this figure and the experimental system, six transistors,
such as Isolated Gate Bipolar Transistors (IGBT), are used as power switches. Other
possible alternatives include Bipolar Junction Transistors (BJT), MOS Field Effect
Transistors (MOSFET), Gate Turn Off Thyristors (GTO), etc. Since the inverters for
BDCM and PMSM use the same structure, the difference in the switching pattern will be
responsible for the different phase current wave forms. Generally speaking, BDCM
requires six-step switched current waveforms to generate constant torque, while PMSM
requires sinusoidal current waveforms to generate constant torque. For both types, the
maximum torque can only be produced when the phase currents are properly
synchronized with the rotor position. During current control synchronizing phase currents
requires rotor position measurement. As for BDCM, considering the trapezoidal phase
currents, only six discrete points per electrical cycle needed to be detected, and this can
be achieved by using three hall sensors. As for PMSM, the continuous measurement of
the rotor position is necessary to produce the required sinusoidal phase currents. Usually
measurement is achieved using resolvers and encoders. Recently, the sensorless methods
have been attracting research interests toward eliminating the use of the position sensors
4
in the system [3, 4, 5].
Figure 1-2: Three Phase Two-Level Inverter
With the power of digital signal processors, the motor control systems tend to be
implemented with digital techniques recently. The computing power of the digital signal
processor (DSP) makes it possible to employ advanced control algorithms in the control
system. The replacement of hardware by software may reduce the system cost
significantly, and also make the system more flexible.
The importance of the current control loop is obvious in the motor control system.
This thesis will focus on current control for PMSM and its digital implementation.
In the PMSM drive application the current/torque control loop is the inner loop,
and field oriented control is used. Field oriented control in the PMSM drive application is
obtained by simply setting the direct axis current to zero in the rotor synchronous frame
[6].
In this thesis two current control structures are studied. One classical current
control structure is composed of two or three phase current control loops in the stationary,
abc, frame [7, 8, 9, 10, 11, 12]. Since the current references to the controllers are
sinusoidal functions of the rotor position, this structure is referred to as sine wave current
control. Another current control structure includes two current control loops in the rotor
synchronous, dq0, frame [7, 8, 9, 10, 13, 12]. In this thesis, this current control structure
PMACVac
5
is referred to as vector current control.
The further study involves the problems in the digital implementation of the
current control system and system modeling. In the digitally implemented current control
system, the basic plant model is a first order plus time delay system (FOPTD) for each
phase or axis. The systematic design methods of the digital current control system based
on linear quadratic (LQ) optimization are introduced.
Linear quadratic controller design is a time domain method. The basic idea of this
approach is to choose proper controller gains or output feedback gains to minimize the
performance index, which is a linear quadratic function of states, outputs and inputs.
Generally, the LQ design can guarantee good performance in terms of the step response.
To find the empirical formulae for automatic tuning, optimization is repeated for different
values of the normalized plant parameters. In this thesis, the author extends the empirical
optimization formulae for PI control of a FOPTD plant to cover a wider range of the
normalized time delay. The resulting system gain margin and phase margin are presented.
An original development is that the resulting system bandwidth is formulized empirically.
The author also originally presents a set of empirical optimization formulae for an
integral controller for a pure time delay system. Combining these resulting empirical
formulae with the models of the digitally-implemented current control system, the author
proposes systematic design methods to predict required digital update frequency and
PWM frequency in the PMSM current control system design process according to the
desired bandwidth and the maximum operation speed. Furthermore using a relay
feedback tuning process, the current control system can be tuned with these empirical
formulae.
6
Chapter 2: Experimental System
2.1. Overview
The experimental system includes the following hardware components as shown
in Figure 2-1:
• Host Computer
• MC8-DSP-ISA Board
• Interface Board
• Isolation Board
• Integrated Power Stage
• PMSM Brushless Servomotor with Integral Resolver
• Current Sense Board
• Resolver to Digital Converter Board
• Dynamotor Servo Drive
• PMSM Brushless Dynamotor with Integral Resolver
• Power Supply
The software includes the following programs:
• Host PC Interface Program
• L180 Graphical User Interface
• DSP Vector Current Control Program
• DSP Sine Wave Current Control Program
7
Figure 2-1: Experimental System
2.2. PMSM Brushless Servomotor and Dynamotor
In the experimental system, two permanent magnet synchronous motors are used
as the servomotor and dynamotor separately. The servomotor is MOOG’s G412-200, and
the dynamotor is MOOG’s G412-400. Both of them belong to the MOOG G410 Series.
MOOG’s G410 series motors are electronically commutated synchronous AC motors
with permanent magnet field excitation. The motors’ specifications can found in Table 2-
1.
8
Table 2-1: Motor Specification
Metric[English] G412-200 G412-400
Rated voltage, per phase pk pkV − 310 310
Maximum voltage, per phase pk pkV − 360 360
Continuous stall torque Mo [ ]Nm lb in− 0.25 [2.2] 0.50 [4.4]
Continuous stall current lo rmsA 0.65 1.2
Peak torque Mmax [ ]Nm lb in− 0.70 [6.2] 1.5 [13.3]
Peak current lmax rmsA 1.9 3.7
Nominal speed nN rpm 8100 7400
Nominal power PN [ ]W hp 0.15 [0.20] 0.33 [0.44]
Maximum speed nmax rpm 11500 10000
Torque constant kT [ ]rms rmsNm A lb in A− 0.37 [3.3] 0.42 [3.7]
Back EMF constant kb ( )[ ]pk pkV rad s V krpm 0.3[31.42] 0.34[35.60]
Motor terminal resistance Rtt Ω 50.9 20.7
Motor inductance Ltt mH 29.7 15.7
Inertia w/o brake 2 2 -4kg cm [lb - insec ×10 ] 0.09 [0.80] 0.13 [1.2]
Pole Pairs 4 4
2.3. L180 Digital Servo Drive Amplifier
The L180 servo drive amplifier is designed to control MOOG brushless servo
motors. The L180 servo drive is a fully digital drive. It has four operation modes, which
are analog velocity control, analog current/torque control, digital velocity control and
9
digital current/torque control. It can communicate with host computer via the serial port
connection. With “L180 Graphical User Interface”, the servo drive can be configured
according to the motor specification and the desired operation mode. In the experimental
system, the drive model is L180A-310A. The electrical specification is listed in the
following table.
Table 2-2: L180A-310A Drive Specification
3~main line Unit L180A-310A
Continuous current Arms 5
Apeak 7
Maximum current Arms 10
Apeak 14
Continuous power kW 1.9
Maximum power kW 3.9
Single phase operation causes a power reduction to 1/3 of the power rating above
2.4. DSP Board (MC8-DSP-ISA Board)
The MC8-DSP-ISA board is a product of Precision MicroDynamics Inc. It can be
used in data acquisition and motion control.
After the correct installation of both software and hardware on the host PC, the
DSP program can be downloaded directly into the on-chip memory of DSP chip
The board facilities are listed below:
• On-board Analog Devices 21061 (SHARC) DSP, with 128K words of
10
external zero wait-state SRAM. The DSP has full access to all board resources.
All of the DSP’s memory can be read by the host PC.
• 96 bits of digital input, divided into Port A, B and C each of 32 bits. Port A
can generate interrupts.
• 32 bits digital outputs, which can be enabled in 2 banks of 16 bits. Outputs
can be pulled high or low in groups of 8 bits via jumper selection.
• 16 Digital-to-Analog outputs, 14 bits, output range -10V to +10V.
• 8 Analog-to-Digital inputs, 14 bits, input range -10V to +10V.
• 8 Quadrature Decoders, capable of handling up to 5.33 million edges per
second (more if the signals are noise-free).
• Programmable Interval Timer (PIT). Self-loading timer generating an
interrupt and/or an on-board SYNC signal at intervals up to 1030 seconds with
a 240 ns resolution.
• Watchdog Timer: Reloadable countdown timer that zeros the DAC outputs
and generates an external signal when it expires. Up to 125ms delays, in 2us
increments.
• Interrupts: From the PIT signal, SYNC signal (internal and external source)
and from the digital inputs. Interrupts to the on-board DSP and PC are
generated independently.
• 8 PWM Outputs: The minimum PWM update frequency is 7814Hz with
32MHz clock.
2.5. PowIRTrain
The IRPT1058 PowIRTrain from International Rectifier is an integrated power
11
stage for 0.75hp motors. It provides the complete power function for a 0.76 hp variable
frequency, variable voltage AC motor controller. The PowIRTrain combines a power
module IRPT1058A with a Driver-Plus Board IRPT1058D. The power module
IRPT1058A contains a single phase input bridge rectifier, three-phase IGBT inverter,
current sensor shunts and a thermistor. The Drive-Plus Board contains DC link capacitors,
capacitor soft charge function using NTC thermistor, surge suppression MOV, IGBT gate
drivers, DC bus voltage and current feedback signals, protection circuit and local power
supply. PowIRTrain can provide 3-phase PWM power supply with variable frequency
and variable voltage with a user-provided PWM controller. In Figure 2-2, the simplified
block diagram is shown within an AC motor control system.
Figure 2-2: The IRPT 1058 PowIRTrain within a Motor Control System
2.6. Shaft Position Sensor
The motor shaft position is measured by the resolver integrated into the motor and
IRPT1058C
System Power Supply
PWM Generator
Feedback Processing
Keyboard
180-240V Single phase input
PWM variable Frequency output
Feedback (Non-isolated)
AC Motor
12
an external resolver-to-digital-converter board. On the resolver to digital converter board,
the main chips are AD2S99 and AD2S90. AD2S99 is a programmable sinusoidal
oscillator. It provides sine wave excitation for resolvers, and also provides a synchronous
reference output signal (3V p-p square wave) that is phase locked to its SIN and COS
inputs. By setting the corresponding jumpers, AD2S99 can be programmed to generated
2 kHz, 5 kHz, 10 kHz and 20 kHz excitations.
AD2S90 is a complete 12-bit resolution tracking resolver-to-digital converter. A
Type Π servo loop is used to track the input sine and cosine signals and convert them into
digital representation of the input angle. The bandwidth is set internally at 1 kHz. The
maximum tracking rate is 375 RPS at 12-bit resolution. The shaft angle information is
available in two forms, absolute series binary and incremental A quad B. One absolute
binary output has 12 bits of resolution. The encoder emulation output A, B, and NM
continuously produce signals equivalent to a 1024 line encoder.
2.7. Isolator Board
The isolator board is used to provide galvanic isolation between the PowIRTrain
and DSP Board via the Interface Board. The isolated digital signals include 6 PWM drive
signals from the DSP Board to PowIRtrain, the PWMTRIP fault signal from the
PowIRTrain to the DSP Board. The isolated analog signals include the bus voltage
feedback signal from PowIRTrain to the DSP Board.
2.8. Current Sensor Board
Two Current Sensor Boards are stacked. Each sensor board has two current
sensors. Each sensor is connected within the circuit in series and can provide an analog
13
voltage output proportional to measured current. These analog voltages are scaled for the
input to the ADC of the DSP Board. These current sensors can sense the maximum
current of 8 Amps for DC, AC or pulsed currents, and provide suitable output for
sampling.
2.9. Power Supply
In the system, 230V AC power for drives and motors is provided by Line
Isolation-Startup Transformer 298F.
14
Chapter 3: PID Control Tuning Method Review and
System Identification by Relay Feedback
3.1. Introduction
Proportional integral derivative (PID) controllers have been widely used in
industry, and it seems their popularity will persist for the near future. In this chapter the
typical PID tuning methods will be reviewed, and then the relay feedback is introduced in
the application of system identification.
In the past, various forms of the PID controller have been developed for specific
purposes. In the time domain the standard PID controller has the form below.
0
1( ) ( ) ( ) ( )t
p di
du t K e t e t dt T e tT dt
= + +
∫ (3-1)
re y y= − (3-2)
Its standard frequency domain form is
1( ) (1 )c p di
G s K T sT s
= + + (3-3)
3.2. Ziegler-Nichols (ZN) Method
ZN method was first introduced by Ziegler and Nichols in 1940s [14], and has
been widely known as the heuristic method to set the gains of PID controller for good
performance in industrial processes. The ZN tuning method has an open loop version and
a closed loop version.
15
3.2.1. Open Loop ZN Tuning Method
Open loop ZN tuning is applicable to any plant that can be approximated by a first
order plus time delay system (FOPTD). The plant transfer function is
( )1p
K sG s eTs
τ−=+
(3-4)
In this method, the controller gains are set by a simple open loop test. With the
controller in the manual mode, the plant input is changed suddenly. The plant output
follows one of the curves shown in Figure 3-1. In the self regulated system response, a
straight line is drawn tangent to the system response at the inflection point to determine
the plant time constant T , dead time τ and slope S . For an unstable system, the slope S
is determined by drawing a straight line along the ascent of the response as shown Figure
3-1. After the identification of the dead time τ and slope of the rise S , the normalized
slope can be computed by (3-5)
* SSp
= (3-5)
The PID controller gains are given in Table 3-1 by Ziegler-Nichols open loop tuning
method.
16
Figure 3-1: Open Loop ZN Tuning Method
Table 3-1: Open Loop ZN Tuning Method
Controller Type pK iT dT
P *
1Sτ
N/A N/A
PI *
0.9Sτ
3.33τ N/A
PID *
1.2Sτ
2τ 0.5τ
Controller Output
Tτ
p
Time
Self Regulated System Response
Unstable System Response
t
T
T/S T T=
/S T t=
τ
17
The open loop ZN tuning process is simple since only one experiment is
necessary. The system is not required to operate at its stability limit during the
experiment. With the experiment result the controller gains can be calculated very easily
by applying the table above. However, since this experiment is performed under open
loop condition, if a significant load change occurs during the test, no correction is taken
and the test result may be easily distorted. Sometimes if the measurement is noisy, it may
be difficult to determine the slope at the inflection point accurately. This method is also
sensitive to the controller calibration errors.
3.2.2. Closed Loop ZN Tuning Method
The closed loop ZN tuning method is a frequency domain tuning method. In the
beginning of this tuning process, only the proportional controller is applied and all other
controller gains are set to zeros. The proportional gain should be small enough to make
the system stable at the beginning. Then the proportional gain is carefully increased until
a steady oscillation occurs for a small step input. This is often referred to by the term
“continuous cycling,” which means a sustained oscillation with constant amplitude. The
ultimate gain uK is the proportional gain that causes the continuous cycling in the system.
The oscillation period is the ultimate period uP as indicated in Figure 3-2. After finding
the ultimate gain and ultimate period, the PID controller gains can be calculated by Table
3-2 given by the closed loop ZN tuning method.
18
Table 3-2: Closed Loop Ziegler-Nichols Tuning
Controller Type
pK iT dT
P 0.5 uK N/A N/A
PI 0.45 uK 1.2
uP N/A
PID 0.6 uK 2uP
8uP
Limit Cycle
-0.2
0
0.2
0.4
0.6
0.8
1
1.2
1.4
1.6
1.8
1 1.2 1.4 1.6 1.8 2
Time(Sec)
Out
put
Pu
Figure 3-2: Closed Loop ZN Tuning
In practice, the original closed loop ZN method may be difficult to apply in the
working plant. In real world systems, to make the system work at the stability limit may
not be acceptable. Another problem is that this method often ends with poor damping
corresponding to 0.2ζ ≅ [15], which may be too small for many applications. The
resulting closed-loop system can be very sensitive to system parameter variation.
19
3.3. Relay Feedback Tuning
Before the relay was introduced into auto tuning for PID controllers by Astrom
and his co-workers in 1980s [16], it was widely used in the 1950s as an amplifier. It was
also applied in adaptive control in the 1960s. A typical example was the self-oscillating
adaptive controller developed by Minneapolis Honeywell at that time. That controller
could offer an amplitude margin of mA 2= , and was used in several missiles. The details
can be found in [17].
3.3.1. Astrom-Hagglund Method
In 1980s, Astrom and his co-workers introduced the application of the relay into
the PID controller auto tuning procedure [16, 18]. Figure 3-3 corresponds to the Astrom-
Hagglund method. In this tuning procedure, the system is first driven to a convenient
steady state. Then the control switches to the tuning relay. This results in a permanent
oscillation. By measuring the oscillation amplitude and frequency, one point on the
Nyqusit plot of the plant can be approximated by the describing function of the relay.
Figure 3-3: Relay Tuning Scheme
Gp(s)
Tuning Relay
PID
y(t)u(t)y* (t) +
-
20
3.3.2. Describing Function of a Relay
System identification by using a relay is closely related to the describing function
of the relay. The describing function can describe the nonlinear system or component,
and is based on the two basic assumptions:
• If the input to the nonlinear element is sinusoidal, though the output of the
nonlinear element is not sinusoidal, the output of the nonlinear element is
periodic with the same period as the input;
• Only the fundamental harmonic component of the output is significant.
These two assumptions are valid since various nonlinear elements can satisfy
them, such as a relay. Generally, the higher order harmonic components of the output
have much smaller amplitudes than the fundamental harmonic component of the output.
Most of time the linear system is like a low-pass filter and the higher order harmonic
components are attenuated by the linear system.
The describing function is defined as the complex ratio of the fundamental
harmonic component of the output to the input.
11
YN=X
φ∠ (3-6)
Where
N = describing function
X = amplitude of the input sinusoid
1Y = amplitude of the fundamental harmonic component of output
1φ = phase shift of the fundamental harmonic component of output
21
To find the fundamental harmonic component of the nonlinear element output, the
output ( )y t must be expressed in the Fourier series.
01
01
( ) ( cos sin )
( sin( ))
n nn
n nn
y t A A n t B n t
A Y n t
ω ω
ω φ
∞
=
∞
=
= + +
= + +
∑
∑ (3-7)
Where
2
0
1 ( ) cos ( )nA y t n td tπ
ω ωπ
= ∫ (3-8)
2
0
1 ( )sin ( )nB y t n td tπ
ω ωπ
= ∫ (3-9)
2 2n n nY A B= + (3-10)
1tan ( )nn
n
AB
φ −= (3-11)
3.3.3. Describing Function of Relay without Hysteresis
The input and output waveform of a relay without hysteresis is shown in Figure 3-
4. For the sine wave input, the output is a square wave as shown. In the corresponding
Fourier series, 0A is zero since the nonlinearity is symmetric, and the coefficients of the
cosine terms are also zeros since the output waveform is an odd function.
Hence
1( ) sinn
ny t B n tω
∞
==∑ (3-12)
The fundamental harmonic component of ( )y t is
1 1 1( ) sin siny t B t Y tω ω= = (3-13)
22
Where
2
10
2
0
1 ( )sin ( )
1 1 4sin ( ) ( )sin ( )
Y y t td t
MM td t M td t
π
π π
π
ω ωπ
ω ω ω ωπ π π
=
= + − =
∫
∫ ∫ (3-14)
Hence
14( ) sinMy t tωπ
= (3-15)
The describing function is given then by
1Y 4N= 0X
MXπ
°∠ = (3-16)
Figure 3-4: Relay without Hysteresis
3.3.4. Describing Function of a Relay with Hysteresis
For the relay with hysteresis, its output and input wave is shown in Figure 3-5.
input
output
t
t
x
M
M
-M
y(t) y(t)=Y1sin(ωt)
x(t)=Xsin(ωt)
23
Figure 3-5: Relay with Hysteresis
The plot shows that the output of the relay is square wave with a phase lag
11 sin ( )t h Xω −= . The fundamental harmonic component is
1 1 1 1 1( ) cos sin sin( )y t A t B t Y tω ω ω φ= + = + (3-17)
Where
2
1 10
1 4 4( )cos ( ) sinM MhA y t td t tX
π
ω ω ωπ π π
= = − = −∫ (3-18)
2 2
1 1 20
1 4 4( )sin ( ) cos 1M M hB y t td t tX
π
ω ω ωπ π π
= = = −∫ (3-19)
and
11 sin ( )t h Xω −= (3-20)
So
14MYπ
= (3-21)
and
input
output t
t
x
M
M
-M
y(t) y(t)=Y1sin(ωt+Ф)
x(t)=Xsin(ωt)
-h h
t1
h
-h
24
11 sin ( )h
Xφ −= − (3-22)
The describing function can be given then
111
Y 4N= sin ( )X
M hX X
φπ
−∠ = ∠− (3-23)
3.3.5. Describing Function Analysis of a Relay in the Loop
Assuming the plant is a minimum phase system, the closed loop system with a
relay in the control loop is shown in Figure 3-6
Figure 3-6: Closed Loop System with Tuning Relay
If the higher harmonics can be well attenuated, and the relay can be approximated
by its describing function, then the close loop transfer function is:
( ) ( )( )( ) 1 ( )cl
C j NG jG jR j NG j
ω ωωω ω
= =+
(3-24)
The characteristic equation is:
1 ( ) 0NG jω+ = (3-25)
Going further:
1( )G jN
ω = − (3-26)
The 1N
− locus of a relay is a straight line parallel to the real axis in the complex plane
for any given relay as demonstrated by (3-27).
G(s) Tuning Relay c(t)r (t) +
-
25
1 2 21 sin ( )4 4 4
X h hX h jN M X M M
π π π−− = − ∠ = − − − (3-27)
Generally speaking, if the plant’s ( )G jω Nyquist locus goes through the third
quadrant, it may intersect the 1N
− locus, and the system may exhibit a sustained
oscillation or limit cycle at the intersection point.
In Figure 3-7, assume the system originally operates at point A, where the
oscillation amplitude is aX and the frequency is aω . If a slight disturbance is applied to
the system and the input to the relay is increased, the operating point moves from A to B.
Point B corresponds to the critical point or to be -1+j in the complex plane for the linear
system. In this case, since the ( )G jω locus does not enclose point B in Nyquist sense, the
amplitude will decrease and the operating point will move backwards to A. If the slight
disturbance causes the input to the relay to decrease slightly, the operating point moves
from point A to point C. Similar to the case in which the ( )G jω locus encloses the critical
point 1 j− + in linear system analysis, the amplitude of the oscillation will increase, and
the system operating point will move backwards to point A. So the point A possesses
convergent characteristics and the system operation at the point A is stable (i.e. the limit
cycle at this point is stable). By similar analysis, if the point A possesses divergent
characteristics, it corresponds to an unstable limit cycle.
26
Figure 3-7: Stability Analysis of Limit Cycle Operation with Relay
3.3.6. Critical Point Identification
When a relay without hysteresis is used in the system tuning or identification
process, since the describing function of the relay is real, the relay is like a proportional
amplifier and its gain is 4MNXπ
= . If the stable oscillation occurs with this relay, and
considering that the plant is a low pass filter which attenuates the higher harmonics, the
output of the system will be sinusoidal or a sinusoid-like wave having magnitude X.
From (3-25):
( ) 1NG jω = (3-28)
The ultimate gain can be approximated by:
1 4( )u
MKG j Xω π
= = (3-29)
G(jw)
A CB
Re
Im
X →∞ 0X →1N
−
27
The system ultimate gain and ultimate frequency can be easily approximated
using the relay feedback test. After the test, various methods like the ZN method can be
used to calculate the PID or PI controller gains based on the ultimate gain and ultimate
frequency.
Compared with the classical Ziegler-Nichols method, relay feedback is easier to
automate and also avoids tedious changing of the proportional gain.
3.3.7. Parameter Identification via Relay Test for Specific
Systems
For some specific systems, we may know the system model form and only some
parameters are unknown. In this case, the system parameters may be identified by the
relay test. For example, if the plant is a FOPTD system then it is described by (3-4),
which is repeated (3-30)
( )1p
K sG s eTs
τ−=+
(3-30)
Assuming the DC gain K is known, the plant time delay and time constant can be found
by (3-31) and (3-32)
22 1u
u
K KT
ω−
= (3-31)
22arctan( 1)u
u
K Kπτ
ω− −
= (3-32)
If a relay with hysteresis is used in the relay feedback test, the locus of 1N
− is a
straight line parallel to the real axis in the third quadrant, and its offset from the real axis
i.e. the imaginary part of the locus, is determined by h and M . By varying the magnitude
28
of hysteresis h , multiple points on the Nyqusit locus of ( )pG jω can be identified. For
the FOPTD, a two-point test can give enough information to identify the system
parameters.
If a point 1 1 1( , )X ω and a point 2 2 2( , )X ω have been identified, from (3-26), (3-
33) and (3-34) can be found for point 1. (3-35) and (3-36) can be found for point 2. The
system parameter , , and K T τ can be found by solving these equations.
122
141
K XMT
πω
=+
(3-33)
1 1 11 1
1
tan ( ) sin ( )hTX
τω ω π− −+ = − (3-34)
222
241
K XMT
πω
=+
(3-35)
1 1 22 2
2
tan ( ) sin ( )hTX
τω ω π− −+ = − (3-36)
For the second order plus time delay system, the system parameters can also be
identified by a two-point relay test. Using (3-37) to describe this system,
2 2( )2 1pK sG s e
T s Tsτ
ζ−=
+ + (3-37)
After identification of the points 1 and 2, which correspond to 1 1( , )X ω and 2 2( , )X ω ,
using (3-26), equations (3-38) to (3-41) can be solved for the system parameters.
12 22 2 2
11 14(1 ) 4
K XMT T
πω ζ ω
=− +
(3-38)
1 11 1122
11
2tan ( ) sin ( )1
T hXT
ζ ω τω πω
− −+ = −−
(3-39)
29
22 22 2 2
22 24(1 ) 4
K XMT T
πω ζ ω
=− +
(3-40)
1 12 2222
22
2tan ( ) sin ( )1
T hXT
ζ ω τω πω
− −+ = −−
(3-41)
30
Chapter 4: Optimal Design for PID Controllers via LQ
Approach
4.1. Introduction to LQ Design
Linear quadratic controller design is a time domain design method. The basic idea
is to select proper controller gains or output feedback gains to minimize the performance
index, which is a linear quadratic function of states, outputs and inputs.
Most of what follows in this section is a summary and rework of methods
presented by Stevens and Lewis [19] for clarity. The system structure is represented in
Figure 4-1. This approach allows designing a servo control system that has any structure.
The complete structure includes a unity-gain outer loop and the compensator dynamics.
The control gains include two parts. The first part includes the plant output feedback
gains, and the second part includes the compensator output gains. The control gains are
chosen to minimize a quadratic performance index. In this approach, the controller
structure can be determined before the gain design. In some cases this is desired because
there is a wealth of experience and knowledge indicating that some specific controller
structure will yield good control performance for the specific plant. For example, for the
first order plus time delay system, a PI controller can be used in practice to get the good
control performance.
31
Figure 4-1: Plant with Compensator of Desired Structure
The plant in the above figure can be described by
p p p p px A x B u= + (4-1)
p p py C x= (4-2)
p p pz H x= (4-3)
with the state ( )px t , the control input to the plant ( )pu t , the measured output available
for the output feedback ( )py t and the performance output ( )pz t defined in Figure 4-1.
The controller dynamics are described by
w Fw Ge= + (4-4)
v Dw Je= + (4-5)
where ( )w t is the compensator state vector, and ( )v t is the compensator output. The
input to the compensator is the tracking error ( )e t .
( ) ( ) - ( )pe t r t z t= (4-6)
Compensator -L Plant
Hp
Cp -Kpl
Performance Output zp(t)
Measured Output
xp(t) u(t) v(t) e(t) r(t)
yp(t)
32
The matrices , , ,F G D J are known for the given compensator structure. Now the control
input to the plant can be described by
pl pu K y Lv= − − (4-7)
where , plK L should be found by minimizing the performance index.
The complete system with the compensator is described by the following state
equations.
0 0ddt 0
pp p p
p
Ax x Bu r
GH F Gw w = + + −
(4-8)
0 0pp p
p
Cy xr
JH D Jv w
= + − (4-9)
]0 pp
xz H
w
=
(4-10)
The control input to the plant is
] ppl
yu K L
v
= −
(4-11)
The system state equation can be further simplified by redefining the state, output and
matrix variables.
x Ax Bu Gr= + + (4-12)
y Cx Fr= + (4-13)
z Hx= (4-14)
f f fu K y K Cx K Fr= − = − − (4-15)
Here the state ( ) nx t R∈ , control input ( ) mu t R∈ , reference input ( ) qr t R∈ , performance
output ( ) qz t R∈ , and measured output ( ) py t R∈ . The augmented matrices and vectors in
33
(4-12) through (4-15) are defined by comparing to (4-8) through (4-11). The closed loop
system is
( ) ( )
f f
c c
x A BK C x G BK F rA x B r
= − + −
≡ + (4-16)
At this point, it is convenient to define the deviation system because this will
allow the optimal tracking problem to be converted to the regulation form. Denoting the
steady state value by overbars and the deviation from the steady state values by tildes,
and then the state, output and input deviation are given by
( ) ( )x t x t x= − (4-17)
( ) ( )y t y t y Cx= − = (4-18)
( ) ( )z t z t z Hx= − = (4-19)
The tracking error ( ) ( ) ( )e t r t z t= − is given by
( ) ( )e t e t e= + (4-20)
And the error deviation can be given by the follow if the input is a step of size 0r .
0 0( ) ( ) ( ) ( )e t e t e r Hx r Hx Hx z= − = − − − = − = − (4-21)
Ac is nonsingular since in any acceptable design the closed-loop plant will be
asymptotically stable. In steady state,
00 c cA x B r= + (4-22)
10c cx A B r−= − (4-23)
The steady state error is
10 0(1 )c ce r Hx HA B r−= − = + (4-24)
From (4-17),
34
( ) ( )x t x t x= + (4-25)
Plug (4-23) and (4-25) into (4-16), the deviation system can be expressed as
cx A x= (4-26)
y Cx= (4-27)
z Hx e= = − (4-28)
For the tracking problem, the performance index is given in terms of the deviation
system. Considering that the design is based on step-response shaping, and the closed-
loop plant is asymptotically stable, the system state and output will approach their steady
values over time under the step reference command. So the steady values of the state and
output will not be zero, and it is not convenient to incorporate the state and output into
the performance index. On the other hand, it is concerned how well the system state and
output approach their steady values, which can be represented by the dynamics of
deviation system. The time independent performance index is given by (4-29) and the
time dependent index is given by (4-30).
0
1 1( )2 2
T T TJ x Qx u Ru dt e Ve∞
= + +∫ (4-29)
0
1 ( )2
k T T TJ t x Px x Qx u Ru dt∞
= + +∫ (4-30)
For these time independent and time dependent performance indices, local
minimization solutions based on gradient techniques are given in [19]. The details of the
solutions are re-listed in Table 4-1 and Table 4-2. At this point the design of the
controller becomes the selection of the weighting matrices. Generally matrices
, , , P Q R V are symmetric positive semi definite. Engineering experience is important
guidance for the selection of weighting matrices. Stevens and Lewis give some useful
35
suggestions in [19].
Table 4-1: LQ Tracker with Time Independent Performance Index [19]
0
System Model
Control-
Performance Index
1 1( )2 2
Optimal Output Feedback Gain
0=
0=
0= (
f
T T T
T TTmc c f f
Tmc c
TT T T Tmf c
x Ax Bu Gry Cx Frz Hx
u K y
J x Qx u Ru dt e Ve
H A P PA Q C K RK CS
H A S SA XP
H RK CSC B PSC B A PP
∞
−
= + += +=
=
= + +
∂ = + + +∂∂ = + +∂∂ = − +∂
∫
0
0
10
0
10 0
)
with a step magnitude and
where
Optimal Cost 1 1( )2 2
TT T T T Tc
c c
T T TTc c c c
c f
c f
T
H VH xy B A H Vr y
r r
x A B ry Cx Fr
X xx A B r r B A
A A BK CB G BK F
J tr PX e Ve
−
−
− −
+ −
= −= +
= =
= −
= −
= +
36
Table 4-2: LQ Tracker with Time Dependent Performance Index [19]
0
0 0 0
1 1 1 1
-1 1 1 2
System Model
Control-
Performance Index
1 ( )2
Optimal Output Feedback Control
0
0
0
0
f
k T T T
Tc c
Tc c
Tk c k k c k
Tk c k
x Ax Bu Gry Cx Frz Hx
u K y
J t x Px x Qx u Ru dt
g A P P A P
g A P P A P
g A P P A P
g A P
∞
− − −
= + += +=
=
= + +
= ≡ + +
= ≡ + +
= ≡ + +
= ≡
∫
1
1 1
2 2 1
0 0 1
0 0
0
10
0
!
0
0 !
0
0
0= ( )
with a step magnitude and
TTk c k f f
Tc k k c
Tc k k c k
Tc k k c k
Tc c
TT T T T Tmf k k k c k
c c
Tc
P A k P Q C K RK C
A S S A X
A S S A k S
A S S A S
A S S A SH RK CS C B P S P S C B A P xyPr r
x A B ry Cx Fr
X xx A
−
− −
− − −
−
−
−
+ + + +
= + +
= + +
= + +
= + +∂ = − + + +∂
= −= +
= = 10 0
where
Optimal Cost 1 ( )2
T T Tc c c
c f
c f
B r r B A
A A BK C
B G BK F
J tr PX
−
= −
= −
=
37
4.2. PI/PID Controller Design by LQ Approach
In this section, the design methods of PI controllers for FOPTD systems and PID
controllers for the second order plus time delay systems are developed based on LQ
design techniques. Also empirical formulae for the gains of the PI and PID controller are
found for specific performance indices.
4.2.1. PI Controller for FOPTD
The plant is the first order plus time delay system described by (4-31)
( )1p
K sG s eTs
τ−=+
(4-31)
The PI controller has the form
1( ) (1 )ic p p
i
KG s K Ks T s
= + = + . (4-32)
In order to facilitate the procedure of finding the empirical tuning formulae, the
normalized plant and control transfer functions are defined with respect to the plant time
constant T . Also, the normalized plant DC gain is forced to be one by moving the
original DC gain K to the controller proportional gain. Defining the new variable 's Ts= ,
the plant and controller transfer functions can be rewritten as
'' '
'' '
1 1( )1 1p
s sTG s e es s
ττ− −= =
+ + (4-33)
''' '
'
1 1( ) (1 )= (1 )c p pi i
G s KK KT T ssT
= + + . (4-34)
In the normalized plant transfer function, only the normalized time (NT) delay
affects the LQ design result. The Pade approximation is used to approximate the time
38
delay term, and then the normalized plant transfer function is converted to a state
equation. The resulting state equation is shown below,
p p p p px A x B u= + (4-35)
p p p pz y C x= = (4-36)
The PI controller dynamics are described by the state equation
w Fw Ge= + (4-37)
v Dw Je= + (4-38)
where [ ] [ ] 0 10 , 1 , , and
1 0F G D J = = = =
.
Since only the unity-outer loop feedback is used, the complete system dynamics
are
0 00
p pA Bx xd u rw F w Gdt GH
= + + −
(4-39)
[ ] [ ] [ ]xv JH D J r
w
= − +
(4-40)
]0x
z Hw
=
(4-41)
' 'p iu K K v = − (4-42)
The optimal feedback gain vector for the specific performance index is the PI controller
gains. When the optimal feedback gain vector is found, the PI controller gains will be
determined immediately. The design result depends on the performance index selection.
In this thesis, several specific performance indices are studied in detail. The first
performance index studied is the time-independent performance index, where
39
, 0, and 0TQ H H R V= = = . Essentially, this performance index is the well known
integral square error (ISE) performance criterion. The second performance index studied
is the time-dependent performance index where TP H H= , 0Q = , 0R = , 0V = and
2k = . It is the known as the integral squared time weighting error (ISTE) performance
criterion. The third performance index studied is the time-dependent performance index
where , 0, 0, 0, 4.TP H H Q R V and k= = = = = It is known as IST2E. The empirical
formulae for the above three performance indices have been developed by M. Zhuang
and D.P. Atherton in a normalized time delay range of 0.1 to 2 [20]. In this thesis, the
formulae will be developed to cover a wider normalized time delay range for the three
performance indices.
To find the empirical formula for automatic tuning, optimization is repeated for
different values of the normalized delay time Tτ , The time delay term is approximated by
the first order Pade approximation when the normalized time delay is less than 0.1,
otherwise, the 3rd order Pade approximation is used.
From Figure 4-2 to Figure 4-7, the relationships between the optimal proportional
gain, the integral time constant, and the normalized time delay for the performance
indices of ISE, ISTE and IST2 E are shown. In these figures, the original LQ design result
and the empirical formulae are plotted together. It should be noticed that in the
proportional gain figures, the logarithmic coordinates are used.
40
Kp(ISE)
0.10
1.00
10.00
100.00
0.01 0.10 1.00 10.00
Normalized Time Delay
Kp
LQ Design Emprical Formula
Figure 4-2: Proportional Gain of PI controller vs. NT Delay with ISE
Ti(ISE)
0.00
1.00
2.00
3.00
4.00
5.00
6.00
7.00
8.00
0.00 2.00 4.00 6.00 8.00 10.00 12.00
Normalized Time Delay
Ti
LQ Design Empirical Formula
Figure 4-3: PI Integral Time Constant vs. NT Delay with ISE
41
Kp(ISTE)
0.10
1.00
10.00
100.00
0.01 0.10 1.00 10.00
Normalized Time Delay
Kp
LQ Design Emperical Formula
Figure 4-4: PI Proportional Gain vs. NT Delay with ISTE
Ti(ISTE)
0.00
1.00
2.00
3.00
4.00
5.00
6.00
0.00 2.00 4.00 6.00 8.00 10.00 12.00
Normalized Time Delay
Ti
LQ Design Emperical Formula
Figure 4-5: PI Integral Time Constant vs. NT Delay with ISTE
42
Kp(IST^2E)
0.10
1.00
10.00
100.00
0.01 0.10 1.00 10.00
Normalized Time Delay
Kp
LQ Design Emprical Formula
Figure 4-6: PI Proportional Gain vs. NT Delay with IST2E
Ti(IST^2E)
0.00
0.50
1.00
1.50
2.00
2.50
3.00
3.50
4.00
4.50
5.00
0.00 2.00 4.00 6.00 8.00 10.00 12.00
Normalized Time Delay
Ti
LQ Design Emprical Formula
Figure 4-7: PI Integral Time Constant vs. NT Delay with IST2E
The empirical formulae are obtained using least square techniques to fit to the LQ
design results. The following general formulae are used. The coefficients of the formulae
43
depend on the performance index and the value of the normalized time delay.
'p
1K ''
bac d
ττ
= ++
(4-43)
2' ' 'iT e f gτ τ= + + (4-44)
The actual PI controller proportional gain and integral time constant can be expressed
then by
p1 1( )bK aK T c d
T
ττ
= + +
(4-45)
2( ) ( )iT e f g TT Tτ τ = + +
(4-46)
The coefficients of the empirical formulae are listed in Table 4-3 and Table 4-4.
44
Table 4-3: Empirical Formula Coefficients Table (1) for PI Controllers
Tτ range 0.01~0.1 0.1~1
Performance
Index
ISE ISTE IST2E ISE ISTE IST2E
a 6.1918E-01
3.0904E-01
6.9730E-02
3.3739E-01
2.1748E-01
-2.4465E+00
b -1.0321E+00
-1.0538E+00
-1.2042E+00
8.6781E-02
2.5543E-01
-1.0251E+00
c 6.8788E+00
3.8624E+00
2.0161E+00
1.3393E+00
1.7348E+00
3.3274E-01
d 3.1912E-01
1.7662E-02
5.2334E-03
4.7205E-04
-2.8402E-03
-2.1071E-03
e 7.0441E+00
3.0128E+00
8.7634E-01
4.3507E-02
-4.8355E-02
1.1961E-01
f -5.3836E-01
6.3030E-02
2.7341E-01
3.8175E-01
4.1762E-01
7.1533E-02
g 1.4664E+00
1.0013E+00
9.9852E-01
1.4373E+00
9.9912E-01
1.0010E+00
45
Table 4-4: Empirical Formula Coefficients Table (2) for PI Controllers
Tτ range 1~5 5~10
Performance
Index
ISE ISTE IST2E ISE ISTE IST2E
a 3.3585E-01
2.4310E-01
3.7763E-01
3.8091E-01
2.9030E-01
3.1022E-01
b 1.1625E-01
1.4896E-01
-1.1864E+00
6.3547E-02
7.4693E-02
-1.2548E+00
c 1.3471E+00
1.8692E+00
-5.7016E-02
1.5063E+00
2.2243E+00
-9.9624E-03
d -1.0742E-02
-5.4684E-02
3.9433E+00
8.3843E-02
1.3721E-01
3.5255E+00
e 1.1244E-02
1.1052E-02
1.2896E-02
1.8999E-03
1.7445E-03
1.5687E-03
f 4.6570E-01
3.5339E-01
2.6528E-01
5.4811E-01
4.3604E-01
3.6336E-01
g 1.3789E+00
1.0022E+00
8.9982E-01
1.1933E+00
8.1472E-01
6.8359E-01
In Figure 4-8 and Figure 4-9, the gain margin and phase margin are shown against
the normalized time delay in the range of 0.01 to 10. The time dependent performance
indices (ISTE and IST2E) give about 60 degrees of phase margin and the gain margin is
in the range of 6dB to 9.5dB. The time independent performance index give a gain
margin of 6dB and the phase margin varies from 45 degrees to 65 degrees. Based on such
empirical formulae, the bandwidth is also predictable. In Figure 4-10, the crossover
frequency vs. the normalized time delay is plotted. Empirical formulae for the bandwidth
as a function of the normal time delay have been found using the least squares fit
46
techniques. These formulae have the form as given below, and their coefficients are
listed in Table 4-2.
( )bc
aT T
τω = (4-47)
The bandwidth frequency bf :
( )2 2
c bb
afT T
ω τπ π
= = (4-48)
Table 4-5: Crossover Frequency Formula Coefficients for PI Controllers
ISE ISTE IST2E
a 0.8127 0.6701 0.5959
b -0.9850 -0.9439 -0.9492
This bandwidth relationship will be useful in the systematic design approach
developed in the chapter 6. They will be used to help choose lower bounds on the update
and PWM frequency of a digital motor controller.
47
Gain Margin
0.00
1.00
2.00
3.00
4.00
5.00
6.00
7.00
8.00
9.00
10.00
0.01 0.10 1.00 10.00
Normalized Time Delay
Gai
n M
argi
n (d
B)
ISE ISTE IST^2E
Figure 4-8: Gain Margin of ISE, ISTE, and IST2E Design
Phase Margin
0.00
10.00
20.00
30.00
40.00
50.00
60.00
70.00
80.00
0.01 0.10 1.00 10.00
Normalized Time Delay
Phas
e M
argi
n (d
eg)
ISE ISTE IST^2E
Figure 4-9: Phase Margin of ISE, ISTE, and IST2E Design
48
Crossover Frequency (rad/sec)
0.01
0.10
1.00
10.00
100.00
0.01 0.10 1.00 10.00
Normalized Time Delay
Cro
ssov
er F
requ
ency
(rad
/sec
)
ISE ISTE IST^2E
Figure 4-10: Crossover Frequency of ISE, ISTE, and IST2E Design
4.2.2. PID Controller for the Second Order plus Time Delay
System
In the controller design process, if pole-zero cancellation is applied, the system
can be simplified significantly. For example, in the PI controller design for a FOPTD, if
the PI controller zero is designed to cancel the plant pole, the resulting system only
includes an integral controller and a pure time delay. Similarly, in the PID controller
design for a 2nd order plus time delay system, the same simplified system can obtained by
using controller zeros to cancel the plant poles. For this simplified system, the integral
controller gains can be found by the LQ approach. If such design is repeated against the
normalized time delay, empirical formulae can be obtained for the controller gain and
resulting system bandwidth. In this section, the design process is based on a PID
controller for a 2nd order plus time delay system for the purpose of generality, while the
49
result is easily applied on the PI controller design for a FOPTD. These methods are not
used in later sections, although they are presented here. They are presented as an
alternative to the controller design methods presented in the previous section. These
previous methods are used in later sections.
For the second order plus time delay system described by (4-49)
2 2( )2 1pK sG s e
T s Tsτ
ζ−=
+ + (4-49)
The PID controller has the form
2( 1)( ) =
pdi
i i ic p d
KKK s sK K KG s K K ss s
+ += + + (4-50)
Defining 's Ts=
'
2( ')' 2 ' 1
sT
pKG s e
s s
τ
ζ−
=+ +
(4-51)
22
1 1( ' ' 1)( ')= 1 '
pdi
i ic
KKK s sK T K TG s
sT
+ + (4-52)
In order to simplify the PID controller design procedure and find a simple
empirical tuning rule, the zeros of the PID controller can be used to cancel the poles of
the system.
22 '
2
'
1 1( ' ' 1)( ') 1 ' 2 ' 1'
'
pdi
si i T
c p
si T
KKK s sK T K T KG G s e
s ssT
K KT es
τ
τ
ζ−
−
+ +=
+ +
=
(4-53)
After this simplification, the design turns into finding the optimal integral gain iK for the
50
pure time delay system. The Pade approximation is used to approximate the pure delay
term, and another first order term is added to the plant transfer function to make it proper.
The state space equation can be found from the transfer functions like the design
procedure of the PI controller for FOPTD.
The state space equation of the integral controller is
w Fw Ge= + (4-54)
v Dw Je= + (4-55)
where [ ] [ ] [ ] [ ]0 , 1 , 1 , and 0F G D J= = = =
For the different performance indices, the optimal gain settings of the integral
control are found by using the LQ design program. In Figures 4-11, 4-12 and 4-13, the
product of iK K are plotted against the normalized time delay from 0.01 to 10. A uniform
empirical formula has been found to approximate the plots.
( )bi
aKKT T
τ= (4-56)
From (4-53), the proportional gain and the derivative gain can be found by
2p iK K Tζ= (4-57)
2d iK K T= (4-58)
The resultant system crossover frequency and bandwidth can be predicted by the
following formulae for the three performance indices:
( )dc
cT T
τω = (4-59)
( )2
db
cfT T
τπ
= (4-60)
51
Table 4-6: Empirical Formula Coefficients Table for Integral Controllers
Tτ range 0.01~10
Performance Index ISE ISTE IST2E
a 0.7318 0.5886 0.5076
b -1 -1 -1
c 0.7318 0.5886 0.5076
d -1 -1 -1
Phase Margin(deg) 48.1 56.3 60.9
Gain Margin (dB) 6.6 8.5 9.8
The simulation results are plotted in the following figures. Since this design
method offers constant phase margin and gain margin over the range of the normalized
time delay, it can be expected the step response have same shape if we rescale the step
response along the time axis using the normalized time delay.
In this section, the PID LQ design is simplified to an integrator for a pure time
delay plant by pole-zero cancellation. This design approach can be extended to PI design
for FOPTD. Using the PI controller zero to cancel the FOPTD pole will result in a pure
time delay plant and an integrator. The empirical formulae developed in this section can
be used.
52
Ki(ISE)
0.01
0.10
1.00
10.00
100.00
0.01 0.10 1.00 10.00
Normalized Time Delay
Ki
LQ Design Emperical Formula
Figure 4-11: Integral Gain for ISE
Ki(ISTE)
0.01
0.10
1.00
10.00
100.00
0.01 0.10 1.00 10.00
Normalized Time Delay
Ki
LQ Design Emperical Formula
Figure 4-12: Integral Gain for ISTE
53
Ki(IST^2E)
0.01
0.10
1.00
10.00
100.00
0.01 0.10 1.00 10.00
Normalized Time Delay
Ki
LQ Design Emperical Formula
Figure 4-13: Integral Gain for IST2E
Gain Margin
0.00
2.00
4.00
6.00
8.00
10.00
12.00
0.01 0.10 1.00 10.00
Normalized Time Delay
Gai
n M
argi
n (d
B)
ISE ISTE IST^2E
Figure 4-14: Gain Margin for ISE, ISTE, and IST2E
54
Phase Margin
0.00
10.00
20.00
30.00
40.00
50.00
60.00
70.00
0.01 0.10 1.00 10.00
Normalized Time Delay
Phas
e M
argi
n (d
eg)
ISE ISTE IST^2E
Figure 4-15: Phase Margin for ISE, ISTE, and IST2E
Crossover Frequency(rad/sec)
0.01
0.10
1.00
10.00
100.00
0.01 0.10 1.00 10.00
Normalized Time Delay
Cro
ssov
er F
requ
ency
(rad
/sec
)
ISE ISTE IST^2E
Figure 4-16: Crossover Frequency of ISE, ISTE, and IST2E
55
Chapter 5: PMSM Current Control
5.1. Introduction
In the PMSM drive application, the multi-loop structures are commonly used to
implement the current/torque, speed, and position control [1]. Usually, the current/torque
control loop is the inner loop, and its performance is a crucial factor for the whole system.
The current control loop should be able to control the stator flux position and amplitude,
as well as compensate for the nonlinearity of the components in the system. Field
oriented control is commonly used in this loop. Field oriented control was first applied
on the induction motor by Blaaske to get comparable dynamic performance to a DC
motor [21]. Then, this concept was extended to control of other kinds of ac machines
such as permanent magnet synchronous machines. It turns out that field oriented control
on PMSM is easier to implement because of the absence of the slip frequency current
which appears in the induction machine [22].
One classical current control structure is composed of two or three phase current
control loops in the stationary, abc, frame [7, 8, 9, 10, 11, 12], since the current reference
to the controllers are sinusoidal functions of rotor position, this structure is referred to as
sine wave current control. Another current control structure includes two current control
loops in the rotor synchronous, dq0, frame [7, 8, 9, 10, 12, 13] and is referred to as the
vector current control.
In this chapter, these two current control structures are compared under the ideal
condition (analog control), where the ideal controlled voltage source is used and no delay
is considered.
56
5.2. Vector Current Control
In the electric machine analysis, it is convenient to express the angle in the
electrical degrees or electrical radians. In multi pole machine, with P pole pairs, the angle
value measured in electrical units is P times the angle value measured in the actual
spatial unit. Correspondingly the electrical speed and the rotor speed are related by the
following equation
s rPω ω= (5-1)
where sω is the synchronous speed, rω is the rotor speed.
This current control structure is based on the PMSM rotor synchronous ,dq0,
model. The rotor synchronous, dq0, frame is locked to the rotor, and its direct or d axis is
aligned with the rotor flux linkage phasor afλ . Its quadrature or q axis is aligned with the
resulting back EMF phasor. θ is defined as the angle between the q axis and the phase A
axis, and eθ is defined as the angle between the d axis and the stator phase A axis as
demonstrated in Figure 5-1.
Figure 5-1: Phasor Diagram
In the rotor synchronous, dq0, frame, the PMSM can be modeled with following
θ
eθ
id
iq
afλ
57
assumptions [2]:
i. Saturation is neglected although it can be taken into account by
parameter changes;
ii. The induced back EMF is sinusoidal;
iii. Eddy currents and hysterics losses are negligible;
Based on such assumptions, the machine can be modeled in the rotor synchronous,
dq0, frame using following equations.
q q q s ddv Ridtλ ω λ= + + (5-2)
d d d s qdv Ridtλ ω λ= + − (5-3)
q q qL iλ = (5-4)
d d d afL iλ λ= + (5-5)
Here and d qL L are the stator d and q inductance under the condition of alignment with
rotor d and q axes respectively, afλ is the magnet flux linkage amplitude, and R is the
stator resistance.
Variables in the rotor synchronous, dq0, frame and stator a, b, c variables are
related by Park transform. In the following equation, f can be current i or voltage v .
0
2 2cos( ) cos( ) cos( )3 3
2 2 2sin( ) sin( ) sin( )3 3 3
1 1 12 2 2
q a
d b
c
f ff ff f
θ θ π θ π
θ θ π θ π
− + = − +
(5-6)
58
0
cos( ) sin( ) 12 2cos( ) sin( ) 13 32 2cos( ) sin( ) 13 3
a q
b d
c
f ff ff f
θ θ
θ π θ π
θ π θ π
= − −
+ +
(5-7)
The electric torque Te is
e3T [ ( ) ]2 af q d q d qP i L L i iλ= + − (5-8)
The equation of the motor dynamics is
e L r rdT T B Jdt
ω ω= + + (5-9)
where B the damping constant, J is the moment of inertia.
If the PMSM has the uniform magnetic structure like the surface magnet motor,
d qL L= , the electric torque is determined only by the q axis current qi regardless of
whether di is purposely set to zero or not [23]. In field oriented control, good practice is
to force the direct axis current to zero and the make stator flux perpendicular to the rotor
flux. In this case, the electrical torque is proportional to the q axis current.
Rearranging the equation (5-2), (5-3) and (5-10) with (5-4) and (5-5) in the state
space form gives the following.
( ) /q q q s d d s af qd i v Ri L i Ldt
ω ω λ= − − − (5-10)
( ) /d d d s q q dd i v Ri L i Ldt
ω= − + (5-11)
( ) /r e L rd T T B Jdtω ω= − − (5-12)
These equations are nonlinear generally. While in the steady state, the rotor speed is a
59
constant variable or slowly varying variable compared with other state variables and can
be treated as constant. Based on this model, if a PI controller is used in each current
control loop, then zero tracking error can be expected for the constant current reference.
For each loop, the coupling and the back EMF disturbance are constant in steady
state. For the q axis loop, the tracking performance is more important than regulation
performance because qi is set by the outer loop according to the desired torque; while for
the d axis, the regulation performance is much more important because di is usually set
to zero.
A simulation scheme follows with the simulation results for a step input and a
sinusoidal input at 3000rpm. The motor parameters are these given in chapter 2 for the
drive motor and the PI controller gains are Kp=50(V/A) and Ki=85690(V/A-sec).
Figure 5-2: Simulation Scheme of Vector Current Control
60
Vector Current Control
-0.4
0
0.4
0.8
1.2
0.00 0.01 0.01 0.02 0.02 0.03 0.03 0.04 0.04 0.05 0.05
Time (Sec)
Cur
rent
(Am
p)
Iq Id Iq Command
Figure 5-3: Simulation Result of Vector Current Control for Step Response
Vector Current Control
-0.8
-0.6
-0.4
-0.2
0
0.2
0.4
0.6
0 0.002 0.004 0.006 0.008 0.01 0.012 0.014 0.016 0.018 0.02
Time (Sec)
Cur
rent
(Am
p)
Iq Id Iq Command
Figure 5-4: Simulation Result of Vector Current Control for Sinusoidal Response
61
5.3. Sine Wave Current Control
Sine wave current control is also known as the phase current control. In this
current control structure, two or three controllers are directly applied on the phase current
control loops. In the stationary, abc, frame, the PMSM model can be presented as shown
below.
abc abc abcdv Ridtλ= + (5-13)
In this equation R is the stator resistance, and abcv , abci and abcλ are stator voltage, stator
current and stator flux linkage vectors respectively. These vectors have the form of (5-14)
a
abc b
c
ff f
f
=
(5-14)
The flux linkages of stator phases a, b, c resulting from the currents flowing in the stator
windings are given in [6].
2 2
2 2
2 2
ms msms ls
ms msabcs ms ls abc
ms msms ls
L LL L
L LL L i
L L L L
λ
+ − − = − + − − − +
(5-15)
where and ms lsL L are the stator winding self inductance and leakage inductance. Using
the fact that 0a b ci i i+ + = for the wye connection, it can be found
62
3 0 02
30 02
30 02
3 2
ms ls
abcs ms ls abc
ms ls
ms ls abc
L L
L L i
L L
L L i
λ
+ = + + = +
(5-16)
The flux linkage contributed by the rotor permanent magnet is
cos( ) sin( )2 2cos( ) = sin( )3 32 2cos( ) sin( )3 3
e
abcr af e af
e
θ θ
λ λ θ π λ θ π
θ π θ
= − − + +
(5-17)
where θ is the angle between the rotor q axis and the stator A axis and eθ is the angle
between the rotor direct axis and the stator phase A axis as demonstrated Figure 5-1
sin( )3 2sin( - )2 3
2sin( )3
abc abcs abcr ms ls abc afL L i
θ
λ λ λ λ θ π
θ
= + = + × + +
(5-18)
Substituting the stator flux linkage equation into (5-13) gives,
cos( )( ) ( ) ( )1 2( ) ( ) ( ) cos( )
3( ) ( ) ( ) 2cos( )
3
as as asaf s
bs bs bss s s
cs cs cs
i t i t v td Ri t i t v tdt L L L
i t i t v t
θλ ω
θ π
θ π
= − + − −
+
(5-19)
where 32s ms lsL L L= + is defined as the synchronous inductance [24]. The phase equivalent
63
circuit of the PMSM is shown in Figure 5-5, where cos( )af saf
se
Lλ ω
θ= .
Figure 5-5: Equivalent Phase Circuit
In the sine wave current control structure, the two or three PI controllers are used
to control the phase currents. The advantages and disadvantages of two or three loops
have been discussed [7, 11]. The phase current references are generated according to the
rotor position and the equivalent current amplitudes in the rotor synchronous, dq0, frame,
which is directly associated with the electrical torque. The equation for the phase current
reference generation for the stator flux perpendicular to the rotor is listed in (5-20) and
(5-21).
0
cos( ) sin( ) 12 2cos( ) sin( ) 13 32 2cos( ) sin( ) 13 3
aref qref
bref dref
cref ref
i ii ii i
θ θ
θ π θ π
θ π θ π
= − −
+ +
(5-20)
Since generally the direct axis current is required to be zero so that the stator flux can be
perpendicular to the rotor, the phase current reference can be simplified as
cos( )2cos( )32cos( )3
aref
bref qref
cref
ii ii
θ
θ π
θ π
= −
+
(5-21)
RsL
afe
+
−av
+
−
ai
64
The wave current reference is a sinusoidal function of θ and its amplitude is the q axis
current.
The back EMF on each phase is a sinusoidal disturbance whose amplitude is
proportional to the rotor speed and whose frequency is associated with the rotor speed.
The phase current controller should be able to reject this kind disturbance effectively if
the rotor speed is small enough.
If the torque or q axis current control reference is sinusoidal with an frequency of
qf , the reference current to the phase current controller is
cos(2 )cos( )
1 [cos(2 ) cos(2 )]2
qref q s
qref q s q s
I f t t
I f t t f t t
π ω α
π ω α π ω α
−
= − + + + − (5-22)
where α is 2 20, and 3 3π π− for the phase a, b, and c. The higher frequency component
of the reference current is at 2
sqf
ωπ
+ . The phase current controllers must have much
higher bandwidth than 2
sqf
ωπ
+ to satisfy the application requirements. Since the phase
current reference is sinusoidal, it is not possible to get zero tracking error under
conditions of constant speed and constant q axis current reference. The tracking error will
increase when the rotor spins faster.
In steady state, the electrical angular velocity is sω , and stθ ω= , the closed loop
amplitude ratio and the phase lag are 1A and 1α at sω . So the phase current can be
presented as
65
1
1 1
1
cos( )2cos( ) 32cos( )3
a
b ref
c
ii A Ii
θ α
θ π α
θ π α
−
= − −
+ −
(5-23)
Transforming the phase current into the rotor synchronous, dq0, frame by Park Transform,
such phase lag and amplitude attenuation degrade the motor performance as shown in (5-
24)
1
1 1
0
cos( )sin( )
0
q
d ref
ii A Ii
αα
=
(5-24)
The transfer function for each phase back EMF can be presented as
( )( )
1 ( ) ( )p
dc p
G sG s
G s G s= −
+ (5-25)
If the plant pole is cancelled by the PI controller zero, ( )dG s can simplified to (5-26)
2( )( )d
s p i
sG sL s R K s K
= −+ + +
(5-26)
The back EMF on phase a, b, c can be presented as
cos( )( )2( ) cos( )3
( ) 2cos( )3
ads
bds af s
cds
v tv tv t
θ
λ ω θ π
θ π
= −
+
(5-27)
The currents corresponding to such disturbances are
66
2
2 2
2
cos( )( )2( ) cos( )3
( ) 2cos( )3
sads
bds af s s
cds
s
ti ti t A ti t
t
ω α
λ ω ω π α
ω π α
−
= − −
+ −
(5-28)
The amplitude damping ratio 2A and the phase lag 2α can be determined from the
transfer function with the corresponding frequency sω . 2α is larger than 90 .
Transforming such currents into the rotor synchronous, dq0, frame,
2
2 2
0
( ) cos( )( ) sin( )( ) 0
qds
dds af s
ds
i ti t Ai t
αλ ω α
=
(5-29)
Finally, the currents represented in the rotor synchronous, dq0, frame are
1 2
1 1 2 2
0
( ) cos( ) cos( )( ) sin( ) sin( )( ) 0 0
qs
ds ref af r
s
i ti t A I Ai t
α αα λ ω α
= +
(5-30)
In simulation and experimental results, it is obvious that such disturbance cause
the current offsets on the q and d axes from the desired values. The simulation scheme in
MATLAB/SIMULINK is shown in Figure 5-6.
Figure 5-6: Simulation Scheme of Sine Wave Current Control
67
In Figure 5-7 and Figure 5-8, the simulated system responses for a sinusoidal
input and step input are shown for simulation at 3000RPM. The quadrature and direct
axis currents obviously deviate from the references. The motor parameters are these
given in chapter 2 for the drive motor and the PI controller gains are Kp=50(V/A) and
Ki=85690(V/A-sec).
Sine Wave Current Control
-0.8
-0.4
0
0.4
0.8
1.2
0 0.01 0.02 0.03 0.04 0.05
Time (Sec)
Cur
rent
(Am
p)
Iq Id Iq Command
Figure 5-7: Simulation Result of Sine Wave Control for Step Response
68
Sine Wave Current Control
-2
-1.5
-1
-0.5
0
0.5
1
1.5
0 0.005 0.01 0.015 0.02
Time (Sec)
Cur
rent
(Am
p)
Iq Id Iq Command
Figure 5-8: Simulation Result of Sine Wave Control for Sinusoidal Response
69
Chapter 6: Digital Implementation and Systematic
Design of PMSM Current Control
In Chapter 5, the continuous time domain models of PMSM and corresponding
current control methods are presented, and the two current control structures are
compared theoretically.
Recently, the developments in DSP techniques and power electronic components
have made it possible to implement high performance current control for PMSM via
digital implementation. This chapter will focus on the digital implementations for these
two current control structures. The digital implementations of these current control
structures have at least two differences from the analog implementation: the PWM
technology application and the effects caused by digitization.
The experimental system also includes a second motor driven by an off-the-shelf
amplifier, the L-180. For the experimental data in this thesis the second motor is used to
drive the system at a constant velocity.
6.1. Digital Implementation Architecture for PMSM Current
Control
The two current control structures, sine wave current control and vector current
control, share the same hardware configuration in our experimental system. The
experimental system is composed of a host computer, a motion control DSP card (MC8),
an integrated power stage, a permanent magnet synchronous motor and necessary sensors.
The differences between the two current control structures lie in the control algorithm of
70
the DSP programs.
6.1.1. Sine Wave Current Control Structure
The sine wave current control structure for the PMSM is described in Figure 6-1
[7, 8, 9, 10, 11, 12]. In the digital implementation of this sine wave current control system
all control algorithms are implemented in the DSP program. Compared with analog
implementation or pure hardware implementation, this implementation method is the
most flexible. The components implemented in DSP program in Figure 6-1 are the phase
reference generator, the three or two PI controllers and the duty cycle computation for the
PWM.
Figure 6-1: System Schematic of Sine Wave Current Control
• Phase Current Reference Generator
The phase current reference generator generates the phase current references for
Resolver to Digital Converter
A/D Fire Circuits
Phase current Reference Generator
Controller
Duty computation
-
+
Iaref
Ibref
Icref
…
…
ia
Current Amplitude Reference
βa βb βc
ib ic
VDC
+
-
71
the each current control loop. The inputs to the reference generator are the rotor
position rθ and desired current amplitude. The rotor position comes from the
resolver/quadrature encoder and can be easily translated into the electric angle θ by the
equation rPθ θ= . The desired current amplitude is proportional to with the desired
torque. In most applications it would come from an outer speed or position control loop.
The equation that the phase current reference generator uses is
cos( )2cos( )32cos( )3
aref
bref qref
cref
ii ii
θ
θ π
θ π
= −
+
(6-1)
• PI Controller
The PI controller is designed in the continuous time domain and implemented by
the approximation equation:
10
( ) ( ) ( )k
k p k i s nn
u t K e t K T e t+=
= + ∑ (6-2)
Where 1( )ku t + is the controller output, ( )ke t is the error to the controller, sT is the
sampling period, and pK and iK are the proportional and integral gains respectively. For
the good approximation, the sampling frequency should be sufficiently fast.
• Duty Cycle Computation
Duty cycle computation uses the outputs of the PI current controllers to generate
the PWM drive signals with the calculated duty cycle. In the experimental system, a
center-aligned PWM modulation method is used. The behavior of the duty cycle
computation is examined below.
72
At any moment, one switch of each leg in the inverter is on and the other switch is
off. The three legs can be driven to 8 unique states. For each leg, one is used to represent
the state that the top switch is on and bottom switch is off. Zero is used to represent the
state that the top switch is off and the bottom switch is on. The inverter states are encoded
by three digits and listed in Table 6-1.
Table 6-1: Inverter State Definitions
U000 U100 U110 U010 U011 U001 U101 U111
abc 000 100 110 010 011 001 101 111
The states of U000 and U111 are zero states, which correspond to the situation
that all three motor terminals are connected to the lower bus or upper bus of the DC
supply.
The immediate outputs of the PI controllers are compared with each other, and the
minimum one will be used to offset the phase voltage references. As a result, there is
always one phase voltage reference at zero with respect to the ground line of the DC
supply. In this PWM period, the leg associated with this phase has no switching action
and the phase stay at the ground. Less switch action means less energy loss caused by
inverter switching.
The duty cycle calculation equation is
'ii
Bus
vV
β = . (6-3)
where , ,i a b c= for each phase.
Aligning the ON state of each leg to the center of the PWM period, the switch
73
patterns are listed in Table 6-2. Every PWM period starts from U000 and ends in U000,
and at each state transition, only one switching action occurs.
Table 6-2: Inverter Switching Patterns
a b cv v v> >
a c bv v v> >
b a cv v v> >
b c av v v> >
c a bv v v> >
c b av v v> >
'av a cv v− a bv v− a cv v− 0 a bv v− 0
'bv b cv v− 0 b cv v− b av v− 0 b av v−
'cv 0 c bv v− 0 c av v− c bv v− c av v−
Switching
Patterns
000100110100000
UUUUU
⇒⇒⇒⇒
000100101100000
UUUUU
⇒⇒⇒⇒
000010110010000
UUUUU
⇒⇒⇒⇒
000010011010000
UUUUU
⇒⇒⇒⇒
000100110100000
UUUUU
⇒⇒⇒⇒
000001011001000
UUUUU
⇒⇒⇒⇒
In the practical system implementation, the dead time of the power stages need to
be considered. Dead time is the time between turning one switch in a leg off and the other
one on. Correction terms are added to the duty cycle calculation to minimize the
distortions caused by the dead time. Detailed discussion of this can be found in [25]
Using the minimum value of the three phase voltage references to offset the
reference voltage will not change the voltage vector in the rotor synchronous, dq0, frame.
This can be verified by (6-4), where only the zero-sequence variable is changed by the
offset of the phase variables.
74
0
2 2cos( ) cos( ) cos( )3 3
2 2 2sin( ) sin( ) sin( )3 3 3
1 1 12 2 2
2 2cos( ) cos( ) cos( )3 3
2 2 2sin( ) sin( ) sin( )3 3 3
1 1 12 2 2
q a offset
d b offset
c offset
v v vv v vv v v
θ θ π θ π
θ θ π θ π
θ θ π θ π
θ θ π θ π
− + − = − + − −
− +
= − +
02 03
32
a
b
coffset
vvv v
−
(6-4)
• DSP Program Implementation
The DSP control programs were written in C. The development environment is
VisualDSP++ for the Sharc processor family. The flow chart for the sine wave current
control program is presented below.
75
Figure 6-2: Program Flow Chart of Sine Wave Current Control
The control algorithm is implemented in an interrupt service subroutine driven by
a clock running at the sampling frequency. From the program flow chart, the timing
scheme of the server subroutine is presented below.
Start
Initialize pointes, global variables, interrupt
Handle message exchange with the host PC
Read the sampling measurement.Current/Position
Phase Current Reference Generation
PI Control
Generate Command
Generate Synchronous Signals to start sampling and PWM output
Calculate PWM Duty Cycle
Return to Main Program
Store Data if Required
Interrupt Entrance
76
Figure 6-3: Timing Chart of Sine Wave Current Control
From Figure 6-3, the delay between the sampling and the corresponding output is
one sampling period if we neglect the sampling time and output delay caused by PWM.
6.1.2. Vector Current Control Structure
Figure 6-4: System Schematic of Vector Current Control
The digital implementation structure is described in Figure 6-4 [7, 8, 9, 10, 12,
Resolver to Digital Converter
A/D Fire Circuits
Duty computation
Iqref
βa βb βc
Ia Ib Ic -> Iq Id Electrical Position
Controller-
+
Controller-
+
Uqd0 -> Ua Ub Uc
Idref=0
iq
id
tTk Tk+1 Tk+2
Computation
Sampling and PWM Update
Computation
Sampling and PWM Update
Computation
Sampling and PWM Update
77
13]. The vector current control shares the hardware structure with sine wave current
control. Some components of the control algorithm are also the same, such as duty cycle
computation, and the PI controller algorithm. In the vector current control structure,
controlled variables are not directly the stator current; instead, the controlled variables are
the currents and d qi i in the rotor synchronous, dq0, frame. The components that do not
appear in the sine wave current control structure are listed below.
• Conversion from the stationary, abc, frame to the rotor synchronous, dq0, frame
This conversion is used to transform the stator current from the stationary, abc,
frame into the rotor synchronous, dq0, frame. The inputs to this conversion are the rotor
position and the current sensor outputs. The transformation equation is Park transform (6-
5).
0
2 2cos( ) cos( ) cos( )3 3
2 2 2sin( ) sin( ) sin( )3 3 3
1 1 12 2 2
q a
d b
c
f ff ff f
θ θ π θ π
θ θ π θ π
− + = − +
(6-5)
• Conversion from the rotor synchronous, dq0, frame to the stationary, abc, frame
This conversion is used to transform the variables from the rotor synchronous,
dq0, frame into the stationary, abc, frame. The inputs to this conversion are the PI
controller outputs, which are the voltages in the rotor synchronous, dq0, frame. The
transformation equation is the inverse Park transform (6-6)
78
0
cos( ) sin( ) 12 2cos( ) sin( ) 13 32 2cos( ) sin( ) 13 3
a q
b d
c
f ff ff f
θ θ
θ π θ π
θ π θ π
= − −
+ +
(6-6)
• DSP Program Implementation
The DSP program for vector current control shares the program structure
with sine wave current control. The program flow chart is presented below.
Figure 6-5: Program Flow Chart of Vector Current Control
Start
Initialize pointes, global variables, interrupt
Handle message exchange With the host PC
Read the sampled measurement. Current/Position
Current Conversion (abc -> dq0)
PI Control
Generate Command
Generate Synchronous Signal to start sampling and PWM output
Calculate PWM Duty Cycle
Return to main program
Store Data if Required
Voltage Conversion (dq0 -> abc)
Interrupt Entrance
79
The timing diagram of the vector control program is basically same with the sine
wave current structure as shown in Figure 6-3.
6.2. Effects of Digitization and PWM on the Current Control
System Design
In digital implementation of the current control for permanent magnet
synchronous motors time delay is inevitable. On the motion control board in our system
the sensor circuits are synchronized by a signal, which will trigger A/D conversion, latch
DAC output and quadrature decoder counts (the decoders will provide the rotor position
in our system). From the timing diagram shown in Figure 6-3, the time delay is one
sampling period. Further delay is caused by PWM. This time delay is complex to analyze,
but one-half of the PWM update period is a good approximation [26, 27].
Generally for the permanent magnet synchronous motor current control design,
the delay effects in the digital implementation can be neglected in the case that the time
delay is small enough compared with the electric time constant of the motor, and the
motor maximum speed is low. In this case, the system can be designed using continuous
time models. Sometimes, the digital update period and PWM update period are not small
enough to be neglected and the delay effects should be taken into account in the system
design and tuning process to guarantee good system performance. Usually, faster PWM
update and digital update can result in better system performance, but considering that the
inverter loss will increase when the switching frequency increases, if the system
performance can be satisfied, lower switching frequency may be preferred. Another
limitation for the small digital update period is the DSP computation power; a small
digital update period requires a more powerful digital signal processor and may raise the
80
system cost.
Another effect of the digital implementation of the current control is the ripples
caused by the discrete time control. Actually it is the nature of the discrete time control
since the output of the controller is not smooth, instead, the output of the controller is
stair step pattern. Since the plant is usually a low pass filter it will filter out the higher
frequency components and output smooth movement.
With the popularity of the digital implementation of motor control system, the
practical problems in such implementations have attracted a lot of interest. T.A. Sakharuk
and his coworkers presented the analytic result to quantify the effects of low-switching
frequency in ac drives supplied by pulse-width modulation power electronic inverters in
[28]. Their studies focus on the effects of the PWM. Different from the conventional
modeling procedure where the PWM switching frequency is assumed high enough and
the resulting waveform can be replaced by its first order harmonics in the control-
oriented model, their model provides a new PWM gain which accounts for the effects of
low switching frequency. Also a formula for the magnitude of the current ripple is given
using a piecewise linear approximation for the current. The investigation was also made
by Vladimir Blasko and his coworkers on the sampling methods of voltage and current
signals in electric drives. They analyzed the limitation of the bandwidth of a current
controller according to the time delay in the sampling and PWM in [26]. Further analysis
is presented by Bon-Ho Bae in [27].
Using PWMT to indicate the PWM update period and sT to indicate the digital
update period, sT must be greater than PWMT since it is meaningless if the PWM update
period is larger than the digital update period. Usually the digital update period is set as a
81
multiple of the PWM update period, i.e. ( 1, 2,...)s PWMT nT n= = . The total time delay
caused by the digital implementation and PWM is the summation of one digital update
period and one half the PWM update period. Using dT to indicate the total time delay,
2PWM
d sTT T= + [26, 27].
In Bae’s work, the analysis starts from complex vector analysis and the similar
time sequence to that used in our experimental system, which is represented below.
Figure 6-6: Time Sequence of Current Sampling, Calculation and PWM Output
The relationship of vector presentations in the stationary dsqs0s frame and the
rotor synchronous, dq0, frame is demonstrated in Figure 6-7. The superscripts s and e
indicate the stationary and synchronous reference variables respectively, and superscript
* indicates the reference value. The angle between the stationary reference frame and the
synchronous reference frame is eθ , the transformation of the vector present in the two
reference frames is
* *ejs e
dqs dqsv v e θ= (6-7)
* *eje s
dqs dqsi i e θ−= (6-8)
t t+Ts t+2Ts
Current Sampling
Calculation PWM Output
PWM Update
θe θe+Tsωs θe+2Tsωs
82
Figure 6-7: Synchronous Reference Frame Quantities in the Stationary Reference Frame
Under the assumption that the synchronous speed sω is constant during the time
delay, the stator refereed voltage reference for the PWM generation *
_sdqs digitalv by
averaging is [27]
* * *2
( ) (1.5 )_
1 ( , )s
s e s s e
s
Tj j Ts e e
dqs digital dqs s s dqss T
v v e d K T e vT
ω τ θ ω θτ ω+ += =∫ (6-9)
where
2( , ) sin( )2s s
s ss s
TK TT
ωωω
= (6-10)
The error caused by the frame rotation is
*
*
( 1.5 ) ( )
(1.5 ) ( , ) ( , )( , )
e s s D
s s e
j e j T jdqs
error j T es s s ss s dqs
e v e efK T K TK T e v
θ ω θ
ω θ ω ωω
− −
+= = = (6-11)
In Bae’s work, the time delay is replaced by a first order term, whose time
constant is the delay. It is approximated by one sampling period and one half of a PWM
update period. In the design procedure, the delay term will remain. The block diagram
ds
d
qsq
θe
*edqsv
*edsv
*eqsv
83
follows.
Figure 6-8: Complex Vector Block Diagram of Vector Current Control
The frame rotation causes errors on the magnitude and vector phase of the voltage
vector. The magnitude of the voltage is multiplied by the scalar value 1/ ( , )e sK Tω , and
the phase of the voltage vector is delayed by Dθ , which is the rotating angle of the
reference frame during one and a half sampling periods.
The error in the voltage phase causes additional coupling between the d axis and q
axis. It is more obvious if the system is presented as below.
Figure 6-9: System Model of Vector Current Control (1)
p iK s Ks+
( 1.5 )
( , )
s sj T
s s
eK T
ω
ω
−
dT se−1
s s sL s R j Lω+ +
edqsi
*edqsi
edqse
edqsi
Plant Controller
Error Caused By Digital
Implementation
Processing And PWM Delay
p iK s Ks+ 1
( , )s sK Tω dT se−1
sL s R+
s sLω
*eqsi
sqse
-
++
-eqsi
Plant Controller
cos( )Dθ
sin( )Dθ
p iK s Ks+ 1
( , )s sK Tω dT se−1
sL s R+*e
dsisdse
+
++
-edsicos( )Dθ
sin( )Dθs sLω
-
-
+
+
+
-
84
Since the complete system is a multi-input multi-output system, a convenient way
to describe the system is using the state space equation. Using a first order term to replace
the output time delay term in the system, 11
dT s
d
eT s
− ≈+
, and defining the state variables
as indicated in the figure,
Figure 6-10: System Model of Vector Current Control (2)
The state space equation can be defined as below.
x Ax Bu= + (6-12)
y Cx= (6-13)
*
*qs
ds
iu
i
=
, qs
ds
iy
i
=
(6-14)
e sLω
*eqsi
sqse
eqsi
Plant Controller
*edsi
sdse
edsi
e sLω
−
1( , )e sK Tω cos( )Dθ
sin( )Dθ
1s iK
pK
cos( )Dθ
sin( )Dθ
1( , )e sK Tω
1s iK
pK
1s
1
dT−
1
dT1s
s
RL
−
1
sL
1s
s
RL
−
1
sL1s
1
dT−
1
dT
1x
+ +
+ + +
+
+
+
+
−
− −
−
+ +
+
+
+
+
+
+
+
+
+
2x
3x
4x
5x
6x
−
85
1 0 0 0
10 0 0
cos( ) sin( ) cos( ) sin( )1 0( , ) ( , ) ( , ) ( , )
sin( ) cos( ) sin( ) cos( )10( , ) ( , ) ( , ) ( , )1 0 0 0 0 0
ss s
ss s
D p D p D i D i
d s s d s s d d s s d s s
D p D p D i D i
d s s d s s d d s s d s s
RL L
RL L
k k k kA
T K T T K T T T K T T K Tk k k k
T K T T K T T T K T T K T
ω
ω
θ θ θ θω ω ω ωθ θ θ θω ω ω ω
− −
−
− − −=
− − −
−0 1 0 0 0 0
−
,
0 00 0
cos( ) sin( )( , ) ( , )
sin( ) cos( )( , ) ( , )1 00 1
D p D p
d s s d s s
D p D p
d s s d s s
k kT K T T K T
Bk k
T K T T K T
θ θω ωθ θω ω
− =
, 1 0 0 0 0 00 1 0 0 0 0
C
=
(6-15)
In the sine wave current control structure, the digitization and rotor reference
frame rotation cause error on the phase current reference generation. A similar process to
that used in [27] can be used to find such error. Considering the phase current reference
generation process, its purpose is essentially to transform the desired current vector from
the rotor synchronous, dq0, frame to the stationary, abc, frame and results in the phase
current references for each phase. Usually the d axis component of the reference current
vector is zero as discussed previously.
86
Figure 6-11: Rotation of the Synchronous Reference Frame Corresponding to the Time Delay
With the time sequence shown in Figure 6-3, the synchronous reference frame
rotation and the trace of the reference current vector move as shown in Figure 6-11.
Similar to the process to develop (6-11), for the given time t, the corresponding reference
current vector output is from ( st T+ ) to ( 2 st T+ ), under the assumption that the
synchronous frequency sω is constant during the time delay and the current reference
vector for the control loop is derived by averaging the current vector reference from
( st T+ ) to ( 2 st T+ ).
* * *2
( ) (1.5 )_
1 ( , )s
s e s s e
s
Tj j Ts e e
dqs digital dqs s s dqss T
i i e d K T e iT
ω τ θ ω θτ ω+ += =∫ (6-16)
where
2( , ) sin( )2s s
s ss s
TK TT
ωωω
= (6-17)
The error caused by the conventional transformation which is same with (6-12) can be
ds
d(t)
qs
q(t)
θe
*edqsi
d(t+Ts)
d(t+2Ts)
q(t+Ts)
q(t+2Ts)
87
calculated as,
*
*
( 1.5 ) ( )
(1.5 ) ( , ) ( , )( , )
s s D
s s e
j e j T jdqs
error j T es s s ss s dqs
e i e efK T K TK T e i
θ ω θ
ω θ ω ωω
− −
+= = =
Differing from the vector current control structure, the error caused by the synchronous
reference frame rotation is not in the phase current control loops; instead, it is in the
phase current reference generation process as shown in Figure 6-11. One phase current
control loop is shown in Figure 6-12 including the time delay term separately.
Figure 6-12 Phase Current Reference Generation with the Error Caused by Rotation
Figure 6-13: One Phase Current Control Loop in Sine Wave Current Control
6.3. Simulation Models
In the development of current control methods and system modeling, two levels
of simulation models have been developed. The first level simulation model for vector
current control uses the scheme in Figure 6-9, and the first level simulation model for
sine wave current control used the scheme in Figure 6-12 and Figure 6-13. At this level,
all components are continuous. The effects of rotor rotation and digitization are emulated
( )
( , )
Dj
s s
eK T
θ
ω
− Inverse Park’s
Transform
iq*
id*
ia_digital*
ib_digital *
ic_digital *
p iK s Ks+
dT se−1
sL s R+*
_a digitali
afe
-
++
-
ai
Plant Controller
88
by a corresponding continuous gain and time delay. The second level simulation models
use the PMSM model and universal bridge from the SimPowerSystems library in
MATLAB SIMLINK. The controllers are written in C and emulate the control program
used in the experimental system. In Figure 6-14 and 6-15, the first level simulation
models for vector current control and sine wave current control are shown. In Figure 6-16,
the second level simulation model for both of the current control structures is shown.
Figure 6-14: First Level Vector Current Control Simulation Model
Figure 6-15: First Level Sine Wave Current Control Simulation Model
89
Figure 6-16: Second Level Vector and Sine Wave Current Control Simulation Model
6.4. Systematic Design of PMSM Current Control System
For a given current control structure, the design procedure will be to find the
proper digital update frequency and PWM update frequency, and determine the PI
controller gains to satisfy the system requirements like the bandwidth and the maximum
motor speed. In the coming sections, the design procedure will be presented for both
current control structures.
6.4.1. Systematic Design of PMSM Vector Current Control
The complete model of digital implementation of vector current control is
presented in the previous section. In this model, the system is a time varying system. The
coupling between the two axis loops depends on the motor speed and the sampling period.
In the case of low speed, the coupling caused by digital implementation between
90
the d and q axis loops is weak and the electric coupling in the motor is also weak. While
in the high speed condition, the couplings between the two loops become stronger and
even affect the system stability.
Neglecting the coupling between the two loops, each loop can be simplified as
shown in Figure 6-17.
Figure 6-17: Vector Current Control PI Controller Design Model
The term cos( )( , )
D
e sK Tθ
ω is approximately one and can be neglected in the design procedure.
Suppose the desired bandwidth is bf , and the maximum speed is sω . Define the
plant transfer function as 1( ) dT sp
s
G s eL s R
−=+
. The following design is based on the LQ
optimization equations since LQ optimization can guarantee system stability and good
performance. The steps are listed below.
• According to the plant transfer function ( )pG s , the time constant sLTR
= .
Plug it into the equation ( )2
bb
afT T
τπ
= (4-48), the time delay can be found
by 12( )s b s b
dL f LTR aR
πτ= = , where values of a and b depend on the selected LQ
performance index. The resulting time delay is the maximum time delay for
the desired bandwidth. With this resulting time delay and correctly set PI
controller gains, the system is optimized with the desired bandwidth in the
p iK s Ks+ cos( )
( , )D
s sK Tθ
ω dT se−1
sL s R+*
i + -
i
91
sense of the selected performance index.
• From 2
PWMd s
TT T= + , the digital update period and PWM update period can
be determined. Usually s PWMT kT= for 1,2...k = . Considering the issue of the
ripples caused by PWM, it is a good practice to have the PWM update period
less than one-fifth of the motor electrical time constant.
• Determine the PI controller proportional gains pK and integral time constant
iT by (4-45) and (4-46) and corresponding iK .
• Check the system stability by using the complete system state space equation
at maximum speed by (6-12). If the system is unstable at desired high speed,
use a higher bandwidth to repeat the design process.
From this procedure, the digital update frequency and PWM update frequency
will be determined for good performance at low speed. If the system becomes unstable at
the desired high speed, the digital update frequency or PWM update frequency should be
increased. The gain margin and phase margin of the resultant system varies depending on
the LQ design performance index. For the given desired bandwidth, among the three
performance indices, ISE, ISTE and IST2E, ISE usually result in an aggressive design.
This means the resultant system’s digital update frequency and PWM update frequency
are lowest and its stability margin is smallest. Conversely, IST2E usually result in a
conservative design, meaning the resultant system’s digital update frequency and PWM
update frequency are highest and its stability margin is largest.
6.4.2. Systematic Design of PMSM Sine Wave Current Control
The current control system design based on sine wave current control structure
92
has a similar design procedure as the vector current control design procedure.
Since the electric torque is determined by the q axis current in the rotor
synchronous, dq0, frame, it is reasonable to give the system design requirements in the
term of q axis current bandwidth. In the sine wave current control structure, as discussed
previously, the current reference is a sinusoidal function of the rotor position and the
frequency is the electrical frequency of the motor. If the reference current in the rotor
synchronous reference is also sinusoidal, and its frequency is the desired current loop
bandwidth bf , the higher frequency component of the reference current is at 2
sbf
ωπ
+ .
Therefore the current loop bandwidth should be larger than2
sbf
ωπ
+ . The design
procedure is listed below.
• Determine the desired phase current loop bandwidth ' ( )2
sb bf k f ω
π= + . Since
the phase lag will cause the current shift on the d and q axis, and eventually
degrade the torque response, the phase current bandwidth is set to k multiples
of +2
sbf
ωπ
with k=5…10 for the smaller phase lag.
• Plug the phase time constant sLTR
= and the desired phase current loop
bandwidth 'bf into the equation ( )
2b
bafT T
τπ
= (4-48) to determine the total
time delay 12 '( )s b s b
dL f LTR aR
πτ= = . The resulting time delay is the maximum
time delay for the desired bandwidth. With this resulting time delay and
correctly set PI controller gains, the system is optimized with the desired
93
bandwidth in the sense of the selected performance index.
• Use 2
PWMd s
TT T= + to determine the digital update period and PWM update
period. Usually s PWMT kT= for 1,2...k = . Considering the issue of the ripples
caused by PWM, it is a good practice to have the PWM update period be less
than one-fifth of the load time constant, i.e. the motor electrical time constant
in this application.
• Since the error in the phase current reference generation process (see Fig. 6-
15) caused by rotor rotation is not in the closed loop, check the value of
cos( )( , )
D
s sK Tθ
ω, which represent the DC gain on the q axis. To limit the resultant
error to be less than 1%, cos( ) 1 0.01( , )
D
s sK Tθ
ω− < .
• Determine the PI controller proportional gains pK and integral time constant
iT by (4-45) and (4-46), and the corresponding iK
6.5. Design Examples
In this section, the design examples will be presented for the two current control
structures. Both simulated and experimental results will also be presented.
6.5.1. Vector Current Control Design Example
Current Control loop specification:
Bandwidth: 200bf Hz=
Maximum Speed: 2000rpm
94
(1) Maximum Time delay calculation
Use ISTE optimal criterion, 0.6701, -0.9439a b= = for (4-48).
12( ) 5.3040e-004secs b s bd
L f LTR aR
π= =
(2) In this example, the motor electrical time constant is 0.6 msec. The digital update
frequency and PWM update frequency can be found by2
PWMd s
TT T= + , Let
4s PWMT T= , which results in 4.7147e-004sec, 1.1787e-004secs PWMT T= = .
(3) Determine the PI controller gains by the LQ optimal equations. In this example,
the ISTE is used.
22(V/A), 27611(V/A-sec).p iK K= =
In the following figures, the current step responses at different speeds are
presented with simulation data and experimental data. The step response overshoot tend
to increase with increasing speed. This can be explained by observing the roots of the
closed loop system. One pair of complex roots move to right side and will pass the
imaginary axis when the motor operating speed is high enough. This is demonstrated in
Figure 6-18. The simulation and the experimental results show that the model is accurate
in predicting the system stability.
95
Eigenvalues at Different Speeds
-2500.00
-2000.00
-1500.00
-1000.00
-500.00
0.00
500.00
1000.00
1500.00
2000.00
2500.00
-2500.00 -2000.00 -1500.00 -1000.00 -500.00 0.00 500.00
Real
1000 rpm 2000 rpm 3000 rpmImag
Figure 6-18: Eigenvalues for Different Speed
96
Simulation (Level-1, 0rpm)
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1
0 0.005 0.01 0.015 0.02
Time (Sec)
Cur
rent
(Am
p)
Iq Id Iq Command
(a) First Level Simulation
Simulation (Level-2, 0rpm)
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1
0 0.005 0.01 0.015 0.02
Time (Sec)
Cur
rent
(Am
p)
Iq Id Iq Command
(b) Second Level Simulation
97
Experimental Result (0rpm)
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1
0 0.005 0.01 0.015 0.02
Time (Sec)
Cur
rent
(Am
p)
Iq Id Iq Commnad
(c) Experimental Result
Figure 6-19: Simulation and Experimental Result at 0 rpm for Step Response
98
Simulation (Level-1, 1000rpm)
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1
0 0.005 0.01 0.015 0.02
Time (Sec)
Cur
rent
(Am
p)
Iq Id Iq Command
(a) First Level Simulation
Simulation (Level-2, 1000rpm)
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1
0 0.005 0.01 0.015 0.02
Time (Sec)
Cur
rent
(Am
p)
Iq Id Iq Command
(b) Second Level Simulation
99
Experimental Result (1000rpm)
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1
0 0.005 0.01 0.015 0.02
Time (Sec)
Cur
rent
(Am
p)
Iq Id Iq Commnad
(c) Experimental Result
Figure 6-20: Simulation and Experimental Result at 1000rpm for Step Response
100
Simulation (Level-1, 2000rpm)
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1
0 0.005 0.01 0.015 0.02 0.025 0.03
Time (Sec)
Cur
rent
(Am
p)
Iq Id Iq Command
(a) First Level Simulation
Simulation (Level-2, 2000rpm)
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1
0 0.005 0.01 0.015 0.02 0.025 0.03
Time (Sec)
Cur
rent
(Am
p)
Iq Id Iq Command
(b) Second Level Simulation
101
Experimental Result (2000rpm)
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1
0 0.005 0.01 0.015 0.02 0.025 0.03
Time (Sec)
Cur
rent
(Am
p)
Iq Id Iq Commnad
(c) Experimental Result
Figure 6-21: Simulation and Experimental Result at 2000 rpm for step response
102
Simulation (Level-1, 3000rpm)
-30
-20
-10
0
10
20
30
0 0.01 0.02 0.03 0.04 0.05
Time (Sec)
Cur
rent
(Am
p)
Iq Id Iq Command
(a) First Level Simulation
Simulation (Level-2, 3000rpm)
-8
-6
-4
-2
0
2
4
6
0 0.01 0.02 0.03 0.04 0.05
Time (Sec)
Cur
rent
(Am
p)
Iq Id Iq Command
(b) Second Level Simulation
103
Experimental Result (3000rpm)
-2.5
-2
-1.5
-1
-0.5
0
0.5
1
1.5
2
2.5
0 0.01 0.02 0.03 0.04 0.05
Time (Sec)
Cur
rent
(Am
p)
Iq Id Iq Commnad
(c) Experimental Result
Figure 6-22: Simulation and Experimental Result at 3000rpm
104
Simulation (Level-1, 200Hz, 0rpm)
-0.8
-0.6
-0.4
-0.2
0
0.2
0.4
0.6
0.8
0 0.01 0.02 0.03 0.04
Time (Sec)
Cur
rent
(Am
p)
Iq Id Iq Command
(a) First Level Simulation
Simulation (Level-2, 200Hz, 0rpm)
-0.8
-0.6
-0.4
-0.2
0
0.2
0.4
0.6
0.8
0 0.01 0.02 0.03 0.04
Time (Sec)
Cur
rent
(Am
p)
Iq Id Iq Command
(b) Second Level Simulation
105
Experimental Result (200Hz, 0rpm)
-0.8
-0.6
-0.4
-0.2
0
0.2
0.4
0.6
0.8
0 0.01 0.02 0.03 0.04
Time (Sec)
Cur
rent
(Am
p)
Iq Id Iq Commnad
(c) Experimental Result
Figure 6-23: Simulation and Experimental Result at 0 rpm for Sine Wave Command
The simulation and experimental results show that the first and second level
models can demonstrate the main features of the system, and the second level model
tends to be more accurate in the details.
6.5.2. Sine Wave Current Control Design Example
Current Control loop specification:
Bandwidth: 100bf Hz=
Maximum Speed: 1000rpm ( 419 / secs radω = )
(1) Redefine the phase current loop bandwidth
' 5( ) 8332
sb bf f Hzω
π= + =
106
(2) Maximum total time delay calculation
Use ISTE optimal criterion, 0.6701, -0.9439a b= = for (4-48)
12 '( ) 1.1694e-4secs b s bd
L f LTR aR
π= = .
(3) Using a digital update frequency and a PWM update frequency that are equal. The
total time delay will be 1.5 times the digital update period.
/1.5 7.7963e-5secs dT T= = .
(4) At the desired maximum speed, 0.0490radDθ = , cos( ) 1 0.0012 0.01( , )
D
s sK Tθ
ω− = < .
(5) Determine the PI controller gains by the LQ optimal equations.
77(V/A), 122840(V/A-sec)p iK K= =
107
Simulation (Level-1, 0rpm)
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1
0 0.005 0.01 0.015 0.02
Time (Sec)
Cur
rent
(Am
p)
Iq Id Iq Command
(a) First Level Simulation
Simulation (Level-2, 0rpm)
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1
0 0.005 0.01 0.015 0.02
Time (Sec)
Cur
rent
(Am
p)
Iq Id Iq Command
(b) Second Level Simulation
108
Experimental Result (0rpm)
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1
0 0.005 0.01 0.015 0.02
Time (Sec)
Cur
rent
(Am
p)
Iq Id Iq Commnad
(c) Experimental Result
Figure 6-24: Simulation and Experimental Result at 0 rpm for Step Response
109
Simulation (Level-1, 1000rpm)
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1
0 0.005 0.01 0.015 0.02
Time (Sec)
Cur
rent
(Am
p)
Iq Id Iq Command
(a) First Level Simulation
Simulation (Level-2, 1000rpm)
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1
0 0.005 0.01 0.015 0.02
Time (Sec)
Cur
rent
(Am
p)
Iq Id Iq Command
(b) Second Level Simulation
110
Experimental Result (1000rpm)
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1
0 0.005 0.01 0.015 0.02
Time (Sec)
Cur
rent
(Am
p)
Iq Id Iq Commnad
(c) Experimental Result
Figure 6-25: Simulation and Experimental Result at 1000 rpm for Step Response
Simulation (Level-1, 2000rpm)
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1
0 0.005 0.01 0.015 0.02
Time (Sec)
Cur
rent
(Am
p)
Iq Id Iq Command
(a) First Level Simulation
111
Simulation (Level-2, 2000rpm)
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1
0 0.005 0.01 0.015 0.02
Time(Sec)
Cur
rent
(Am
p)
Iq Id Iq Command
(b) Second Level Simulation
Experimental Result (2000rpm)
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1
0 0.005 0.01 0.015 0.02
Time (Sec)
Cur
rent
(Am
p)
Iq Id Iq Commnad
(c) Experimental Result
Figure 6-26: Simulation and Experimental Result at 2000rpm for Step Response
112
Simulation (Level-1, 100Hz, 0rpm)
-0.5
-0.4
-0.3
-0.2
-0.1
0
0.1
0.2
0.3
0.4
0.5
0 0.005 0.01 0.015 0.02
Time (Sec)
Cur
rent
(Am
p)
Iq Id Iq Command
(a) First Level Simulation
Simulation (Level-2, 100Hz, 0rpm)
-0.5
-0.4
-0.3
-0.2
-0.1
0
0.1
0.2
0.3
0.4
0.5
0 0.005 0.01 0.015 0.02
Time (Sec)
Cur
rent
(Am
p)
Iq Id Iq Command
(b) Second Level Simulation
113
Experimental Result (100Hz, 0rpm)
-0.5
-0.4
-0.3
-0.2
-0.1
0
0.1
0.2
0.3
0.4
0.5
0 0.005 0.01 0.015 0.02
Time (Sec)
Cur
rent
(Am
p)
Iq Id Iq Commnad
(c) Experimental Result
Figure 6-27: Simulation and Experimental Result at 0 rpm for 100Hz Sine Wave Command Response
The simulation and experimental results show that the first and second level
simulation models can demonstrate the main system characteristics. The second level
simulation tends to be more accurate in details. In order to control currents effectively at
high speed, the phase current control loops should have higher bandwidth, which requires
a fast digital update frequency and a fast PWM update frequency. Unfortunately a higher
digital update frequency and a higher PWM update frequency will make the system
impractical or raise the cost. The previous results also demonstrate a systematic approach
to the selection of minimum update and PWM frequencies given desired bandwidth and
motor speed.
114
6.6. Automatic Tuning
In the previous sections, the two current control structures have been discussed
and the systematic design procedures are also presented based on LQ design results. In
this section, the tuning process is to be presented based on relay feedback and the LQ
design result. The example system uses the vector current control structure. The digital
update frequency and PWM update frequency are 10kHz . In this example, the relay
without hysteresis is used, and it is implemented in the DSP program. It is applied on the
q axis current control loop.
For the q axis current control loop, the plant can be model as a first order plus
time delay system as discussed previously.
( )1p
K sG s eTs
τ−=+
The DC gain is first tested using open loop test. The applied DC voltage is 20volts,
and the q axis current is 0.6 amps when the motor rotor is held stationary, so the DC gain
can be calculated as
0.6 0.03(A/V)20
K = = .
Figure 6-28 is the experimental test result using the relay with an output
amplitude of 40volts (M=40). The ultimate period can be identified as 0.6ms (Tu=0.6ms),
and the ultimate gain by (3-29)
4 134(V/A)uMkXπ
= =
The time constant and the time delay are approximated below by (3-31) and (3-32).
115
22
22
15.11 4sec
arctan( 1)1.68 4sec
u
u
u
u
K kT e
K ke
ω
πτ
ω
−= = −
− −= = −
The identified time delay approximately 1.5 times the digital update period. This
shows that the modeling of the digital implementation is valid. The identified time
constant also approximates the actual motor time constant.
Experimental Result (0rpm)
-0.5
-0.4
-0.3
-0.2
-0.1
0
0.1
0.2
0.3
0.4
0.5
0 0.005 0.01
Time (Sec)
Cur
rent
(Am
p)
Iq Id
Figure 6-28: Relay Test Result
Using the relay test result, the PI controller gains with various tuning methods
discussed in the previous sections are listed in Table 6-3. In Figure 6-29, the step
responses are shown for the different gain settings.
116
Table 6-3: Auto Tuned PI Controller Gains
Kp(V/A) Ti(sec) Ki(V/A-sec)
ZN 60 5e-4 120000
ISE 86 8e-4 107160
ISTE 64 5.8e-4 111050
Experimental Result (ZN, 0rpm)
-0.3
-0.2
-0.1
0
0.1
0.2
0.3
0.4
0.5
0.6
0 0.005 0.01 0.015 0.02
Time (Sec)
Cur
rent
(Am
p)
Iq Id Iq Commnad
(a) ZN
117
Experimental Result (ISE, 0rpm)
-0.3
-0.2
-0.1
0
0.1
0.2
0.3
0.4
0.5
0.6
0 0.005 0.01 0.015 0.02
Time (Sec)
Cur
rent
(Am
p)
Iq Id Iq Commnad
(b) ISE
Experimental Result (ISTE, 0rpm)
-0.3
-0.2
-0.1
0
0.1
0.2
0.3
0.4
0.5
0.6
0 0.005 0.01 0.015 0.02
Time (Sec)
Cur
rent
(Am
p)
Iq Id Iq Commnad
(c) ISTE
Figure 6-29: Step Responses for Different PI Controller Gain Settings
118
Chapter 7: Conclusion
The objective of this thesis is to investigate the systematic design methods for
DSP-based PMSM current control. Chapter 2 gives a detailed description of the
experimental system used in the thesis. In Chapter 3, the ZN PID control tuning was
reviewed and the relay test was introduced to identify the plant and facilitate the
automatic tuning process. For the first order plus time delay and second order plus time
delay plants, equations have been developed to identify the system parameters. In
Chapter 4, the optimal design of PI/PID control is proposed based on LQ optimization.
For the performance indices of ISE, ISTE and IST2E, empirical formulae for setting the
PI controller gains of a FOPTD plant are developed in a wider range of the normalized
time delay compared with known empirical formulae for the same purpose. The resulting
systems gain margin and phase margin are also presented. Furthermore, the resulting
bandwidth is formulized originally in this thesis as another empirical formula. Like the
case of PI controller design for a FOPTD plant, the set of empirical formulae for an
integral controller design for a pure time delay system are presented originally for the
gain setting and resulting system bandwidth. This set of formulae is useful when pole-
zero cancellation is applied in the PID/PI controller design process. The resulting system
has constant gain margin and phase margin in the studied range of the normalized time
delay, and the values only depend on the selected performance index. In Chapter 5,
vector current control structure and sine wave current structure were examined under
ideal conditions.
In Chapter 6 more accurate system models were presented for the digitally
implemented current control system for both control methods while considering the
119
digital update frequency and PWM frequency. The systematic design processes were
developed for vector current control and sine wave control to determine minimums for
the digital update frequency and PWM frequency, and PI gains according to the desired
bandwidth and maximum motor speed. The validity of the proposed design processes was
tested by simulation and experiments. For a given system, the automatic relay tuning
process can be used to determine the PI controller gains for good performance after it is
implemented. The research shows that the vector current control structure is better than
the sine wave current structure especially in the high speed application. The automatic
tuning example demonstrates the auto tuning process for a vector current control system.
This auto tuning process can be useful for final tuning of the system to account for the
errors in the design model.
In this thesis, the PMSM current loop bandwidth, digital update frequency and
PWM update frequency, and PI controller gains are set by empirical formulae from LQ
design. Actually, the same process can be applied on other known PI controller automatic
tuning rules such as ZN tuning method.
In this thesis, the proposed systematic design methods focus on the system
specifications of bandwidth, gain margin and phase margin. The resulting system is
reasonable in terms of control performance. However, in future research other system
performance measurements such as current ripple might be investigated. The
relationships between current ripple and the digital update frequency and PWM
frequency may be determined to improve the proposed design methods.
120
REFERENCES
[1] Thomas M. Jahns, “Motion Control with Permanent-Magnet AC Machines”,
Proceeding of the IEEE, Vol. 82, No. 8, August, 1994, pp. 1241-1252
[2] Pragasen Pillay and Ramu Krishnan, “Modeling, Simulation, and Analysis of
Permanent-Magnet Motor Drives, Part І: The Permanent-Magnet Synchronous
Motor Drive”, IEEE Transactions on Industry Applications, Vol. 25, No. 2,
March/April 1989, pp. 265-273
[3] Rajashekara, K., Kawamura, A., "Sensorless control of permanent magnet AC
motors",Industrial Electronics, Control and Instrumentation, 1994. IECON '94.,
20th International Conference on , Volume: 3 , 5-9 Sept. 1994, pp. 1589 - 1594
vol.3
[4] Toliyat, H.A., Hao, L., Shet, D.S., Nondahl, T.A., "Position-sensorless control of
surface-mount permanent-magnet AC (PMAC) motors at low speeds", Industrial
Electronics, IEEE Transactions on , Volume: 49 , Issue: 1 , Feb. 2002, pp. 157 –
164
[5] Nahid-Mobarakeh, B., Meibody-Tabar, F., Sargos, F.-M., "Mechanical sensorless
control of PMSM with online estimation of stator resistance", Industry
Applications, IEEE Transactions on , Volume: 40 , Issue: 2 , March-April 2004,
pp. 457 - 471
[6] D.W. Novotny, and T.A. Lipo, “Vector Control and Dynamics of AC Drives”,
Oxford Science Publications, 1998. p46.
[7] Bolopion, A., Jouve, D., and Pacaut, R., “Control of Permanent Magnets
Synchronous Machines: a Simulation Comparative Survey”, Power Electronics
121
Specialists Conference, 1990. PESC '90 Record., 21st Annual IEEE , 11-14 June
1990, pp. 374-383
[8] Jouve, D., Rognon, J.P., and Roye, D., “Effective Current and Speed Controllers
for Permanent Magnet Machines: a Survey”, Applied Power Electronics
Conference and Exposition, 1990. APEC '90, Conference Proceedings 1990.,
Fifth Annual , 11-16 March 1990, pp. 384-393
[9] Kazmierkowski, M.P., and Malesani, L., “Current Control Techniques for Three-
phase Voltage-source PWM Converters: a Survey”, Industrial Electronics, IEEE
Transactions on , Volume: 45 , Issue: 5 , Oct. 1998, pp. 691-703
[10] Champenois, G., Mollard, P., Rognon, J.P.,"Two Digital Torque Control
Structures for Inverter Fed Permanent Magnets Sinusoidal Synchronous
Machines", Industrial Electronics Society, 1988. IECON '88. Proceedings., 14
Annual Conference of ,Volume: 3 , 24-28 October 1988, pp. 725 – 730
[11] Y. Baudon, D. Jouve, JP. Rognon, "Influence of Control Strategy on Neutral
Point Voltage Behaviour in Permanent Magnet Synchronous Machines", Power
Electronics Specialists Conference, 1989. PESC '89 Record., 20th Annual IEEE ,
26-29 June 1989, pp. 784 - 790 vol.2
[12] Champenois, G., Mollard, P., Rognon, J.P., "Effective digital torque control
systems for permanent magnets converter fed sinusoidal synchronous
machines",Industry Applications Society Annual Meeting, 1988., Conference
Record of the 1988 IEEE , 2-7 Oct. 1988, pp. 259 - 265 vol.1
[13] T.M. Rowan, R.J. Kerkman, "A New Synchronous Current Regulator and an
Analysis of Current Regulator PWM inverter", IEEE-IA.22 n4, July/August 86
122
[14] Ziegler J.G. and Nichols N.B. “Optimum Setting for Automatic Controllers”
Trans. ASME 1942 65, pp. 433-444
[15] Astrom, K.J. and Hagglund, T. “Automatic Tuning of PID Controllers” , ISA,
1988
[16] Astrom, K.J., and Hagglund, T., "Automatic Tuning of Simple Regulators with
Specification on Phase and Amplitude Margin", Automatica, 1984, 20,(5) pp.
645-651
[17] “Honeywell’s History and Philosophy in the Adaptive Control Field. Proc. Self
Adaptive Flight Control Symposium, Wright Patterson AFB, Ohio, Wright Air
Development Center
[18] Astrom, K.J., and Hagglund, T., "Industrial Adaptive Controllers Based on
Frequency Response Techniques", Automatica, 1991, 27, (4), pp. 599-609
[19] Brian L. Stevens and Frank L. Lewis, “Aircraft Control and Simulation”, Second
Edition, Wiley, 2003
[20] M. Zhuang, and D.P. Atherton, “Automatic Tuning of Optimum PID Controllers”,
IEE Proceedings-D, Vol. 140, No. 3, May, 1993, pp. 216-224
[21] F. Blaaske, "The Principle of Field Orientation as Applied to the New Transvector
Closed-loop Control System for Rotating Field Machines", Siemens Review, vol.
34, pp. 217-220, 1972
[22] P. Pillay, “Vector Control of AC Permanent Magnet Machines” Electrical
Machines and Drives, 1989. Fourth International Conference, pp. 293-297
[23] M.F. Rahman, K.S. Low, and K.W. Lim “Approaches to the Control of Torque
and Current in a Brushless DC Drive” Electrical Machines and Drives, 1993.
123
Sixth International Conference on (Conf. Pub. No. 376) , 8-10 Sep 1993, pp. 594-
599
[24] A.E. Fitzgerald, Charles Kingsley, Jr. and Stephen D. Umans, “Electric
Machinery”, Sixth Edition, McGraw Hill, 2003
[25] Richard Valentine, “Motor Control Electronics Handbook”, McGraw Hill, 1998
[26] Vladimir Blasko, Vikram Kaura, and Walter Niewiadomski , “Sampling of
Discontinuous Voltage and Current Signals in Electrical Drives: A System
Approach”, IEEE Transaction on Industry Applications, Vol.34, No.5,
September/October 1998, pp. 1123-1130
[27] Bon-Ho Bae, Seung-Ki Sul, “A Compensation Method for Time Delay of Full-
Time Synchronous Frame Current Regulator of PWM AC Drives”, IEEE
Transaction on Industry Applications, Vol.39, No.3, May/June 2003, pp. 802-810
[28] T.A.Sakharuk, A.M.Stankovic, G.Tadmor, and G.Eirea “Modeling of PWM
Inverter-Supplied AC Drives at Low Switching Frequencies”, IEEE Transaction
Circuits and Systems: Fundamental Theory and Applications,Vol.49, No.5, May
2002, pp. 621-631
124
Appendix A: Current Control DSP Program Source Code
• File Name: dmcmsg.h
/************************************************************************/
/************** HOST-DSP COMMUNICATION CONSTANTS **********************/
#define GET_STATUS 0x30 // dsp updates the status structure with its values
#define GET_GAINS 0x40 // dsp updates the gain structure with its values
#define GET_POS 0x50 // dsp updates the postion structure with its values
#define CHANGE_GAINS 0x60 // dsp reads gains from gain structure
#define RESET 0x70 // reset all encoders and commands
#define CHANGE_PARAMS 0x80 // dsp reads the mag used for steps and periodic waveforms
#define ENABLE_LIMIT 0xA0 // set error limit mode
#define DISABLE_LIMIT 0xB0 // disable error limit mode
#define START_STORE 0xC0 // start storing data
#define STOP_STORE 0xD0 // stop storing data
/************************************************************************/
/*********** Constants for Drive motor ***************************/
#define DRV_STEP_DN_I 0x1100 // decrement the current command
#define DRV_STEP_UP_I 0x1110 // increment the current command
#define DRV_STEP_DN_P 0x1200 // decrement the pos command
#define DRV_STEP_UP_P 0x1210 // increment the pos command
#define DRV_STEP_DN_V 0x1300 // decrement the vel command
#define DRV_STEP_UP_V 0x1310 // increment the vel command
#define DRV_NOWAVE 0x1500
#define DRV_START_SINE 0x1510 // start a sine wave
#define DRV_START_SQUARE 0x1520 // start a square wave
#define DRV_CURRENT_CONTROL 0x1600 //ste the drive motor into the current control loop
#define DRV_POS_CONTROL 0x1610 //set the drive motor into the position control loop
#define DRV_VEL_CONTROL 0x1620 //set the drive motor into the velocity control loop
#define ENABLE_DRV_CNTRL 0x1710 //enable the Drive motor Amps
#define DISABLE_DRV_CNTRL 0x1700 //disable the Drive motor Amps
125
/****************************************************************************/
/************** STRUCTURES SHARED BY HOST AND DSP ********************/
typedef struct
float Drv_Kp,Drv_Ki,Drv_Kd,Drv_NH,Drv_PosErrLimit; // Parameters for position control for the
//drive motor
float Drv_Kpi,Drv_Kii,Drv_Kt,Drv_IErrLimit, Drv_Feedback_Kp; // Parameters for current/torque
//control for the drive motor
float Dyn_Kp, Dyn_Ki, Dyn_Kd, Dyn_NH, Dyn_PosErrLimit; //Parameters for the
//position control loop of the dyno motor
float IaOffset, IaScale;
float IbOffset, IbScale;
float IcOffset, IcScale;
float IBusOffset, IBusScale;
float VBusOffset, VBusScale;
float TorqOffset, TorqScale;
GainStruct;
typedef struct
float Drv_Iq, Drv_IqCom, Drv_Th, Drv_ThCom, Drv_Vel, Drv_VelCom;
float Dyn_IqCom, Dyn_Th, Dyn_ThCom, Dyn_Vel, Dyn_VelCom;
float Drv_Ibus, Drv_Vbus,Torque;
unsigned int Diagnose, ComCount, ErrLimitFlag, DataReady;
PosStruct;
typedef struct
float CurMag, ThMag, VelMag, WaveFreq, SampleFreq;
unsigned int ErrLimitMode, StoreMode;
unsigned int Drv_CntrlMode, Drv_WaveMode, EnableDrvCntrl;
unsigned int Dyn_CntrlMode, Dyn_WaveMode, EnableDynCntrl;
unsigned int DataPtr, TestAxis;
StatusStruct;
typedef struct
float StrokeTime; // Time for the Stroke
ProfileStruct;
126
/************************************************************************/
/************** EXTERNAL MEMORY MANAGEMENT **************************/
// There are 131072 (128K) words of external memory on the MC8 board
// The following allocates some of this
// The dsp program probably allocates 10,000 words for a cos lookup at the end
// of the external memory
#define EXMEM_BASE 0x400000 //start of external memory
#define HANDSHAKE EXMEM_BASE //handshake integer
#define GAINLEN 27 //length of gain structure
#define POSLEN 18 //length of position structure
#define STATUSLEN 15 //length of status structure
#define PROFILELEN 1 //length of profile structure
#define GAINSTART (EXMEM_BASE + 1)
#define POSSTART (GAINSTART + GAINLEN)
#define STATUSSTART (POSSTART + POSLEN) //start of status structure
#define PROFILESTART (STATUSSTART + STATUSLEN) //start of profile structure
#define DATA1START (PROFILESTART + PROFILELEN) //start of data buffer1
#define DAT_NUM 28 // number of data elements stored each sample
#define SAMPLE_NUM 2048 // number samples stored in circular buffer changed from 2000 to
//2048/yt
#define DATA2START (DATA1START + DAT_NUM*SAMPLE_NUM) //start of data buffer2
127
• File Name: dmc.c
#include <21060.h>
#include <signal.h>
#include <stdlib.h>
#include <math.h>
#include "dmcmsg.h"
/************************************************************************/
/************** internal function prototypes **************************/
void servo_loop(int sig);
void get_velocities(void);
void get_all_adcs(float adcs[8]);
void output_dacs07(float dacs[8]);
void init_pointers(void);
void init_interrupts(void);
void handle_msg(unsigned int msg_type);
void gen_commands(void);
void store_data(void);
void gen_cos_table(void);
void update_status(void);
void update_gains(void);
void update_pos(void);
void init_globals(void);
void output_3ph_pwms(float Va, float Vb, float Vc, float Vbus);
int read_resolver_absolute(void);
void reset_gate_driver(void);
void vector_cntrl(void);
void B_PI(void); //biliear PI controller
void sine_cntrl();
void Sinewave_PI(void)
void cmd_reset();
/************************************************************************/
/************** constants *********************************************/
#define BASE 0x480000 // base register address for MC8 registers
#define DT 0.00047 //0.0001 //0.00011//0.0001 // inverse of servo freq (delta T)
#define QMODEVAL 0x1310 // rollover bit always zero, don't allow rollover,
// Tmin is 64 us, reset the encoder
#define PWMPERIOD 0xDBF // Tpwm=0.11msec
128
#define PWMDEAD 0x020 // 0x20 is a 1 usec dead time with a 32 MHz clock
#define VBUS 330.0 // Nominal bus voltage of inverter
#define PHASE_MAX_CURRENT 1.9 //peak stall current of the drive motor
/************************************************************************/
/*** pointers to registers and structures, should be constants ********/
int *DIGOUTD,*DAC,*ADC,*SOFTSYNC,*OEDIG,*DIGINA,*QDCOUNT,*QDMODE, *VEL;
int *PWMtop,*PWMbot,*PWMCnt,*PWMEn,*PWMLE;
float *COSTABLE, *DATA1, *DATA2;
unsigned int *HNDSHK;
GainStruct *GAIN;
PosStruct *POS;
StatusStruct *STATUS;
ProfileStruct *PROF;
/************************************************************************/
/************** general global variables **************************************/
float CurMag, ThMag, VelMag, WaveFreq, SampleFreq;
unsigned int ErrLimitMode=1, StoreMode=0, ErrLimitFlag=0;
unsigned int DataPtr=0, StoreDelay=20;
unsigned int Diagnose = 0, ComCount = 0;
unsigned int DataReady = 0, DataReadyPtr;
volatile unsigned int IntrptCount=0;
float DataTime=0;
float Th1Scale, Th2Scale,TorqScale,TorqOffset,VbusScale,VbusOffset;
float IaScale,IaOffset,IbScale,IbOffset,IcScale,IcOffset,IbusScale,IbusOffset;
float Torque;
/******Global variables for the drive motor control*********/
float Drv_Kp,Drv_Ki,Drv_Kd,Drv_NH,Drv_PosErrLimit; // Parameters for position control for the
//drive motor
float Drv_Kpi,Drv_Kii,Drv_Kt,Drv_IErrLimit, Drv_Feedback_Kp; // Parameters for current/torque
//control for the drive motor
float Drv_Id, Drv_Iq, Drv_IqCom, Drv_Th, Drv_ThCom, Drv_Vel, Drv_VelCom; //Position ststus of
//the drive motor
unsigned int Drv_CntrlMode, Drv_WaveMode, EnableDrvCntrl;
float Drv_Umax, Drv_Imax; //for the device safety
float Drv_UOffset; //To compensate the d/a offset
float Drv_IComOffset,Drv_ThComOffset,Drv_VelComOffset; //for the wave mode of the drive motor
//int ThElec;
129
float Drv_Ibus,Drv_Ia,Drv_Ib,Drv_Ic,Drv_Vbus,Drv_Va,Drv_Vb,Drv_Vc,Drv_Vd,Drv_Vq;
float Drv_Orig_Va, Drv_Orig_Vb, Drv_Orig_Vc; //the exact values just after PI controller
float Drv_IaCom, Drv_IbCom, Drv_IcCom; // for the comparation with sinewave control
/************************************************************************/
/************************************************************************/
void main (void)
unsigned int i, msg_type;
int flag = 0;
float PhaseVolts[3];
init_pointers();
init_globals();
gen_cos_table();
init_interrupts();
*PWMCnt=(PWMPERIOD-1); *PWMEn=0xff00; //set PWM freq and disable PWM outputs
*OEDIG=0x0003; // enable digital output port
*DIGOUTD=0x0000; //yt According to the circuit logic, clear PD3 to disable L180
for (i=0;i<4;i++)
QDCOUNT[i]=0; QDMODE[i]=QMODEVAL;
// reset all encoders
while (!IntrptCount);
i=read_resolver_absolute();
QDCOUNT[0]=i; QDMODE[0]=QMODEVAL;
QDCOUNT[1]=i; QDMODE[1]=QMODEVAL; // reset both encoders
Drv_IqCom=0; Drv_ThCom=Th1Scale*i;
cmd_reset();
*HNDSHK = 0;
while(1) // loop looking for message from host
if ((*HNDSHK) & 0x80000000) // if msg from host
msg_type=(*HNDSHK)&0x0ffffff0;
handle_msg(msg_type); // handle the msg
*HNDSHK = 0; // write a handshake
ComCount++; // DIAGNOSE CAN BE PUT ANYWHERE AND SET TO
//ANYTHING
// IT WILL BE PRINTED TO THE SCREEN EVERY 0.25 Sec
130
/************************************************************************/
/************************************************************************/
void handle_msg(unsigned int msg_type)
unsigned int i;
if(msg_type == ENABLE_DRV_CNTRL)
Drv_ThCom=Drv_Th; Drv_IqCom=0.0; Drv_VelCom=0.0;
reset_gate_driver(); EnableDrvCntrl=1;
else if(msg_type == DISABLE_DRV_CNTRL)
EnableDrvCntrl = 0;
else if(msg_type == GET_STATUS)
update_status();
else if(msg_type == GET_GAINS)
update_gains();
else if(msg_type == GET_POS)
update_pos();
else if(msg_type == CHANGE_GAINS)
EnableDrvCntrl = 0;
Drv_Kp=GAIN->Drv_Kp; Drv_Ki=GAIN->Drv_Ki; Drv_Kd=GAIN->Drv_Kd;
Drv_NH=GAIN->Drv_NH;
Drv_PosErrLimit=GAIN->Drv_PosErrLimit;
Drv_Kpi=GAIN->Drv_Kpi; Drv_Kii=GAIN->Drv_Kii; Drv_Kt=GAIN->Drv_Kt;
Drv_IErrLimit=GAIN->Drv_IErrLimit;
Drv_Feedback_Kp = GAIN->Drv_Feedback_Kp;
IaOffset = GAIN->IaOffset; IaScale = GAIN->IaScale;
IbOffset = GAIN->IbOffset; IbScale = GAIN->IbScale;
IcOffset = GAIN->IcOffset; IcScale = GAIN->IcScale;
IbusOffset = GAIN->IBusOffset; IbusScale = GAIN->IBusScale;
VbusOffset = GAIN->VBusOffset; VbusScale = GAIN->VBusScale;
TorqOffset = GAIN->TorqOffset; TorqScale = GAIN->TorqScale;
else if(msg_type == RESET)
cmd_reset();
131
else if(msg_type == CHANGE_PARAMS)
EnableDrvCntrl = 0;
CurMag=STATUS->CurMag; ThMag=STATUS->ThMag; VelMag=STATUS->VelMag;
if (STATUS->WaveFreq > 1.0/(10.0*DT))
WaveFreq = 1.0/(10.0*DT);
else if (STATUS->WaveFreq < 0.01)
WaveFreq = 0.01;
else
WaveFreq = STATUS->WaveFreq;
if ((STATUS->SampleFreq > 1.0/DT) || (STATUS->SampleFreq < 10.0))
StoreDelay = 1;
else
StoreDelay = 1/DT/STATUS->SampleFreq;
else if(msg_type == ENABLE_LIMIT)
ErrLimitMode = 1;
else if(msg_type == DISABLE_LIMIT)
ErrLimitFlag=ErrLimitMode = 0;
else if(msg_type == DRV_STEP_DN_I)
Drv_IqCom -= CurMag;
else if(msg_type == DRV_STEP_UP_I)
Drv_IqCom += CurMag;
else if(msg_type == DRV_NOWAVE)
Drv_WaveMode=DRV_NOWAVE;
else if(msg_type == DRV_START_SINE)
Drv_IComOffset=Drv_IqCom; Drv_ThComOffset=Drv_ThCom;
Drv_VelComOffset=Drv_VelCom;
Drv_WaveTime = 0; Drv_WaveMode=DRV_START_SINE;
else if(msg_type == DRV_START_SQUARE)
Drv_IComOffset=Drv_IqCom; Drv_ThComOffset=Drv_ThCom;
132
Drv_VelComOffset=Drv_VelCom;
Drv_WaveTime = 0; Drv_WaveMode=DRV_START_SQUARE;
else if(msg_type == DRV_CURRENT_CONTROL)
Drv_CntrlMode = DRV_CURRENT_CONTROL;
else if(msg_type == START_STORE)
DataPtr=0; DataTime=0; StoreMode=1;
else if(msg_type == STOP_STORE) StoreMode=0;
/************************************************************************/
/***** update the status structure read and written by the host *********/
void update_status(void)
STATUS->CurMag=CurMag; STATUS->ThMag=ThMag; STATUS->VelMag=VelMag;
STATUS->WaveFreq=WaveFreq; STATUS->SampleFreq=1.0/DT/StoreDelay;
STATUS->Drv_WaveMode=Drv_WaveMode; STATUS->Drv_CntrlMode=Drv_CntrlMode;
STATUS->Dyn_WaveMode=Dyn_WaveMode; STATUS->Dyn_CntrlMode=Dyn_CntrlMode;
STATUS->ErrLimitMode=ErrLimitMode;
STATUS->EnableDrvCntrl = EnableDrvCntrl;
STATUS->EnableDynCntrl = EnableDynCntrl;
STATUS->StoreMode=StoreMode; STATUS->DataPtr=DataPtr;
/************************************************************************/
/**** update the message structure read and written by the host *********/
void update_gains(void)
GAIN->Drv_Kp=Drv_Kp; GAIN->Drv_Ki=Drv_Ki;
GAIN->Drv_Kd=Drv_Kd; GAIN->Drv_NH=Drv_NH;
GAIN->Drv_PosErrLimit=Drv_PosErrLimit; GAIN->Drv_Kpi=Drv_Kpi;
GAIN->Drv_Kii=Drv_Kii; GAIN->Drv_Kt=Drv_Kt;
GAIN->Drv_IErrLimit=Drv_IErrLimit;
GAIN->Drv_Feedback_Kp = Drv_Feedback_Kp;
GAIN->IaOffset = IaOffset; GAIN->IaScale = IaScale;
GAIN->IbOffset = IbOffset; GAIN->IbScale = IbScale;
GAIN->IcOffset = IcOffset; GAIN->IcScale = IcScale;
GAIN->IBusOffset = IbusOffset; GAIN->IBusScale = IbusScale;
GAIN->VBusOffset = VbusOffset; GAIN->VBusScale = VbusScale;
133
GAIN->TorqOffset = TorqOffset; GAIN->TorqScale = TorqScale;
/************************************************************************/
/**** update the message structure read and written by the host *********/
void update_pos(void)
POS->Drv_Iq=Drv_Iq; POS->Drv_IqCom=Drv_IqCom;
POS->Drv_Th=Drv_Th; POS->Drv_ThCom=Drv_ThCom; POS->Drv_Vel=Drv_Vel;
POS->Drv_VelCom=Drv_VelCom;
POS->Drv_Ibus=Drv_Ibus; POS->Drv_Vbus=Drv_Vbus; POS->Torque=Torque;
POS->Diagnose=Diagnose; POS->ComCount=ComCount;
POS->ErrLimitFlag=ErrLimitFlag, POS->DataReady=DataReady;
/************************************************************************/
/** with pwm outputs high for >12 usec pull reset pin lo for >2 usec ****/
void reset_gate_driver(void)
EnableDrvCntrl=0; *PWMEn=0xff00; //disable PWM outputs
IntrptCount=0; while(IntrptCount<2); // Wait for at least one full servo cylcle
*DIGOUTD=*DIGOUTD&0xFFFB; // Clear RESET
IntrptCount=0; while(IntrptCount<2); // Wait for at least one full servo cylcle
*DIGOUTD=*DIGOUTD|0x0004; // Set RESET
/************************************************************************/
/************************************************************************/
void servo_loop(int sig)
float dacs[8], adcs[8];
int i;
static float buf_Ia[5]=0, 0, 0, 0, 0, buf_Ib[5]=0, 0, 0, 0, 0, buf_Ic[5]=0, 0, 0, 0, 0;
static int buf_pos=0;
float ave_DrvIa, ave_DrvIb, ave_DrvIc;
IntrptCount++;
*DIGOUTD = *DIGOUTD|0x0010; // Set PD4 for scope watch
*DIGOUTD = *DIGOUTD^0x0020; // Toggle PD5 for scope watch
get_all_adcs(adcs);
Drv_Ia=IaScale*(adcs[0]+IaOffset); Drv_Ib=IbScale*(adcs[1]+IbOffset);
Drv_Ic=IcScale*(adcs[2]+IcOffset); Drv_Ibus=IbusScale*(adcs[3]+IbusOffset);
Drv_Vbus=VbusScale*(adcs[4]+VbusOffset); Torque=TorqScale*(adcs[5]+TorqOffset);
134
Drv_Th=Th1Scale*QDCOUNT[0]; // read encoders
ThElec=QDCOUNT[0]; ThElec=ThElec-(ThElec/1024)*1024; //ThElec=ThElec-(ThElec/1024)*1024-
//256; inverse qd axis used in blocked rotor test for d axis
if (ThElec<0) ThElec=1024+ThElec;
get_velocities();
gen_commands();
//Depend on the used control structure, the unused used control structure should be commented
//vect_cntrl() for vector current control
//sine_cntrll for sine wave current control
vector_cntrl(); //vector current control
//sine_cntrl(); //sine wave current control
if (StoreMode) store_data(); //store data in external memory
output_dacs07(dacs);
*SOFTSYNC=0x0001; // writing any value generates a sync signal
if (ErrLimitFlag) EnableDrvCntrl=0; // do after store_data
if (EnableDrvCntrl)
*PWMEn=0xFFFF; // enable PWM outputs
else
*PWMEn=0xFF00; // disable PWM outputs
*DIGOUTD = *DIGOUTD & 0xFFEF; // clear bit PD4 for scope watch
/************************************************************************/
/************************************************************************/
void vector_cntrl(void)
int Th2pi3, Th_2pi3, Th_90, Th2pi3_90, Th_2pi3_90;
float P[2][3];
Th2pi3=ThElec+341; if(Th2pi3 > 1023) Th2pi3 -= 1024;
Th_2pi3=ThElec-341; if(Th_2pi3 < 0) Th_2pi3 += 1024;
Th_90=ThElec-256; if(Th_90 < 0) Th_90 += 1024;
Th2pi3_90=ThElec+85; if(Th2pi3_90 > 1023) Th2pi3_90 -= 1024;
Th_2pi3_90=ThElec-597; if(Th_2pi3_90 < 0) Th_2pi3_90 += 1024;
P[0][0]=COSTABLE[ThElec]; P[0][1]=COSTABLE[Th_2pi3]; P[0][2]=COSTABLE[Th2pi3];
P[1][0]=COSTABLE[Th_90]; P[1][1]=COSTABLE[Th_2pi3_90]; P[1][2]=COSTABLE[Th2pi3_90];
//According the Parkson transform, a factor 2/3 needed from the phase coordinte to the dq coordinate
Drv_Id = 0.666666667*(P[1][0]*Drv_Ia+P[1][1]*(-Drv_Ia-Drv_Ic)+P[1][2]*Drv_Ic);
Drv_Iq = 0.666666667*(P[0][0]*Drv_Ia+P[0][1]*(-Drv_Ia-Drv_Ic)+P[0][2]*Drv_Ic);
B_PI(); //ErrLimitFlag set in here
135
Drv_Va = (P[0][0]*Drv_Vq+P[1][0]*Drv_Vd);// /VBUS;
Drv_Vb = (P[0][1]*Drv_Vq+P[1][1]*Drv_Vd);// /VBUS;
Drv_Vc = (P[0][2]*Drv_Vq+P[1][2]*Drv_Vd);// /VBUS;
if ((Drv_Vc <= Drv_Va)&&(Drv_Vc <= Drv_Vb))
Drv_Va=Drv_Va-Drv_Vc; Drv_Vb=Drv_Vb-Drv_Vc; Drv_Vc=0;
if ((Drv_Va >= Drv_Vb)&&(Drv_Va > VBUS))
Drv_Vb=Drv_Vb/Drv_Va*VBUS; Drv_Va=VBUS;
else if (Drv_Vb > VBUS)
Drv_Va=Drv_Va/Drv_Vb*VBUS; Drv_Vb=VBUS;
else if ((Drv_Vb <= Drv_Va)&&(Drv_Vb <= Drv_Vc))
Drv_Va=Drv_Va-Drv_Vb; Drv_Vc=Drv_Vc-Drv_Vb; Drv_Vb=0;
if ((Drv_Va >= Drv_Vc)&&(Drv_Va > VBUS))
Drv_Vc=Drv_Vc/Drv_Va*VBUS; Drv_Va=VBUS;
else if (Drv_Vc > VBUS)
Drv_Va=Drv_Va/Drv_Vc*VBUS; Drv_Vc=VBUS;
else
Drv_Vb=Drv_Vb-Drv_Va; Drv_Vc=Drv_Vc-Drv_Va; Drv_Va=0;
if ((Drv_Vb >= Drv_Vc)&&(Drv_Vb > VBUS))
Drv_Vc=Drv_Vc/Drv_Vb*VBUS; Drv_Vb=VBUS;
else if (Drv_Vc > VBUS)
Drv_Vb=Drv_Vb/Drv_Vc*VBUS; Drv_Vc=VBUS;
Diagnose=ThElec;
output_3ph_pwms(Drv_Va,Drv_Vb,Drv_Vc,VBUS);
/************************************************************************/
136
/************************************************************************/
void output_3ph_pwms(float Va, float Vb, float Vc, float Vbus)
float duty, Voltage[3];
int HalfPeriod, TopCount, BotCount, i;
Voltage[0]=Va; Voltage[1]=Vb; Voltage[2]=Vc;
HalfPeriod = (int)(PWMPERIOD/2);
for(i=0;i<3;i++)
duty = Voltage[i]/Vbus;
if (duty > 1.0) duty = 1.0;
else if (duty < 0.0) duty = 0.0;
BotCount = (int)(duty*HalfPeriod); TopCount =(int) (BotCount-PWMDEAD);
if (TopCount < 0) TopCount = 0;
PWMtop[i]=0x80000000 + ((HalfPeriod+TopCount)<<16) + (HalfPeriod-TopCount);
PWMbot[i]=((HalfPeriod+BotCount)<<16) + (HalfPeriod-BotCount);
*PWMLE = 0x00;
/************************************************************************/
/************************************************************************/
int read_resolver_absolute(void)
// PD0 = SCLK, PD1=NotCS, PA0 = Data
int ResolverValue=0, i, PlaceValue=2048;
*DIGOUTD=*DIGOUTD&0xFFFE; // Clear SCLK
*DIGOUTD=*DIGOUTD|0x0002; // Set Chip Select
IntrptCount=0; while(IntrptCount<2); // Wait for at least one full servo cylcle
*DIGOUTD=*DIGOUTD&0xFFFD; // Clear Chip Select
IntrptCount=0; while(IntrptCount<2); // Wait for at least one full servo cylcle
for(i=0;i<12;i++)
*DIGOUTD=*DIGOUTD|0x0001; // Set SCLK
IntrptCount=0; while(IntrptCount<2); // Wait for at least one full servo cylcle
*DIGOUTD=*DIGOUTD&0xFFFE; // Clear SCLK
IntrptCount=0; while(IntrptCount<2); // Wait for at least one full servo cylcle
ResolverValue += PlaceValue*(*DIGINA & 0x0001); //Read a bit of data
PlaceValue = PlaceValue>>1; // Divide place holder value by 2
*DIGOUTD=*DIGOUTD|0x0002; // Set Chip Select
return (ResolverValue);
137
/************************************************************************/
/************************************************************************/
void get_velocities(void)
float velocity[2];
int DxDt, Dx, Dt, i;
for(i=0;i<2;i++)
DxDt = VEL[i];
Dt = DxDt & 0xffff;
if (Dt == 0xffff)
velocity[i] = 0.0;
else
Dx = (DxDt>>16) & 0x3ff;
if (Dx & 0x200) Dx = Dx | 0xfffffc00;
velocity[i] = Dx*32.0E6/Dt;
Drv_Vel = Th1Scale*velocity[0]/6.0;
/************************************************************************/
/************************************************************************/
void store_data(void)
static int count=0;
unsigned int mem_ptr, i;
count++;
if (count >= StoreDelay)
count = 0; DataPtr++;
if (DataPtr > (SAMPLE_NUM-1)) DataPtr=0;
DataTime = DataPtr*DT*StoreDelay;
mem_ptr = DataPtr*DAT_NUM;
//Time,Th1,Th2,ThCom,Vel1,Vel2,VelCom,Toruqe,IqCom,Iq,Id,Ibus,Ia,Ib,Ic,Vbus,Va,Vb,Vc,
//Uamp
//Drv_IaCom Drv_IbCom Drv_IcCom Drv_Orig_Va Drv_Orig_Vb Drv_Orig_Vc Drv_Vq
//Drv_Vd
DATA1[mem_ptr]=DataTime; DATA1[mem_ptr+1]=Drv_Th;
DATA1[mem_ptr+3]=Drv_ThCom; DATA1[mem_ptr+4]=Drv_Vel;
138
DATA1[mem_ptr+6]=Drv_VelCom; DATA1[mem_ptr+7]=Torque;
DATA1[mem_ptr+8]=Drv_IqCom; DATA1[mem_ptr+9]=Drv_Iq;
DATA1[mem_ptr+10]=Drv_Id; DATA1[mem_ptr+11]=Drv_Ibus;
DATA1[mem_ptr+12]=Drv_Ia; DATA1[mem_ptr+13]=Drv_Ib;
DATA1[mem_ptr+14]=Drv_Ic; DATA1[mem_ptr+15]=Drv_Vbus;
DATA1[mem_ptr+16]=Drv_Va; DATA1[mem_ptr+17]=Drv_Vb;
DATA1[mem_ptr+18]=Drv_Vc; DATA1[mem_ptr+22]=Drv_IcCom;
DATA1[mem_ptr+23]=Drv_Orig_Va; DATA1[mem_ptr+24]=Drv_Orig_Vb;
DATA1[mem_ptr+25]=Drv_Orig_Vc; DATA1[mem_ptr+26]=Drv_Vq;
DATA1[mem_ptr+27]=Drv_Vd;
/************************************************************************/
/************************************************************************/
void gen_commands(void)
int Drv_SinIndex;
Drv_WaveTime += DT;
if (Drv_WaveTime >= 1/WaveFreq) Drv_WaveTime -= 1/WaveFreq;
Drv_SinIndex = 1024.0*(Drv_WaveTime*WaveFreq) - 256;
if (Drv_SinIndex < 0) Drv_SinIndex += 1024;
/*********Drive motor command generator*************/
if(Drv_CntrlMode==DRV_CURRENT_CONTROL)
if(Drv_WaveMode==DRV_NOWAVE)
Drv_IqCom=Drv_IqCom;
else if(Drv_WaveMode==DRV_START_SINE)
Drv_IqCom = Drv_IComOffset + CurMag*COSTABLE[Drv_SinIndex];
else if(Drv_WaveMode==DRV_START_SQUARE)
if (Drv_WaveTime < 0.5/WaveFreq)
Drv_IqCom = Drv_IComOffset + CurMag;
else
Drv_IqCom = Drv_IComOffset - CurMag;
139
/************************************************************************/
/************************************************************************/
void B_PI(void) // PI Current Controller
float Errd, Errq, VId, VIq,Vsat;
static float VId_1, VIq_1, Errd_1=0.0, Errq_1=0.0;
Errd = -Drv_Id*Drv_Feedback_Kp; Errq = Drv_IqCom-Drv_Iq*Drv_Feedback_Kp;
VId = VId_1 + Drv_Kii*DT*(Errd+Errd_1)/2; VIq = VIq_1 + Drv_Kii*DT*(Errq+Errq_1)/2;
Errd_1 = Errd; Errq_1 = Errq;
Vsat=VBUS/2.0; //this limit will hold down the integrator output, and then degrade the compensatation
//capacity for high speed operation
if (VId > Vsat) VId = Vsat;
else if (VId < -Vsat) VId = -Vsat;
if (VIq > Vsat) VIq = Vsat;
else if (VIq < -Vsat) VIq = -Vsat;
if (!EnableDrvCntrl) VId = 0.0; VIq = 0.0;
Drv_Vd = VId + Drv_Kpi*Errd; Drv_Vq = VIq + Drv_Kpi*Errq;
Vsat=VBUS;
if (Drv_Vd > Vsat) Drv_Vd = Vsat; // with saturation limits
else if (Drv_Vd < -Vsat) Drv_Vd = -Vsat;
if (Drv_Vq > Vsat) Drv_Vq = Vsat; // with saturation limits
else if (Drv_Vq < -Vsat) Drv_Vq = -Vsat;
if (ErrLimitMode)
if ((fabsf(Errd)>Drv_IErrLimit)||(fabsf(Errq)>Drv_IErrLimit))
ErrLimitFlag = ErrLimitFlag | 0x01;
VId_1 = VId; VIq_1 = VIq;
/************************************************************************/
/************************************************************************/
void get_all_adcs(float adcs[8])
int hi_lo, hi_word, lo_word, i;
for (i=0;i<4;i++)
hi_lo=ADC[i];
if (hi_lo & 0x2000) lo_word = hi_lo | 0xffffc000; // bit 13 is sign bit for
else lo_word = hi_lo & 0x00001fff; // the lo word
140
if (hi_lo & 0x20000000) hi_word = (hi_lo>>16) | 0xffffc000; // bit 29 is sign bit for
else hi_word = hi_lo>>16; // the hi word
adcs[2*i]=lo_word*10/8192.0; adcs[2*i+1]=hi_word*10/8192.0;
/************************************************************************/
/************************************************************************/
void output_dacs07(float dacs[8])
unsigned int hi_lo, hi_word, lo_word, i;
for (i=0;i<4;i++)
if (dacs[2*i]<-10.0) lo_word = 0;
else if (dacs[2*i]>9.998) lo_word = 0x3fff;
else lo_word = (unsigned int)(dacs[2*i]*8192.0/10.0+8192.0);
if (dacs[2*i+1]<-10.0) hi_word = 0;
else if (dacs[2*i+1]>9.998) hi_word = 0x3fff;
else hi_word = (unsigned int)(dacs[2*i+1]*8192.0/10.0+8192.0);
hi_lo = lo_word | (hi_word<<16);
DAC[i] = hi_lo;
/************************************************************************/
/************************************************************************/
void gen_cos_table(void)
int i;
float theta;
for (i=0;i<1024;i++)
theta = 2.0*3.1415927*i/1024.0;
COSTABLE[i] = cos(theta);
/************************************************************************/
/************************************************************************/
void init_pointers(void)
DAC=(int *)BASE+0x0004; // address for DAC 0
ADC=(int *)BASE+0x000c; // address for ADC 0
QDCOUNT=(int *)BASE+0x0020; // address for Quad Decoder 0 Count Reg
QDMODE=(int *)BASE+0x0028; // address for Quad Decoder 0 Mode Reg
141
VEL=(int *)BASE+0x0030; // address for DX/DT 0 Reg
DIGOUTD=(int *)BASE+0x0013; // address for digital output port
DIGINA=(int *)BASE+0x0010; // address for digital input port A
OEDIG=(int *)BASE+0x0019; // address for digital output enable
SOFTSYNC=(int *)BASE+0x001f; // address for SOFTSYNC signal
PWMtop=(int *)BASE+0x0024; // address for first four PWM channels
PWMbot=(int *)BASE+0x0034; // address for second four PWM channels
PWMCnt=(int *)BASE+0x002C; // address for PWMCnt Reg
PWMEn=(int *)BASE+0x002D; // address for PWMEn Reg
PWMLE=(int *)BASE+0x002F; // address for PWMLE Reg
COSTABLE = (float *)(EXMEM_BASE + 121072);
GAIN = (GainStruct *)GAINSTART;
POS = (PosStruct *)POSSTART;
STATUS = (StatusStruct *)STATUSSTART;
PROF = (ProfileStruct *)PROFILESTART;
DATA1 = (float *)DATA1START;
DATA2 = (float *)DATA2START;
HNDSHK = (unsigned int *)HANDSHAKE;
/************************************************************************/
/************************************************************************/
void init_globals(void)
int index;
int SegLen = DAT_NUM*SAMPLE_NUM;
Drv_Kp=1.0; Drv_Ki=0.0; Drv_Kd=0.0; Drv_NH=2.0*360.0/4096.0; Drv_PosErrLimit =90.0;
Drv_Kpi=90.3053; Drv_Kii=160221.2; Drv_Kt=3.27; Drv_IErrLimit=0.25;
Drv_Feedback_Kp = 1.0;
Drv_Imax=1.5; Drv_Umax=220;
Drv_UOffset =0.0;
Drv_IComOffset=0.0; Drv_ThComOffset=0.0;
Th1Scale=360.0/4096.0; Th2Scale=360.0/4096.0;
TorqScale=1.0631/*1.017262*/; TorqOffset=0.0; VbusScale=119.05; VbusOffset=0.0;
IaScale=0.502589;IaOffset=-2.024005-1.46E-03;
IbScale=0.5018039;IbOffset=-2.010417-2.35E-02;
IcScale=0.4985377;IcOffset=-2.02; IbusScale=0.5042214;IbusOffset=-2.05;
CurMag=0.05; ThMag=60.0; VelMag=5.0; WaveFreq = 1.0;
142
//initialize the data store segment
for(index=0; index<SegLen; index++)
DATA1[index] = 0.0;
/************************************************************************/
/************************************************************************/
void init_interrupts(void)
unsigned int timer_period;
// contants or globals DT
timer_period = 40000000.0*DT-1; // set up timer 0 to be a clock at the
timer_set(timer_period,10); // desired servo update frequency
interruptf(SIG_TMZ0,servo_loop); // set up servo_loop() as the interrupt
timer_on(); // handler for timer 0 interrupt
/************************************************************************/
/************************************************************************/
void cmd_reset()
int i;
EnableDrvCntrl=0;
ErrLimitMode=1; ErrLimitFlag=0;
Drv_WaveMode=DRV_NOWAVE; Drv_CntrlMode=DRV_CURRENT_CONTROL;
//To make the relative angle with respect to the phase A
i=read_resolver_absolute()-256;
if (i > 1024) i -= 1024;
QDCOUNT[0]=i; QDMODE[0]=QMODEVAL;
QDCOUNT[1]=i; QDMODE[1]=QMODEVAL; // reset both encoders
Drv_IqCom=0.0; Drv_ThCom=Th1Scale*i; Drv_VelCom=0.0;
Drv_IComOffset=0.0; Drv_ThComOffset=0.0;
/************************************************************************/
/************************************************************************/
//In the function, a sine wave controller was implemented. The command is the current sinewave amplitute,
//which can be got from the Iq command on the controller interface
void sine_cntrl(void)
143
int Th2pi3, Th_2pi3, Th_90, Th2pi3_90, Th_2pi3_90;
float P[2][3];
Th2pi3=ThElec+341; if(Th2pi3 > 1023) Th2pi3 -= 1024;
Th_2pi3=ThElec-341; if(Th_2pi3 < 0) Th_2pi3 += 1024;
Th_90=ThElec-256; if(Th_90 < 0) Th_90 += 1024;
Th2pi3_90=ThElec+85; if(Th2pi3_90 > 1023) Th2pi3_90 -= 1024;
Th_2pi3_90=ThElec-597; if(Th_2pi3_90 < 0) Th_2pi3_90 += 1024;
P[0][0]=COSTABLE[ThElec]; P[0][1]=COSTABLE[Th_2pi3]; P[0][2]=COSTABLE[Th2pi3];
P[1][0]=COSTABLE[Th_90]; P[1][1]=COSTABLE[Th_2pi3_90]; P[1][2]=COSTABLE[Th2pi3_90];
Drv_Id = 0.66666667*(P[1][0]*Drv_Ia+P[1][1]*(-Drv_Ia-Drv_Ic)+P[1][2]*Drv_Ic);
Drv_Iq = 0.66666667*(P[0][0]*Drv_Ia+P[0][1]*(-Drv_Ia-Drv_Ic)+P[0][2]*Drv_Ic);
Drv_IaCom = (P[1][0]*0.0+P[0][0]*Drv_IqCom);
Drv_IbCom = (P[1][1]*0.0+P[0][1]*Drv_IqCom);
Drv_IcCom = (P[1][2]*0.0+P[0][2]*Drv_IqCom);
Sinewave_PI();
Drv_Orig_Va = Drv_Va*VBUS; Drv_Orig_Vb = Drv_Vb*VBUS; Drv_Orig_Vc = Drv_Vc*VBUS;
Drv_Vd = 0.66666667*(P[1][0]*Drv_Orig_Va+P[1][1]*Drv_Orig_Vb+P[1][2]*Drv_Orig_Vc);
Drv_Vq = 0.66666667*(P[0][0]*Drv_Orig_Va+P[0][1]*Drv_Orig_Vb+P[0][2]*Drv_Orig_Vc);
if ((Drv_Vc <= Drv_Va)&&(Drv_Vc <= Drv_Vb))
Drv_Va=Drv_Va-Drv_Vc; Drv_Vb=Drv_Vb-Drv_Vc; Drv_Vc=0;
if ((Drv_Va >= Drv_Vb)&&(Drv_Va > 1))
Drv_Vb=Drv_Vb/Drv_Va; Drv_Va=1;
else if (Drv_Vb > 1)
Drv_Va=Drv_Va/Drv_Vb; Drv_Vb=1;
else if ((Drv_Vb <= Drv_Va)&&(Drv_Vb <= Drv_Vc))
Drv_Va=Drv_Va-Drv_Vb; Drv_Vc=Drv_Vc-Drv_Vb; Drv_Vb=0;
if ((Drv_Va >= Drv_Vc)&&(Drv_Va > 1))
Drv_Vc=Drv_Vc/Drv_Va; Drv_Va=1;
else if (Drv_Vc > 1)
Drv_Va=Drv_Va/Drv_Vc; Drv_Vc=1;
else
144
Drv_Vb=Drv_Vb-Drv_Va; Drv_Vc=Drv_Vc-Drv_Va; Drv_Va=0;
if ((Drv_Vb >= Drv_Vc)&&(Drv_Vb > 1))
Drv_Vc=Drv_Vc/Drv_Vb; Drv_Vb=1;
else if (Drv_Vc > 1)
Drv_Vb=Drv_Vb/Drv_Vc; Drv_Vc=1;
Drv_Va *= VBUS; Drv_Vb *= VBUS; Drv_Vc *= VBUS; Diagnose=ThElec;
output_3ph_pwms(Drv_Va,Drv_Vb,Drv_Vc,VBUS);
/************************************************************************/
/************************************************************************/
void Sinewave_PI(void)
float ErrIa, ErrIb, ErrIc, VIa=0, VIb=0, VIc=0, Vsat;
static float VIa_1, VIb_1, VIc_1;
ErrIa = Drv_IaCom-Drv_Ia*Drv_Feedback_Kp; ErrIb = Drv_IbCom-Drv_Ib*Drv_Feedback_Kp;
ErrIc = Drv_IcCom-Drv_Ic*Drv_Feedback_Kp;
VIa = VIa_1+Drv_Kii*DT*ErrIa; VIb = VIb_1+Drv_Kii*DT*ErrIb;
Vsat=VBUS/5.0;
if (VIa > Vsat) VIa = Vsat;
else if (VIa < (-Vsat)) VIa = -Vsat;
if (VIb > Vsat) VIb = Vsat;
else if (VIb < (-Vsat)) VIb = -Vsat;
if (!EnableDrvCntrl) VIa = 0.0; VIb = 0.0; VIc =0.0;
Drv_Va = VIa + Drv_Kpi*ErrIa; Drv_Vb = VIb + Drv_Kpi*ErrIb;
Drv_Vc = -(Drv_Va+Drv_Vb); //calculate the Drv_Vc by Drv_Va and Drv_Vb instead of a PI
//controller
Vsat=VBUS;
if (Drv_Va > Vsat) Drv_Va = Vsat;
else if (Drv_Va < -Vsat) Drv_Va = -Vsat;
if (Drv_Vb > Vsat) Drv_Vb = Vsat;
else if (Drv_Vb < -Vsat) Drv_Vb = -Vsat;
if (Drv_Vc > Vsat) Drv_Vc = Vsat;
else if (Drv_Vc < -Vsat) Drv_Vc = -Vsat;
if (ErrLimitMode)
145
if ((fabsf(ErrIa)>Drv_IErrLimit)||(fabsf(ErrIb)>Drv_IErrLimit)||(fabsf(ErrIc)>Drv_IErrLimit))
ErrLimitFlag = ErrLimitFlag | 0x01;
VIa_1 = VIa; VIb_1 = VIb; //VIc_1 = VIc;
Drv_Va = Drv_Va/VBUS; Drv_Vb = Drv_Vb/VBUS; Drv_Vc = Drv_Vc/VBUS;
146
Appendix B: LQ Design MATLAB Program Code • File Name: lyapunov.m
//Written by Dr. Dale Schinstock
function P=lyapunov(A,Q)
[N,N]=size(Q); M=N*(N+1)/2;
L=zeros(N,N); V=zeros(M,M);
Rv=zeros(M,1);
k=1;
for i=1:N
for j=i:N
L(i,j)=k; L(j,i)=k;
Rv(k)=Q(i,j);
k=k+1;
end
end
for i=1:N
for j=1:N
for k=1:N
V(L(i,k),L(j,k))=A(j,i)+V(L(i,k),L(j,k));
end
end
end
for i=1:N
for j=1:M
V(L(i,i),j)=2*V(L(i,i),j);
end
end
Pv = -V\Rv;
P=zeros(N,N);
k=1;
for i=1:N
for j=i:N
P(i,j)=Pv(k); P(j,i)=Pv(k);
k=k+1;
end
end
147
• File Name: LineSearch.m
%Written by Dr. Dale Schinstock
function [J,K,check] = LineSearch(Kstart,Jstart,Gradstart,NewtonStep,FunHandle)
Alpha=1e-4; Lam = 1;
Slope = Gradstart'*NewtonStep; DoInterps = true;
FirstInterp=true; check = false;
while (DoInterps)
K = Kstart + Lam*NewtonStep;
J = feval(FunHandle,K);
if (J < 0) % Use negative J to indicate instability
Lam = Lam/2; % Cut Lambda and start all over
FirstInterp=true;
else if (J <= (Jstart+Alpha*Lam*Slope))
DoInterps=false; % Sufficient PI decrease
LamNew = Lam;
else if (FirstInterp)
% Minimum lambda for a quadratic fit
LamNew = -Slope/(2*(J-Jstart-Slope));
FirstInterp=false;
else
% Model as cubic polynomial
A=[1/Lam^2 -1/Lam2^2; -Lam2/Lam^2 Lam/Lam2^2];
B=[J - Slope*Lam - Jstart; J2 - Slope*Lam2 - Jstart];
% Cubic Coefficients
C = A*B/(Lam - Lam2); a =C(1); b=C(2);
if (a == 0)
LamNew = -Slope/(2*b);
else
disc = b^2-3*a*Slope;
if (disc < 0)
LamNew = Lam/2;
elseif (b <= 0) LamNew = (-b+sqrt(disc))/(3*a);
else LamNew = -Slope/(b+sqrt(disc));
end
end
end
if (LamNew > Lam/2) LamNew = Lam/2; end % At least cut step in half
148
end
Lam2 = Lam;
J2 = J;
Lam = max(LamNew,0.1*Lam); % Don't cut step too quickly
end
end % Repeat interpolations
149
File Name: DFPmin.m
//Written by Dr. Dale Schinstock
function [Kopt,Jopt,NumIters,Termination,Grad] = DFPmin(FunHandle,initK,MaxIter,Gradtol)
if (nargin < 3) MaxIter = 1000; end
if (nargin < 4) Gradtol = 1e-7; end
EPS = 3e-8; [m1,p1]=size(initK);
N=m1*p1; Hess=eye(N);
K=zeros(m1*p1,1); K(:)=initK; % Form K vector
[J,Grad]=feval(FunHandle,K); NewtonStep = -Hess*Grad;
DoIters=true; NumIters=0; k=0; while (DoIters)
k=k+1; NumIters=NumIters+1;
[Jnew,Knew] = LineSearch(K, J, Grad, NewtonStep,FunHandle);
[Jnew,Gnew]=feval(FunHandle,Knew); % Jnew should same as previous line
dK=Knew-K; dG=Gnew-Grad; dJ=Jnew-J;
HdG=Hess*dG;
J = Jnew; Grad = Gnew; K = Knew;
den1=dK'*dG; den2=dG'*HdG;
if (den1 > sqrt(EPS*(dG'*dG)*(dK'*dK))) % skip Hess update if not positive enough
Hess = Hess + dK*dK'/den1 - HdG*HdG'/den2;
end
if k==10*N
k=0; Hess=eye(N);
end
NewtonStep = -Hess*Grad;
if (NumIters >= MaxIter) DoIters=false; Termination=1; end
if (norm(Grad)*max(norm(NewtonStep),1)/max(J,1)<Gradtol); DoIters=false; Termination=2; end
Kprint=K'
J=J
Gnew=Gnew;
end
Kopt=K;
Jopt=J;
150
• Name File: T0XCostGrad.m
//The original file was written by Dr. Schinstock, this is modified version by Tao Yang
function [J,Grad,P]=T0XCostGrad(Kvector)
global A B C G F H r0 R Q P V m p n
%%%%% Time-independed Cost Function %%%%%%%%%%%%%%%%%%%%
K=zeros(m,p); K(:)=Kvector; % Form K matrix from vector
Ac = A-B*K*C; Aci=inv(Ac);
Bc = G-B*K*F;
xbar = -Aci*(Bc*r0);
ybar = C*xbar + F*r0;
ybar = C*xbar + F*r0;
ebar = r0-H*xbar;
X = xbar*xbar';
Qlyap=C'*K'*R*K*C+Q;
P=lyapunov(Ac,Qlyap);
J=0.5*(trace(P*X)+ebar'*V*ebar) % Cost function
[Pcholesky,Pcheck]=chol(P);
if (Pcheck)
J=-1;
end
if nargout > 1 % Called with 2 output arguments
S=lyapunov(Ac',X);
dHdK = R*K*C*S*C'-B'*P*S*C'+B'*Aci'*P*xbar*ybar'; % Gradient of Hamiltonian
dHdK = dHdK + B'*Aci'*H'*V*(H*xbar*ybar'-r0*ybar'); % Gradient of Hamiltonian
Grad=zeros(m*p,1); Grad(:)=dHdK; % Form vector gradient from matrix
End
151
File Name: T2XCostGrad.m
//The original file was written by Dr. Schinstock, this is modified version by Tao Yang
function [J,Grad,P]=T2XCostGrad(Kvector)
global A B C G F H r0 R Q P V m p n
%%%%%% Time-depended Cost Function %%%%%%%%%%%%%%%%%%%%
K=zeros(m,p); K(:)=Kvector; % Form K matrix from vector
Ac = A-B*K*C; Aci=inv(Ac);
Bc = G-B*K*F;
xbar = -Aci*(Bc*r0);
ybar = C*xbar + F*r0;
ybar = C*xbar + F*r0;
ebar = r0-H*xbar;
X = xbar*xbar';
P0=lyapunov(Ac,P);
P1=lyapunov(Ac,P0);
Qlyap=C'*K'*R*K*C+Q + 2*P1;
P2=lyapunov(Ac,Qlyap);
J=0.5*(trace(P2*X)+ebar'*V*ebar) % Cost function
[Pcholesky,Pcheck]=chol(P2);
if (Pcheck)
J=-1;
end
if nargout > 1 % Called with 2 output arguments
S2=lyapunov(Ac',X);
S1=lyapunov(Ac',2*S2);
S0=lyapunov(Ac',S1);
% Gradient of Hamiltonian
dHdK = R*K*C*S2*C'-B'*(P0*S0+P1*S1+P2*S2)*C'+B'*Aci'*P2*xbar*ybar';
dHdK = dHdK + B'*Aci'*H'*V*(H*xbar*ybar'-r0*ybar'); % Gradient of Hamiltonian
Grad=zeros(m*p,1); Grad(:)=dHdK; % Form vector gradient from matrix
End
152
• File Name: T4XCostGrad.m
%The original file was written by Dr. Schinstock, this is modified version by Tao Yang
function [J,Grad,P]=T4XCostGrad(Kvector)
global A B C G F H r0 R Q P V m p n
%%%%%% Time-depended Cost Function %%%%%%%%%%%%%%%%%%%%
K=zeros(m,p); K(:)=Kvector; % Form K matrix from vector
Ac = A-B*K*C; Aci=inv(Ac);
Bc = G-B*K*F;
xbar = -Aci*(Bc*r0);
ybar = C*xbar + F*r0;
ybar = C*xbar + F*r0;
ebar = r0-H*xbar;
X = xbar*xbar';
P0=lyapunov(Ac,P);
P1=lyapunov(Ac,P0);
P2=lyapunov(Ac,P1);
P3=lyapunov(Ac,P2);
Qlyap=C'*K'*R*K*C+Q + 4*3*2*P3;
P4=lyapunov(Ac,Qlyap);
J=0.5*(trace(P4*X)+ebar'*V*ebar) % Cost function
[Pcholesky,Pcheck]=chol(P4);
if (Pcheck)
J=-1;
end
if nargout > 1 % Called with 2 output arguments
S4=lyapunov(Ac',X);
S3=lyapunov(Ac',4*3*2*S4);
S2=lyapunov(Ac',S3);
S1=lyapunov(Ac',S2);
S0=lyapunov(Ac',S1);
dHdK = R*K*C*S4*C'-B'*(P0*S0+P1*S1+P2*S2+P3*S3+P4*S4)*C'+B'*Aci'*P4*xbar*ybar';
% Gradient of Hamiltonian
dHdK = dHdK + B'*Aci'*H'*V*(H*xbar*ybar'-r0*ybar'); % Gradient of Hamiltonian
Grad=zeros(m*p,1); Grad(:)=dHdK; % Form vector gradient from matrix
end
153
• File Name: LQ4PIFOPTD.m
% PI controller
function [ tolerance, Kopt, Kp_opt, Ki_opt, Jopt, Termination]= LQ4PIFOPTD (tau_ratio, Kinit)
global A B C G F H r0 R Q P V m p n
T = 1; %the plant system time constant
k = 1; %the plant dc gain
tau=T*tau_ratio; %time delay
% Define original dynamic systems
pade_ord = 3; %the order of pade approximation for the time delay term
Tdelay = tf(1,1,'inputdelay', tau);
PTdelay = pade(Tdelay,pade_ord);
[dtnum dtden] = tfdata(PTdelay,'v');
Tplant = zpk(tf(k,[T 1])*PTdelay);
[pnum pden] = tfdata(Tplant, 'v');
[Ap Bp Cp Dp] = tf2ss(pnum, pden); %the plant state equation
Hp = Cp;
% Define PI controller dynamics
Fc = [0]; Gc = [1];
Dc = [0;1]; Jc = [1;0];
% Define the complete system dynamics with the controller dynamics
A = [Ap zeros(pade_ord+1,1);
-Gc*Hp Fc ];
B = [Bp; 0];
G = [zeros(pade_ord+1,1); Gc];
C = [-Jc*Hp Dc];
F = [Jc];
H = [Hp 0];
% LQT OPTIMIZATION
m=1; p=2; n=pade_ord+2;
P = H'*H;
% P = eye(n);
% P = zeros(n,n);
% Q = H'*H;
% Q=eye(n);
Q = zeros(n,n);
rho=0.0;
%rho=0.163*tau^1.7; %for the 10% overshoot ISE
154
R=rho*eye(m);
V=[0];
initK = Kinit;
r0=[1];
[Kopt,Jopt,NumIters,Termination,Grad] = DFPmin(@T4XCostGrad,initK,3000,1e-3); %IST^2E
varioustolerance = Jopt/100000;
tolerance = varioustolerance;
cnt = 0;
while(Termination==1 && cnt<20)
cnt = cnt+1;
initK = Kopt';
[Kopt,Jopt,NumIters,Termination,Grad] = DFPmin(@NavionLatCostGrad,initK,200,varioustolerance);
end;
Kp_opt = Kopt(1);
Ki_opt = Kopt(2);