# Low-Cost Implementation of an Adaptive Neural Network Controller for a Drive with an Elastic Shaft
## 4 Low-Cost Implementation of the Control Algorithm  
The main contribution of this research was the implementation of the designed controller on a low-cost microcontroller board. Power electronic devices were obtained through the application of industrial MENTOR converters. The original software settings of the industrial machines were reconfigured to allow communication with the external speed controller. The required feedback signals were acquired by external sensors; the incremental encoders were attached to the motor and load machine shafts, and the LEM current sensor was attached to the drive powerline. The output was routed directly to the Discovery board with the STM32F4 microprocessor, and the 36,000 ppr incremental encoders were also connected to the MENTOR controllers (Figure 13). The framework between the drives and the microcontroller board was obtained using STMStudio software. The controller structure was designed in Simulink and the C code was generated. The Discovery board was flashed with the obtained firmware, and the variable list file was developed. Based of the file, a human-machine interface (HMI) application was created. The HMI allows the user to observe drive state variables and plot speed transients. The application also provides basic control over the plant. The fully functional low-cost Hardware-in-the-Loop (HIL) system was obtained (Figure 14). The connection between the PC and the Discovery board was obtained with the USB cable and the ST-link embedded in-circuit programmer. Not only did the established connection provide the possibility to flash the new firmware to the board, but also allowed real-time monitoring of the system variables. Figure 14: Data flow between the components of the plant. Figure 13: Schematic diagram of the drive (**a**), and the experimental bench (**b**). The Discovery board with the STM32F407 microprocessor was chosen because of the necessity to use two digital-to-analog converters (DAC). Moreover, the performance and variety of the available connectivity modules on the chosen board were compared to the laboratory dSpace DS1103 hardware. Although the dSpace incorporates an FPGA module, its price exceeds the cost of a Discovery board multiple times. Several chosen parameters are compared in Table 1.  
The low-cost board can be considered less powerful with the synthetic performance of only 210 DMIPS (compared to about 2300 DMIPS obtained by dSpace processor); however, it offers a greater number of general-purpose input/output ports and communication modules. Compared with the dSpace module, the Discovery board incorporates more timers that are multipurpose elements. In the designed structure, the timers were used for encoder data acquisition. The pulses were counted and after the determined period, they were used to calculate the speed of the drive and the load machine. Both devices include processors, which can perform simple data operations in real-time. The FPGA module is not included in the Discovery board, making parallel computation of the RBFNN structure impossible. However, the proposed model was simple enough that the response of the microprocessor was sufficient for the controlled plant. As the speed controllers can be applied in mobile machinery, energy efficiency was also considered. The suggested STM microcontroller average current consumption is declared at the level of 40 mA [55], while dSpace requires up to 750 mA [56]. The software part of the designed HIL was based on the simulation model. The output of the RBFNN speed controller was sent to the torque controller. The signal was then normalized and converted to an analog signal with a corresponding voltage output level. The digital output of the microcontroller was used to switch the relays of the MENTOR power electronics. They were used to define the direction of drive rotation, global enable, and start of operation. To configure the MENTOR drives, the CTSoft application was used (Figure 15). It comprises a wide range of graphical interfaces to change the parameters of the drive.