## 2 Buck Converter Modeling
In real conditions, HIL systems do not require such a level of accuracy (around \(10^{-5}\) or lower), as other sources of errors are also present. However, this source of error prevents the use of Runge-Kutta or other accurate numerical methods that become necessary in more complex models for integration steps around 1 us, which is a typical commercial value. Therefore, the goal of this proposal is to enable the benefits of accurate numerical methods, such as Runge-Kutta, even when relatively high integration steps are used during deadtime events. ## 4 Time Step Subdivision with a Linear Approximation

The initial approximation of Algorithm 2 introduces an undesirable error in the numerical simulation due to the fact that the evolution of \(i_{L}\) and \(v_{\text{C}}\) inside one cycle of duration \(dt\) is not properly calculated during deadtimes with zero-crossing events. A power converter in a correctly designed circuit might typically operate inside a current region where these events are not very frequent, but the objective of hardware-in-the-loop \begin{table}
\begin{tabular}{c c c c c} \hline \hline \(R\) & **Zero-Crossing Events** & **Percentage of Cycles** & \(i_{L}\) **Error (A)** & \(v_{\text{C}}\) **Error (V)** \\ \hline \(7.5\,\Omega\) & 0 & 0\% & \(4.57\times 10^{-12}\) & \(2.42\times 10^{-11}\) \\ \(15\,\Omega\) & 1 & 2\% & \(5.73\times 10^{-6}\) & \(2.83\times 10^{-5}\) \\ \(30\,\Omega\) & 39 & 78\% & \(5.69\times 10^{-6}\) & \(9.34\times 10^{-5}\) \\ \hline \hline \end{tabular}
\end{table} 
Table 2: Number of times \(i_{L}\) crosses zero during a deadtime in 50 switching cycles, percentage of cycles where this occurred, and error in calculation of \(i_{L}\) and \(v_{\text{C}}\) using Algorithm 2 with \(dt=1\) μs and 64-bit floating-point representation. Figure 4: Error in calculation of \(v_{\text{C}}\) and \(i_{L}\) as a function of the time step using Algorithm 2.

simulation is to provide a realistic approximation of the circuit, and especially corner cases must be accurately modeled to allow for validation of the elements being tested in all possible situations. Therefore, a better modeling for the zero-crossing events must be provided. The proposed approximation is to divide the time step into two substeps of length \(dt1\) and \(dt2\), respectively, and perform one calculation for each of these time periods. The first substep is defined by the time that the current takes to reach a zero value within the present simulation step. The second substep is defined by the remaining time of the calculation step, that is, \(dt2=dt-dt1\). Figure 5 shows this situation. The state variables can then be calculated using Algorithm 1 for each substep. The first calculation corresponds to the first substep and uses \(dt1\) instead of \(dt\). The second substep uses \(dt2\) instead of \(dt\). The value of \(dt1\) is calculated using a linear approximation. It can be seen that the ratio between \(dt1\) and \(dt\) is equal to the ratio between \(abs(iL_{n})\) and \(abs(iL_{n})+abs(iL_{n+1})\). Then, the fraction of time step ending with inductor current at zero is given by:

\[\frac{dt1}{dt}=\frac{abs(iL_{n})}{abs(iL_{n})+abs(iL_{n+1})} \tag{11}\]

Algorithm 2 can be modified into its revised version, Algorithm 3. Note that in line 5 (Algorithm 3), the duration of the first substep \(dt1\) is used, and in line 6 (Algorithm 3), the duration of the second substep \(dt2\) is used. At the end of these steps, \(iL_{n+1}\) and \(vC_{n+1}\) are the calculated values of the state variables, either if the condition in the second line was fulfilled or not. In the case that it was fulfilled, the algorithm requires a division (line 3) and two additional executions of the fourth-order Runge-Kutta algorithm (lines 5 and 6). This adds additional complexity to the design, and it must be evaluated if the obtained accuracy offsets that complexity in terms of implementation and logic resource usage.