Double Adaptive PI-Structure for Regulating a Microgrid DC Bus Using a Flyback-Based Battery Charger/Discharger Converter

: DC microgrids are composed of loads, renewable sources, and storage devices that require control and protection to operate safely. The ﬂyback converter is an alternative to connect paralleled batteries with nominal voltage DC buses; however, until now, complex controllers have been proposed, making difﬁcult their implementation. On the other hand, when the voltage of a DC microgrid is not properly controlled, the loads may be damaged due to the voltage outside of the safe range. Therefore, proposed in this paper are two adaptive PI-structures to control a battery charger based on a ﬂyback converter to be used in DC microgrids. The ﬁrst adaptive current controller regulates the magnetizing current for stabilizing the system, and the second adaptive voltage controller regulates the voltage of the DC bus to protect the elements of the microgrid. The methodology to design the adaptive parameters of the PI-structures is developed as follows: ﬁrst, the power stage of the ﬂyback converter is introduced to derive a control-oriented model. The battery and the DC bus of the microgrid, which are interfaced by the ﬂyback converter, are represented with widely accepted approaches. The second step is focused on modeling the system. The ﬂyback converter, which includes a capacitance to model the DC microgrid, is represented by a dynamic model. The differential equations are averaged, and several transfer functions of the main variables are obtained. In the third step, the transfer functions are used to design the PI adaptive current controller and the PI adaptive voltage controller. In the last step, several recommendations are made to implement the power and control stages in low-cost hardware. An application example with realistic parameters is carried out in PSIM to validate the controller loops design. A battery of 12 V is connected to a DC microgrid of 48 V through a ﬂyback converter with a switching frequency of 50 kHz. The settling time and deviation of the DC microgrid voltage, after a perturbation, are 0.845 ms and 2.04 V respectively, while the maximum values are adjusted to be 1 ms and 2.4 V. The simulation results validate the proposed procedure and the effectiveness of the PI-structures in regulating the magnetizing current and the DC bus voltage.


Introduction
Energy storage systems (ESSs) are essential elements in AC and DC microgrids (MGs) since they compensate for the unbalances between generation and load produced by unpredictable renewable energy sources, like photovoltaic and wind turbine generators [1][2][3]. Although there are different ESSs technologies, like batteries, supercapacitors, flywheels, superconducting magnetic energy storage, pumped hydro, among others [4], batteries have established as the most widely used ESS technology. Lithium-ion batteries are particularly important since they correspond to 93% of the 5 GW energy storage capacity installed in 2020, according to the International Energy Agency [5]. a phone [20], and feeding a LED light system [22]. However, these papers do not provide general design procedures that can be applied for other applications, since in [20] the authors determine the PI's proportional gain (k p ) and the integral time (t i ) by testing three different arbitrary values for each parameter, while in [21,22] the authors do not provide any design procedure of k p and t i .
The solutions proposed in [23,24] have the same structure as the ones introduced in the previous paragraph, but they use a two-poles/two-zeros compensator instead of a PI, and the flyback output voltage is regulated to feed a DC motor. In both papers, the compensator's parameters are designed to obtain the desired frequency response in a particular operating point of the system.
Other papers report cascade PIs to regulate the flyback output voltage to implement an electric vehicle battery charger [25,26], where the flyback input voltage is regulated by another converter with an independent controller. The cascade controller proposed in these papers has an inner loop with a PI that tracks a reference of the current injected to the battery, while the outer loop is a PI that regulates the flyback output voltage by manipulating the reference of the inner loop. In [26] the authors use frequency response to determine k p and t i of both PIs to obtain a stable system for a particular operating point. Nevertheless, in [25] the authors do not provide any design procedure for the proposed controllers.
The linear controllers for flyback-based charging or discharging (i.e., one direction of power flow) systems described before are designed for a single operating point with fixed controller parameters. Therefore, those controllers cannot guarantee the same dynamic performance of the system for any operating condition. Moreover, the papers that use linear controllers do not provide a detailed design procedure to determine the controllers' parameters, which makes difficult their application for a charging/discharging system power flows in both directions of the converter. Additionally, the SMC controller proposed in [15] provides a variable switching frequency of the converter, which makes it difficult to design the converter and filters, and requires analog circuitry for its implementation.
This paper proposed a cascade linear controller with adaptive parameters for a flybackbased charging/discharging system along with a detailed design procedure of the controller's parameters. In the cascade controller, the outer loop regulates the DC bus voltage by manipulating the magnetizing current reference, whereas the inner loop tracks such reference by modifying the duty cycle. The inner loop is implemented with a proportional controller with an adaptive gain (k i ) to guarantee that the closed-loop crossover frequency is 1/5 of the switching frequency (F); while the outer loop is realized with a PI with two adaptive parameters (x p and x i ), where x p assures a damping ratio equal to 1 whilst x i is designed to fulfill the desired settling time, a maximum deviation, and a closed-loop crossover frequency less than F/25. The paper includes a detailed design procedure for the three controller parameters and guarantees the same dynamic performance of the DC bus voltage for any operating condition. Therefore, the main contributions of the paper are: (1) a cascade controller implemented with two adaptive linear compensators that guarantee the system stability and the desired dynamic performance for any operating point and mode (i.e., charging, discharging, or null); (2) a detailed design procedure of the cascade controller parameters (k i , x p , and x i ) considering the system stability and the bandwidth restrictions of the inner and outer loops; (3) a flyback-based charging/discharging system that operates at a constant switching frequency with an adaptive linear controller, which facilitates the design of the converter as well as the controller implementation.
The rest of the paper is organized as follows: Section 2 introduces a control-oriented model of the system, the description of the proposed cascade controller, and the design procedure. Section 3 shows an application example of the proposed design procedure, which illustrates that the system is stable and show the same dynamic performance for different operating conditions. Section 4 closes the paper with the conclusions.

