Implementation of a method of numerical integration of average voltages at the integration step for designing microcontroller models of electrotechnical systems Oleksiy Kuznyetsov1*, Oleksandr Kuznietsov2, Mykola Semeniuk3 1 Department of Electromechanics and Electronics, Hetman Petro Sahaidachnyi National Army Academy 32 Heroiv Maidanu Str., 79000, Lviv, Ukraine 2 Lviv Centre ofInstitute for Space Research of National Academy of Science and State Space Agency 5-A Naukova Str., 79060, Lviv, Ukraine 3 Department of Electromechatronics and Computer-Controlled Electromechanical Systems, Lviv Polytechnic National University, 12 S. Bandera Str., 79000, Lviv, Ukraine * E-mail: oleksiy.kuznyetsov@ukr.net Abstract. Hardware implementation of models of electrotechnical and electromechanical systems is widely recognized as a practice allowing hardware-in-the-loop technique, as well as simpler techniques like state observers or estimators. While hardware-in-the-loop technique is rather complicated, state observers or estimators are often implemented even on low-end microcontrollers. The paper presents a method of numerical integration of average voltages at the integration step for implementing a model of electrotechnical system on a low-end microcontroller because of its high operational speed and numerical stability. The developed model is emulated as a program in the C language and implemented on the Texas Instruments MSP430 platform. General guidelines are proposed for implementing of a method for designing a microcontroller model of the electrotechnical system. Such model is suitable as a basis for designing microcontroller emulators of electrotechnical and electromechanical systems or their elements serving as estimators or state observers. Keywords: electrotechnical system, microcontroller model, emulation, low-end microcontroller, method of average voltages at the integration step Izvedba numerične integracije povprečnih vrednosti napetosti v integracijskem koraku pri snovanju mikrokrmilniških modelov elektrotehniških sistemov Za modeliranje elektrotehniških in elektromehanskih sistemov s strojno opremo uporabljamo strojno opremo v zanki in opazovalnike stanj. V primerjavi s strojno opremo v zanki lahko opazovalnike stanj izvedemo z mikrokrmilniki. V članku je predstavljena metoda za numerično integracijo povprečnih vrednosti napetosti v integracijskem koraku pri izvedbi modela elektrotehniškega sistema z mikrokrmilnikom. Razviti model smo emulirali v programskem jeziku C in izvedli na platformi Texas Instruments MSP430. Predlagamo splošne smernice za načrtovanje elektrotehniškega sistema, izvedenega z mikrokrmilniškim modelom. Predstavljeni model je primeren kot osnova za načrtovanje mikrokrmilniških emulatorjev elektrotehniških in elektromehanskih sistemov. 1 Introduction The simulation technology enhances its functionality by enabling operation of virtual models together with the physical equipment via ADC and DAC. One of the techniques enabling this operation is hardware-in-the-loop (HiL), where the simulation software replaces a process or an object as a part of a complicated system. Examples of the HiL applications are, but not limited to: testing of controllers [1], failure analysis of the power equipment [2], etc. These applications require a real-time operation for their functioning. Thus, a suitable resolution for a 50-Hz power system is roughly 50 ^s; high-frequency switching circuits require smaller steps [3]. Hence, the technologies such as FPGA ([1, 2]) or DSP ([4]) are utilized as a hardware basis. O uR(t) uL(t) Uc(t) (a) Es u(t) at the integration step Rs o (b) Figure 1. Branch of the electric circuit (a) and its equivalent circuit at the integration step according to AVIS (b). Other techniques employing a hardware implementation of models are state observers or estimators. They are softwares operating in parallel with a physical equipment that estimates an inner state or inner variables of a real system. Compared to HiL, in general, they require simpler models, depending on the complexity of the system description, e.g., the model of a wind turbine may be used for estimating the wind speed [5], or the wind speed and a couple of electrical variables [6], such as active powers, currents etc. Observers or estimators are implemented even on low-end microcontrollers [7, 8]; however, this often makes the real-time operation impossible. Recent paers are devoted to implementing models of electrical and mechanical systems [9], PEM fuel cell [10], varicap diode [11], etc., on low-end microcontrollers. However, these models are suitable for applications with slow-varying values or even for those operating with steady-state values. However, even low-end microcontrollers are utilized as a tool for testing the design methodologies used for implementation of a model on a microcontroller [9]. Communications of models with a physical equipment are widely utilized in laboratory teaching of students as demonstrated on examples of Universidad de los Andes (Bogotá, Colombia) [12], National Technical University of Athens (Greece) [13], and the Federal University of Technology (Paraná, Brazil) [14]. In the paper we propose to utilize a method of average voltages on the integration step (AVIS) [15] for the mathematical description of electrotechnical systems due to its high operating speed and numerical stability as compared to conventional methods of numerical integration for electrotechnical [16] and electromechanical [17, 18] systems. The paper introduces the AVIS method for implementing models of electrotechnical systems on a low-end microcontroller. 2 Analysis of Electric Circuits Using the AVIS Method 2.1 General Description of the Method In most common cases, every single branch of a complex electric circuit is represented as serial-connected electromotive force e, resistance R, inductance L, and capacitance C with applied voltage u on its terminals (Fig. 1a). Considering integration step At starting at to, the Kirchhoffs voltage law for the branch is represented in the form of formula (1): J t0 +At — j(u -e -mä - wc -ml )dt = 0, (1) where u, e, uR, uC, and uL are instantaneous values of the applied voltage, electromotive force, and voltages on appropriate elements of the branch. In other words, equation (1) represents the AVIS balance for the branch. The AVIS method is based on algebraization of differential equations representing the branch, considering the current waveform at the integration step between io and ii as an m-order polynomial [15]. The consideration results in representing the branch in Fig. 1a at the integration step as serial-connected equivalent electromotive force Es and equivalent resistance Rs with a current i1 flowing through the branch (Fig. 1b). Therefore, Es and Rs are calculated at each integration step as follows [15]: E „ — E u DA u + R - + At 2-(m + l)(m + 2) L0 Y m +1 C 2 (m + l)(m + 2) ( RAtk m - k At -I - + (k +1)! m +1 Atk+1 (m + l)(m + 2)-(k + l)(k + 2) C (k + 2)! (m + l)(m + 2) d(k ) i (k ) and R = R At _+_+Li m +1 C(m + l)(m + 2) At dt (2) (3) where io is the current, uro and uco are the voltages at the resistance and capacitance, all at the beginning of the step; Lo and L\ are the branch inductances at the beginning and at the end of the step; U and E are the u + 0 0 k=1 average values at the step of the applied voltage and j t0 +At ^ t0+At electromotive force: U - — \u dt, and E - — f edt. At J At J 2.2 Algorithm for the Electric-Circuit Analysis at the Integration Step Analysis of the electric circuit using the AVIS method at each integration step [16] is further explained. First, the equivalent diagram at the integration step for the analyzed circuit is generated (an example of the electric circuit and its equivalent diagram at the integration step is demonstrated in Fig. 2). Afterwards, the following is performed at the integration step: 1. Calculation of derivatives at the beginning of the integration step. Equations are based on the known methods to analyze the electric circuit. 2. Determination of the equivalent parameters of every branch of the electric circuit (equivalent electromotive force Esi (2) and resistance RSi (3)). 3. Calculation of the currents at the end of the integration step. Since the circuit at the integration step is treated as a DC circuit, the calculation can be based on the Kirchhoff's law, loop current method or nodal analysis. 4. Determination of the voltages on the capacitor at the end of integration step uci. Equation (4) is used [16]: At / x Am ■ i0 + h ) + , Mk) . (4) i- k d(k) /„ __I C(m +1) m-1 Atk+1 1 "I (k ) i{k +1)! Cm +1 d t 2.3 Example of the Electric-Circuit Analysis at the Integration Step The circuit of Fig. 2a is depicted by mathematical model ((5)-(8)). These formulae are an application of (2)-(4) for each branch of the circuit utilizing the second-order AVIS (m = 2). Thus, the first derivatives of the currents at the beginning of the integration step are defined as: Si r3 C3 S5 1—M 1 'h C2 R4 Ri ■e Ei Es Rs JN'ii Rsi <3k, jfhi (a) Rs3 Es3 0 Rs2 Es2 ¡4i Rs4 I Es Q hi Rs5 Es 1 © (b) Figure 2. Diagram of the analyzed electric circuit (a) and its equivalent diagram at the integration step using AVIS. The equivalent electromotive forces of the branches are: Es, = E1 -+ i^ + L -^ d'" Es2 = UC 20 + ^ 3 At J 10 6 d t ( L 5 At 1. At2 d E At 12C„ 12C2 d t Es3 R3i30 UC30 + ( R 5 At ^ ( R At At2 - + - v 3 12C3 j d i 6 12C 3 J 30 d t (6) e =-ri + R. i - RA dR Es4 RA° + 3i40 6 d t ' E5 = E - r^+( R+L i - RAt s5 5 5 50 I 3 At J 50 6 dt the equivalent resistances of the branches are: d h0 _E - R1i10 - R3i30 UC 30 R4^40 d t A d i20 _ UC30 - UC20 + R3i30 + R4i40 d t L , d i50 _ E5 - R5i50 " R4i40 d t L5 d i30 _ d i10 _d i20 d t d t d t d i40 = d i30 + d i50 d t d t d t (5) R = R + LL, s1 3 At Rs2 = ~ + ^ 12C2 At R„ - R+ - At 3 12C3 R = R4 Rs5 = R + L5; s5 3 At (7) L 5 L 2 i- k and finally, the voltages on the capacitors at the end of the integration step are calculated as: At / . x At2 d i20 20 + ( 20 +i21)+ "dT" At — (2i30 + /31 )- 3C At d i30 6C3 d t (8) 3 Implementation of the Mathematical Model on a Microcontroller 3.1 Parameters of the Selected Platform The main objective of our study was to implement AVIS method on a low-cost microcontroller platform and to observe any possible "bottlenecks" of the implementation. Therefore, the selected platform is a 16-bit Texas Instruments MSP430G2553 with the clock speed up to 16 MHz, 512 B RAM, and 2 x 16-bit timers. Before implementing the model, we should note that the typical applications of the MSP430 family include "low-cost sensor systems that capture analog signals, convert them to digital values and then process the data for display or transmission to a host system" [19]. However, the platform provides a tool for testing the design as well as for debugging the implementation algorithm. In contrast to [9], the selected platform allows for a floating-point operation, for which reason there are no rounding errors for the fixed-point operation. 3.2 Implementing AVIS on a Microcontroller Consider an electrotechnical system described by the connections such as the electric circuit in Fig. 2a with switches S1 and S2 turning on simultaneously. Then, the mathematical model of the system using the AVIS method is described by (5)-(8), and the algorithm of the analysis of the system would be as described in Subection 2.2. The currents at the end of the integration step and the voltages on the capacitors are unknown; the currents are calculated by the loop-current method by using the Cramer's rule. These calculations are performed in a loop and implemented on a microcontroller as a C program utilizing the IAR Embedded Workbench. As for the authors' opinion, the simplest technique of observation of the calculated variables is setting the dependence between the variables and duty cycle of the output PWM signal [20]. The microcontroller timer utilizes the SMCLK clock (of about 1.1 MHz) and sets the PWM period (Capture Compare Register 0, CCR0) to 256 clock ticks (that gives about 4 kHz). The timer runs in the "up" mode, counting from zero to the CCR0 value. Capture Compare Register 1, CCR1, is used for setting the duty cycle (when the timer counts to the CCR1 value, an interrupt is generated). Afterwards, the RC low-pass filter converts the obtained PWM signal to an analog waveform. The time scale for each waveform is expanded so as to obtain one iteration result for each change in the PWM period. Therefore, the waveforms are suitable for observation on an oscilloscope. After iteration, any further calculation stops until the permission (until the key switches from 0 to 1). Afterwards, the final values of the currents or voltages are converted to integer values and resized to match the desired range from 0 to 256 (in a real application, the range is closer, e.g. from 50 to 250 in order to avoid distortions). At the interrupt, the calculated integer value defines the CCR1 value and permits further calculations (the key switches to 1). 4 Results and Discussions As noted, when the algorithm is implemented on a microcontroller platform, the iteration time is 41.4 ms. At a time step of 10-4 s, this gives only 2.4 ms of the emulated time (the time taken for a model emulated on a microcontroller) for a second of a real time. When the parameters of the circuit are constant, the equivalent resistances at step Rsi are constant, too (3). Therefore, with a simplified algorithm, the calculation made outside the loop, the time taken for the iteration is hence reduced to 37.4 ms. Another computation optimization involves a matrix operation. Using specific formulae to calculate the currents at the end of a simulated integration step, instead of solving the matrix equations by using appropriate functions in a general form, reduces the iteration to 25.2 ms. This makes the designed emulator suitable for only a non-real-time operation when the steady-state values are required. Fig. 3 demonstrates results of using a mathematical model of a system on a microcontroller. Each subfigure contains two plots; one corresponds to a desktop simulation (simulated), and the other is a waveform obtained after filtering the output PWM signal of a microcontroller (further termed measured) as explained in Subsection 3.2. Both plots are combined into a single graph so that the real time of the measured plot corresponds to the calculation time of the simulated one. The time ratio, and also the scales on both ordinate axes, are selected so that the measured value and the anticipated value of the measurement can be compared at any time. Fig. 3 represents the values that correspond to the currents and voltages in the electrotechnical system in Fig. 2a. Compared to the desktop simulation, emulation on a microcontroller provides an adequate time-scalable representation of the simulated signals. 5 CONCLUSIONS AND FUTURE WORK The method of numerical integration of average voltages at the integration step (AVIS) is implemented + u™ = u 2.4 2 1.6 1.2 0.8 0.4 Time (s) 0.002 0.004 4 8 12 Time (s) o 3 2.5 > ^ 2 ro ra | 1.5 Time (s) 0.002 0.004 0.006 0.008 10 15 Time (s) 20 O 1.6 1.2 0.8 Time (s) 0.002 0.004 0.006 8 12 Time (s) 1.2 08 g 0.4 £ o 0 -0.4 Time (s) 0 0.002 0.004 2.4 £ 1.6 1.2 0.006 120 80 40 8 12 16 Time (s) 20 £ 2.4 2 1.6 1.2 0.8 Time (s) 0.002 0.004 0.006 2 =3 o 4 8 12 Time (s) 20 Time (s) 0 0.002 0.004 1.6 1.4 40 S^ (0 l 20 8 12 Time (s) Figure 3. Waveforms of the values of the circuit in Fig. 2a as a result of a desktop simulation and emulation on a microcontroller (voltages measured at the output of the microcontroller). 0 0 3 2 2 0 0 5 0 2 2 0 4 0 2 0 0 on a low-end microcontroller platform to design microcontroller models of electrotechnical systems. The method is selected and used for its high operational speed and numerical stability. Our model of the electrotechnical system utilizing the AVIS method is realized as a program in the C language and implemented on a Texas Instruments MSP430 platform. As shown, the device emulates the system, thus, computational capacities of the platform allow using it as a base for the state observers or estimators. At the current stage, our study serves only as a general guideline for implementing a method of the average voltages at the integration step for designing microcontroller models of electrotechnical systems. Our future work will be towards: (i) selection of a practical for emulators, such as electric drives, photovoltaic systems, etc.; (ii) implementation of guidelines for developing low-cost platform real-time applications. Appendix A Parameters of the Simulated Circuit Ei = 100 V, Ri = 20 Q, Li = 10 mH, L2 = 10 mH, C2 = 10 pF, R3 = 1 Q, C3 = 10 pF, R4 = 15 Q, E5 = 50 V, R5 = 1 Q, L5 = 20 mH. References [1] D. Tormo, L. Idkhajine, E. Monmasson and R. Blasco-Gimenez, "Evaluation of SoC-based embedded real-time simulators for electromechanical systems," in IECON 2016 - 42nd Annu. Conf. IEEE Ind. Electron. Soc., Florence, Italy, 2016, pp. 4772-4777. doi: 10.1109/IECON.2016.7793185 [2] G. Aiello, M. Cacciato, G. Scarcella and G. Scelba, "Failure analysis of AC motor drives via FPGA-based hardware-in-the-loop simulations," Elect. Eng., 2017, vol. 99, no. 4, pp. 13371347. doi: 10.1007/s00202-017-0630-3 [3] M. D. Omar Faruque et al, "Real-Time Simulation Technologies for Power Systems Design, Testing, and Analysis," IEEE Power Energy Technol. Syst. J., vol. 2, no. 2, pp. 63-73, 2015. doi: 10.1109/JPETS .2015.2427370 [4] S. Choe, S. Ko, S. Y. Kim and S. K. Sul, "Small scaled Power Hardware-In-The Loop and control method of ship integrated power system with active front end converter and battery energy storage system using low cost multicore DSP," in 2014 16th Eur. Conf. Power Electron. Appl., Lappeenranta, 2014, pp. 1-10. doi: 10.1109/EPE.2014.6910818 [5] I. Ivanovic, M. Barisic, and Z. Ribaric Tecec, "Implementing the wind speed estimation algorithm in the target embedded control system," in 17th Int. Conf. Elect. Drives Power Electron. (EDPE 2013), Dubrovnik, Croatia. 2013, pp. 340-345. [6] T. B. Rasmussen, G. Yang, A. H. Nielsen and Z. Y. Dong, "Implementation of a simplified state estimator for wind turbine monitoring on an embedded system," in 2017 Federated Conf. Comput. Sci. Inform. Syst. (FedCSIS), Prague, 2017, pp. 11671175. doi: 10.15439/2017F250 [7] C. T. Chu, H. K. Chiang, and R. S. Wu, "Sliding mode fuzzy neural network estimator using 8-bit microcontroller for motor fan air volume control," in 2014 Int. Symp. Next-Gen. Electron. (ISNE), 2014, pp. 1-4. doi: 10.1109/ISNE.2014.6839369 [8] E. Koley, R. Kumar, and S. Ghosh, "Low cost microcontroller based fault detector, classifier, zone identifier and locator for transmission lines using wavelet transform and artificial neural network: A hardware co-simulation approach," Int. J. Electr. Power Energy Syst., vol. 81, pp. 346-360, Oct. 2016. doi: 10.1016/j.ijepes.2016.02.015 [9] S. Nuratch, "Study and implementation of microcontroller-based system dynamics emulator using numerical method and reduction of order technique," in 201613th Int. Conf. Electr. Eng./Electron. Comput. Telecommun. Inf. Technol. (ECTI-CON), Chiang Mai, 2016, pp. 1-6. doi: 10.1109/ECTICon.2016.7561446 [10] N. Karami, R. Outbib, and N. Moubayed, "A low-cost microcontroller based 500-watt PEM Fuel Cell emulator," in 2012 IEEE Int. Syst. Conf. SysCon 2012, 2012, pp. 1-4. doi: 10.1109/SysCon.2012.6189439 [11] I. Turkoglu, "Hardware implementation of varicap diode's ANN model using PIC microcontrollers," Sensors Actuators A Phys., vol. 138, no. 2, pp. 288-293, Aug. 2007. doi: 10.1016/J.SNA.2007.05.003 [12] D. Celeita, M. Hernandez, G. Ramos, N. Penafiel, M. Rangel, J. D. Bernal, "Implementation of an educational real-time platform for relaying automation on smart grids," Elect. Power Syst. Res., vol. 130, 2016, pp. 156-166. doi: 10.1016/j.epsr.2015.09.003 [13] P. C. Kotsampopoulos, V. A. Kleftakis and N. D. Hatziargyriou, "Laboratory education of modern power systems using PHIL simulation," IEEE Trans. Power Syst., vol. 32, no. 5, pp. 39924001, 2017. doi: 10.1109/TPWRS.2016.2633201 [14] L. P. Sampaio and S. A. O. da Silva, "Graphic computational platform integrated with an electronic emulator dedicated to photovoltaic systems teaching," IETPower Electron., vol. 10, no. 14, p. 1982-1992, 2017. doi: 10.1049/iet-pel.2016.1018 [15] O. Plakhtyna, "Numerical one-step method of electric circuits analysis and its application in electromechanical tasks," (in Ukrainian), Bull. Natl. Tech. Univ. "KhPI, " vol. 30, pp. 223-225, 2008. [16] Z. Klosowski, O. Plakhtyna, and P. Grugel, "Applying the method of average voltage on the integration step length for the analysis of electrical circuits," Zeszyty Naukowe, Elektrotechnika, vol. 17, no. 264, 2014, pp. 17-31. [17] O. Plachtyna, Z. Klosowski, and R. Zarnowski, "Mathematical model of DC drive based on a step-averaged voltage numerical method," (in Polish), Przeglqd Elektrotechniczny, vol. 87, no. 12a, pp. 51-56, 2011. [18] O. Kuznyetsov, "Modeling of electromechanical systems based on induction machine using method of average voltage on the integration step length," UPB Sci. Bull. Ser. C Electr. Eng. Comput. Sci., vol. 79, no. 2, pp. 169-180, 2017. [19] Texas Instruments, "MSP430G2x53, MSP430G2x13 mixed signal microcontroller," SLAS735J datasheet, Apr. 2011 [Revised May 2013]. [20] M. Mitchell, Using PWM Timer_B as a DAC, Appl. Rep. SLAA116, Dec. 2000. Oleksiy Kuznyetsov received his M.Sc. degree in electric drives (2006), and Ph.D. degree in electrotechnical complexes and systems (2011), all from Lviv Polytechnic National University. Currently, he is an associate professor at the Hetman Petro Sahaidachnyi National Army Academy (Lviv, Ukraine). His research interests include electromechanical and electric power systems with semiconductor converters and embedded systems. Oleksandr Kuznietsov received his M.Sc. degree in computers (1973) from the Lviv Polytechnic National University (Lviv, Ukraine). Currently, he is a research fellow of the Lviv Centre of Institute for Space Research of National Academy of Science and State Space Agency. His research interests include embedded systems. Mykola Semeniuk received his M.Sc. degree in electric drives (2007) from the Lviv Polytechnic National University (Lviv, Ukraine) and Fachhochschule Giessen-Friedberg (Giessen, Germany), and his Ph.D. degree in electrotechnical complexes and systems (2011) from the Lviv Polytechnic National University. Currently, he is an associate professor at the Lviv Polytechnic National University. His research interests include excitation systems of synchronous generators.