Design of an On-Grid Microinverter Control Technique for Managing Active and Reactive Power in a Microgrid

This paper presents the design and implementation of an on-grid microinverter control technique for managing active and reactive power based on a dq transformation. The system was implemented in a solar microinverter development kit (Texas Instruments—TMDSSOLARUINVKIT). This microinverter has two stages: DC-DC and DC-AC. The DC-DC stage contains an active clamp flyback converter, where the maximum power point tracking (MPPT) of the solar panel is obtained with a current-based incremental conductance algorithm. The DC-AC stage comprises a dual-buck inverter in which voltage-, current-, and phase-tracking control loops are implemented to control the active and reactive power. These techniques were simulated in MATLAB using the proposed mathematical model and experimentally validated in the solar development kit. The results show that the simulated model behaved similarly to the real system, and the control techniques presented good performance. The maximum power point (MPP) of the solar panel was monitored in the DC-DC stage using a current reference provided by the incremental conductance MPPT algorithm and was regulated by a 2P2Z control. The algorithm is robust against continuous changes in irradiance, as it quickly follows the ideal power and continually operates at a point close to the MPP. In addition, the active and reactive power control in the DC-AC stage enables the microinverter to supply the maximum active power. Moreover, the microinverter supplies reactive power according to a defined reference and within the established limits. The proposed mathematical model of the microinverter can be used to design new control techniques and other microinverter topologies. In addition, this active and reactive power-control technique can be implemented in low-power and low-cost microinverters to successfully maintain power quality in small microgrids.


Introduction
The depletion of natural resources and environmental degradation are current research topics that have generated great concern today due to their accelerating impacts on climate change. Part of the issue is that the primary generation units that supply the increasing power demand are dependent on non-renewable resources, such as coal, oil, and natural gas. This is why the use of renewable energies close to the loads must be rapidly promoted in order to mitigate the effects of climate change.
Microgrids have been proposed as a way to address this transformation by maximizing the efficiency and flexibility of renewable energy resources. A microgrid is an integrated energy system consisting of interconnected loads and energy resources that are distributed within clearly defined electrical limits, acting as a single controllable entity for the power grid [1,2].
Microgrids are made up of different elements, and distributed generators are essential for their correct operation. These present a challenge in terms of interaction with the the dq transformation. This control technique allowed accurate active and reactive power sharing without alteration of the frequency of the microgrid. Simulations and hardware in the loop (HIL) were used to demonstrate the effectiveness of the control.
On the other hand, an investigation carried out with a microinverter from Texas Instruments (TI) is found in [12]. In this research, a computational model was made and a description of the microinverter's hardware was provided, in addition to the calculations used by the flyback and dual-buck controllers.
Additionally, some investigations, such as those of [13][14][15], were based on using an active clamp flyback converter in the DC-DC stage and a dual-buck inverter in the DC-AC stage of the TI microinverter. In [13], the main features were presented, and the performance of the active clamp flyback converter was analyzed; this also showed that this converter could provide zero-voltage switching (ZVS). In [14], problems with the dual-buck inverter were discussed, such as the use of more inductors than in a traditional full-bridge inverter, the decreased power density, and the increased system cost. For this reason, a modified cascade full-bridge dual-buck inverter was proposed. In [15], a new circuit structure and a control method were proposed for a high-power interleaved dual-buck inverter, where zero-cross distortion was eliminated, the current stress of the switch was reduced, and the total harmonic distortion at low output power was decreased.
In this research, a control strategy for managing active and reactive power is implemented based on the dq transformation. The modeling and simulation of the complete system were carried out in MATLAB, and the necessary controllers for the two stages of the microinverter were designed. In the DC-DC stage, the maximum power point of the solar panels is monitored, together with the generation of the current reference, which is given by the incremental conductance algorithm and regulated by a 2P2Z control.
In the DC-AC stage, an anti-windup PI controller is implemented for the DC bus voltage, which follows the desired reference and regulates the active power supplied by the microinverter. Then, a phase-locked loop based on a generalized second-order integrator is used, which is fundamental for calculating the P and Q control. In addition, a 3P3Z current controller is proposed, which follows the reference given by the P and Q control. Finally, a feedback linearization strategy is implemented, which compensates disturbances caused by the grid voltages in the 3P3Z control.
The P and Q control is implemented in the TI solar microinverter development kit (TMDSSOLARUINVKIT). The control delivers the maximum active power and supplies reactive power according to the defined reference and within the established limits. In addition, with the possibility of changing the reference values of the voltage in the DC bus and the power, it allows easy integration with a secondary control in order to carry out the correct power management in a microgrid. The performance of the system is evaluated through different case studies.
The main contributions of this paper can be defined as follows. (1) The mathematical model of the commercial microinverter (TMDSSOLARUINVKIT) allows the design of control techniques in simulations and obtains a similar behavior to that of the dynamics of real equipment, thus ensuring its correct functioning during implementation. (2) Our research demonstrates that the proposed active and reactive power control technique may be used in this experimental microinverter (TMDSSOLARUINVKIT), allowing future research on low-cost commercial microinverters. (3) The implementation of an active-and reactive-power-control technique in a low-power microinverter opens up the prospect of using these controls to maintain power quality in small microgrids. This paper is organized as follows. The preliminaries and descriptions of the models are presented in Section 2, the numerical simulations and experimental tests are presented in Section 3, and the conclusions and future work are presented in Section 4.