Proposed Cascade Controller and Design Procedure
This section begins with the description of the charging/discharging system considered in this paper along with its main elements. Such description is used afterward to explain the control-oriented model used for the analysis and design procedure of magnetizing current controller. With the inner controller designed, the section continues with the system model assuming a controlled magnetizing current, which is used to analyze the DC bus voltage adaptive PI regulator and its design procedure. This section closes with a summary of the proposed controller design procedure to help the reader with its implementation.

Circuital Interface
The power electronics interface proposed for this application is based on a bidirectional implementation of a flyback converter. The main advantages of this converter are the galvanic isolation, which protects the battery from failures occurring on the DC bus due to problems on the devices of the MG; and the variable voltage conversion ratio, which enables to develop a single solution suitable for multiple MGs with different bus voltage requirements.
A simplified model of the battery interface application is presented in Figure 1, which shows the flyback converter modeled with an ideal transformer with a turn ratio 1:n interacting with both the magnetizing (L m ) and the leakage (L k ) inductances. Such a power converter is designed with two complementary MOSFETs (MOS 1 and MOS 2 ) to enable the bidirectional power flow between the battery and the bus; moreover, those MOSFETs are activated using a complementary dual driver, such as the UC1715 Complementary Switch FET Driver [27], which produces the complementary activation signals u for MOS 1 andū = 1 − u for MOS 2 . The control signal of this power circuit is the duty cycle d of the converter, thus a PWM circuit is included in the circuital interface of Figure 1. The MOSFETs are selected to have built-in current sensing capabilities, which are needed to implement the control structure of the battery interface. Some examples of those MOSFETs are the BUK7908-40AIE [28], BUK7107-55AIE [29], and IMZ120R045M1 [30], which have TrenchPLUS current sensing circuits; and the IRCZ24 [31] that has HEXSence internal current sensors. Finally, the capacitance of the bus is labeled as C bus , which must be designed depending on the MG requirements as will be discussed in Section 2.4.

