PV-Battery Assisted Three-Level T-Type Inverter for AC Residential Nanogrid Realized With Small-Scale HIL Units

Hardware-in-the-loop (HIL) testing methods by means of HIL units or real-time simulators (RTS), are becoming broadly accepted for validating of control systems in many technical areas. This new approach brings advantages such as the acceleration of the industrial and the research development cycle and offers a risk-free and flexible environment for the testing and the evaluation stages before the control deployment in the physical system. Nevertheless, the realization of such methodology can be very challenging in some large or complex plants. In this scenario, a proper simulation of the physical system, that is, the development of its accurate digital twin, demands a suitable and reliable sectioning of the different components into different parts running in parallel into different HIL units. This is the case of a nanogrid (nG) involving some prosumers with renewable energy resources (RES), and their corresponding multiple power electronic converters. These power electronic converters operate at high switching frequencies, which require a very low simulation time step, as well as a high number of input and output signals in closed-loop operation. This work analyzes in detail how to realize a digital twin of a two-prosumer residential nG including a photovoltaic (PV)-battery assisted three-level T-type (3L T-Type) inverter and managed by a hierarchical grid-forming (GFM) control structure by means of RTS based on the RT Box 1 by Plexim. The analysis allows to test the proposed GFM controls and the control hardware in steady and transient conditions, validating their accurate performance.


I. INTRODUCTION
Aiming to reduce the worldwide carbon footprint, renewable energy sources (RES) are being nowadays increasingly connected into the current electrical system. These RES, such as wind and solar photovoltaic (PV), together with energy storage systems (ESS) are power electronic-based The associate editor coordinating the review of this manuscript and approving it for publication was Zhilei Yao . energy distributed systems and, at the same time, they are considered the key enabling technology for the urgent green energy transition [1]. A residential nanogrid (nG) (for example, a prosumer-based residential building) is one of the high-interesting scenarios where we can find such kind of distributed system [2], [3], [4]. Few years ago, those power electronic-based energy distributed systems were typically operated in grid-following (GFL) mode, acting as current sources exchanging active and reactive power [5], [6].
Nevertheless, the use of grid-forming (GFM) power electronic units is gaining high research and industrial attention due to the wide range of associated benefits of providing gridsupport and ancillary services [7], [8], [9], [10]. The GFM approach allows to ''form'' a grid by generating its own voltage, however, the low inertia and variability in RES production may cause disturbances affecting to its grid stability: e.g., large voltage and frequency sags and swells, and to its grid power quality. Due to that, the GFM control structures must provide viable control strategies to successfully implement nGs under contingency conditions [11]. Hence, a comprehensive and in-depth research of the dynamic performance of GFM control schemes designed for nGs under a broad spectrum of RESs and their power electronic converters in many operating conditions, is essential prior to their final deployment and systematic building in residential environments. Consequently, a risk-free environment for designing and testing GFM controls and nG topologies is vital in such relatively large and expensive systems.
Hardware-in-the-loop (HIL) systems and power hardwarein-the-loop (PHIL) simulations for microgrids and nGs give engineers the possibility to predict the performances of various control strategies based on GFM approaches [12], [13]. It accelerates the development cycle, increasing the number of tested nG scenarios and power-electronic units, along with safety and no damages on the plant, since it is simulated. This simulated plant is often known as the digital twin of the real physical system [14]. Fortunately, there is a decreasing trend in the cost of computational power and chips, and several small-scale real-time simulators are an accessible technology today (e.g., Typhoon HIL, dSPACE, Speedgoat, RT Box, etc.). Furthermore, this technology offers dedicated embedded coder support packages to program by means of blocks, which also helps to accelerate the development time.
In the domain of power electronic converters, some features are demanded to those real-time simulators (RTS). One is a simulation time step significantly lower than the switching period (which is decreasing due to modern wide-bandgap semiconductors) in order to guarantee an accurate simulation. Another is a low latency to simulate the system dynamics, which is particularly fast in power electronic interfaces, specially operating with RES. At the same time, it will be required to easily connect the controller hardware (the socalled device under test (DUT)) by a suitable interface, which controls the power part running in the RTS. Even though the computational capability and the number of input-output channels in the RTS or small-scale HIL units are increasing day by day, the proper emulation of complex systems involving multiple power electronic converters may be very challenging when using these hardware [15], as in the case of a nG or a microgrid. High-fidelity HIL testing of microgrids or nGs requires reading many inputs at high sampling rates, as for example capturing the switching signals generated by the DUT. Once those control signal are captured, the RTS produces the outputs according to the expected behavior of the equivalent real nG, including many power switches. This fact will require a valid sectioning of the nG model demanding to be simulated on multiple RTS/small-scale HIL units in parallel. In fact, it is the particular subject to be analyzed and verified in this work for a particular residential nG with different RES and power electronic converters. This issue (the sectioning of the power stage) is considered a trending research topic in recent days, and only few works in the literature address this critical stage [15].
Motivated by this, the contribution of this paper is significant in several ways. Firstly, the paper addresses the critical issue of sectioning a complex power system by interconnecting different RTS or small-scale HIL units, which is a current research methodology but has only been addressed by a few works in the literature. Secondly, the paper presents a digital twin of an islanded AC residential nG that includes two prosumers, RESs, ESS, and common loads connected at the nG point-of-common-coupling (PCC). This model considers various power converter topologies, including a three-phase three-level T-type inverter (3L T-type), a dualactive-bridge (DAB) power converter, which acts as an interface to the ESS and allows for bidirectional power flow with a high-voltage gain ratio, and a conventional three-phase twolevel (2L) voltage source inverter (VSI). Thirdly, the paper demonstrates the effectiveness of the proposed approach in evaluating the dynamic performance of GFM controls in realtime and validating the developed control running in the real hardware controller. Overall, this paper contributes to the existing knowledge by presenting a comprehensive model and an effective approach for testing and validating nGs, which is essential for the development and deployment of reliable and efficient modern RES-based power systems.
The structure of the paper is as follows. Section II describes in detail the case of study, including the structure of the ac residential nG, specifications and the control associated to each power electronic converter. Special attention is paid to the GFM units operating in parallel to supply the considered load. For the ESS and the DAB, two main control modes are designed, namely the day and the night mode respectively. Section III explains step by step the proposed arrangement of the testing setup environment, based on the RT Boxes 1 by Plexim and other specific hardware. Due to the high number of switching signals and computational demands, a carefully sectioning of the power stage is required and explained for a proper simulation in multiple HIL units. Section IV shows and discusses the main HIL results in a particular test in different residential nG steady and transient conditions, validating the accurate performance of the different controllers. Finally, section V concludes the papers.