Materials and Methods
In this section, the injection system model, which includes a solar panel system and two microinverter stages, is presented. In addition, the design of the DC-DC and DC-AC controllers is included. Finally, the programming tasks are implemented in the microcontroller's card with all the steps necessary for the proper operation of the system.

Model of the Injection System
The design and implementation of the control techniques for managing the active and reactive power were performed with the TI solar microinverter development kit (TMDSSOLARUINVKIT). Figure 1 shows the general diagram of this system. This on-grid microinverter can be divided into two main stages: DC-DC and DC-AC. In this section, the mathematical formulation of the system is presented in three main parts: solar panel, active clamp flyback, and dual-buck inverter.

Solar Panel Model
A solar panel is made up of photovoltaic cells in series and in parallel. A model of the equivalent circuit can be seen in Figure 2. Its components are a set of classic pn-junction diodes, which, through the photoelectric effect, convert solar radiation into electrical energy, a current source, and resistive elements that emulate the losses that occur in a real environment [16]. The source I ph is the photogenerated current at a fixed value of solar radiation, the shunt resistance (R sh ) represents the current loss due to leakage, and the series resistance (R s ) is used to represent the voltage drop at the output. Moreover, N s is the number of cells in series, and N p is the number of modules in parallel.
The diode current can be written as: where where, k = 1.3807 × 10 −23 JK −1 is the constant of Boltzmann, q = 1.6022 × 10 −19 C is the charge of the electron, T C is the operating temperature of the cell in Kelvin, A is the ideality factor of a p-n junction whose value is between 1 and 5, I s is the saturation current, and V pv is the output voltage of the panel [17]. By applying Kirchhoff's law and using Equation (1) in the equivalent circuit (Figure 2), the output current (i pv ) generated by a photovoltaic cell is given by: The photogenerated current I ph depends on the solar irradiance and the cell temperature present in the measurement. It is described by: where I sc is the short-circuit current, G is the solar irradiance, G re f = 1000 W/m 2 is the solar irradiance under standard conditions, k i is the short-circuit current temperature coefficient, and T re f is the working temperature of the cell under normal conditions (298°K). The saturation current of the cell I s changes with temperature [17] according to: where E g is the energy of the semiconductor in its forbidden band or bandgap, and I RS is the inverse saturation current of the cell at the reference temperature and solar irradiance, which is given by: Finally, for N s photovoltaic cells in series and for N p modules in parallel, the output current i pv of the panel can be written as:

Active Clamp Flyback Model
A DC-DC flyback converter is an isolated version of the buck-boost converter. A transformer is used to eliminate any direct electrical connection (DC) between the input and output of the power converter. Figure 3 shows the active clamp flyback circuit implemented in the TI solar microinverter development kit (TMDSSOLARUINVKIT). The version of the converter with an active clamp (branch C ac and Q ac ) can provide zero-voltage switching (ZVS), thus reducing switching losses and electromagnetic interference (EMI) and increasing efficiency [13,18]. Furthermore, the capacitor C 1 with the diode D 1 provides a voltage multiplier circuit at the output of the converter. This multiplier circuit operates in a direct converter mode to transfer energy from the input to the output. From the multiplier, the following is obtained: For modeling, the active clamp stage is omitted, and it is divided into two subintervals.

• Subinterval 1
If Q 1 is on, the primary side current increases, the inductance L p is charged, and energy is stored. On the secondary side, D 1 and D 2 are off. Therefore, the following equations can be obtained: • Subinterval 2 If Q 1 is off, power is transferred to the secondary side immediately, and the current i p decreases to zero. On the secondary side, if V Ls < 0, the capacitor C 2 is charged through the diode D 2 , and if V Ls > 0, the capacitor C 1 is charged through the diode D 1 ; therefore, V Cout is charged to 2V Ls . Then: From the transformation relation n, it is known that i s = i p n . Therefore, Equations (11) and (12) can be written as: When the input is u = V in and the state variables are then, with Equations (9) and (10), the state-space system model for subinterval 1 is: Now, considering Equations (13) and (14), the state-space system model for subinterval 2 is: The general model of the system is obtained by using the general notation of the state-space averaging technique [20] as follows: where d = 1 − d, and d is the duty cycle. From Equations (18) and (19), the following expression is obtained: The flyback converter's inputs are u = [d Vin] T ; therefore, the model found in Equation (20) is non-linear. To find the linearized model around the steady-state points of the system, the following expressions are calculated: Table 1 shows the parameters used in the model.

Parameter Value
The inverter's output is connected to the electrical grid. The inverter consists of two DC-AC buck converters ( Figure 4) operating in one of the half cycles of the line-voltage AC V LN . The MOSFETs Q 6 , Q 3 , the diode D 1 , and the inductor L 4 make up the first buck converter when V LN is positive. The MOSFETs Q 5 and Q 4 , the diode D 2 , and the inductor L 3 form the second buck converter when V LN is negative. The main inductors, L 3 and L 4 , the capacitor C f , and a second pair of small inductors, L 1 and L 2 , make up an LCL filter at the inverter's output. In each half cycle, the corresponding upper MOSFET, Q 6 or Q 5 , remains fully on. The lower MOSFETs, Q 3 and Q 4 , operate at a high PWM frequency ( f = 50 kHz) when the buck converter changes in the respective half cycle [19]. Figure 5 summarizes the behavior of the PWMs.
As only one buck converter is active at each half cycle of V LN , the model of the circuit can be simplified to that of an LCL filter ( Figure 6). R i and R g are the internal resistances of the inductors (L i = L 3 = L 4 and L g = 2L 1 ), and V in is the steady-state voltage of the buck converter. Then, V i = dV bus , with d as the duty cycle.   Applying Kirchhoff's voltage and current laws to the LCL filter, the following equations are obtained: Therefore, the dynamic behavior of the system is given by: Using the following expression as state variables, and using u = [V i V LN ] T as input variables, a linear representation of the system in state space is: Alternatively, by applying the Laplace transform to Equations (22)- (25), we can obtain the transfer function for i L , which is given by: (32) Table 2 shows the parameters used in the model.

