## 4 Real-Time Implementation and Experimental Set-Up  
Section 3 introduced a very important step in the development of a prototype, namely the numerical simulation step. At the numerical simulation stage, generally referred to as Software-In-the-Loop (SIL), both the mathematical model of the controlled process and the mathematical model of the controller run on a host PC, and the execution of the closed-loop simulation program does not overlap with the so-called real-time execution, where there is a correlation between the evolution of the real signals and the speed of display in the monitoring-and-control software application. At this stage, the controller parameters are adjusted and the performance of the analysed control systems is compared in a safe operating environment. After this stage, there is the option of going through the Processor-In-the-Loop (PIL) stage, where the driven process is still simulated but the controller is real, but the final stage of developing a prototype controller is the Hardware-In-the-Loop (HIL) stage, where the driven process is real and the controller is also implemented in an embedded system [42]. The PMSM-SCS based on the DTC strategy presented in this article uses the Matlab/Simulink development environment, which uses the Motor Control Blockset (MCB) and Embedded Coder Support Package (ECSP) toolboxes suitable for Texas Instruments C2000 microcontrollers for real-time implementation [43; 44]. The MCB toolbox provides the ability to implement the proposed control structures in the SIL stage through specialised blocks for real-time implementation in the HIL stage. The ECSP toolbox allows the corresponding code of the PMSM control algorithm to be generated and executed, based on the DTC control strategy. The generated code runs on C2000 microcontrollers, specifically the TMS320F28379D microcontroller [45]. Real-time software blocks include enhanced pulse-width modulator (ePWM) control, serial peripheral interface (SPI) serial communication control, host PC and embedded-system communication blocks, digital motor control (DMC) specific blocks, and the IQMath library for optimising code for real-time computation through fixed-point implementation, while maintaining high accuracy. Key features of the TMS320F28379D microcontroller include a 32-bit floating-point Control Law Accelerator (CLA) module that performs mathematical computations concurrent with the main processor on a 32-bit fixed-point architecture. We also recall that the main processor has a clock frequency of 200 MHz, 1 MB of flash memory, 16-bit digital-to-analogue converters (DACs), serial communication ports and a general-purpose input/output (GPIO) subsystem [42]. To interface with the TelcoMotion DT4260 PMSM (TelcoMotion, Taichung, Taiwan), a 3-phase smart gate module driver with current shunt amplifiers and SPI-type BOOSTXL-DRV8305 (Texas Instruments, Dallas, TX, USA) is used, which communicates with the LAUNCHXL-F28379D development board on which the TMS320F28379D main controller is integrated (Figure 18). Following the real-time implementation of the PMSM-SCS based on the DTC strategy, a series of speed reference-signal variations imposed by the real-time monitoring and control software interface were implemented in Simulink on the PC host. \begin{table}
\begin{tabular}{c c c c c c} \hline \hline
**Type of Controller for PMSM-SCS** & **Response Time [ms]** & \begin{tabular}{c} **Settling Time** \\ **[ms]** \\ \end{tabular} & \
\begin{tabular}{c} **Speed Ripple** \\ **[rm]** \\ \end{tabular} &
\begin{tabular}{c} **FD of PMSM Speed Signal** \\ \end{tabular} \\ \hline PI & 12 & 72 & 43.36 & 0.984540 +/ - 0.051130 \\ PI-BOA & 9.2 & 30 & 37.17 & 0.984526 +/ - 0.051321 \\ FOPI & constant flux & 7.9 & 15 & 35.61 & 0.984599 +/ - 0.051421 \\ TID & 5.9 & 14.5 & 34.38 & 0.986350 +/ - 0.026742 \\ FO-Lead-Lag & 3.2 & 9.1 & 33.54 & 0.986710 +/ - 0.026879 \\ SMC & variable flux & 2.3 & 2.3 & 32.79 & 0.987770 +/ - 0.027187 \\ FOSMC & 2.2 & 2.2 & 32.21 & 0.987950 +/ - 0.027261 \\ \hline \hline \end{tabular}
\end{table}