Battery
Microgrid Bus  The circuital interface of Figure 1 models the battery with the voltage source v b , and the MG bus is modeled with the C bus capacitance and the current source i bus , which combines the currents provided by the sources and consumed by the MG loads. Finally, the circuital interface has the following sensors for control purposes: the MOSFETs currents i M1 and i M2 , the battery voltage v b , the bus voltage v bus , and the current exchanged with the bus i bus , which could be positive (discharge mode), negative (charge mode), or zero (null mode).
This circuital interface must be controlled, by imposing an appropriate duty cycle, to provide a regulated bus voltage, which ensures a safe operation of the devices forming the MG. The following sections deal with the design of such a controller.

Control-Oriented Model
The correct design of the bus voltage controller requires a control-oriented model of the circuital interface, which is developed in this subsection.
The first state of the circuital interface occurs when u = 0 (thusū = 1), which produces the following equations for the bus voltage v bus , magnetizing current i m , leakage current i k , MOSFETs currents i M1 and i M2 : Similarly, the second state of the circuital interface occurs when u = 1 (thusū = 0), which produces the following equations: Those equations are averaged within the switching period T of the PWM using the duty cycle definition d = 1 T · T 0 u dt, where F = 1/T is the switching frequency: In stable conditions the previous derivatives are equal to (or near) zero, which leads to the following stable values for the duty cycle and magnetizing current: The next step to obtain a control-oriented model is to summarize the averaged differential Equations (9) and (10) into the following matrix format: For this circuital interface, the states vector X m and the inputs vector U m are defined as given in (17), which produces the A m and B m matrices reported in (18) and (19), respectively.
Matrices C m and D m depend on the outputs Y m defined for the system. Since the main objective is to regulate the bus voltage to ensure a safe operation of the MG, thus, the first option is to define where s is the Laplace variable and I is the identity matrix, leads to the following transfer function: The previous transfer function has a right-hand zero (RHZ), i.e., a positive zero; hence, a feedback linear-loop for a power converter designed with such a transfer function will be unstable as discussed in [32]. Therefore, the voltage in this type of system is commonly regulated using cascade structures with an inner current controller as it is discussed in [25,26], which avoids the problem of the RHZ if it is not present in the current-to-duty cycle transfer function.
To design an inner current controller, it is necessary to obtain the I m (s) d(s) transfer function. Thus, the output vector is defined as Y m,i = [i m ], which produces the matrices C m,i = [1 0] and D m,i = [0 0 0]. Then, applying the matrix-to-transfer function transformation I m (s) d(s) = C m,i · (s · I − A m ) −1 · B m + D m,i leads to the following transfer function: Such a transfer function (21) does not have RHZ because all the terms in the numerator are positive (including 1 − d > 0); thus, it is possible to design a stable current loop for the flyback converter using a linear controller. The G i m ,d (s) transfer function is rewritten as given in (22) to reduce the mathematical expressions, where z 1 and z 2 given in (23) describe the zero, and σ given in (24) describes the poles. It must be noted that z 2 expression uses the steady i m value previously obtained in (14).
Finally, the previous z 1 , z 2 , and σ values must be evaluated at the operating point in which the MG is operating. Therefore, the following sections propose adaptive controllers, which are automatically modified to compensate for the changes on z 1 , z 2 , and σ.