II. AC RESIDENTIAL NANOGRID SPECIFICATIONS AND FEATURES
The main schematic diagram of the islanded nG is illustrated in Figure 1. Two independent prosumers are feeding a residential load connected at the PCC. Each prosumer consists  of a distributed generation (DG) unit connected to a RES unit (modelled as an ideal voltage source). An ESS assisted 3L T-Type inverter with LCL filter acts as interface between the RES of prosumer 1 and the PCC. The DAB converter allows bidirectional power flow between the nG and the ESS. On the contrary, a 2L VSI is employed for prosumer 2 for simplification. Suitable LCL output filters have been designed for each VSI to reduce harmonics and facilitate the active and the reactive power flow between prosumers, according to [16]. A detailed description of the control stages and power converter topologies will be provided in the next sections.

A. POWER ELECTRONIC CONVERTERS
In this paper, three different power converter topologies are employed as the constituent power hardware elements of the nG, which are depicted in Figure 1. The 3L T-Type inverter is a high-competitive three-level topology that dispenses with the clamping diodes used in its counterpart, the neutral-pointclamped (NPC) inverter, in addition to offering some benefits such as better efficiency within the medium switching frequency range [17], [18]. The DAB converter is a widely used topology to achieve bidirectional power transmission. This dc-dc converter is composed of two H-bridges, a highfrequency transformer, and a leakage inductance, offering high efficiency and soft switching capability [19]. Finally, the well-known 2L VSI topology completes the nG power electronics. The main design parameters of each power converter are summarized in Table 1.

