1. Introduction
The hardware in the loop (HIL) simulation consists of the substitution of a real element for a digital system solving a mathematical model in real time. It is a technique widely used in segments such as the automotive, military, aerospace industry and more recently in power electronics (Faruque & Dinavahi, 2010), mainly to carry out tests and validation of new products, which could be dangerous, expensive or with complicated scenarios to obtain in a real environment.
Power electronics present challenges with respect to HIL simulation, caused by the high switching frequencies used, which are in the range of tens of kilohertz (kHz). There is commercial equipment that allows to conduct the HIL simulation for power converters (Karimi et al., 2010; Li et al., 2010; Mayet et al., 2017; Ramos et al., 2017). However, they present the disadvantage of a high economic cost, in addition, the solution time is in the range of microseconds, which limits the switching frequency used, it is recommended that the solution time be at least 100 times smaller than the switching period (Dagbagi et al., 2016), additionally, there are not control over the solution method used to solve the continuous system. Due to this, various researchers have developed customized systems based mainly on FPGAs to perform HIL simulation, achieving solution times in the order of hundreds of nanosecond conductor (Jiménez et al., 2014; Li & Jean, 2017; Lucia et al., 2010; Majstorovic et al., 2011; Matar & Iravani, 2013; Selvamuthukumaran & Gupta, 2014; Wang et al., 2014), however, languages with a high learning curve are used, such as VHDL or Verilog to carry out the implementation, which, significantly increases the complexity the implementation.
The HIL simulation begins with the development of a mathematical model in continuous time, to implement the model in a digital system; it must be solved using some numerical method. The most used numerical method is the Euler method, due to the easy implementation, some other methods such as Heun and fourth order Runge-Kutta, are mentioned as possibilities to perform the HIL simulation (Saralegui et al., 2018), however, experimental results are not obtained.
There are two types of HIL the controller hardware in the loop (CHIL) and the power hardware in the loop (PHIL). In CHIL the objective is to test the controller, in Mitsugi et al. (2020) it is used to test the control of an energy storage system, in Amiri et al. (2020), it is used to test the controller of a converter used to correct the power factor, in Zucuni et al (2020), and (Estrada et al., 2021), it is used to test a new cost function for predictive controllers, in Busarello et al. (2020) it is used to test digital controls for converters connected to the electrical network, the HIL simulation is helpful to reduce the time to market for new products.
In PHIL, the objective is to test the converter. Examples of this equipment are PV emulators, wind turbine emulators or any power supply that can emulate the behavior of an energy system generator.
This article discusses four numerical methods from the point of view of an FPGA-based HIL design: Euler, Heun, midpoint, and fourth order Runge-Kutta. The design effort is analyzed considering the resources used in the FPGA and the precision of the simulation, making the comparison against a real converter. The case study is a buck converter, which is a switched converter, so the equations are constantly changing, in each switching period.
The rest of the paper is organized as follows: Section II describes the case study and the equations that model the converter. Section III shows how to apply the different numerical methods to solve the converter model. Section IV shows the results obtained in the simulation conducted by each method and finally, section V presents the conclusions.
2. Buck converter modelling
As a case study, the buck converter is used (Figure 1), to evaluate the HIL simulation, this is a converter widely used as a power source for consumer electronics.
The buck converter has seven elements: a power supply (v in ), a switch (S), a diode (D), an inductor (L), a series resistance of inductor (R L ), a capacitor (C), and a load (R)
To model the converter, the following considerations were made: the switch and the diode are considered ideal.
The buck converter has three switching states, determined by the control signal of the switch S and the value of the inductor current (i L ).
The first state occurs when the switch is on, and the diode is not conducting as seen in Figure 2. The second state begins when the switch is turned off and the diode begins to conduct (Figure 3), and the third state occurs when the Inductor current is equal to zero and the switch is off as shown in Figure 4. However, when the power converter is operating in continuous conduction mode (CCM), only the first two states are present. The differential equations are obtained using Kirchhoff's laws.
Applying Kirchhoff's laws to the circuit in Figure 2, we obtain the equations for i L (Eq. 1) and the voltage across the capacitor (v C ) (Eq. 2).
Where R DS is the MOSFET on resistance.
In all states i O is equal to (Eq. 3):
In the same way, but using the circuit of Figure 3, the equations for i L (Eq. 4) and v C (Eq. 5) are obtained.
Where V D is the forward voltage of the diode.
Applying Kirchoff's laws to the circuit in Figure 4, the (Eqs. 6 and 7) are obtained:
Equations (1) - (7) model the converter in the three states that it can present.
3. Numerical method solution
To solve differential equations using numerical methods, a known value (y k ) and the slope of the function (θ) are used, with these data it is possible to calculate an approximation to the following value (y (k+1) ), of the function in an integration time (h), this can be seen graphically in Figure 5.
The main difference between the different numerical methods is how θ is calculated (Butcher, 2008).
Table 1 shows the formulation to obtain the solution by the different methods.
Table 1 Formulation of the different numericalmethods used.
Method | Formulation |
Euler |
|
Midpoint |
|
Heun |
|
Fourth order RK |
|
In Appendix A Table A1 the solution of the buck converter model using Euler method is shown. In Appendix B the solution using Heun method, in Appendix C the solution using Midpoint method is shown and finally in Appendix D the solution using the fourth order RK, these solutions are easily implemented in high-level languages, such as C or using programs such as Matlab or LabVIEW. In this paper LabVIEW was used for its simplicity, power and for the characteristic of being able to download its code directly on FPGA-based platforms, in this paper a CompactRIO system Model 9067 with a 667 MHz Dual-Core CPU, 512 MB DRAM, 1 GB Storage and Zynq-7020 FPGA is used.
In Figure 6 the experimental testbed used to obtain the results is shown. It can be seen the elements used during the tests.
The main ones are: a function generator to generate the PWM signal, the buck converter, the CompactRIO in which the converter model is programmed and the analog outputs (in this case the simulated inductor current and capacitor voltage), are obtained, an oscilloscope to be able to visualize the signals of the real converter and the simulation at the same time, and finally, the CPU in which the model of the converter was programmed, the graphic user interface (GUI), is running.
In Figure 7 a block diagram of the experimental test bed is shown.
4. Results
The buck converter was designed using the methodology shown in Kazimierczu (2008); the values for the passive components are shown in Table 2.
Table 2 Buck converter design parameters.
Parameter | Value | Units |
vin | 24 | V |
C | 10 | µF |
L | 500 | µH |
RL | 0.12 | Ω |
R | 12 | Ω |
The numerical solution of the continuous model was programmed using the methodology shown in (Estrada et al. 2020)
Tests were performed with a fs of 100 kHz and then with a f s of 50 kHz using the numerical methods mentioned above. Figure 8 shows the current and voltage transient comparison between a real converter and the converter model using the four different numerical methods and a f s 100 kHz.