Adaptive Current Controller
The design of the current controller is performed using the G i m ,d (s) transfer function given in (22); thus, the duty cycle d is generated to regulate the magnetizing current i m . This process is carried out adopting the feedback structure presented in Figure 2, where the proportional controller k i is located in the feedback loop. The design of the k i value requires the calculation of the closed-loop transfer function T i , which describes the behavior of I m (s) for changes on the reference value I r (s). Applying block diagram algebra to Figure 2 leads to the following transfer function for the current loop: Taking into account that the magnetizing current is not the main variable intended to be controlled, the only restriction applied to T i is to constrain the transfer function gain at the maximum frequency in which the averaged model (21) accurately represents the circuit behavior. The gain of the T i (s) transfer function, given as a function of the angular frequency, is reported in (26).
The bandwidth of the closed loop transfer function T i (s) must be restricted to the bandwidth of the model G i m ,d (s) used for the control design, otherwise the closed-loop system will operate in a frequency range in which the converter has not been modeled. In [33] it was confirmed the validity of the averaged model of a switching converter at 1/5 of the switching frequency (F), thus that is the bandwidth adopted for the design of k i . Therefore, Equation (26)  for an angular frequency ω x = 2 · π · F/5 results in the following k i expression: Therefore, the k i value must be dynamically calculated, using (27), to ensure the desired behavior of the current controller for any operating condition. Taking into account that z 1 , z 2 , and σ depend on v b , v bus , and i bus , such variables must be measured to update periodically the k i value, thus adapting the current controller to the operating conditions imposed by both the battery and MG.
Finally, the steady-state gain M i of the current loop transfer function (25) must be calculated, since such gain affects the stable value of the magnetizing current as I m = M i · I r . Therefore, such an M i gain must be included in the model designed to develop the bus voltage controller, which is analyzed in the following section. The M i value is calculated by evaluating (26) for ω = 0 rad/s as follows: n·i bus (28) It must be noted that the final M i value was calculated by replacing the z 2 and σ values given in (23) and (24), respectively, and using the k i value updated with Equation (27). Therefore, the M i value is also an adaptive quantity.

Adaptive Voltage Controller
The next step needed to design the bus voltage controller is to obtain a closed-loop model of the circuital interface including the current control loop. The electrical equivalent of the flyback converter considering the current loop is presented in Figure 3a, where the average current of the second MOSFET i M2 is regulated by the current loop, which imposes the value reported in Equation (12)   Applying the Kirchhoff current law and capacitor differential equation to the circuit of Figure 3a, in the Laplace domain, leads to the bus voltage equation given in (29). Such an expression depends on both the reference current i r and bus current i bus , where the latter one corresponds to the main perturbation of the system. From such an expression, two transfer functions are defined: G v,i r given in (30), which describes the behavior of v bus to changes on the current reference i r ; and G v,i bus given in (31), which describes the behavior on v bus to perturbations on the bus current i bus . Figure 3b shows the block diagram of the cascade voltage loop, which considers a voltage controller named H v . Such a voltage controller processes the error between the voltage reference v r and the bus voltage v bus to produce the reference i r of the current loop. Thus, the output of the voltage controller i r is the input of the transfer function G v,i r , while bus current i bus is the input of the transfer function G v,i bus . Finally, the bus voltage is the result of the contribution of both G v,i r and G v,i bus .
This work proposes the design of a classical PI controller for H v as given in (32), where x p is the proportional parameter and x i is the integral parameter.
Applying block diagram algebra to Figure 3b leads to the transfer function for the voltage loop given in (33), which describes the effect of i bus perturbations on the bus voltage v bus . Thus, the design of H v parameters must be performed using such a transfer function. However, it is noted that the transfer function coefficients depend on both M i and d, which change with the operating point. Therefore, H v parameters x p and x i must be adapted to ensure consistent behavior of the bus voltage.
The adaptation of x p and x i is performed by normalizing those values concerning both M i and d, obtaining the normalized parameters α p and α i as given below: Then, replacing the normalized parameters (34) into the bus voltage transfer function (33) leads to the normalized closed-loop transfer function given in (35), which exhibits constant coefficients, thus a consistent behavior of the bus voltage could be ensured.
The controller design must be performed for the worst perturbation possible on the bus current, which corresponds to a step current with an arbitrary amplitude ∆I bus ; thus, in the Laplace domain, it is i bus = ∆I bus s . Then, evaluating the bus voltage from the normalized transfer function (35) Considering the canonical second-order denominator s 2 + 2 · ρ · ω n · s + ω 2 n enables to obtain the expressions for the natural frequency ω n and damping ratio ρ of the previous transfer function, as follows: To provide a bus voltage without oscillations, the damping ratio is defined as ρ = 1. Then, replacing such ρ value in (37) results in the following relation between α p and α i : Replacing the previous relation into expression (36), and applying the inverse Laplace transformation, leads to the time-domain waveform of the bus voltage given in (39), which is the response of the voltage loop to the worst-case perturbation i bus = ∆I bus s .
The design of the voltage controller is performed to impose the following performance criteria:

1.
Maximum settling time t s needed to restore the bus voltage into an acceptable band [− , ]. In engineering, the most commonly used band for the settling time is = 2%, but any other value can be used depending on the MG requirements.

2.
Maximum bus voltage deviation MD after the bus current perturbation occurs.

3.
Finally, in [33] was confirmed that the validity of the current loop model on a cascade voltage control structure, like the one modeled in Figure 3, is limited to 1/5 of the current loop bandwidth. Therefore, since the current loop bandwidth was limited to ω x = 2 · π · F/5, the cut-gain frequency ω c of the transfer function (36) must be limited to 1/25 of the switching frequency; thus, a maximum angular frequency ω c = 2 · π · F/25 must be ensured.
For the first performance criterion, i.e., the settling time, Expression (39) is solved for v bus = · v r and t = t s by using the LambertW function (W), which provides the expression of t s as a function of the controller parameter α i and bus capacitance C bus : For the second performance criterion, i.e., the maximum deviation, Expression (39) is derived as given in (41), which enables to find the time t MD needed to reach the maximum voltage deviation that occurs when dv bus dt = 0; Equation (42) provides the expression for t MD .
Finally, replacing the previous t MD value on the bus voltage Equation (39) provides the expression of MD as a function of the controller parameter α i and bus capacitance C bus : The third performance criterion is calculated by first obtaining the magnitude of (35) depending on the angular frequency as given in (44). Then, solving that equation for the −3 dB magnitude, thus T v,N(ω) = 1 √ 2 , provides the expression of the cut-gain frequency ω c as a function of the controller parameter α i and bus capacitance C bus , which must be lower or equal than F/25 as given in (45).
Finally, the maximum acceptable setting time t * s and bus voltage deviation MD * are defined depending on the operational requirements of the sources and loads connected to the MG. Therefore, the non-linear equation system given in (46) must be solved to calculate both the controller parameter α i and bus capacitance C bus needed to ensure the correct operation of the MG. Figure 4 summarizes the offline process needed to design both the voltage controller parameters (α i and α p ) and the bus capacitance (C bus ). Such a design process must be performed a single time since the adaptability of the control system will compensate for the changes in the operating point. The figure also summarizes the online process needed to adapt both the current and voltage loops to the changes on the operating point; this process must be performed in real-time, using analog or digital circuitry, to ensure that the controller parameters always have the correct values.

Summary of the Design Procedure
Calculate p using (38) Calculate xp and xi using (34) Calculate d using (13) or measure d = ir -ki·im from current loop Calculate ki using (23), (24) and (27)

Results and Discussion
This section introduces the validation of the proposed controller and its dynamic performance by using an application example for a battery charging/discharging system. The section begins with a description of the implementation of the proposed controller, including the estimation procedure of the magnetizing current and the online calculation of the adaptive controller's parameters (k i , x p , and x i ). Then, the section shows the dynamic performance of the proposed controller beginning with the magnetizing current for charging, discharging, and null operating modes. Finally, the section introduces an example of the design procedure of the DC voltage regulator and shows that the dynamic behavior meets the desired criteria (t s , MD, and w c ) for the different operating conditions.