B. CONTROL STAGES
A GFM control structure [9] is implemented for each prosumer VSI as illustrated in Figure 2. An external power loop based on the droop technique aims to perform power sharing among prosumers while maintaining the voltage and frequency of the nG under certain limits. The droop control exploits the existing coupling between the active power and the reactive power with the phase angle and the voltage, respectively, through the following relationships: where f * nG and V * C,i are the reference values of frequency and RMS voltage, f i and V C,i are the frequency and RMS voltage in each power converter, P * i and Q * i are the setpoints of active and reactive power of each VSI, P i and Q i are the measured active and reactive power, and m pi and m qi are the droop coefficients selected based on the maximum active and reactive rated power of each DG unit and the maximum value of frequency and voltage deviations.
Although a synchronization unit is not required for the normal operation of the nG, a back-up PLL is included for the pre-synchronization of prosumer i. Power calculations are derived from the measured voltage at the filter capacitor v Cf ,i and the nG side current i L2,i , and subsequently filtered. Additionally, the virtual impedance technique is used to overcome the problem of active and reactive power coupling by introducing a virtual voltage drop across a virtual impedance Z v (s) [20] with the following transfer function: where L v is the virtual impedance inductance and ω c is the cut-off frequency. The voltage reference in the filter capacitor v * Cf ,1 provided by the droop control is accurately tracked by proportionalresonant (PR) cascade dual inner loops in the αβ reference frame with an outer voltage control loop for regulating v Cf ,i , and a current control loop for regulating the inverter side current i L1,i . The PR control stage outputs the modulation signals for the pulse-width-modulation (PWM) generation. Two different modulation techniques, one for each VSI, are employed. The space vector PWM (SVPWM) technique described in [21], with minimum common-mode voltage (CMV) and dc-link capacitors voltage balancing ability, is used for the 3L T-Type inverter. On the contrary, the 2L-VSI is switched by means of a simple carrier-based PWM.
Regarding the DAB control, two modes of operation are considered as depicted in Figure 3, which are selected by signal m. During the day operation, the reference active power P * ESS provided to the ESS system is tracked by means of a PI controller and the dc-link voltage control is not considered. On the contrary, during the night mode, the RES unit is isolated from the dc-link of prosumer 1 and the DAB must be capable to exchange active power in both directions between the nG and the ESS, while maintaining the reference dc-link voltage. For that purpose, the voltage at the high-voltage side (v dc ) is measured. In both cases, the controller acts on the phase shift angle Φ to be fed to a variable PWM generator that allows the phase shift between the PWM carriers to be dynamically adjusted. Four different PWM signals are generated, two for each H-bridge, being the high voltage H-bridge phase shifted an angle Φ with respect to the low voltage H-bridge.
In addition, the dc-link voltage control of the DAB during night mode can be highly beneficial when integrating a PV array model into the nG system, utilizing either maximum power point tracking (MPPT) or reference power point tracking (RPPT) control algorithms [22], depending on the battery's charge level and the load connected at the PCC. In this scenario, the PV array model, along with an additional dc-dc boost converter stage, replaces the previous ideal voltage source in prosumer 1, as illustrated in Figure 4, to showcase the nG system's flexibility in working in MPPT and RPPT modes while maintaining the GFM approach. The algorithms employed for this case study are based on the perturb and observe (P&O) method, using an adaptive step to optimize the steady-state performance [22]. During MPPT, the P&O algorithm adjusts the duty cycle of the dc-dc converter to bring the PV array to its maximum power point. By regulating the dc-link voltage, the DAB can either absorb or inject energy as required to meet the nG load demand, thereby maintaining the GFM approach.
However, in light load conditions, it is possible that the excess power supplied by the solar panel may fully charge the battery, rendering it incapable of absorbing any more energy and hence unable to continue controlling the dc-link voltage. To avoid this scenario, the dc-dc boost converter is switched to RPPT mode, and the P&O algorithm starts tracking the active power reference provided by the primary control. To guarantee a null average power delivered by the DAB, a PI controller is employed to update the RPPT reference, taking into account load fluctuations and power losses, as shown in Figure 4. For this purpose, the output current of the DAB (i DAB ) is measured to determine the power delivered or absorbed. The RPPT mode is activated when a control signal indicates that the battery is charged, or the charging power exceeds a particular threshold. It is worth noting that the battery must have a charging margin to maintain dc-link voltage control, hence the RPPT mode is initiated before the battery is completely charged. In the hierarchical control structure of the nG, the droop based GFM approach corresponds to the primary control  layer, for which no communications links are necessary. However, the droop control mechanism presents some drawbacks, such as frequency and voltage deviations. In order restore the frequency and the voltage, a centralized secondary controller was implemented as illustrated in Figure 5 [23] and [24].
The second-order generalized integrator phase-lockedloop (SOGI-PLL) approach was employed for the detection of the frequency and the voltage amplitude, ω nG and E nG , respectively, at the PCC. Two PI controllers are responsible for generating the control signals δ ωi , δE i to be fed to the primary controllers of each prosumer with the aim of tracking the nominal references values of frequency and voltage, ω * nG and E * nG , respectively. The main design parameters of the hierarchical control of the islanded nG are summarized in Table 2.