Design of the DC-DC Controllers
The purpose of the control in the DC-DC stage is to capture the maximum energy from the solar panel. With the solar panel model obtained in Section 2, the power curve at different irradiance points can be obtained (Figure 7). It is observed that the output power is at its maximum only in a single voltage and current point. In addition, this point can change under different atmospheric conditions and solar irradiance.
Therefore, the maximum power point tracking (MPPT) of the panel must be monitored. For this, various MPPT techniques have been developed [21][22][23][24][25][26]. In this research, the incremental conductance algorithm is implemented to achieve this objective, and the scheme is shown in Figure 8. The control loop guarantees that the solar panel current is regulated to the current reference i re f delivered by the MPPT algorithm. This is accomplished by adjusting the duty cycles of the flyback converter's power MOSFETs. In addition, the proposed scheme includes digital filters for eliminating noise in the current and voltage measurements of the solar panel.

Incremental Conductance MPPT
The incremental conductance algorithm (INCC) shown in Figure 9 takes the voltage V pv and the current i pv of the panel as inputs. Then, it calculates the differentials dV and dI. Its operation is based on the fact that the slope of the solar panel power curve is zero at the maximum power point (MPP), positive to the left of the MPP, and negative to the right [27]. From the above, it can be deduced that in the MPP: Consequently, the following conditions are obtained: Therefore, the MPP can be traced by comparing the instantaneous conductance (I/V) with the incremental conductance (dI/dV) [19]. Once the MPP is reached, the solar panel's operation remains at this point unless a change is observed. The algorithm decrements or increments I re f to track the new MPP.

Current Control
For the current control G c , a 2-pole 2-zero compensator (2P2Z) is used. The pulsetransfer function of the 2P2Z control is: If a 1 = 1 and a 2 = 0 are assumed, we can compare them with the pulse-transfer function of a PID, which is given by: By relating Equations (38) and (39), we obtain: Using MATLAB and the flyback converter model found in Section 2, the controller is designed, and the constants k P = 0.0714, k I = 0.0203, and k D = 0 are obtained. Therefore,

Signal Filtering
The voltage and current values were measured in the solar panel with a SIGLENT SHS1062 oscilloscope and a sampling frequency of 20 kHz at the ADC acquisition points of the microinverter control card.
As the discrete Fourier transform shows that the panel current has high-frequency noise ( Figure 11), a Butterworth-type low-pass IIR filter was designed with a cutoff frequency of 115 Hz and order of 2 to eliminate the harmonics from the grid and guarantee high attenuation in high-frequency components. The filter is described by: where the gain k = 52.25 × 10 −6 and An eight-point-average filter was implemented for the panel voltage signal V pv because considerable high-frequency magnitudes were not observed in the Fourier transform. The filter is described by:

Design of the DC-AC Controller
The control in the DC-AC stage guarantees synchronization with the electrical grid and the active and reactive power injection with references defined by the user (V re f , P re f , and Q re f ). The signals needed to control the DC-AC stage include the line voltage V LN , the DC bus voltage V bus , and the main inductor current i L . To achieve the effective operation of the inverter, the control scheme in Figure 12 is proposed, where the voltage-control loop is implemented to regulate V bus , the current-control loop to regulate i L , and the phase-locked loop (PLL) for active and reactive power control.

Voltage Control (PI)
The voltage-control loop employs an anti-windup PI controller and regulates the input voltage of the DC bus to the reference value V re f . The controller output is given by: where u p and u i are the proportional part and integral part, respectively. Their values are related in the following way: where r(k) is the reference signal, y(k) is the system output, K p is the proportional constant, and K i is the integral constant. The term w(k) takes values of 1 or 0, providing a means of deactivating the integrator path when output saturation occurs. It prevents the full-term winding up and improves the response time when recovering from saturation [19]. The controller's output saturates according to the upper (U max ) and lower (U min ) limits that are programmable by the user, i.e.: The pre-saturated (v 1 (k)) and post-saturated (u v (k)) terms are compared to determine if saturation is produced, and the following expression finds the value w(k): By using MATLAB to implement the inverter model found in Section 2 and adjusting its values with the real system, the constants K p = 1 and K I = 0.001 are obtained, and the limits U min = 0.025 and U max = 0.8 are defined. Additionally, for the voltage signal V bus , an eight-point average filter is implemented, as shown in Equation (44).

