## 2 Buck Converter Modeling
The algorithm calculates the state variables \(i_{L}\) and \(v_{C}\) at fixed time steps. The source of error in the simulation comes from the fact that at some point in time the inductor current reaches zero and must remain at zero. This moment does not necessarily happen at the time of the step calculation but can correspond to an instant which from the physical point of view lies within the simulation step. A straightforward approach to handle this situation is to set the inductor current to zero when it reaches zero during a deadtime. Figure 2 shows this situation: the inductor current reaches zero at some point within the \(dt\) time step, so it is forced to be zero at \(t_{n+1}\)The calculation algorithm for each time step of the numerical simulation can be expressed with the pseudo-code of Algorithm 2. ```
1:\((iL_{n+1},vC_{n+1})\leftarrow\textsc{calculateRK4}(iL_{n},vC_{n},dt,R,L,C,S1,S2,v_{s})\)
2:if\(sign(iL_{n+1})\
eq sign(iL_{n})\) AND \(S1=\textit{open}\) AND \(S2=\textit{open}\)then\(\triangleright\) iL crosses zero during a deadtime
3:\(iL_{n+1}\gets 0\)
4:endif
```

**Algorithm 2** State variable calculation with basic \(i_{L}\) saturation behavior

The value of \(i_{L}\) at \(t_{n+1}\) is zero, in accordance with the physical equivalence of the model, so it might be argued that this solution is close enough because it delivers the correct value of \(i_{L}\) at the moment \(t_{n+1}\). However, both variables \(i_{L}\) and \(v_{C}\) are interdependent: the calculation of \(v_{C}\) at \(t_{n+1}\) depends on the value of \(i_{L}\), and the value of \(i_{L}\) at the following cycle \(t_{n+2}\) depends on the value of \(v_{C}\) at \(t_{n+1}\), and so on successively. This means that if the error in calculation of \(v_{C}\) at \(t_{n+1}\) is significant, it will propagate onto \(i_{L}\) the next cycle \(t_{n+2}\), and then over the whole model. To verify the magnitude of the error introduced by this approach, the circuit under analysis was simulated with the values of \[\frac{dv_{C}}{dt} =\frac{i_{C}}{C} \tag{1}\]2 This buck converter is a real battery former that is used to make the initial charge of batteries. The three values for the resistor R correspond to the converter providing power to the load in different situations: high current, medium current, and low current. The battery-forming application requires low current at initial and final charging stages, as the battery impedance is high at those points, and high current during the intermediate forming stage. Although the impedance of the real batteries used in the experiments dropped down to 1.2 \(\Omega\), experiments showed that any value of R lower than 7.5 \(\Omega\) will not cause zero crossings in the current. This means that average inductor currents over 1.33 A do not cause deadtimes. Therefore, the value of 7.5 \(\Omega\) is used as the high-current case. \begin{table}
\begin{tabular}{c c} \hline \hline
**Variable** & **Value** \\ \hline \(R\) & 7.5, 15 and 30 \(\Omega\) \\ \(L\) & 850 \(\mu\)H \\ \(C\) & 35 \(\mu\)F \\ Switching frequency & 10 kHz \\ \(v_{s}\) & 25 V \\ time \(S1=\) closed & 40 \(\mu\)s \\ deadtime 1 & 10 \(\mu\)s \\ time \(S2=\) closed & 40 \(\mu\)s \\ deadtime 2 & 10 \(\mu\)s \\ \hline \hline \end{tabular}
\end{table} 
Table 1: Values chosen for the buck converter. Figure 2: \(iL\) crosses zero during a deadtime (dotted line) and is forced to zero (continuous line). As stated before, when the load requires a higher current (modeled with \(R=7.5\;\Omega\)), zero-crossing events during deadtimes do not take place. This means that the \"if\" condition in Algorithm 2 is never fulfilled and the inductor current is never forced to zero. This can be used as the reference case to assess the contribution of the zero-crossing events to the global error. As zero-crossing events do not happen, the main contributor to the error must be the discretization inaccuracies inherent to the fourth-order Runge-Kutta method used.