III. CONTROLLERS DESIGN
This section addresses the design of the different controllers involved in the control strategy.

A. PR CASCADE DUAL INNER LOOPS CONTROL
In order to facilitate the analysis and the design of the voltage/current cascade PR controllers, the system to be controlled has been simplified to its equivalent single-phase converter model with output filter. This approximation can be easily extended to the three-phase converter system of the case of study of this paper without lack of generality, permitting to employ conventional stability analysis techniques.
The equivalent single-phase block diagram of the control system is depicted in Figure 6 (a), which can be derived from  Kirchhoff's law. By applying block algebra, the simplified closed-loop block diagram of the PR cascade dual inner loop for the single-phase converter is obtained as illustrated in Figure 6 (b), which can be easily modelled and tuned through simulation tools such as Simulink from Matlab. In this diagram, the transfer functions G i v (s) and G v i (s) are defined as in (4) and (5), shown at the bottom of the next page, whereas C V (s) and C I (s) account for the transfer functions of the PR voltage and current controllers, respectively, where K PV , K PI , K RV and K RI are the proportional and resonant gain terms, and ω 0 is the resonant frequency: The selected gains of the voltage/current PR controllers are K PV = 0.05, K PI = 4, K RV = 150, and K RI = 5000, respectively, which were tuned by means of the Control System Tuner from Matlab. The design criteria was adopted following the guidelines in [25] with an outer voltage loop faster than the inner current loop in order to meet the design requirements. This feature improves the control by permitting a faster current tracking of the inner loop but avoiding any dangerous current overshoot, as the largest control action comes from the PR voltage controller output (i * L1 ). Figure 7 illustrates the poles and zeros location of the closed-loop control system (Figure 7 (a)) and the response of the capacitor voltage v * Cf to a sinusoidal input unit step (Figure 7 (b)). It can be seen that the system is stable and exhibits a good dynamic transient.