Phase-Locked Loop (PLL)
The PLL is used for synchronizing and monitoring the grid. The phase angle of the grid voltage must be calculated in real time to define the power ratio between the grid and the inverter [28]. In this investigation, the second-order generalized integrator (SOGI)based phase-locked loop (PLL) is implemented ( Figure 13) because it presents harmonic immunity, a fast tracking accuracy, and a rapid dynamic response [6]. The phase detector is composed of an orthogonal signal generator and obtains the Park transform of the waves to detect the components q and d in the rotating reference frame. For the orthogonal signal generator, a second-order generalized integrator (SOGI) [28] is used, as shown in Figure 14. The input signal is the voltage of the power grid. As output signals, two sine waves v and qv with a phase shift of π/2 are generated. The component v has the same phase and amplitude as the input voltage signal V LN . Using the trapezoidal approximation, the closed-loop discrete transfer functions (Hd(z) and Hq(z)) of the SOGI are: where b 0 = x x + y + 4 , qb 0 = ky x + y + 4 , where x = 2kω n T s , y = (ω n T s ) 2 , ω n is the estimated grid frequency, T s is the sampling time, and k is the gain that affects the SOGI bandwidth [28]. With the generated orthogonal signal, the Park transform is applied with V α = v and V β = qv to obtain the components Q and D in the rotating reference frame. The Park transform is given by: Defining an arbitrary input signal, V α = V in cos(θ in ) and V β = V in sin(θ in ), the output of the phase detector (PD) is: Now, assuming that the PLL is synchronized in such a way that θ in − θ out ≈ 0, then, in Vq, we get sin(θ in − θout) ≈ θ in − θout, which is the tracking angle error [19].
Using control theory and using a PI controller as a low-pass filter to keep the error at zero, the closed-loop transfer function of the PLL [28] is given by: Now, comparing Equation (55) with the transfer function of a second-order system and defining a settling time of 30 ms, an error band of 5 %, and a damping coefficient of 0.7, we obtain the constants k p = 166.6 and k i = 27,755.55.
Finally, using the bilinear transformation, the pulse transfer function of the low-pass filter is given by: where,

Active and Reactive Power Control
For power control, a rotating reference frame is used. Figure 15 shows the stationary and rotating reference frames obtained by performing a dq or Park transformation. The subscripts d, q are components in the rotating reference frame, and α, β are components in the stationary frame of reference. The term ω =θ is the angular frequency of the grid [29]. In the rotating reference frame dq, the active output power of the inverter [8] can be determined as: where i d , i q , V d , and V q are the currents and voltages generated on the direct axis (d) and on the quadrature axis (q), respectively. Similarly, the reactive output power injected into the grid is [8]: From the design of the PLL, it can be deduced that when the rotating frame is synchronized with the grid, V q is approximately zero. For this reason, the active power control depends on the current component i d (axis d), while the reactive power control depends on the current component i q (axis q). Thus, using Equations (59) and (60), we obtain: To guarantee that the maximum active power is always injected into the grid, we define P re f = P max (MPP), assuming that there are no losses [8]. However, the reference voltage V re f of the DC bus can be changed to regulate the active power supplied to the grid.
The current reference in the rotating reference frame, i * d and i * q , is transformed into the stationary reference frame by using the inverse Park transformation. Furthermore, these variables are regulated by the current control. The inverse Park transform (dq ⇒ αβ) is given by: In this case, only the real signal needs to be generated, that is, i α . Therefore, the current reference given by the active and reactive power control is: where θ is the voltage angle of the grid obtained by the PLL.