Implementation of the Adaptive Control System
The implementation of the proposed control system is performed using Equations (27) and (28) for real-time calculation of k i and M i , respectively; Equation (34) is used for the real-time calculation of the adapted PI parameters x p and x i ; the feedback structure described in the block diagram of Figure 2 is used to implement the adaptive current loop, and the feedback structure described in the block diagram of Figure 3b is used to implement the adaptive voltage loop. Such an implementation scheme is depicted in Figure 5. Moreover, the calculation of x p and x i requires the value d = 1 − d; thus, such a calculation must be also performed in real-time. Finally, the current loop requires the value of the magnetizing current i m , which cannot be directly measured; instead, the magnetizing current must be reconstructed from the MOSFETs built-in current sensors, which were discussed in Section 2.1 and Figure 1. Such a reconstruction of the magnetizing current i * m is based on Equations (4) and (7), as given in (47), which is also considered in the implementation scheme of Figure 5.
Considering that Equations (27) and (28) require a lot of non-linear calculations, those expressions are most suitable to be processed with a digital microprocessor. Instead, the PI calculations (integration and addition) could be done using analog circuitry like operational amplifiers. On the other hand, the calculation of x p and x i requires divisions and multiplications, which can be done using digital or analog circuits; however, taking into account that Equations (27) and (28) must certainly be calculated using a microprocessor, x p and x i can be calculated inside the same microprocessor. The same approach can be applied to the calculation of d . By contrast, the reconstructed magnetizing current i * m must be calculated using analog circuitry (operational amplifiers), since the current loop must be calculated as fast as possible. Finally, the duty cycle calculated by the current loop is delivered to the PWM, which interacts with a complementary dual-driver to act on both MOSFETs as discussed in Section 2.1.

Application Example and Validation
This subsection presents an application of the proposed solution using realistic parameters, which enables the validation of the proposed control strategy and design process. The main parameters of the application example are given in Table 1, which defines the switching frequency, battery and bus voltages, bus current range, and maximum bus current perturbation. In addition, the example considers a maximum safe deviation of the bus voltage equal to 5% (2.4 V), and a maximum 2% settling time equal to 1 ms. Finally, the transformer adopted for this application is the Vitec 58PR6962 [34], which is widely adopted in high-frequency converters [35]. Table 1. Parameters of the application example.

Parameter
Value The validation of the proposed control system is performed using the professional power electronics simulator PSIM [36], which is widely used in the industry. Figure 6 shows the circuital implementation in PSIM of both power and control systems, which includes the real (non-linear) behavior of the MOSFETs, and both the magnetizing and leakage effects of the high-frequency transformer. Therefore, such a simulation tests the proposed control system under realistic conditions.
In such a circuital implementation, the calculation of k i , M i , d , x p , and x i is performed in real-time using a C-block. That a block is useful to simulate digital microprocessors programmed in C language, such as the TMS320F28335 from Texas Instruments [37], where the C code used to program the C-block can be used, without any major change, to program the digital microprocessor. This is possible due to the C-block uses ANSI C; hence, it is highly portable to other platforms. Figure 6 also highlights the circuital implementation of both adaptive loops, including the reconstruction of the magnetizing current and the PWM circuit. Moreover, the power circuit includes two current sensors simulating the MOSFETs current sensing capabilities; and the bus current is simulated using a current source, which can be modified to simulate the MG current flow generated by the interaction of the devices (sources and loads) connected to the bus. Such a circuital implementation is used to perform two tests: the first one only evaluates the current loop-thus, the voltage loop is disconnected; the second one evaluates the complete control system-thus, both current and voltage loops are active. The first simulation considers the adaptive current loop designed in Section 2.3 following a pre-defined reference, which enables the validation of the correct adaptation of k i even without the action of a voltage controller, i.e., with a non-regulated bus voltage. Figure 6 shows, in the red box, the PSIM implementation of the adaptive current loop; however, in this first simulation i r is generated by a programmable source followed by a 10 kHz low-pass filter, which restricts the i r bandwidth up to 1/5 of the switching frequency to fulfill the k i design given in (27). Figure 7 reports the PSIM circuital simulation of the adaptive current loop for three reference values (i r ), where i r is multiplied by the loop gain M i (28) to validate the accurate regulation of the magnetizing current i m = M i · i r .   The simulation of Figure 7 confirms the correct regulation of the magnetizing current, which is achieved by adapting k i to changes in the bus current, bus voltage, and magnetizing current. Moreover, the simulation also verifies the correct operation of the current loop for charge mode, discharge mode, and null mode, therefore confirming the correct behavior under any operating condition. The next step is to design the parameters of the adaptive voltage loop.
The normalized parameters α p and α i and the bus capacitance C bus are calculated following the flowchart previously presented in Figure 4: solving the system of nonlinear equations reported in that flowchart, using the t * s and MD * values given in Table 1, producing the solution spaces reported in Figure 8. In particular, Figure 8a shows the values of both C bus and α i needed to ensure a maximum deviation lower than MD * , while Figure 8b shows the values of those parameters needed to ensure a settling time lower than t * s . Those figures provide the solution of (46) including the limitation of the voltage loop bandwidth to F/25 defined in (45), thus ensuring the stability of the voltage loop. From Figure 8a,b can be selected particular C bus and α i values to define precise MD < MD * and t s < t * s conditions; in this example, a commercially available C bus = 110 µF capacitance is selected, thus providing a 17% safe margin for the maximum deviation. Similarly, α i = 6400 A/(V · s) is selected to provide a 15% safe margin for the settling time.   Finally, Figure 10 reports the complete PSIM simulation of the double adaptive PIstructure, which corresponds to the circuital implementation of Figure 6 including the adaptive voltage loop. This simulation considers a bus current profile with charge, discharge, and null conditions to evaluate the control system for all the possible conditions. The first step perturbation in the bus current has ∆i bus = 2 A as reported in Table 1, and the simulation shows a settling time t s = 0.845 ms and a maximum voltage deviation MD = 2.04 V, which is in agreement with the design parameters selected from Figure 8 and with the theoretical results reported in the normalized simulation of Figure 9. Therefore, this circuital simulation confirms the validity of both the design process and the practical implementation reported in Figure 6. Moreover, the bus current also exhibits step changes for both charge and discharge conditions, where the bus voltage is always lower than MD; therefore, t s and MD are always below the maximum limits defined in Table 1, i.e., MD * = 5% and t * s = 1 ms, which ensures a safe operation of all the devices connected to the MG.  The simulation of Figure 10 also shows the correct operation of the adaptive current loop, since the magnetizing current i m is always equal to the theoretical value i r · M i . Finally, the figure also shows the dynamic adaptation of the voltage loop parameters x p and x i , which both are modified when the bus voltage and current change. Therefore, the proposed control system always ensures the same desired performance for any operating condition, which is the main objective of the proposed control system.