B. DAB CONTROL
As stated previously, PI based single-loops for both the active power and the voltage control are employed in the DAB converter. This is a widely used approach that relies on an adequate tuning of the PI controller. To successfully achieve the voltage controller tuning, a small-signal dynamic model of the DAB converter needs to be derived due to its inherent non-linearity. This small-signal model can be obtained by linearizing the average model of the converter around a given operation point (Φ). The averaged model of the DAB is obtained by ignoring the dynamics of the leakage inductance current i lk and averaging the values of input and output currents over one switching cycle. Therefore, the DAB is simplified to a first-order system where each H-bridge is substituted by a DC current source dependent on Φ, as illustrated in Figure 8 (a). The assumptions in [26] were considered by modelling the load of the converter, which is the inverter stage, as an equivalent resistor equal to the small-signal input impedance of the inverter at nominal load: The output power and the averaged output current over one switching period are described by [27]: where V i and V o are the output and input voltages, respectively, n is the high frequency transformer turns ratio, f s is the switching frequency, L lk is the leakage inductance, and Φ is the phase shift between the primary and secondary sides of the DAB. Considering small perturbations of the phase shift, Φ= Φ+Φ, i b2 = I b2 + î b2 , the transfer function from Φ to i b2 is described by: From the block diagram of the reduced-order model illustrated in Figure 8 (b), the first order transfer function of v o with respect to Φ is given by: 48012 VOLUME 11, 2023 Authorized licensed use limited to the terms of the applicable license agreement with IEEE. Restrictions apply. Assuming G v o Φ (s) is the model of the plant to be controlled with the phase shift angle as the input variable and, taking into account a PI based single loop controller with unity feedback, the transfer function of the closed-loop system is expressed as: where G c (s) = K p s+K i s . Now the problem is reduced to the design of a PI controller for a first-order system, which can be easily developed through the aforementioned System Control Tuner from Matlab/Simulink. Taking into account the leakage inductance value L lk = 2.44 µF, which was selected to allow a transfer power range large enough for the two operation modes, the linearization point was considered Φ = 35 • for the night mode, where the control system is regulating the voltage. The selected gains for the DAB voltage control during the night mode are K p = 0.017 and K i = 0.17, meeting the design criteria for an overshoot below 20% and a settling time of  approximately 0.3 s. The stability and dynamic behavior of the developed control is illustrated by showing the response of the system to the unit step in Figure 9.
On the contrary, the controller gains for the power control of the day mode were manually adjusted to meet the desired dynamic behavior, with the values K p = 0.01 and K i = 10. For this case, a more experimentally tuning approach was necessary in order to obtain a suitable closed-loop performance of the system.

C. SECONDARY CONTROL
As stated previously, the central secondary control relies on the intercommunication between DG units to achieve global controllability of the nG, restoring the frequency and voltage deviations caused by the actuation of the local primary controls.
The frequency restoration is based on a slow PI control that restores the frequency in the nG to its nominal value (2π50 rad/s). The frequency restoration compensator can be derived as follows: (12) where K pf and K if are the proportional and integral gains of the PI compensator. The error between the measured frequency and the reference are computed and processed through the compensator to generate a control action to be sent to each DG unit. A very similar approach is employed for the voltage restoration in the nG, being a slow PI compensator, the control structure employed to process the voltage signal error that will be sent by means of a low bandwidth communication network to each DG unit. Therefore, the voltage restoration is expressed as: (13) where K pE and K iE are the proportional and integral gains of the PI compensator. The PI control parameters are set to K p = 0.1 and K i = 1 for both the frequency and the voltage control loops ensuring a slower dynamic behavior than the primary control.

IV. DETAILED AC RESIDENTIAL NANOGRID HIL DESCRIPTION
The number of available commercial RTS platforms for HIL testing has greatly increased with the emergence of chip multiprocessors, graphics processing units and fieldprogrammable gate arrays (FPGAs), which have considerably reduced the computation time. Nonetheless, small scale HIL units are limited in terms of the number of analog and digital I/Os, which might become a challenge when simulating more complex systems. Moreover, small scale HIL units are required to run at high sampling rates in order to guarantee high fidelity and accurate switching signals acquisition, posing additional difficulties when simulating computationally demanding plants with a high number of power switches, as it is the case of the islanded nG presented.
To tackle these limitations, the distributed HIL testing structure in Figure 10 is proposed, where a suitable sectioning of the nG hardware permits to run the model in multiple HIL units. This approach facilitates the validation of the embedded code of each prosumer control using Texas Instruments C2000 Delfino microcontrollers, which are properly interfaced with two RT Box 1 from Plexim, acting as the RTS units.
The plant is split up attending to the available PWM signals of each microcontroller unit (MCU): only the 3L T-type inverter converter runs on one of the RT Box simulator, as it presents the highest number of power switches, whereas the 2L-inverter and the DAB are assigned to a second RT Box. The electrical connection between the different parts of the model is achieved by a communication link established through the SFP+ ports available at each RT Box unit.