Current Control
From the transfer function found in Equation (32) of Section 2, it can be seen that the system input is Vi − V LN = dV bus − V LN , and as V LN is an external input that cannot be controlled, it acts as a disturbance for the current control. To avoid this problem and to be able to calculate the duty cycle (d), a feedback linearization technique is used under the assumption that the cut-off frequency of the current loop is much higher than the grid frequency. Consequently, V LN can be treated as a DC parameter compared to the current dynamics of the inductor i L [19]. The proposed scheme is shown in Figure 16. The duty cycle of the PWM that controls the MOSFETs of the inverter is calculated from the feedback linearization as follows: where u i corresponds to the current control's output, and V LN and V bus are the measured variables of the inverter. The following controller is implemented for the 3P3Z current control [19] G c (z) The current reference i Lre f is calculated by multiplying the outputs of the PI controllers and the active and reactive power control, that is:

Implementation
The system was implemented in the TI solar microinverter (Figure 17), which has an active clamp flyback converter, a dual-buck inverter, an F28035 Piccolo controlCARD development board, and conditioning circuits for signal reading. Figure 18 shows the sensed signals and the PWM output necessary to control the microinverter.  The F28035 Piccolo card uses the TMS320F28035 microcontroller from the C2000 line of TI. This card is optimized for processing, sensing, and actuation, thus improving the performance of the control loops for real-time applications, such as industrial motor controllers, solar inverters, electric vehicles, and signal processing. The programming of this card is divided into tasks. In addition, it makes use of parallel processing with a central processing unit (CPU) and the secondary core control law accelerator (CLA), which is a floating-point mathematical accelerator of 32 bits. Figure 19 shows the program initialization process and the creation of tasks that are executed in the CPU and CLA.
One of the essential implementation tasks is protection (Figure 20). This task turns off the microinverter when an overvoltage or overcurrent is presented in any of its sections. This task runs at a frequency of 1 kHz on the main CPU.
When controlling active and reactive power, it is necessary to supply the reference values from an external device, and for this, the UART communication module is used. Figure 21 shows a flow diagram of the communication task.   As current-based MPPT is implemented, it is necessary to run the MPPT algorithm at a lower frequency than that of the 2P2Z compensator to achieve good tracking of the current reference given by the MPPT algorithm. For this case, the MPPT runs at a frequency of 100 Hz, changing the reference of the compensator every 10 ms. Figure 22 shows a flow diagram of the MPPT task. Finally, the flow diagram of the inverter task is shown in Figure 23; in runs with a 50 kHz frequency to achieve a better control action and synchronize with the grid.

Results
With the microinverter and controllers described above, simulation and experimental results were obtained. For power generation, two 150 W solar panels connected in series were used. Table 3 shows the parameters of the solar panel at an irradiance of 1000 W/m 2 and a temperature of 25 • C [30].

Simulation Results
The microinverter circuits and components described in Section 2 were simulated using power electronics blocks in MATLAB Simulink. To simulate the solar panel, the "PV-Array" block with the characteristics in Table 3 was used. The controllers were implemented digitally to achieve a better approximation to the real system by using the MATLAB function block. The simulation was carried out in discrete time with a sampling time of 1 µ s. For the results of the DC-DC stage, the irradiance reference shown in Figure 24 was used to simulate the behavior during the day.  Figure 25 shows the reference generated by the incremental conductance algorithm and the filtered and measured current signals of the panel. It was observed that the 2P2Z control was able to follow the MPPT current reference without steady-state errors, but with some oscillations. Both the incremental conductance algorithm and current control managed to obtain the maximum power from the solar panel, approaching the ideal power, in the face of continuous irradiance variations. The resulting input power is shown in Figure 26. In the results of the DC-AC stage, an irradiance reference of 1000 W/m 2 was used. In Figure 27, the response of the 3P3Z current control is shown, where it is evident that the control is capable of following the reference (i Lre f ), but with some oscillations. In addition, the current delivered to the grid-that is, the output current of the LCL filter i g -is shown. The system's response to the anti-windup PI voltage control ( Figure 28) showed oscillations; large parts of these components were eliminated with the digital filter. Furthermore, it was observed that V bus quickly followed the 250 V reference with a settling time of approximately 0.35 s. In this case, the reactive power reference Q re f was set to zero VAR.