Conclusions
DC MGs are a suitable approach to connect loads, renewable sources, and storage devices to produce electric energy. Loads, sources, and storages devices can be interconnected through power converters that can be used to guarantee a safe operation of the elements and consequently for the entire MG. A formal design of a battery charging/discharging solution based on a flyback converter and two adaptive control loops were proposed in this paper to protect the devices of a DC MG. The design was dominated by a formal procedure that modeled the system and establish three performance criteria to be guaranteed by the controllers: a maximum settling time, a maximum voltage deviation, and a maximum angular frequency. The PI structures are adaptive to changes in the operating point, even for changes in the converter parameters. To encourage the interested community to implement the battery charging solution, a detailed design flowchart was presented. In addition, several recommendations were made to select the hardware that can be used in the implementation of the battery charger and its controllers. Hence, this paper provides three main contributions: (1) an adaptive linear controller that guarantees the system stability and the desired dynamic behavior for any operating condition; (2) a step-by-step design procedure to determine the controller parameters considering the system stability; and (3) a charging/discharging based on a flyback converter with an adaptive linear controller that operates at a fixed switching frequency.
Finally, a practical example simulated in PSIM software confirmed the correct operation of the adaptive current loop and the adaptive voltage loop. The simulation results showed that bus voltage fulfilled the performance criteria defined in the case (t s = 1 ms, MD = 5%, and w c ≤ F/25). However, additional verifications, using real hardware, will be performed in the future to test the proposed control system under commercial conditions. Funding: This work was supported by the Universidad Nacional de Colombia and the Instituto Tecnológico Metropolitano under the research project "Microinversor de alta eficiencia para maximizar la extracción y transferencia de energía desde paneles fotovoltaicos ubicados en zonas con sombreado parcial a cargas de corriente alterna y voltaje estándar (110 V)" (Hermes code 49938, ITM code PE21103).

Institutional Review Board Statement: Not applicable.
Informed Consent Statement: Not applicable.

Data Availability Statement:
The data used in this study are reported in the paper figures and tables.