## 4 Proposed PI Controllers with Online Tuning Mechanism  
Assessment of each controller's performance is carried out under both the steady-state and dynamic conditions. For this purpose, a step change in \(V_{\text{in}}\) is introduced in order to investigate the controller's response. As an approach to improve this response, an online tuning mechanism has been suggested. A number of tuning methods have been proposed in the literature [34; 35; 36]. In this paper, a different tuning algorithm is proposed to add an online tuning feature to the PI controller. The proposed PI controller is basically modified based on the conventional PI controller described in Section 3. Two proposed PI controllers with the online tuning method are employed to control \(V_{1}\), \(V_{2}\), \(V_{3}\) and \(V_{4}\), as portrayed in Figure 5. As compared to the conventional PI controller, the proposed PI controller consists of an additional component in its structure, which is the online tuning module. Here, \(V_{\text{in}}\) signal is required in the online tuning module, so that proper adjustment can be made according to the change in \(V_{\text{in}}\). In this work, the tuning algorithm is designed to tune \(K_{\text{PU}}\) and \(K_{\text{PL}}\). At the same time, \(K_{\text{iU}}\) and \(K_{\text{iL}}\), and the anti-windup parameters for both parts remain unchanged. Then, \(y_{\text{U}}(t)\) and \(y_{\text{L}}(t)\) are compared with the carrier signal to produce the switching signals. As shown in Figure 5, the switching signals of \(S_{1}\) and \(S_{2}\) are complementary to each other. The same also goes for \(S_{3}\) and \(S_{4}\). Figure 6 presents the flowchart of the online tuning algorithm for the upper part of the buck-boost converter. Five equations are derived to generate a new \(K_{\text{PU}}\). Derivation of these equations is made based on the correlation between \(K_{\text{PU}}\) and \(V_{\text{in}}\) that is established after a preliminary testing is carried out. In this testing phase, actual measurement of the output current THD of the inverter is used to build the aforementioned correlation so that tuning error due to the ideal-condition assumption can be minimized. Further details of the preliminary testing are provided in Section 7. Figure 4: Block diagram of the PI controller. Figure 5: Block diagram of the proposed PI controllers with online tuning module. (**a**) Upper part of buck-boost converter. (**b**) Lower part of buck-boost converter. Figure 6: Online tuning mechanism for the upper part of buck-boost converter. Firstly, the present value of V\({}_{\rm in}\) is checked for whether it is similar to its previous value (stored in V\({}_{\rm in,old}\)). V\({}_{\rm in,old}\) is updated to the present value if it is different from the previous value. The new K\({}_{\rm PU}\) is calculated based on the present value of V\({}_{\rm in}\). Then, the previous value of K\({}_{\rm PU}\), K\({}_{\rm PU,old}\) is updated to the new K\({}_{\rm PU}\). If V\({}_{\rm in}\) is between 0 V and 60 V, the new K\({}_{\rm PU}\) is calculated as below:  
\[\rm K_{PU}=0.05~{}V_{in}-1 \tag{3}\]  
A new K\({}_{\rm PU}\) is constant at 2 if V\({}_{\rm in}\) is between 60 V and 80 V. If V\({}_{\rm in}\) is between 80 V and 100 V, the new K\({}_{\rm PU}\) is given by the equation below:  
\[\rm K_{PU}=0.05~{}V_{in}-2 \tag{4}\]  
If V\({}_{\rm in}\) is between 100 V and 280 V, the new K\({}_{\rm PU}\) is constant at 3. The new K\({}_{\rm PU}\) is calculated as below if V\({}_{\rm in}\) is between 280 V and 300 V:  
\[\rm K_{PU}=-0.05~{}V_{in}+17 \tag{5}\]  
If V\({}_{\rm in}\) is the same as V\({}_{\rm in,old}\), then K\({}_{\rm PU}\) is checked for whether it is within the allowable K\({}_{\rm PU}\) band. K\({}_{\rm PU}\) band is defined as the range between the maximum and minimum limits of K\({}_{\rm PU}\). The reason K\({}_{\rm PU}\) must be within the defined range is to maintain capacitor voltages balanced while ensuring that the lowest output current THD can be achieved.