Active and Reactive Power Control
To analyze the process of integrating the inverter with the electrical grid and the active and reactive power control, P re f was established as the power obtained with the MPPT algorithm, and Q re f was set with values of 0, 165, 100, −100, and 50 VAR; the DC bus voltage reference V re f was set to 250 V and was simulated with an irradiance reference of 1000 W/m 2 . In addition, a Simulink dynamic load block (single-phase dynamic load) was used, with 280 W and 100 VAR of active and reactive power, respectively.
The maximum possible power was always injected into the grid when P re f = P max . In Figure 29, it can be observed that the microinverter was capable of delivering almost all of the power consumed by the load. Therefore, the active power consumption in the grid was reduced to values close to zero. Figure 30 shows the reactive power injected by the microinverter, the reference Q re f , the reactive power from the grid, and the reactive power demanded by the load. The P and Q control managed to follow the reference satisfactorily and allowed the generation of both capacitive and inductive reactive power.   Figure 31 shows the phase change of the current with respect to the voltage at the instant in which Q re f changed from 0 to 165 VAR (the power factor changed approximately from 1 to 0.85). It was observed that during the phase shift, there were some oscillations. In this case, the efficiency and the THD i were calculated to evaluate the performance of the microinverter. The combined efficiency of the DC-DC and DC-AC stages was, on average, 92 %, which was similar to the efficiency found in [19] and in the experimental results. The minimum THD i was 2% when Q re f = 0 VAR, and the maximum THD i was 5% when Q re f = 165 VAR (Figure 32). According to the IEEE 1547 standard, the current total harmonic distortion limit for distributed generators is 5% [31]. Therefore, the THD i values found above were within the suggested range. Furthermore, Figure 33 shows the power factor and the efficiency over time.  On the other hand, it was found that, to guarantee the integrity of the components of the microinverter and maintain the appropriate limits of harmonic distortion, the reactive power reference values must be established within the area shown in Figure 34 with a minimum power factor of ±0.85 or ±53% of the total reactive power. As these are simulation results, it is possible to define the reactive power reference Q re f that is equal to the measured reactive power of the load to supply the total power demand, as long as it is within the limits defined above. Therefore, the reactive power consumed from the grid is set to zero ( Figure 35).

Active Power Regulation
As defined above, P re f must take the value of the maximum power or that obtained by the MPPT. In this case, the maximum power determined was 300 W in order to supply the maximum active power and avoid affecting the dynamics of the reactive power control. However, the active power injected by the microinverter could be regulated by changing the reference voltage of the DC bus V re f within the range of 220 to 380 V (hardware limitations). Figure 36 shows the variation in V re f from 250 to 330 V and the decrease in the active power injected by the microinverter.

