# Design and Control of a Battery Charger/Discharger Based on the Flyback Topology
## 2 Proposed Charger/Discharger  
The proposed charger/discharger circuit is based on a bidirectional flyback converter; thus, the classical output diode must be replaced by a second Mosfet. Figure 2 presents the proposed circuit, where Mosfet M\({}_{2}\) replaces the output diode of the unidirectional Flyback converter, while Mosfet M\({}_{1}\) is in the same position for both unidirectional and bidirectional topologies.  
The flyback converter includes a HFT, which provides galvanic isolation and a high voltage conversion ratio. In the circuit of Figure 2, the HFT is highlighted in green color, and it is modeled accounting for both the magnetizing \(L_{m}\) and leakage \(L_{k}\) inductances [35; 36]. The magnetizing inductance is modeled at the primary side, which allows analyzing the effect of the primary control signal \(u\) on the circuit. Instead, the leakage inductance is modeled at the secondary side, which enables the analysis of the dynamic behavior of the DC bus voltage \(v_{dc}\). The HFT is modeled, without loss of generality, with a turn ratio \(1:n\), but any other relation can be adopted.  
In this bidirectional circuit, the primary control signal \(u\) activates/deactivates the Mosfet M\({}_{1}\) at the primary side of the HFT, while the complementary control signal \(\tilde{u}=1-u\) activates/deactivates the Mosfet M\({}_{2}\) at the secondary side of the HFT. The circuital model of the battery charger, depicted in Figure 2, models the interaction between sources and loads connected to the DC bus as a single bus current \(j_{dc}\), which is the result of subtracting  
Figure 2: Proposed circuit for the charger/discharger based on the flyback topology.  
the sources and loads currents, i.e., \(i_{dc}=(i_{\rm{i1}}+i_{\rm{i2}}+\cdots i_{in})-(i_{\rm{i0}}+i_{\rm{i02}}+\cdots i_ {\rm{i0m}})\) using the nomenclature of Figure 1. In addition, the DC bus capacitance is modeled with the \(C_{dc}\) capacitor, which collects the output capacitances of the sources and the input capacitances of the loads connected to the bus.  
The charger/discharger proposed in Figure 2 also includes a control system aimed at regulating the bus voltage \(v_{dc}\), which is needed to provide a safe operating condition to both sources and loads. Such a control system is designed using the sliding-mode control (SMC) theory, and its analysis and stability are studied in the following section. The outputs of the SMC are the converter control signals \(u\) and \(\bar{u}\), thus no PWM is required. Figure 2 also describes the measurements needed by the SMC: current of both the primary \(i_{p}\) and secondary \(i_{s}\) sides of the HFT, battery voltage \(v_{b}\), DC bus voltage \(v_{dc}\), and current \(i_{dc}\). Since both battery and DC bus are isolated by the HFT, a single ground reference is not present, instead the battery and DC bus voltages are measured using differential voltage sensors \(S_{vb}\) and \(S_{vdc}\), respectively. From the circuit it is also noted that the battery current is equal to the current at the primary side of the HFT, thus \(i_{b}=i_{p}\). Finally, the SMC receives the reference value \(v_{r}\) of the DC bus voltage.