A. STRUCTURE OF THE HIL UNIT
Each HIL unit is composed of the three hardware elements depicted in Figure 11. The RTS platform employed is the RT Box 1 from Plexim, with FPGA embedded central processing unit (CPU) cores as processing system. The LaunchPad interface provided by Plexim permits the direct connection of the LaunchXL development kits from Texas Instruments to the RT Box 1 by means of an optimized pinout.
The software PLECS (version 4.6.7, Plexim electrical engineering software) was employed for the code generation by means of a specific library for the TI C2000 processors, taking advantage of the block programming. The microcontroller platform selected for the embedded code validation is the LaunchXL-F28379D evaluation tool for the TMS320F28379D MCU. Voltage and current measurements are sent from the simulated plant to the analog inputs of the microcontroller through the corresponding analog output channels. The PWM modules of the MCU generate the switching signals to be captured by the digital inputs of the RT Box with a sampling time of 7 microseconds. Due to the fast-switching frequency of 20 kHz, a sub-cycle average configuration of the power modules was adopted. In this configuration, voltage and current sources are used to model the power converters and the control signals are computed by periodically averaging the digital input PWM signals. As a consequence of the low I/O latency achieved in the modelled plant, the microcontroller never realizes that it is controlling a simulated model instead of the real system, thus a digital twin of the plant is accomplished.

B. DATA TRANSFER BETWEEN HIL UNITS
The distributed HIL structure of the islanded nG requires a high-speed bidirectional communication link between HIL units to exchange the electrical measurements. For that purpose, the RT Box provides SFP+ ports with a bandwidth of 6.25 Gbps and a latency of two simulation steps. An SFP+ direct attach cable was employed as illustrated in the experimental setup of Figure 12. One additional advantage of the SFP+ ports is the possibility of synchronizing the simulation time steps and the simulation startup between the different RT Boxes.
This is a necessary feature to guarantee consistent electrical and model states. A manager/subordinate relationship between the RT Boxes must be established in such a way that the clock signal of the manager unit is received by the subordinate RT Box via SFP+ connection. The start signal for startup synchronization is likewise sent to the subordinate RT Box by the manager. The simulation step time must be identical both in the manager and subordinate RT Boxes. For the islanded nG case, a simulation time step of 7 microseconds was implemented for both RTS platforms, acting the RT Box of prosumer 2 as the manager for clocks synchronization. A second communication link between the two HIL units is needed for the central secondary control to restore voltage and frequency deviations during a load change.
In the central secondary control structure, all the required data is typically transmitted through a high-data-rate communication infrastructure (CI), e.g., Ethernet communication. Nonetheless, a low band-width communication bus based on the Controller Area Network (CAN) standard was implemented between the LaunchXL platforms for simplification. The secondary control algorithm runs on the micro-controller unit of prosumer 2 and transmits the control signals δω and δE to the GFM control of prosumer 1.