Experimental Results
As in the simulation results, different case studies are proposed in order to evaluate the behavior of the microinverter in both the DC-DC stage and the DC-AC stage. The data were measured with a SIGLENT SHS1062 oscilloscope and a sampling frequency of 25 kHz.
For the DC-DC stage, the voltage and current values of the solar panel were measured at an irradiance of approximately 263 W/m 2 so that the ideal power was 79 W. In Figure 37, the current and voltage of the panel with filtered and measured data can be observed. In Figure 38, the input power is shown, where it can be deduced that the MPPT algorithm, in conjunction with the 2P2Z control, managed to obtain the maximum power from the panel. However, oscillations occurred, mainly due to high-frequency noise, so they were eliminated with the designed digital filters.  In addition to having an on-grid operating mode, the microinverter can be configured for an off-grid mode. Figure 39 shows the current i g , the output voltage, and the THD i = 7.63% obtained with this configuration, which were in a range close to that suggested by the IEEE 1547 standard [31]. This case study was carried out to verify the control algorithm, PWM configuration, and microinverter operation before synchronizing with the grid. After verifying the proper functioning of the microinverter in the off-grid mode, the synchronization stage with the grid and the active and reactive power control were implemented to obtain the results for the DC-AC stage. In Figure 40, the PI voltage control response, which was activated at 1.2 s, is shown. It is evidenced that the DC bus voltage managed to follow the 270 V reference without steady-state error and with a settling time of approximately 0.5 s. Then, P re f was set to be equal to P max , and Q re f was defined with the values of 0, 20, 40, −20, and −40 VAr to analyze the active and reactive power control. Figure 41 shows that the P and Q control supplied capacitive and inductive reactive power according to the defined reference.In addition, the injected active power is presented. When Q re f changed from 40 to 0 VAR, the injected current of the microinverter i g and the grid voltage V LN were compared (Figure 42), and a difference in the phase shift between the two waves of approximately 35 • a 0 • was shown. Similarly, the reactive power reference values for the microinverter must be established with a minimum power factor of ±0.85 or ±53% of the total reactive power to function correctly and guarantee the integrity of its components.
A scenario with a 100 W incandescent light bulb was proposed to analyze the interaction of the microinverter with the grid (Figure 43). In the beginning, the microinverter control was off and, after 4.7 s, it was activated. The microinverter managed to partially compensate the active power consumption of the load when the control system was on. From the previous case studies, some indicators were calculated to evaluate the performance of the microinverter. The combined efficiency of the DC-DC stage and the DC-AC stage was, on average, 88%, and the maximum was 91%, which was similar to that found in [19]. In addition, the total harmonic distortion was calculated ( Figure 44); THD v = 9.4% and THD i = 24.9% were obtained, which are values that were outside the range established by the IEEE 1547 standard [31]. However, these effects may be associated with distortions in the data collected because a THD of 7.6% was found in the off-grid configuration. Figure 44. FFT analysis, current THD, and output voltage.

Conclusions
This research presented the design and implementation of an on-grid microinverter control technique for managing active and reactive power based on a dq transformation. The simulated model allowed us to approach the real behavior of the system, and good performance was obtained for the control techniques. In the DC-DC stage, the maximum power point of the panel was monitored with the generation of the current reference, which was given by the incremental conductance MPPT algorithm and regulated by a 2P2Z control. This algorithm is robust against continuous changes in irradiance, as it quickly follows the ideal power and it always operates at a point close to the MPP. In addition, the 2P2Z control allowed the panel current to follow the reference without steady-state error and low oscillations, results that were evidenced in the simulations and experimentally.
Furthermore, In the DC-AC stage, an anti-windup PI controller was implemented for the DC bus voltage; it followed the desired reference to regulate the active power supplied by the microinverter. Furthermore, a second-order generalized integrator (SOGI)-based phase-locked loop (PLL) was employed to calculate the P and Q control. In addition, a 3P3Z current controller was applied, which followed the reference given by the P and Q control. Moreover, a feedback linearization technique was implemented to compensate for disturbances caused by the voltage of the grid in the 3P3Z control.
Moreover, the P and Q control implemented in the TI solar microinverter and simulations delivered the maximum active power. It supplied reactive power according to a defined reference and within the established limits. In addition, the integration of the microinverter into a microgrid could be performed due to the possibility of changing the reference values of the DC bus voltage and P and Q powers supplied by a secondary control.
This research demonstrated that it is possible to simulate control techniques that behave similarly to those of real equipment to ensure proper operation during implementation. Additionally, it was possible to demonstrate the viability of active and reactive power control techniques using a low-cost commercial microinverter. Finally, by implementing an active and reactive power control technique in a low-power microinverter, these controls can be used in small microgrids to maintain power quality.
In future work, the LCL filter and the structure of the dual-buck inverter can be improved in order to obtain lower harmonic distortion levels in the output current of the microinverter. In addition, the PWM control can be improved to reduce oscillations or distortions around the zero-crossing area. Additionally, it is possible to implement other active and reactive power control techniques and integrate the microinverter into a secondary control for a microgrid.

Conflicts of Interest:
The authors declare no conflict of interest.