Ethercat Based Connected Servo Drive Using Fast Current Loop On PMSM
Ethercat Based Connected Servo Drive Using Fast Current Loop On PMSM
Ramesh T Ramamoorthy
ABSTRACT
This application report helps to evaluate EtherCAT communication and to perform frequency response
analysis of fast current loop (FCL) enabled control loops of a connected servo drive using TI's
TMS320F28388D real-time controller. The platform used is TI's DesignDRIVE IDDK EVM kit and the
C2000Ware MotorControl SDK. Frequency response analysis is performed in software using TI's Software
Frequency Response Analyser (SFRA) library running in realtime on the control MCU F28388D. Besides
controlling the motor, the MCU also performs EtherCAT communication with a TwinCAT running on PC.
F2838x MCU is a part of the C2000™ family of microcontrollers. It has has two C28x CPU cores and an
Arm® Cortex®-M4 core for performing control and communication effectively using a range of powerful
peripherals for digital power and motor control applications. In servo drive space, it enables cost-effective
design of intelligent, high-bandwidth controllers for 3-phase motors, by reducing the system components
and increasing efficiency. The devices are appropriately supported by hardware accelerators to implement
FCL algorithms to rival or surpass similar implementations using FPGA in terms of performance, cost, and
development time.
The application report describes the following:
• Incremental build levels calling modular FCL and EtherCAT functions spread across CPU, M4 and CLA
cores
• Experimental results
Contents
1 Introduction ................................................................................................................... 3
2 Benefits of the TMS320F2838x MCU for High-Bandwidth Current Loop............................................. 3
3 Current Loops in Servo Drives ............................................................................................. 4
4 Outline of the Fast Current Loop Library ................................................................................. 5
5 Fast Current Loop Library Evaluation ..................................................................................... 7
6 Incremental Build Level 1 .................................................................................................. 9
7 Incremental Build Level 2 ................................................................................................. 12
8 Incremental Build Level 3 ................................................................................................. 16
9 Incremental Build Level 4 ................................................................................................ 20
10 Incremental Build Level 5 ................................................................................................. 22
11 Incremental Build Level 6 ................................................................................................. 24
12 Incremental Build Level 7 ................................................................................................ 34
13 Incremental Build Level 8 ................................................................................................ 41
List of Figures
1 Basic Scheme of FOC for AC Motor ...................................................................................... 4
2 Fast Current Loop Library Block Diagram ................................................................................ 5
3 Level 1 Block Diagram ..................................................................................................... 9
4 Expressions Window for Build Level 2 .................................................................................. 10
5 Voltage Angle and SVGEN Ta, Tb, and Tc ............................................................................ 11
6 DAC Outputs Showing Ta, Tb Waveforms ............................................................................. 12
7 Level 2 Block Diagram..................................................................................................... 13
SPRACM9 – June 2019 EtherCAT Based Connected Servo Drive Using Fast Current Loop on PMSM 1
Submit Documentation Feedback
Copyright © 2019, Texas Instruments Incorporated
www.ti.com
List of Tables
1 Summary of FCL Interface Functions ..................................................................................... 6
2 Functions Verified in Each Incremental System Build .................................................................. 8
3 Functional Modules Used in Each Incremental System Build ......................................................... 8
Trademarks
C2000 is a trademark of Texas Instruments.
Arm, Cortex are registered trademarks of Arm Limited.
2 EtherCAT Based Connected Servo Drive Using Fast Current Loop on PMSM SPRACM9 – June 2019
Submit Documentation Feedback
Copyright © 2019, Texas Instruments Incorporated
www.ti.com Introduction
1 Introduction
The concept of FOC of AC drives is well known and is already outlined in many earlier documents from TI.
Modern AC servo drives, depending on the end application, need high-bandwidth current control and
speed control to enable superior performance, such as in CNC machines or in fast and precision control
applications. Because of the high computational burden and the need for flexible PWMs, a combination of
FPGAs, fast external ADCs, and multiple MCUs are used by many designers.
With the TMS320F2838x MCU, due to its higher level of integration, it is possible to implement fast current
loop algorithms with the same external hardware used in classical FOC methods. TI has developed the
FCL algorithm on the F2838x MCU and implemented it on the Design DRIVE IDDK platform. With a 10-
kHz PWM carrier, the current loop gain crossover frequency is expected to exceed 3 kHz, and the closed
loop bandwidth is expected at about 5 KHz (per NEMA ICS 16 and Chinese GBT 16439-2009) and the
maximum duty cycle is expected to be approximately 96%. This document provides information needed to
evaluate this algorithm on the DesignDRIVE IDDK platform.
Besides control, TMS320F2838x MCU has an Arm Cortex-M4 based Connectivity Manager and an
EtherCAT Slave Control peripheral. This helps to seamlessly integrate control and communication in a
single chip to enable development of cost effective solutions for industrial servo drives.
• CLBs
Together, these features provide enough hardware support to increase computational bandwidth
compared to its predecessors and offer superior real-time control performance. In addition, the C2000
ecosystem of software (libraries and application software) and hardware (TMDXIDDK379D) help users
reduce the time and effort needed to develop a high-end digital motor control solution.
VDC
Inv. Park Tr.
iSqref VSqref VSaref
PI d,q
SV 3-phase
PWM Inverter
iSdref VSdref VSbref
PI a,b
q
q
iSq iSa ia
d,q a,b
iSd iSb ib
a,b a,b
Park Tr. Clarke Tr.
AC
Motor
Two motor phase currents are measured. These measurements feed the Clarke transformation module.
The outputs of this projection are designated isα and isβ. These two components of the current along with
the rotor flux position are the inputs of the Park transformation, which transform them to currents (isd and
isq) in d and q rotating reference frame. The isd and isq components are compared to the references isdref
(the flux reference) and isqref (the torque reference). At this point, the control structure shows an interesting
advantage; it can be used to control either synchronous or asynchronous machines by simply changing
the flux reference and obtaining the rotor flux position. In the synchronous permanent magnet motor, the
rotor flux is fixed as determined by the magnets, so there is no need to create it. Therefore, when
controlling a PMSM motor, isdref can be set to zero, except during field weakening.
Because ACIM motors need a rotor flux creation to operate, the flux reference must not be zero. This
conveniently solves one of the major drawbacks of the classic control structures: the portability from
asynchronous to synchronous drives. The torque command isqref can be connected to the output of the
speed regulator. The outputs of the current regulators are Vsdref and Vsqref. These outputs are applied to the
inverse Park transformation. Using the position of rotor flux, this projection generates Vsαref and Vsβref, which
are the components of the stator vector voltage in the stationary orthogonal reference frame. These
components are the inputs of the Space Vector PWM. The outputs of this block are the signals that drive
the inverter.
NOTE: Both Park and inverse Park transformations need the rotor flux position. Obtaining this rotor
flux position depends on the AC machine type (synchronous or asynchronous).
4 EtherCAT Based Connected Servo Drive Using Fast Current Loop on PMSM SPRACM9 – June 2019
Submit Documentation Feedback
Copyright © 2019, Texas Instruments Incorporated
www.ti.com Outline of the Fast Current Loop Library
PWM1 A/B
lsw
FAST CURRENT LOOP
Rg.Out Iph1 (Ia)
QEP
The FCL library uses the following features in the F2838x MCU:
• TMU
• Four high-speed 12- and 16-bit ADCs
• Multiple parallel processing blocks such as CLA
Figure 2 shows the block diagram of the FCL library with its inputs and outputs. The FCL library partitions
the algorithm across the CPU, CLA, and TMU to bring down the latency to under 1.0 µs compared to the
acceptable 2 µs. Further optimization is possible if the algorithm is written in assembly.
The FCL library supports two types of current regulators, a standard PI controller and a complex
controller. The complex controller can provide additional bandwidth over the standard PI controller at
higher speeds. Both current regulators are provided for user evaluation. In the example project, the
current regulator can be selected by setting the FCL_CNTLR macro appropriately and studying how they
compare.
SPRACM9 – June 2019 EtherCAT Based Connected Servo Drive Using Fast Current Loop on PMSM 5
Submit Documentation Feedback
Copyright © 2019, Texas Instruments Incorporated
Outline of the Fast Current Loop Library www.ti.com
For more information on the library, see the Fast Current Loop MotorControl SDK Library User's Guide
available at:
\ti\c2000\C2000Ware_MotorControl_SDK_version\libraries\fcl\docs.
NOTE: The library is written in a modular format and is able to port over to user platforms using
F2837x / F2838x devices if the following conditions are met:
• Motor phase current feedbacks are read into variables internal to the library. However, D
axis and Q axis current feedbacks are available.
• PWM modules controlling motor phase A, B, and C are linked to the library.
• A QEP module connecting to the QEP sensor is linked to the library.
• CLA tasks one through four are used by the library. This must be accommodated in the
user application.
6 EtherCAT Based Connected Servo Drive Using Fast Current Loop on PMSM SPRACM9 – June 2019
Submit Documentation Feedback
Copyright © 2019, Texas Instruments Incorporated
www.ti.com Fast Current Loop Library Evaluation
5.1.1 Hardware
The example project is evaluated on TI’s Design DRIVE Development Kit IDDK - TMDXIDDK379D. The
DesignDRIVE IDDK Hardware Reference Guide and DesignDRIVE IDDK User Guide for the kit can be
found at C:\ti\c2000\C2000Ware_MotorControl_SDK_version\solutions\tmdxiddk379d\docs\.
The DesignDRIVE IDDK Hardware Reference Guide gives an overview of the various hardware functional
blocks in the kit, discusses the various ground configurations it supports and the safety measures
necessary to work with the kit. It is important to understand the hardware and the safety aspects before
working with the kit.
The DesignDRIVE IDDK User Guide helps in setting up the hardware and in getting started with software,
connecting to the target platform and working with the debug environment using Code Composer Studio.
5.1.2 Software
When the MCSDK software package is installed, the FCL software library can be found at
C:\ti\c2000\C2000Ware_MotorControl_SDK_version\libraries\observers\fcl\lib.
The FCL example project can be found at:
C:\ti\c2000\C2000Ware_MotorControl_SDK_version\solutions\tmdxiddk379d\f2838x\ccs\sensored_foc
Here, a few more build levels are added to step through with integrating the FCL library to run the motor in
speed mode and position mode.
SPRACM9 – June 2019 EtherCAT Based Connected Servo Drive Using Fast Current Loop on PMSM 7
Submit Documentation Feedback
Copyright © 2019, Texas Instruments Incorporated
Fast Current Loop Library Evaluation www.ti.com
Table 2 and Table 3 summarizes the core functions integrated and tested at each build level as well as
the cores used to perform the tasks in each of the incremental builds.
8 EtherCAT Based Connected Servo Drive Using Fast Current Loop on PMSM SPRACM9 – June 2019
Submit Documentation Feedback
Copyright © 2019, Texas Instruments Incorporated
www.ti.com Incremental Build Level 1
RC RG
MACRO MACRO
TargetValue SetPointValue Freq
Watch
SpeedRef Window
DlogCh1
Assuming the load and build steps described in the DesignDRIVE IDDK User Guide completed
successfully, this section describes the steps for a “minimum” system check-out which confirms operation
of system interrupt, the peripheral and target independent inverse park transformation and space vector
generator modules, and the PWM initializations and update modules.
1. Open fcl_qep_f2838x_tmdxiddk_settings_cpu1.h and select the level 1 incremental build option by
setting the BUILDLEVEL to FCL_LEVEL1 (#define BUILDLEVEL FCL_LEVEL1).
2. Right-click on the project name and click Rebuild Project.
3. When the build is complete, click on debug button, reset the CPU, restart, enable real time mode, and
run.
Add variables to the expressions window by right-clicking within the Expressions Window and
importing the fcl_f2838x_tmdxiddk_vars_cpu1.txt file from the debug directory. Figure 4 shows the
variables imported into the Expressions Window from this file. Ignore the values shown against the
variables for now.
SPRACM9 – June 2019 EtherCAT Based Connected Servo Drive Using Fast Current Loop on PMSM 9
Submit Documentation Feedback
Copyright © 2019, Texas Instruments Incorporated
Incremental Build Level 1 www.ti.com
4. Set enableFlag to 1 in the watch window. The variable named isrTicker is incrementally increased, as
seen in the watch windows, to confirm the interrupt working properly.
In the software, the key variables to be adjusted are:
a. speedRef : for changing the rotor speed in per-unit.
b. VdTesting : for changing the d-qxis voltage in per-unit.
c. VqTesting : for changing the q-axis voltage in per-unit.
10 EtherCAT Based Connected Servo Drive Using Fast Current Loop on PMSM SPRACM9 – June 2019
Submit Documentation Feedback
Copyright © 2019, Texas Instruments Incorporated
www.ti.com Incremental Build Level 1
These are shown in Figure 5. These are the voltage vector angle, and the pulse width values for the
phases A, B, and C and are denoted as Ta, Tb, and Tc, where Ta, Tb, and Tc waveforms are 120
degrees apart from each other. Specifically, Tb lags Ta by 120 degrees and Tc leads Ta by 120 degrees.
These are generated based on the values of speedRef, VdTesting and VqTesting. These values can be
changed to see the impact on these waveforms. Check the PWM test points on the board to observe
PWM pulses (PWM-1H to 3H and PWM-1L to 3L) and ensure that the PWM module is running properly.
SPRACM9 – June 2019 EtherCAT Based Connected Servo Drive Using Fast Current Loop on PMSM 11
Submit Documentation Feedback
Copyright © 2019, Texas Instruments Incorporated
Incremental Build Level 1 www.ti.com
12 EtherCAT Based Connected Servo Drive Using Fast Current Loop on PMSM SPRACM9 – June 2019
Submit Documentation Feedback
Copyright © 2019, Texas Instruments Incorporated
www.ti.com Incremental Build Level 2
RC RG
MACRO MACRO
TargetValue SetPointValue Freq Out
Iph1 (Ia)
Iph2 (Ib)
Iph3 (Ic)
DlogCh1
DATALOG DlogCh2
Graph
DlogCh3
Window
DlogCh4
SPEED FR QEP
Var1 Speed
On MACRO
QEP Interface Incremental PM
Scope chip Var2 ElecTheta Module Encoder
SpeedRpm Motor
DACs (CLA) Interface
5. Set enableFlag to 1 in the watch window. The variable named isrTicker is incrementally increased as
shown in the Expressions window to confirm the interrupt is working properly. Now set the variable
named runMotor to MOTOR_RUN; the motor starts spinning after a few seconds if enough voltage is
applied to the DC-Bus.
In the software, the key variables to be adjusted are same as in previous level and are given again
below for reference.
a. speedRef: for changing the rotor speed in per-unit
b. VdTesting: for changing the d-axis voltage in per-unit
c. VqTesting: for changing the q-axis voltage in per-unit
During the open loop tests, VqTesting, speedRef, and DC bus voltages must be adjusted carefully for
PM motors so that the generated Bemf is lower than the average voltage applied to motor winding.
This adjustment prevents the motor from stalling or vibrating.
SPRACM9 – June 2019 EtherCAT Based Connected Servo Drive Using Fast Current Loop on PMSM 13
Submit Documentation Feedback
Copyright © 2019, Texas Instruments Incorporated
Incremental Build Level 2 www.ti.com
tripFlagDMC is a flag variable that represents the overcurrent trip status of the inverter. If this flag is set,
then you can adjust the previous settings and try to rerun the inverter by setting clearTripFlagDMC to 1.
This clears tripFlagDMC and restarts the PWMs.
The default current limit setting is to shut down at 8 A. Any of these settings can be fine-tuned to suit your
system. When satisfactory values are identified, write them down, modify the code with these new values,
and rebuild and reload for further tests.
It is possible to shut down the inverter using a digital signal from an external source through H9. No code
is provided currently, but it can be used as an exercise to experiment and learn.
The waveform of channel 2 represents the reference position, while channel 1 represents the estimated
position. The ripple in position estimate is indicative of the fact that the motor runs with some minor speed
oscillation. Because of open-loop control, the rotor position and reference position may not align.
However, it is important to ensure that the sense of change of the estimated angle is the same as that of
the reference; otherwise, it indicates that the motor has a reverse sense of rotation. This can be fixed by
either swapping any two wires connecting to the motor, or reversing the angle estimate as in the
pseudocode in the software (see Equation 1).
angle = 1.0 – angle (1)
To ensure that the function runSpeedFR() works, change the speedRef variable in the Expressions
window, as shown in Figure 9, and check whether the estimated speed variable, speed1.Speed, follows
the commanded speed. Because the motor is a PM motor, where there is no slip, the running speed
follows the commanded speed regardless of the control being open loop.
When the tests are complete, bring the system to a safe stop by reducing the bus voltage, taking the
controller out of real-time mode, and resetting it. Now, the motor stops.
SPRACM9 – June 2019 EtherCAT Based Connected Servo Drive Using Fast Current Loop on PMSM 15
Submit Documentation Feedback
Copyright © 2019, Texas Instruments Incorporated
Incremental Build Level 3 www.ti.com
NOTE: In this build, control is done based on the actual rotor position; therefore, the motor can run
at higher speeds if the commanded IqRef is higher and there is no load on the motor. TI
advises to either add some mechanical load on the motor before the test or apply lower
values of IqRef. When the motor is commanded to run, it is subjected to an initial alignment
stage where the electrical angle and the QEP angle count are set to zero. They are then
forced to run based on an enforced angle until the QEP index pulse is received. Then the
motor runs in full self-control mode based on its own angular position.
16 EtherCAT Based Connected Servo Drive Using Fast Current Loop on PMSM SPRACM9 – June 2019
Submit Documentation Feedback
Copyright © 2019, Texas Instruments Incorporated
www.ti.com Incremental Build Level 3
lsw=0
Constant 0 PWM1 A/B
3-Phase
IqRef IqRef PWM2 A/B Inverter
lsw=1, 2
RC RG lsw lsw
MACRO MACRO
TargetValue SetPointValue Freq Out FAST CURRENT LOOP
Rg.Out Iph1 (Ia)
SpeedRpm QEP
PM
Motor
Level 3 verifies the dq-axis current regulation performed by PI modules and speed measurement modules.
Figure 10. Level 3 Block Diagram Showing Inner Most Loop - FCL
SPRACM9 – June 2019 EtherCAT Based Connected Servo Drive Using Fast Current Loop on PMSM 17
Submit Documentation Feedback
Copyright © 2019, Texas Instruments Incorporated
Incremental Build Level 3 www.ti.com
This variable indicates the amount of time elapsed between the feedback sampling and PWM updating.
The elapsed time, or latency, is computed based on the count of the EPWM timer right after the PWM
update. The value shown here is more than the actual update time by a few clock cycles. Immediately
after setting the runMotor flag to MOTOR_RUN and the motor begins to run, the latency time shows up as
nearly 1.25 µS due to initial setup in the code. This amount of latency occurs at a time when the duty
cycle is moderate and is therefore acceptable. After this period, you can refresh the latency time by setting
fclClrCntr to 1. Regardless of SAMPLING_METHOD, latency remains the same for a given FCL_CNTLR.
When FCL_CNTLR is a PI_CNTLR, the latency is about 0.96 µs compared to 0.98 µs with a
CMPLX_CNTLR (see the following note).
NOTE:
• These times can be reduced further by around 0.1-µs range using code inline and other
optimization techniques. Because the evaluation code is in library format, it has certain
overheads.
• The sampling window for ADC is kept wide enough to ensure a cleaner signal
acquisition. Depending on board layout and circuits feeding in to ADC channels, it may
be possible to reduce this time window by nearly 60%.
18 EtherCAT Based Connected Servo Drive Using Fast Current Loop on PMSM SPRACM9 – June 2019
Submit Documentation Feedback
Copyright © 2019, Texas Instruments Incorporated
www.ti.com Incremental Build Level 3
NOTE: Because H7 is not populated, GPIO16 and GPIO18 are used for timing purposes instead of
for designed functional assignment. If H7 is to become populated, comment out the
associated code and restore the functional assignment.
Figure 12 shows the latency discussed previously in the form of a scope plot, where the rising edge of the
channel 2 and channel 1 waveforms signify the instances of the ADC SoC event and completion of all
PWM updates, respectively. These events are brought out over GPIO16 and GPIO18, and may be probed
over [Main]-R31 and [Main]-R33, respectively. The time seen in the scope plot may be slightly more than
fclLatencyInMicroSec. This additional time is needed for the CPU to return from FCL library and to set
GPIO .
SPRACM9 – June 2019 EtherCAT Based Connected Servo Drive Using Fast Current Loop on PMSM 19
Submit Documentation Feedback
Copyright © 2019, Texas Instruments Incorporated
Incremental Build Level 4 www.ti.com
Auto switched
Constant 0 lsw=0
from start
PWM1 A/B
Ref IqRef lsw=1
SpeedRef PI 3-Phase
MACRO lsw=2 IqRef PWM2 A/B Inverter
Fbk
Spd Reg
IdRef IdRef PWM3 A/B
RC RG lsw lsw
MACRO MACRO
TargetValue SetPointValue Freq Out FAST CURRENT LOOP
Rg.Out Iph1 (Ia)
SpeedRpm QEP
PM
Motor
Level 4 verifies the speed PI module and speed loop.
Figure 13. Level 4 Block Diagram Showing Speed Loop With Inner FCL
20 EtherCAT Based Connected Servo Drive Using Fast Current Loop on PMSM SPRACM9 – June 2019
Submit Documentation Feedback
Copyright © 2019, Texas Instruments Incorporated
www.ti.com Incremental Build Level 4
Figure 14. Flux and Torque Components of the Stator Current in the Synchronous Reference Frame
Under 0.33-pu Step-Load and 0.3-pu Speed
SPRACM9 – June 2019 EtherCAT Based Connected Servo Drive Using Fast Current Loop on PMSM 21
Submit Documentation Feedback
Copyright © 2019, Texas Instruments Incorporated
Incremental Build Level 4 www.ti.com
9.1 Observation
In the default set up, the current loop bandwidth is set up as 1/18 of the SAMPLING FREQUENCY for
both CMPLX_CNTLR and PI_CNTLR. As the bandwidth is increased, control becomes stiff and the motor
operation becomes noisier as the controller reacts to tiny perturbations in the feedback trying to correct
them, see the note below. The gain cross over frequency (or open loop bandwidth) can be taken up to 1/6
of the SAMPLING_FREQUENCY and still get good transient response over the entire speed range
including higher speeds. If the motor rotation direction is reversed occasionally due to any malfunction, try
restarting it by setting runMotor to MOTOR_STOP and then MOTOR_RUN again. It may need some fine
tuning in transitioning from lsw = QEP_WAIT_FOR_INDEX to lsw = GOT_INDEX. This can be used as an
exercise to fix it.
NOTE: The fast current loop is a high bandwidth enabler. When the designed bandwidth is high, the
loop gains can also be high. This pretty much ties the loop performance to the quality of
current feedback. If the SNR of current feedback signal into the digital domain is poor, then
the loop can be very audibly noisy as the controller tries to minimise the error. If the noise is
bothersome, the user may be required to reduce the bandwidth to avoid the audible noise.
22 EtherCAT Based Connected Servo Drive Using Fast Current Loop on PMSM SPRACM9 – June 2019
Submit Documentation Feedback
Copyright © 2019, Texas Instruments Incorporated
www.ti.com Incremental Build Level 5
9. Bring the system to a safe stop by reducing the bus voltage, taking the controller out of real-time mode
and reset. Now the motor stops.
Figure 15 shows the implementation block diagram.
Level 5 Incremental System Build Block Diagram
Auto switched
Ref from start
PositionRef Constant 0 lsw=0 PWM1 A/B
PI Ref
SpeedRef
MACRO PI IqRef lsw=1 3-Phase
Fbk IqRef PWM2 A/B
Pos Reg MACRO lsw=2 Inverter
Fbk
Spd Reg
IdRef IdRef PWM3 A/B
RC RG lsw lsw
MACRO MACRO
TargetValue SetPointValue Freq Out FAST CURRENT LOOP
Rg.Out Iph1 (Ia)
SpeedRpm QEP
PM
Motor
Level 5 verifies the position PI module and position loop.
Figure 15. Level 5 Block Diagram Showing Position Loop With Inner FCL
In the scope plot shown in Figure 16, the position reference, and position feedback are plotted. They are
aligned with negligible lag, which may be attributed to software. If the Kp and Ki gains of the position loop
controller are not chosen properly, this may lead to oscillations in the feedback or a lagged response.
Figure 16. Scope Plot of Reference Position to Servo and Feedback Position
NOTE:
• If the motor response is erratic, then the sense of turn of the motor shaft and the
encoder may be opposite. Swap any two phase connections to the motor and repeat the
test.
• The position control implemented here is based on an initial aligned electrical position (=
0). If the motor has multiple pole pairs, then this alignment can leave the shaft in
different mechanical positions depending on the prestart mechanical position of the
rotor. If the mechanical position repeatability or consistency is needed, then the QEP
index pulse must be used to set a reference point. This may be taken as an exercise.
SPRACM9 – June 2019 EtherCAT Based Connected Servo Drive Using Fast Current Loop on PMSM 23
Submit Documentation Feedback
Copyright © 2019, Texas Instruments Incorporated
Incremental Build Level 6 www.ti.com
NOTE:
• The disturbances due to analog signal path and quantization will impact the loop
performance and hinder high bandwidth selections that can be verified using SFRA
results. Therefore it is important to provide a current feedback with a higher SNR.
• When evaluating current loops, if it is possible to hold the motor speed constant, it will
help to minimize the impact of speed jitter related errors in the SFRA results. This is
particularly useful when studying the Iq loop. If the voltage decoupling of current loop is
good, then this requirement may not matter.
This tool provides the ability to study the D-axis or Q-axis current loops or the speed loop. The motor can
be run at different speed / load conditions and at different bandwidths and the performance can be
evaluated at each of these conditions. It can be seen that the controller can provide the designed
bandwidth under all these conditions with a certain tolerance.
24 EtherCAT Based Connected Servo Drive Using Fast Current Loop on PMSM SPRACM9 – June 2019
Submit Documentation Feedback
Copyright © 2019, Texas Instruments Incorporated
www.ti.com Incremental Build Level 6
SFRA
Control PWM1 A/B
SpeedRef
PI
Fbk MACRO IqRef PWM2 A/B
3-Phase
Spd Reg
+ IdRef
Inverter
PWM3 A/B
Auto switched
lsw
from start
FAST CURRENT LOOP
Rg.Out Iph1 (Ia)
SPEED FR
Speed MACRO ElecTheta Iph2 (Ib)
QEP
PM
Motor
QEP
The implementation block diagram is given in Figure 17. The SFRA tool injects noise signal into the
system at various frequencies and analyzes the system response and provides a Bode Plot of the actual
physical system as seen during the test.
SPRACM9 – June 2019 EtherCAT Based Connected Servo Drive Using Fast Current Loop on PMSM 25
Submit Documentation Feedback
Copyright © 2019, Texas Instruments Incorporated
Incremental Build Level 6 www.ti.com
This demo uses the GUI 'SFRA_GUI_MC'. However, the user is encouraged to experiment with the other
GUI as well to study the plant. With the SFRA_GUI, the user can plot the same graph as in
SFRA_GUI_MC by passing the argument 'SFRA_GUI_PLOT_GH_CL' in the function configureSFRA() as
shown in the code snippet below.
configureSFRA(SFRA_GUI_PLOT_GH_CL, ISR_FREQUENCY); // to plot GH and CL plots using SFRA_GUI
But the inferences from the plots are not according to that in SFRA_GUI_MC. Therefore, we advice to
configure SFRA for 'SFRA_GUI_PLOT_GH_H' so that the user can see open loop, closed loop and plant
model plots using these two GUIs, by using one at a time. For digital power applications, SFRA_GUI_MC
inferences may not apply and so SFRA_GUI can be used to display closed loop plots as well.
26 EtherCAT Based Connected Servo Drive Using Fast Current Loop on PMSM SPRACM9 – June 2019
Submit Documentation Feedback
Copyright © 2019, Texas Instruments Incorporated
www.ti.com Incremental Build Level 6
SPRACM9 – June 2019 EtherCAT Based Connected Servo Drive Using Fast Current Loop on PMSM 27
Submit Documentation Feedback
Copyright © 2019, Texas Instruments Incorporated
Incremental Build Level 6 www.ti.com
4. Click ‘Refresh Comports’ button to get the Comport number show up in the window.
5. Select the Comport representing the connection to the target C2000 board.
6. Uncheck ‘Boot on Connect’
7. Click OK button
28 EtherCAT Based Connected Servo Drive Using Fast Current Loop on PMSM SPRACM9 – June 2019
Submit Documentation Feedback
Copyright © 2019, Texas Instruments Incorporated
www.ti.com Incremental Build Level 6
8. This should establish the connection to the MCU control card/launchpad and the GUI will appear as
shown in Figure 21 indicating the connection status at the bottom left corner.
9. The frequency sweep related settings are shown in ‘FRA Settings’ Panel. These values are already
pre-filled from the C2000 device and they can be left as is.
10. As mentioned earlier, the visual difference between the two GUIs is in the pull down menu under 'FRA
Settings' starting with Open Loop.
a. In the SFRA_GUI, this pull down menu helps to select between Open Loop Model and Plant Model
b. In the SFRA_GUI_MC, this pull down menu helps to select between Open Loop Model and Closed
Loop Model
c. This menu becomes relevant after a complete noise injection sweep of the system at various
frequencies. Then the user can pick and view the plot of choice using this menu.
d. Bandwidth reporting is different as mentioned earlier. Gain cross over frequency is reported in the
open loop plot of the SFRA_GUI_MC instead of bandwidth as in SFRA_GUI.
This completes the initial setup of GUI environment.
SPRACM9 – June 2019 EtherCAT Based Connected Servo Drive Using Fast Current Loop on PMSM 29
Submit Documentation Feedback
Copyright © 2019, Texas Instruments Incorporated
Incremental Build Level 6 www.ti.com
Figure 22. SFRA Open Loop Bode Plots of the Current Loop Showing Magnitude and Phase Angle
30 EtherCAT Based Connected Servo Drive Using Fast Current Loop on PMSM SPRACM9 – June 2019
Submit Documentation Feedback
Copyright © 2019, Texas Instruments Incorporated
www.ti.com Incremental Build Level 6
Figure 23. SFRA Closed Loop Bode Plots of the Current Loop Showing Magnitude and Phase Angle
SPRACM9 – June 2019 EtherCAT Based Connected Servo Drive Using Fast Current Loop on PMSM 31
Submit Documentation Feedback
Copyright © 2019, Texas Instruments Incorporated
Incremental Build Level 6 www.ti.com
Figure 24. SFRA Open Loop Bode Plots of the Current Loop - Current Feedback With High SNR
Figure 25. SFRA Closed Loop Bode Plots of the Current Loop - Current Feedback With High SNR
NOTE: With the hardware platform IDDK, there is scope for improving the SNR of the current signal
feeding into the ADCs of the MCU. Therefore, higher bandwidth tests can be more noisier
(chattering in nature) on this platform.
32 EtherCAT Based Connected Servo Drive Using Fast Current Loop on PMSM SPRACM9 – June 2019
Submit Documentation Feedback
Copyright © 2019, Texas Instruments Incorporated
www.ti.com Incremental Build Level 6
11.7 Inferences
SPRACM9 – June 2019 EtherCAT Based Connected Servo Drive Using Fast Current Loop on PMSM 33
Submit Documentation Feedback
Copyright © 2019, Texas Instruments Incorporated
Incremental Build Level 6 www.ti.com
Figure 26. Plot of Gain Cross over Frequency vs Phase Margin as Experimentally Obtained
The group of plots at the bottom is obtained for conventional control, and it is obvious that the gain cross
over frequency is too low and that as the gain cross over frequency is increased, the phase margin drops
a lot faster.
The group of plots at the top is obtained with FCL. The gain cross over frequency is nearly thrice that of
the classical method for a given phase margin. And also, as the gain cross over frequency is increased,
the relative drop in phase margin is very low compared to the classical method. This effectively means
that FCL can provide a higher bandwidth or gain cross over frequency at a higher phase margin.
34 EtherCAT Based Connected Servo Drive Using Fast Current Loop on PMSM SPRACM9 – June 2019
Submit Documentation Feedback
Copyright © 2019, Texas Instruments Incorporated
www.ti.com Incremental Build Level 7
NOTE: Control power supply to the IDDK is alone needed for this build level therefore the user may
turn off the high voltage dc power to the kit.
2. When the build is complete, click the Debug button, reset the CPU, restart, enable real-time mode, and
run.
3. Add the following variable in the ‘Expressions Window’:
a. countMainLoop : counter to just show activity in ECAT main loop function
b. ipcCMToCPUDataBuffer : data buffer written by CM for use by CPU1
c. ipcCPUToCMDataBuffer : data buffer written by CPU1 for use by CM
d. dataBufferFromCM : buffer copy of message from CM
e. dataBuffertoCM : buffer copy of messge to CM
4. Running the code will enable the GPIOs needed for EtherCAT and also passed over the ownership of
EtherCAT slave peripheral to CM, besides setting up the IPC on CPU1 side for data transfer between
CPU1 and CM. Now is the time to load / run the code on CM to initialize the EtherCAT peripheral.
NOTE: If ever the EtherCAT was assigned to CPU1 in any of the immediate previous evaluation
projects and is now being assigned to CM, then make sure to power cycle the controlCARD
before running the CM project to ensure that CPU1 has fully relinquished the EtherCAT
peripheral.
NOTE: Any modifications to the requirement given in demo will require the generation of new slave
stack files via the SSC tool and also corresponding changes to the application source code.
This will have to be rebuilt to get a new executable for loading into the CM.
The source files given by TI for EtherCAT support are only HAL files needed for this function
and will not be sufficient to compile and generate an executable. However, if the user
generates a slave stack, the CM project provided here will be able to generate an
executable.
SPRACM9 – June 2019 EtherCAT Based Connected Servo Drive Using Fast Current Loop on PMSM 35
Submit Documentation Feedback
Copyright © 2019, Texas Instruments Incorporated
Incremental Build Level 7 www.ti.com
6. Run the code. This would configure the ECAT slave controller and also the IPC on CM side for data
transfer between CM and CPU1.
Now the ECAT slave controller is ready to connect to ECAT master, and in this demo, the ECAT master is
TwinCAT running on the user's development computer.
b. Right click on this icon and select Tools->TwinCAT Switch Runtime. From the Tc- SwitchRuntime
window, verify that it is active. When active, it will only provide the option to Deactivate. Don’t
Deactivate!
36 EtherCAT Based Connected Servo Drive Using Fast Current Loop on PMSM SPRACM9 – June 2019
Submit Documentation Feedback
Copyright © 2019, Texas Instruments Incorporated
www.ti.com Incremental Build Level 7
c. If the icon is not present, then locate the TwinCAT Runtime executable from the file system.
(Default installation location is typically: C:/TwinCAT/TcSwitchRuntime)
4. Start up Visual Studio with TwinCAT using one of the following methods:
a. Recommended: Right click the TwinCAT Config Mode icon from the Windows notification panel
and select TwinCAT XAE
b. installed desktop icon: TwinCAT XAE
c. Use installed Start Menu icon under Beckhoff folder: TwinCAT XAE
5. Once Visual Studio running, verify that the main toolbar has options TwinCAT and PLC shown. If these
aren’t present, then the TwinCAT Switch Runtime isn’t active.
6. Within Visual Studio, create a new EtherCAT project. Select File -> New -> Project and under
templates select TwinCAT Projects then TwinCAT XAE Project (XML format). Fill in a name (say
f2838x_iddk) and click OK.
7. Now that the project is created, verify that a realtime Ethernet adapter is installed.
a. In Visual Studio, select the TwinCAT menu from the main toolbar and select Show Realtime
Ethernet Compatible Devices
b. In the popup window, under Installed and ready to use devices (realtime capable) category, if no
connections are shown, select one from the list of Compatible devices and click Install.
8. TwinCAT setup is now complete.
NOTE: Port 0 is the top Ethernet port on the side of the controlCARD with two Ethernet connections.
3. In Visual Studio on the left side solution explorer, expand the Project, then expand I/O
4. Right click on Devices and select Scan
a. A dialog will popup stating that Not all types of devices can be found automatically. Click OK.
5. Once scanning is complete, a popup window will appear. The following options may appear:
a. A popup stating that 1 new I/O devices found where the device is Device 2 (EtherCAT Automation
Protocol). This or any other device numbers besides Device 1 is correct, click OK.
b. A popup stating that no devices have been found or stating that 1 new I/O devices found where the
device is Device 1 (EtherCAT Automation Protocol). This means some setup is incorrect. Verify
that the example is running on the device (or at least has gone through the GPIO setup and reset
of the EtherCAT IP). If the procedure is followed correctly, it should have identified Device 2. The
setup procedure may be repeated again carefully.
6. After clicking OK, another popup will ask to Scan for boxes. Click Yes.
7. After clicking Yes, another popup will ask to Activate Free Run. Click Yes.
8. In the solution explorer on the left, under devices you should see Device 2 (EtherCAT). Under that,
there will be a Box #. This Box is the controlCARD ESC.
9. The EtherCAT master communication is now setup with the slave device.
SPRACM9 – June 2019 EtherCAT Based Connected Servo Drive Using Fast Current Loop on PMSM 37
Submit Documentation Feedback
Copyright © 2019, Texas Instruments Incorporated
Incremental Build Level 7 www.ti.com
38 EtherCAT Based Connected Servo Drive Using Fast Current Loop on PMSM SPRACM9 – June 2019
Submit Documentation Feedback
Copyright © 2019, Texas Instruments Incorporated
www.ti.com Incremental Build Level 7
6. To observe the ECAT messages as variables in CCS, right-click within the CCS Expressions window
and choose Import. Then browse to and select fcl_f2838x_tmdxiddk_ecat_vars.txt file from the debug
directory.
SPRACM9 – June 2019 EtherCAT Based Connected Servo Drive Using Fast Current Loop on PMSM 39
Submit Documentation Feedback
Copyright © 2019, Texas Instruments Incorporated
Incremental Build Level 7 www.ti.com
7. Within TwinCAT, double-click on the discovered EtherCAT box and observe that the EtherCAT slave is
running in OP mode.
8. Within TwinCAT, expand the explorer to the EtherCAT box (I/O --> Devices -->Device 2 (EtherCAT) -->
Box 1 (F2838x CM EtherCAT Slave(SYSTEM))) and find the various output/input mappings as shown
in Figure 33. Double click on Box1 to get the F2838x CM slave input /output data window as shown in
Figure 34.
a. Select Input mapping 0 to view all the status feedback from the drive. The following are the drive
parameters monitored through EtherCAT
a. SpeedStatus
b. PositionStatus
c. TorqueStatus
d. DriveStatus
b. Select Output mapping 0 to view and enter all the commands to the drive
a. DriveCommand
b. SpeedReference
c. PositionReference
40 EtherCAT Based Connected Servo Drive Using Fast Current Loop on PMSM SPRACM9 – June 2019
Submit Documentation Feedback
Copyright © 2019, Texas Instruments Incorporated
www.ti.com Incremental Build Level 8
9. This build level is a loop back example to verify the EtherCAT functionality. So, if the command data
entered in a certain output mapping variable is returned back in a certain input mapping variable, it
confirms the functionality of EtherCAT slave on the F2838x. The loop back association is as follows:
a. SpeedReference --> SpeedStatus
b. PositionReference --> PositionStatus
c. DriveCommand --> DriveStatus
For example, the data entered in 'SpeedReference' in output mapping should return back to show up in
'SpeedStatus' in input mapping if EtherCAT slave is functioning properly.
NOTE: Since this build level attempts to drive the motor, high voltage dc power to the kit should be
restored at this point.
NOTE: Any modifications to the requirement given in demo will require the generation of new slave
stack files via the SSC tool and also corresponding changes to the application source code.
This will have to be rebuilt to get a new executable for loading into the CM.
SPRACM9 – June 2019 EtherCAT Based Connected Servo Drive Using Fast Current Loop on PMSM 41
Submit Documentation Feedback
Copyright © 2019, Texas Instruments Incorporated
Incremental Build Level 8 www.ti.com
42 EtherCAT Based Connected Servo Drive Using Fast Current Loop on PMSM SPRACM9 – June 2019
Submit Documentation Feedback
Copyright © 2019, Texas Instruments Incorporated
IMPORTANT NOTICE AND DISCLAIMER
TI PROVIDES TECHNICAL AND RELIABILITY DATA (INCLUDING DATASHEETS), DESIGN RESOURCES (INCLUDING REFERENCE
DESIGNS), APPLICATION OR OTHER DESIGN ADVICE, WEB TOOLS, SAFETY INFORMATION, AND OTHER RESOURCES “AS IS”
AND WITH ALL FAULTS, AND DISCLAIMS ALL WARRANTIES, EXPRESS AND IMPLIED, INCLUDING WITHOUT LIMITATION ANY
IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT OF THIRD
PARTY INTELLECTUAL PROPERTY RIGHTS.
These resources are intended for skilled developers designing with TI products. You are solely responsible for (1) selecting the appropriate
TI products for your application, (2) designing, validating and testing your application, and (3) ensuring your application meets applicable
standards, and any other safety, security, or other requirements. These resources are subject to change without notice. TI grants you
permission to use these resources only for development of an application that uses the TI products described in the resource. Other
reproduction and display of these resources is prohibited. No license is granted to any other TI intellectual property right or to any third
party intellectual property right. TI disclaims responsibility for, and you will fully indemnify TI and its representatives against, any claims,
damages, costs, losses, and liabilities arising out of your use of these resources.
TI’s products are provided subject to TI’s Terms of Sale (www.ti.com/legal/termsofsale.html) or other applicable terms available either on
ti.com or provided in conjunction with such TI products. TI’s provision of these resources does not expand or otherwise alter TI’s applicable
warranties or warranty disclaimers for TI products.
Mailing Address: Texas Instruments, Post Office Box 655303, Dallas, Texas 75265
Copyright © 2019, Texas Instruments Incorporated