A. TEST DESCRIPTION
For an easier understanding of the HIL experimental nG operation, different events and time operation sequences were designed as summarized in Table 3. The nominal active and reactive powers demanded by the load at rated voltage VOLUME 11, 2023  Reference signals P * i , Q * i , V * C,i and δ * i for the droop control were calculated to achieve equal power sharing among prosumers at the nominal nG voltage conditions with E * nG = 230 V and a voltage phase at the PCC of 0 • . For the electrical calculations, the voltage drop caused by inductors L 2,i and the virtual impedance inductance L v were taken into account.
The different steps taken during the start-up procedure are described as follows: 1) The control stage is compiled and sent to both Launchpad units.
2) The plant to be executed on the manager RT Box 1 (RTS 2) is compiled and sent.
3) The plant of the subordinate RT Box 1 (RTS 1) is deployed, when the subordinate receives the start-up signal, the HIL simulation begins. 4) DC-link capacitors are charged by the electrical connection of both prosumers with their respective ideal input voltage sources. 5) The switching of the prosumer 2 inverter is activated with its corresponding reference signal (230V, 0 rad, 50 Hz). 6) The back-up PLL of prosumer 1 starts synchronization with the nG voltage. 7) Once the back-up PLL is synchronized, the switching of prosumer 1 inverter is activated. The voltage reference angle of prosumer 1 is pre-computed through the conventional real power flow problem formulation between two buses in order to deliver half of the load power for a reactance equal to L 2,1 . 8) Droop control is activated and the back-up PLL is turned off. The following section describes the experimental results obtained.  rtss are synchronized, the hil simulation begins at step 3. At step 4, the dc-links are charged to their nominal voltage value, which is illustrated with v dc and v c2 . this charging process demands peak input currents around 18 a, which is considered a safe current. At step 5, prosumer 2 starts feeding the load on its own and the inverter input current i in,2 increases to approximately 11 a. At this point, the presynchronization sogi is activated (Step 6), where the sogi frequency f sogi starts tracking the ng frequency. At step 7, prosumer 1 starts switching with the pre-computed phase angle. now each prosumer delivers half of the load power and the filter capacitor voltages v cf ,1 and v cf ,2 are in phase, as illustrated in the top sub-plot of Figure 13. finally, droopcontrol is activated at Step 8. Figure 14 (a) shows the time evolution of the active power (P i ), the reactive power (Q i ), the frequency (f i ) and the RMS voltage (v Cf ,iRMS ) of each prosumer operation during events a-e. Additionally, signals v PCC , i load , E nG and f nG were measured at the PCC as depicted in Figure 14 (b), where a steady-state detailed view at phase a of v PCC and i load is also illustrated. During event a, prosumer 2 starts feeding the residential load with the total nominal power, while prosumer 1 remains unconnected. Consequently, there is a high voltage drop at the filter and virtual impedance inductors which causes E nG to be below 230 V. At event b, the back-up PLL allows prosumer 1 to start injecting half of the nominal active power synchronously. The frequency and voltage of the nG are now really close to the nominal values.