Figure 8 Transient of the real converter and HIL simulation using a fs = 100 kHz. CH1 vO real converter, CH2 iL real converter, CH3 vO HIL simulation and CH4 iL HIL simulation. (a) Euler method, (b) Midpoint method, (c) Heun method and (d) 4th Order Runge-Kutta method.
Once the results of all numerical methods are obtained for a f s of a 100kHz, the mean arithmetic error (MAE) is obtained, which is the average of all the errors at each instant of time, comparing the results of the HIL simulations with those of the real circuit. These results are shown in Table 3.
Table 3 Real and simulated converter comparison using different numerical method and a fs of a 100kHz.
Method | MAE vC | MAE iL |
Euler | 0.591586345 V | 0.057833333 A |
Midpoint | 0.635297661 V | 0.078457986 A |
Heun | 0.594257028 V | 0.100714859 A |
RK4 | 0.550870111 V | 0.080648135 A |
The same tests were performed reducing the f s from 100 kHz to 50 kHz. Figure 9 shows the current and voltage transient comparison between a real converter and the converter model using the four selected numerical methods with a switching frequency of 50 kHz. Again, obtaining the errors of each numerical method, but now with a f s of 50kHz, Table 4 was obtained with a comparison between each numerical method can be observed clearly.

Figure 9 Transient of the real converter and HIL simulation using a fs = 50 kHz. CH1 vO real converter, CH2 iL real converter, CH3 vO HIL simulation and CH4 iL HIL simulation. (a) Euler method, (b) Midpoint method, (c) Heun method and (d) 4th Order Runge-Kutta method.
Table 4 Real and simulated converter comparison using different numerical method and a fs of a50kHz.
Method | MAE vC | MAE iL |
Euler | 0.440902708 V | 0.070655968 A |
Midpoint | 0.448815261 V | 0.108716867 A |
Heun | 0.439157472 V | 0.07177332 A |
RK4 | 0.45856 V | 0.096722 A |
In Figure 8 a load change was carried out in order to verify the behavior of the model. The load was changed from 24W to 12W. The results prove that the HIL system presents a good transient behavior with any numerical method. In addition to the comparison in Tables 3 and 4, to analyze the effectiveness of the numerical methods, the number of computational resources and solution time that each method requires is obtained. Table 5 shows the resources and time used by each numerical method.
Table 5 Comparison of used resources and execution time using different methods.
Method | Register | LUTs | DSP | Total | Execution time |
Euler | 2.3% | 4.8% | 9.5% | 7.2% | 150ns |
Midpoint | 2.8% | 5.9% | 16.8% | 9.9% | 325ns |
Heun | 2.8% | 6.2% | 16.8% | 9.4% | 350ns |
Runge-Kutta | 4.05% | 10.7% | 49.5% | 16.7% | 750ns |
Conclusions
The results reported in Tables 3, 4 and 5 show the arithmetic mean error between the developed HIL simulator and a real buck converter prototype. It can be seen that although Euler's method is considered the worst numerical method in terms of accuracy (as long as they have the same solution time), it is the method that contains the least error, and this is because it is the method with the shortest solution time which helps its accuracy.
Another crucial point to consider is the error when the switching frequency increases, since it is recommended that the solution time of the real-time simulation is at least 100 times smaller than the switching period of the converter, so, the one with the smallest error working at 100 kHz is Euler's method.
The results obtained shows that, although there are better numerical methods than Euler's with respect to stability and error, this is the best method for HIL systems where the integration time must be kept small and resources are limited, such as the case of power converters.
Although the results show that the Euler method is the best for high switching frequencies, the other methods are also capable of solving a system in real time and can be used for other types of applications where the integration time does not have to be so small and computational resources are not a limitation in its implementation.