B. HIL RESULTS
During event c, the droop control is activated, with small changes with respect to the previous situation, as the generation equals consumption. At evet d, the load variation causes a decrease in the active and the reactive demanded power, to which the droop controls of both prosumers react causing a deviation of the frequency and voltage, reaching  values of 50.06 Hz and 234 V at the PCC, respectively. It can be observed that prosumer 1 presents a further decrease of active and reactive power than prosumer 2 due to lower droop constants. Figure 15 illustrates the time evolution of the nG side currents i L2,1 (Figure 15 (a)) and i L2,2 (Figure 15 (b)) during the HIL operation. In order to demonstrate the stable dynamic behavior of the system, a detailed view of the transient at the time of connection of prosumer 1 (Figure 15 (c)) and a detailed view of the steady-state operation of the system during event e (Figure 15 (d)) are depicted, where only the phase a was considered for visualization purposes.
The voltage at phase a is also included to show that no dangerous voltage peaks are attained. A smooth and fast connection of prosumer 1 was observed, indicating a proper design of the PR inner control loops. Additionally, good quality sinusoidal waveforms were obtained at steady-state operation.
Although a good transient and steady state behavior of the PR control was observed, it is interesting to analyze its effect on the whole nG system when there is a marked reference change of the PR control setpoints, involving a drastic change in the power sharing among prosumers. For this purpose, the transient view of the nG evolution during a change in the droop-control reference phase angle and reference active power during event c is illustrated in Figure 16. The new  reference values are δ * 1 = 0.06 rad, δ * 2 = 0.001 rad, P * 1 = 5270 W rad and P * 2 = 1810 W. During the test, power fluctuations are observed in both prosumers, which are caused by the droop-control dynamics. However, the power quickly stabilizes in a few seconds, matching the new active power references. During the transient, the dc-link voltage (v dc ) and the current and voltage waveforms at the PCC (v PCC , i Load ) barely suffer any fluctuations, demonstrating the almost negligible effect of the designed PR control on the nG system behavior.
In order to test the ESS ability to deliver or absorb active power following the system requirements, the DAB control was programmed to start discharging the battery with a reference power of 1 kW during event b, until a reference power step occurs at event d, reversing the direction of the current to charge the battery with 1 kW.
The time evolution of the battery current i ESS is illustrated in Figure 17 (a). A detailed view of i ESS during the reference change is shown in Figure 17 (b), where v PCCa and the dc-link voltage of prosumer 1 (v dc ) are also depicted to demonstrate the stability of the system. A fast and overdamped transient is observed from a positive current value of approximately 20 A to a negative current value of the same magnitude.
The night control mode of the ESS was tested by completely disconnecting the PV unit from prosumer 1 and repeating the complete HIL test. Figure 18 shows the evolution during the different time events of i ESS (Figure 18 (a)) and v dc (Figure 18 (b)). It can be observed that the ESS successfully regulates the value of v dc by tracking the reference voltage of v * dc = 800 V, with small errors due to measurements inaccuracies.
Finally, the flexibility of the nG was tested by conducting MPPT and RPPT tests. As previously mentioned, an additional dc-dc boost converter together with a PV array were integrated into the nG by replacing the ideal voltage source    switching frequency of 20 kHz. The corresponding MCU was responsible for controlling this stage, where P&O algorithms were executed with a sample time of 10 ms. The PV array consists of two strings of 35 BP365 PV modules each, and the P-V characteristic was illustrated in Figure 19. The overall HIL test was repeated for this case study for events a-d, with the main waveforms displayed in Figure 20. At event b, prosumer 1 connects to the nG and the MPPT algorithm starts acting on the dc-dc converter duty cycle while the DAB starts controlling v DC . Initially, the DAB provided the necessary active power demanded by the nG since the MPPT algorithm was slower than v DC control. Once the maximum power point is reached, the DAB begins charging the battery with -859 W. A detailed view of the dc-link voltage transient shows controlled and brief fluctuations, demonstrating the adequate performance of the controllers. At event d, the load change causes a decrease in the demanded active power, thus forcing the DAB to absorb the excess active power below −2000 W. At this point, the RPPT operation mode of the dc-dc converter quickly replaces MPPT to prevent full charging of the battery, as light load conditions were detected. The RPPT output power of the PV array now matches the demanded active power of the nG, and the mean power of the DAB was close to zero. Figure 21 shows v Cf ,1 and i L2,1 during the same test, demonstrating the stable behavior of the ac-side, which is barely affected by the designed controllers performance.
Additionally, the effect of the DAB dc-link voltage control during MPPT on the overall system is analyzed by changing the voltage reference v * DC from 800V to 750V during event c. Figure 22 shows the time evolution of the three active powers, the output ac currents of each prosumer and the PV and dc-link voltages during the reference step. It can be observed that P 1 remains practically unchanged during the transient despite v DC fluctuations, showing that the designed PR control is unaffected by the operation of dc-side controllers, which are able to rapidly adjust the system operation to match the new voltage reference.

VI. CONCLUSION
In this paper, a two-prosumers residential nG, including a PVbattery assisted 3L T-Type inverter topology and managed by a hierarchical GFM control structure was successfully realized by means of a distributed HIL simulation, permitting to dispense with a hardware prototype to test the control algorithms. In addition to facilitate a parallel development of power converters and microcontrollers programming, the adopted approach helps to reduce the design cost as any physical damage to power converters is prevented. The novelty of this paper is summarized as follows: 1) A detailed description of the distributed HIL methodology for the nG realization and the technical solutions adopted for the testing of the GFM control approach was carried out. Therefore, valuable information to the field of PV islanded microgrids control is provided, considering that few studies in the literature address a suitable sectioning of an islanded nG for HIL testing.
2) The paper demonstrates the effectiveness of the proposed approach in evaluating the dynamic performance of GFM controls in real-time and validating the developed control running in the real hardware controller, which can potentially accelerate the development cycle.
3) The results obtained highlight the potential of smallscale HILs units, such as RT Box 1 from Plexim, in the HIL realization of complex power systems with a high number of power switches for embedded code validation. This paper can encourage researchers and serve them as starting point to resort to this type of RTS devices for HIL control testing in complex power electronics plants.
Overall, the novel approach for testing and validating nGs presented in this paper represents an advance of the existing knowledge and provides a valuable framework for the development and deployment of reliable and efficient modern RES-based power systems.