Modeling and Design of the Vector Control for a Three-Phase Single-Stage Grid-Connected PV System with LVRT Capability according to the Spanish Grid Code

: This article deals with the vector control in dq axes of a three-phase grid-connected photovoltaic system with single-stage topology and low-voltage-ride-through capability. The photovoltaic generator is built using an array of several series-parallel Suntech PV modules and is modeled as a Lookup Table (two-dimensional; 2-D). The requirements adopted when grid voltage sags occur are based in both the IEC 61400-21 European normative and the allowed amount of reactive power to be delivered according to the Spanish grid code, which avoids the disconnection of the inverter under grid faults by a limitation in the magnitude of the three-phase output inverter currents. For this, the calculation of the positive- and negative-sequences of the grid voltages is made and a conventional three-phase Phase-Locked Loop is used for the inverter-grid synchronization, allowing the control of the active and reactive powers solely with the dq components of the inverter currents. A detailed enhanced flowchart of the control algorithm with low-voltage-ride-through capability is presented and several simulations and experiments using Matlab / SIMULINK and the Controller Hardware-in-the-Loop simulation technique, respectively, are run for several types of one- and three-phase voltage sags in order to validate its behavior.


Introduction
The increase of the penetration of renewable agents in the energy mix [1], together with the necessity to maintain the stability of the electric power systems make the new grid codes more restrictive nowadays for grid-connected photovoltaic (PV) systems and other renewable agents [2][3][4][5]. For example, these systems must remain connected under certain conditions so as to improve the voltage profile of the utility grid when there are voltage sags [6][7][8]. In addition, the amplitude of the three-phase inverter currents needs to be limited to its nominal value in order to avoid its automatic disconnection from the utility grid avoiding the inverter failure. The two conditions mentioned above are known as Low-Voltage-Ride-Through (LVRT) capability [8].
The LVRT capability is one of the challenges in the operation of grid-connected PV systems [6], and several scientific papers have been involved so as to be able to reach a better behavior [6][7][8][9]. In order to explain the operation of grid-connected PV systems under fault condition, a study of a PV generator and its LVRT capability in dynamic conditions was carried out in [10] when different grid faults occur. The improvement of the LVRT capability for a two-stage grid-connected three-level inverter (with a dc/dc converter) of a three-phase PV generator can be observed in [6]. The authors present an algorithm to calculate the current references in the rotating orthonormal dq axes and a Second Order Generalized Integrator (SOGI) [11] was employed to compute the actual value of the voltage in order to detect the voltage sags in the utility grid.
A method to enhance the LVRT capability for a three-phase single-stage grid-connected PV system is shown in [12] where a LVRT control-block is added to the current and voltage loops in the rotating orthonormal dq axes of a grid-connected PV system, attaining an effective performance for the active (P) and reactive (Q) powers support during fault conditions. The added LVRT control-block regulates the reactive power using the error between the load voltage and its reference, which produces a new reference for the quadrature q component of the output three-phase inverter currents, meanwhile the active power is regulated by a current limiter to the d component. In this case, the measurement of the load voltage is needed in order to carry out the LVRT strategy.
For small power grid-connected PV systems commonly used in buildings, single-phase inverters are employed and scalar control algorithms are exerted. On the contrary, for large power grid-connected PV systems, vector control algorithms are applied to the three-phase inverters in order to exert a decouple control of P and Q.
The main aim of this paper is to study the vector control algorithms of large power grid-connected PV systems with LVRT capability. For this, a three-phase single-stage grid-connected PV system is analyzed and tested under several grid faults in a realistic setup using Controller-Hardware-in-the-Loop (CHIL) simulations. The LVRT capability will follow the recommendations described in the IEC 61400-21 normative [12,13]. However, as far as the authors are concerned, the amount of reactive power to be injected into the utility grid during grid faults in agreement with the depth of the voltage sag in Spain has not been commonly studied in the scientific literature, and this paper will deal with this current lack of knowledge.
The paper is organized as follows: Section 2 describes the vector control of the power subsystem, including the cascaded control made by the innermost current control loops and an outermost voltage control loop, together with the synchronization algorithm. This section also describes a strategy for the limitation of the inverter currents during voltage sags, controlling the active and reactive powers, and yielding a proper LVRT capability for the Spanish grid code, although it can be easily extrapolated to international ones. The validation of the control strategies is carried out with several simulations and experiments in Sections 3 and 4, respectively, where Matlab/SIMULINK [14] blocksets are used for the former, meanwhile the latter is carried out with the CHIL Simulation approach [15][16][17]. The conclusions are presented in Section 5.

Control of the PV System
The block diagram of the three-phase grid-connected PV system of this article is shown in Figure 1. The power subsystem encompasses the PV generator, the inverter, the L filter, the transformer and the low-voltage utility grid. From Figure 1, it is worth noting a three-wires system with two degrees of freedom, allowing the decoupled control of P and Q.
The control subsystem is made by the cascaded control with the innermost current loop and the outermost DC voltage loop together with Pulse Width Modulation (PWM) module, as well as the Positive Negative Sequence Detector (PNSD) + dq Phase-Locked Loop (PLL) module used to synchronize the inverter with the grid for a controllable power factor operation. The maximum and non-maximum power point (MPP and non-MPP) of the PV generator are tracked according to the voltage sag and its depth, meanwhile Ref_P and Ref_Q are the appropriate references for the active and the reactive powers, respectively during normal or faulty operations.

Control of the Inverter Currents
A vector control is applied to the inverter currents with two PI regulators (PIid and PIiq) in order to control its dq components. The equations include the cross-coupling terms-ωLid and ωLiq and a decouple strategy is recommended for a better transient behavior. Thus, the outputs of PIid and PIiq plus the compensating cross terms are the dq components of the reference command inverter voltages (ud and uq). Then, ud and uq are fed to the PWM module after the application of the inverse Park's transformation [18]. Finally, the output of the PWM module is the status of the power switches of the power semiconductor devices (e.g., Insulated Gate Bipolar Transistors (IGBTs)) of the three-phase inverter.

Control of the DC Bus Link Voltage
The control of the DC link voltage is made with the outer voltage regulator [19] allowing the balance between the power delivered by the PV generator and the power injected into the low-voltage utility grid. The PIVDC regulator is fed by the error between V * DC and VDC, and its output becomes the reference of the active power (Ref_P) that is proportional to the maximum available power at the input. The d component of the reference inverter current i * d is proportional to Ref_P, but inversely proportional to the positive-sequence of the grid voltages uACd+.
A similar situation is valid for the q component of the inverter currents. The reference of the reactive power (Ref_Q) is set in an open loop scheme and is able to control the power factor. The q component of the reference inverter current i * q is proportional to Ref_Q, but also inversely proportional to the positive-sequence of the grid voltages uACd+.

Control of the Inverter Currents
A vector control is applied to the inverter currents with two PI regulators (PI id and PI iq ) in order to control its dq components. The equations include the cross-coupling terms-ωLi d and ωLi q and a decouple strategy is recommended for a better transient behavior. Thus, the outputs of PI id and PI iq plus the compensating cross terms are the dq components of the reference command inverter voltages (u d and u q ). Then, u d and u q are fed to the PWM module after the application of the inverse Park's transformation [18]. Finally, the output of the PWM module is the status of the power switches of the power semiconductor devices (e.g., Insulated Gate Bipolar Transistors (IGBTs)) of the three-phase inverter.

Control of the DC Bus Link Voltage
The control of the DC link voltage is made with the outer voltage regulator [19] allowing the balance between the power delivered by the PV generator and the power injected into the low-voltage utility grid. The PI VDC regulator is fed by the error between V * DC and V DC , and its output becomes the reference of the active power (Ref_P) that is proportional to the maximum available power at the input. The d component of the reference inverter current i * d is proportional to Ref_P, but inversely proportional to the positive-sequence of the grid voltages u ACd +.
A similar situation is valid for the q component of the inverter currents. The reference of the reactive power (Ref_Q) is set in an open loop scheme and is able to control the power factor. The q component of the reference inverter current i * q is proportional to Ref_Q, but also inversely proportional to the positive-sequence of the grid voltages u ACd +.  Figure 2 depicts a synchronization scheme using a PNSD and a PLL for three-phase systems [20], known as PNSD + dq PLL. Figure 2 depicts a synchronization scheme using a PNSD and a PLL for three-phase systems [20], known as PNSD + dq PLL.

Synchronization Algorithm
On one hand, the PNSD calculates both the positive-and the negative-sequences of the grid voltages during unbalances [21], in order to detect the voltage sags (see equations (1)-(3)). The quadrature components of the grid voltages uACq+ − are fed to two PI regulators in order to reduce their values to zero producing the positive-and negative-sequences of the angular speeds ω+-of the grid voltage vector uAC. It is worth noting that initial values of the angular speeds ωoffset+ − are added to reduce the time to track the phase angles, improving the PLL stability. Finally, two integrators compute the phase angle θ+ −, although only the positive-sequence θ+ is feedback to the vector control of the inverter currents, as it is shown in Figure 1. On the other hand, the Fault Signal is activated when the normalized depth of the voltage sag (Vgf) is less than 0.85 (see equation (6)).
where the operator 1/j (named S90) is described as: with unity gain at all frequencies and a phase of −90° at the nominal frequency ω0.

Control of P and Q
The P and Q powers delivered to the utility grid can be expressed as: where uACdq and idq are the dq components of the grid voltages and the inverter currents, respectively. However, according to the synchronization algorithm depicted in Figure 2, the q components of the grid voltages are set to zero and only the positive-sequence θ+ is feedback to the controller. Thus, equation (4) can be reduced as follows: On one hand, the PNSD calculates both the positive-and the negative-sequences of the grid voltages during unbalances [21], in order to detect the voltage sags (see Equations (1)-(3)). The quadrature components of the grid voltages u ACq + − are fed to two PI regulators in order to reduce their values to zero producing the positive-and negative-sequences of the angular speeds ω+ − of the grid voltage vector u AC . It is worth noting that initial values of the angular speeds ω offset + − are added to reduce the time to track the phase angles, improving the PLL stability. Finally, two integrators compute the phase angle θ+ −, although only the positive-sequence θ+ is feedback to the vector control of the inverter currents, as it is shown in Figure 1. On the other hand, the Fault Signal is activated when the normalized depth of the voltage sag (V gf ) is less than 0.85 (see Equation (6)).
where the operator 1/j (named S90) is described as: with unity gain at all frequencies and a phase of −90 • at the nominal frequency ω 0 .

Control of P and Q
The P and Q powers delivered to the utility grid can be expressed as: where u ACdq and i dq are the dq components of the grid voltages and the inverter currents, respectively. However, according to the synchronization algorithm depicted in Figure 2, the q components of the grid voltages are set to zero and only the positive-sequence θ+ is feedback to the controller. Thus, Equation (4) can be reduced as follows: and P and Q can be controlled solely with the orthonormal d and q components of the inverter currents, respectively.

Limitation of the Output Currents of the Inverter during Voltage Sags
According to several grid codes [9,22], the inverter not only must not be disconnected from the grid when there are severe short-time duration faults, but also a certain amount of Q must be delivered to the grid in agreement with the depth of the sag. In addition, the inverter currents must be limited to its nominal value amplitude in order to avoid its automatic disconnection from the utility grid. This behavior is called LVRT and several standards appear in many countries to regulate its application. Figure 3a,b depict the voltage profile for LVRT according to IEC 61400-21 [12,13] and the Q to be injected into the utility grid in agreement with the allowed depth of the sag in Spain [9], respectively. and P and Q can be controlled solely with the orthonormal d and q components of the inverter currents, respectively.

Limitation of the Output Currents of the Inverter during Voltage Sags
According to several grid codes [9,22], the inverter not only must not be disconnected from the grid when there are severe short-time duration faults, but also a certain amount of Q must be delivered to the grid in agreement with the depth of the sag. In addition, the inverter currents must be limited to its nominal value amplitude in order to avoid its automatic disconnection from the utility grid. This behavior is called LVRT and several standards appear in many countries to regulate its application. Figure 3a,b depict the voltage profile for LVRT according to IEC 61400-21 [12,13] and the Q to be injected into the utility grid in agreement with the allowed depth of the sag in Spain [9], respectively. One of the steps to be able to implement the LVRT capability is to quickly detect the voltage sag through the calculation of the value of Vgf by measuring the grid voltages, extracting its positivesequence and normalizing with the amplitude of the line-to-line grid voltages (see equation (6)) [9]. The depth of the voltage sag according to IEC 61400-21 is limited to a value of Vgf bellow 0.85 in order to consider that a voltage sag has occurred. The value of Smax will be calculated using the positive-and negative-sequences of the grid voltages and the nominal apparent power Snom, normalizing again with the amplitude of the line-to-line utility grid voltages (see equation (7)) [9].
where Vgf is the normalized depth of the voltage sag.
where the nominal apparent power Snom is around 507 kVA (see Table 2). Figure 4 depicts the enhanced flowchart for the implementation of the LVRT capability of the grid-connected inverter during voltage sags for the Spanish case, although it is worth noting that any other international grid code can be valid by using the appropriated voltage profile for the LVRT and changing some values of the parameters in equation (8) accordingly. The flowchart allows not only One of the steps to be able to implement the LVRT capability is to quickly detect the voltage sag through the calculation of the value of V gf by measuring the grid voltages, extracting its positive-sequence and normalizing with the amplitude of the line-to-line grid voltages (see Equation (6)) [9]. The depth of the voltage sag according to IEC 61400-21 is limited to a value of V gf bellow 0.85 in order to consider that a voltage sag has occurred. The value of S max will be calculated using the positiveand negative-sequences of the grid voltages and the nominal apparent power S nom , normalizing again with the amplitude of the line-to-line utility grid voltages (see Equation (7)) [9]. where V gf is the normalized depth of the voltage sag.
where the nominal apparent power S nom is around 507 kVA (see Table 2). Figure 4 depicts the enhanced flowchart for the implementation of the LVRT capability of the grid-connected inverter during voltage sags for the Spanish case, although it is worth noting that any other international grid code can be valid by using the appropriated voltage profile for the LVRT and changing some values of the parameters in Equation (8) accordingly. The flowchart allows not only the injection of reactive power to the utility grid during faults, but also a certain amount of active power, while not exceeding of the nominal amplitude of the three-phase currents.
If V gf ≥ 0.85, no fault is detected and a normal operation is achieved with no reactive power injected into the grid and allowing the application of the Maximum Power Point Tracking (MPPT) algorithm. In this case, the PV generator delivers the maximum power to the utility grid for a given irradiance and temperature, and the output of the MPPT module is the DC voltage reference command V * DC MPP for the outer voltage control loop which corresponds to the maximum power P* (Ref_P = P*).
On the contrary, if V gf < 0.85, the Fault Signal flag is activated and there are five possibilities: 1.
If V gf < 0.2 for more than 0.15 s or 0.2 ≤ V gf < 0.5 for more than 0.58 s or 0.5 ≤ V gf < 0.85 for more than 0.27 s, the inverter must be disconnected from the utility grid.

2.
If the fault has a duration less than the previous situation, a certain amount of reactive (Q) according to Equation (8) and active (P) powers are delivered to the utility grid according to the value of V gf and S max . 3.
For depth sags, Q might be greater than S max and a limitation to the delivered reactive and active powers are imposed (Ref_Q = S max , P max = 0).

4.
If P max > P*, the MPPT algorithm is activated, the maximum power is delivered by the PV generator to the grid (Ref_P = P*) and the DC link voltage reference command is V DC * MPP.

5.
If P max < P*, the non-MPPT algorithm is activated instead, and the power delivered to the grid is P max (Ref_P = P max ) with the V DC * non-MPP as the DC link voltage reference command Finally, Figure 5 depicts the operation with MPPT and non-MPPT algorithms for no fault and faulty operations, respectively. It is clear that during the fault the amplitude of the positive-sequence of the grid voltages decreases and the outer DC voltage controller will try to increase the amplitude of the output inverter currents so as to be able to balance the power at the output of the PV generator and the active power delivered to the grid for MPP operation. However, due to the current limitation imposed by the grid code, the non-MPP operation mode is activated and will ensure the correct balance of power when voltage sags occur because the output voltage of the PV generator will move to the right in the PV curve of Figure 5 (from (V DC * MPP, P*) to (V DC * non-MPP, P max ).
The Perturbation and Observation MPPT algorithm is used in this paper [23]. However, any other algorithm with similar behavior can be used.

Simulation Studies
Several tools are employed in the dynamic simulation of renewable systems. The choice will depend on the available hardware and software resources, the allowed speed of the simulation and the possibility to integrate these tools in a hierarchical scheme for hybrid models, etc. Among them, IREQ's power system simulator of Hydro-Québec [24], EMTP-RV of EMTP Alliance [25], and Matlab/SIMULINK from the MathWorks [26] can be mentioned.
All these tools can use fixed-and variable-step solvers to compute the states of the dynamic system, and both of them can either support continuous or discrete states. The fixed step size of the solver for discrete systems will have a noticeable influence in the speed of the simulation and its accuracy, where a tradeoff between these two features is mandatory (for smaller step size, the accuracy is higher, but a longer simulation time will be achieved, and vice versa). In addition, this solver will be used if code generation is needed as it will be done in this paper.
Matlab/SIMULINK is the leading technical tool for engineers and scientists all around the world and its models are validated in many technical works and scientific papers [27]. In this article, some simulations will be made in this section using SIMULINK blocks in order to validate the studies carried out. Figure 6 shows the SIMULINK model of the grid-connected photovoltaic system and the solver employed. As can be seen, the size of the fixed-step discrete solver is Ts_Plant = 5.1196 μs, yielding 3906 samples in one period of 20 ms, which is small enough to validate its accuracy.

Simulation Studies
Several tools are employed in the dynamic simulation of renewable systems. The choice will depend on the available hardware and software resources, the allowed speed of the simulation and the possibility to integrate these tools in a hierarchical scheme for hybrid models, etc. Among them, IREQ's power system simulator of Hydro-Québec [24], EMTP-RV of EMTP Alliance [25], and Matlab/SIMULINK from the MathWorks [26] can be mentioned.
All these tools can use fixed-and variable-step solvers to compute the states of the dynamic system, and both of them can either support continuous or discrete states. The fixed step size of the solver for discrete systems will have a noticeable influence in the speed of the simulation and its accuracy, where a tradeoff between these two features is mandatory (for smaller step size, the accuracy is higher, but a longer simulation time will be achieved, and vice versa). In addition, this solver will be used if code generation is needed as it will be done in this paper.
Matlab/SIMULINK is the leading technical tool for engineers and scientists all around the world and its models are validated in many technical works and scientific papers [27]. In this article, some simulations will be made in this section using SIMULINK blocks in order to validate the studies carried out. Figure 6 shows the SIMULINK model of the grid-connected photovoltaic system and the solver employed. As can be seen, the size of the fixed-step discrete solver is Ts_Plant = 5.1196 µs, yielding 3906 samples in one period of 20 ms, which is small enough to validate its accuracy.
Several PV modules and its equivalent circuits are shown in different works [28][29][30], and an expression of the output voltage and current relation is presented in [31].
The methods and equations used to obtain the parameters of the equivalent circuit are shown in [31,32]. From the datasheet of a STP320-24-Ve polycrystalline PV module manufactured by Suntech [33], the obtained parameters for the PV module at standard test conditions (STC) (irradiance G = 1000 W/m 2 and temperature T = 25 • C) are shown in Table 1 and will be used in this paper. Table 2 shows the array sizing of the created PV generator at standard STC conditions using the parameters of the PV module in Table 1, attaining a maximum output power of 506.91 kW. Several PV modules and its equivalent circuits are shown in different works [28][29][30], and an expression of the output voltage and current relation is presented in [31].
The methods and equations used to obtain the parameters of the equivalent circuit are shown in [31,32]. From the datasheet of a STP320-24-Ve polycrystalline PV module manufactured by Suntech [33], the obtained parameters for the PV module at standard test conditions (STC) (irradiance G = 1000 W/m 2 and temperature T = 25 °C) are shown in Table 1 and will be used in this paper.   Tables 1 and 2, several I-V and P-V curves of the PV generator for different irradiances and T = 25 • C are traced as can be seen in Figure 7. These curves are then used to build a Lookup Table (2-D) in SIMULINK [14] in order to evaluate the proposed control strategies under several test conditions. Parallel resistance Rp = 4.24074 Ω Series resistance Rs = 0.3437 Ω Ideally factor of the diode m = 1.1238 Table 2 shows the array sizing of the created PV generator at standard STC conditions using the parameters of the PV module in Table 1, attaining a maximum output power of 506.91 kW.  Tables 1 and  2, several I-V and P-V curves of the PV generator for different irradiances and T = 25 °C are traced as can be seen in Figure 7. These curves are then used to build a Lookup Table (2-D) in SIMULINK [14] in order to evaluate the proposed control strategies under several test conditions.    Table 3 shows the parameters of the power subsystem and Figure 9 shows its Simulink model, whereas Table 4 describes the parameters of the control subsystem and Figure 10 shows its Simulink model. Table 4 highlights in bold letters the proper tuned PI regulators, calculating its constants with the aim, firstly to optimize its dynamic behavior and, secondly to ensure a zero steady-state error [34].    Table 3 shows the parameters of the power subsystem and Figure 9 shows its Simulink model, whereas Table 4 describes the parameters of the control subsystem and Figure 10 shows its Simulink model. Table 4 highlights in bold letters the proper tuned PI regulators, calculating its constants with the aim, firstly to optimize its dynamic behavior and, secondly to ensure a zero steady-state error [34].  In Figures 11-18, the time evolution of the voltage sag (p.u.), the DC link voltage, the inverter voltage, and the DC current delivered by the PV generator, respectively, are depicted in (a); the grid  A triggered subsystem can be observed in Figure 10a which indicates that this block will be run a different sample rate than the power subsystem. The whole block will be run at a sample frequency of 24.416 kHz (T reg = 40.957 µs), the same as the switching frequency of the inverter in order to attain the synchronization of the sample process [35]. The magenta color block computes the MPPT and the non-MPPT algorithms shown in Figure 5 for a specific irradiance and temperature, setting the proper DC bus voltage reference (V DC *).
The bandwidth of the innermost current loop (green color blocks in Figure 10a) must be greater than the bandwidth of the outermost voltage loop (red color block in Figure 10a) in order to analyze them as two independent controllers. In addition, the switching nature of the inverter produces ripple in the inverter currents that will be attenuated by selecting the proper parameters of the current regulators. Moreover, the voltage loop must reject the effect of the AC utility grid voltage as a perturbation in the current loop, having a bandwidth even smaller [35].
The PI regulators of the PLL (inside the red color block of Figure 10b) are tuned and normalized according to the settling time (T set ), the damping factor (ζ) and the amplitude of the grid voltages [36,37].
In Figure 10b, the PNS Fault detection + the PQ References Generator are described in detail. The magenta color block calculates the adequate reactive power (Q) according to Equation (8), whereas the green color block calculates the active and reactive power references used in the LVRT algorithm described by the flowchart in Figure 4.
In Figures 11-18, the time evolution of the voltage sag (p.u.), the DC link voltage, the inverter voltage, and the DC current delivered by the PV generator, respectively, are depicted in (a); the grid voltage, the grid current, the active and reactive powers, respectively, are depicted in (b). Several types of voltage sags are applied at 1 s for two irradiances G = 1000 and 500 W/m 2 and the grid currents indicates no overcurrent during the short-time duration fault events in all cases. When the voltage sag ends, the no faulty operation mode of the PV system is established (P = 500 kW and 250 kW, respectively, and Q = 0). Figures 11 and 12 show the time evolution of the several variables mentioned above when a three-phase deep voltage sag of 90% occurs for irradiances G of 1000 and 500 W/m 2 , respectively. The DC link voltage increases from 810 to 995 and 954 V, respectively, whereas the DC current delivered by the PV generator is around 50 A for both situations during the fault due to mainly the copper and the inverter losses. The delivered P is zero and Q is 50 kVAr for both irradiances.

Three-Phase Voltage Sag
On the contrary, Figures 13 and 14 show the time evolution of the several variables when a three-phase deep voltage sag of 70% occurs for irradiances G of 1000 and 500 W/m 2 , respectively. The same previous results are attained, but the delivered Q during the sag is 150 kVAr. Figures 15 and 16 show the time evolution of several variables when a deep voltage sag of 90% in phase 3 occurs for irradiances G of 1000 and 500 W/m 2 , respectively. The DC link voltage increases from 810 to 976 and 995 V, respectively, whereas the DC current delivered by the PV generator are 140 A and zero, respectively, during the fault. The mean values of the delivered P are 100 kW and zero, respectively; the mean values of the delivered Q are 150 kVAr for both irradiances. Figures 17 and 18 show the time evolution of the several variables when a moderate voltage sag of 50% in phase 3 occurs for irradiances G of 1000 and 500 W/m 2 , respectively. The DC link voltage increases from 810 to 937 and 878 V, respectively, whereas the DC current delivered by the PV generator reaches 330 and 230 A, respectively, during the fault. The mean values of the delivered P are 300 and 175 kW, respectively, whereas the mean values of the delivered Q are zero for both irradiances. Figures 11 and 12 show the time evolution of the several variables mentioned above when a three-phase deep voltage sag of 90% occurs for irradiances G of 1000 and 500 W/m 2 , respectively. The DC link voltage increases from 810 to 995 and 954 V, respectively, whereas the DC current delivered by the PV generator is around 50 A for both situations during the fault due to mainly the copper and the inverter losses. The delivered P is zero and Q is 50 kVAr for both irradiances.  On the contrary, Figures 13 and 14 show the time evolution of the several variables when a threephase deep voltage sag of 70% occurs for irradiances G of 1000 and 500 W/m 2 , respectively. The same previous results are attained, but the delivered Q during the sag is 150 kVAr.  On the contrary, Figures 13 and 14 show the time evolution of the several variables when a threephase deep voltage sag of 70% occurs for irradiances G of 1000 and 500 W/m 2 , respectively. The same previous results are attained, but the delivered Q during the sag is 150 kVAr.

Experiments
Some experiments are carried out using the CHIL simulation technique as an additional validation to the previous simulations. The power subsystem (including the PV generator, the three-phase, the inverter, the L filter and the utility grid) is modeled with PLECS tools, while the control subsystem is modeled using SIMULINK blocks. In both cases, the C-codes are generated using the Model-Based design method and downloaded into the Digital Real-Time Simulator (DRTS) [38] for the former, and into the real microcontroller for the latter, running both in real-time [39].
The block diagram of the implemented CHIL setup is shown in Figure 19, where several input/output digital and analog signals mimic the real-time behavior of the power subsystem. The inverter is modeled as a switch-mode device (not averaged model), making the whole model more realistic if compared with simulation results, and attaining more accurate results of the voltages, currents, active and reactive powers, among others, very similar if these variables were measured in a real platform. In addition, with this approach the control subsystem works as if it were connected to the signal conditioners of a real power subsystem but avoiding the power flow and attaining a safe operation, allowing some risky tests so as to be able to validate the proper behavior of the control algorithms. The sample time (T s ) for the DRTS is set to 5.1196 µs, whereas the sample time of the controller (T reg ) is set to 40.957 µs; the latter has a delay of 3 2 T reg = 61.44 µs in the worst case. Finally, several measurements are displayed and recorded in the host PC in order to monitor the behavior of the grid-connected PV system.
Two hardware units are employed in the setup: the PLECS RT Box 1 [40] working as the DRTS for the power subsystem (see Figure 20b in which Ts_Plant = 5.1196 µs and the PLECS accuracy is set to 0.1%), and the TMS320F28379D Dual-Core Delfino Microcontroller [41] as the control subsystem as can be seen in Figure 21. Figure 21 shows the ADC interface of the microcontroller, the programming of the interruption service routine synchronized to the switching frequency, as well as the PWM signals sent to the PLECS RT Box 1. On the other hand, Figure 22 shows the detailed SIMULINK model of the control subsystem, highlighting the signal conditioning at the left of Figure 22a for a 12 bits ADC in the microcontroller, as well as the signal conditioning at the right of Figure 22b. a real platform. In addition, with this approach the control subsystem works as if it were connected to the signal conditioners of a real power subsystem but avoiding the power flow and attaining a safe operation, allowing some risky tests so as to be able to validate the proper behavior of the control algorithms. The sample time (Ts) for the DRTS is set to 5.1196 μs, whereas the sample time of the controller (Treg) is set to 40.957 μs; the latter has a delay of = 61.44 μs in the worst case.
Finally, several measurements are displayed and recorded in the host PC in order to monitor the behavior of the grid-connected PV system.  Two hardware units are employed in the setup: the PLECS RT Box 1 [40] working as the DRTS for the power subsystem (see Figure 20b in which Ts_Plant = 5.1196 μs and the PLECS accuracy is set to 0.1%), and the TMS320F28379D Dual-Core Delfino Microcontroller [41] as the control subsystem as can be seen in Figure 21. Figure 21 shows the ADC interface of the microcontroller, the programming of the interruption service routine synchronized to the switching frequency, as well as the PWM signals sent to the PLECS RT Box 1. On the other hand, Figure 22 shows the detailed SIMULINK model of the control subsystem, highlighting the signal conditioning at the left of Figure 22a for a 12 bits ADC in the microcontroller, as well as the signal conditioning at the right of Figure 22b.    In Figures 23 and 24, some tests are shown to demonstrate the LVRT capability when a threephase deep voltage sag of 90 and 70% occur at an irradiance G = 500 W/m 2 . The time evolution of the DC link voltage and the DC current delivered by the PV generator, the grid voltages and currents at the grid side, and P and Q powers delivered to the low-voltage utility grid are shown in (a), meanwhile the same variables are depicted in (b) during the voltage sags, where the values of the nominal period (T = 20 ms) of the voltages and currents, and P and Q powers can be observed for the normal and faulty operation modes.
In both tests, the Maximum Power Point (MPP) of the PV generator is tracked when there is no voltage sag and the VDC*MPP DC bus reference voltage is applied to the control algorithm to do the power balance, reaching P a value of 250 kW whereas a zero Q is attained for unity power factor operation. However, the DC link voltage increases during the voltage sag because the limitation in the amplitude of the line currents to its nominal rated value decreases the P delivered to the utility grid and a VDC*non-MPP DC bus reference voltage is set in this situation. At the same time, some amount of Q is needed according to equation (8) so as to be able to improve the voltage profile of grid In Figures 23 and 24, some tests are shown to demonstrate the LVRT capability when a three-phase deep voltage sag of 90 and 70% occur at an irradiance G = 500 W/m 2 . The time evolution of the DC link voltage and the DC current delivered by the PV generator, the grid voltages and currents at the grid side, and P and Q powers delivered to the low-voltage utility grid are shown in (a), meanwhile the same variables are depicted in (b) during the voltage sags, where the values of the nominal period (T = 20 ms) of the voltages and currents, and P and Q powers can be observed for the normal and faulty operation modes.   In both tests, the Maximum Power Point (MPP) of the PV generator is tracked when there is no voltage sag and the V DC *MPP DC bus reference voltage is applied to the control algorithm to do the power balance, reaching P a value of 250 kW whereas a zero Q is attained for unity power factor operation. However, the DC link voltage increases during the voltage sag because the limitation in the amplitude of the line currents to its nominal rated value decreases the P delivered to the utility grid and a V DC *non-MPP DC bus reference voltage is set in this situation. At the same time, some amount of Q is needed according to Equation (8) so as to be able to improve the voltage profile of grid voltages during the sags.

Conclusions
In this article, the vector control of a three-phase single-stage grid-connected PV system is carried out in the rotating orthonormal dq axes with LVRT capability according to the IEC 61400-21 European normative, and to the Spanish grid code regarding the amount of reactive power to be delivered to the utility grid, which is the main novelty of the paper. Specifically, the LVRT capability was tested with several voltage sags imposed to the three-phase utility grid voltages at different irradiances in the PV generator.
When voltage faults were introduced to the utility grid, the proposed control algorithm of the three-phase single-stage grid connected inverter exerted the proper limitation of the three-phase output currents through the inverter to its nominal values in order to avoid the triggering of its overcurrent protection and the disconnection from the utility grid. Thus, the DC link voltage of the PV generator increases in order to track the new active power and make the power balance; meanwhile, some reactive power is delivered to the grid in order to improve its voltage profile. When voltage sags end, the DC voltage decreases until the maximum power point is tracked for normal operation, whereas the reactive power is set to zero in order to achieve a unity power factor.
Finally, the simulations carried out with Matlab/SIMULINK together with the experiments using the CHIL simulation technique validate the appropriate assessment of the control algorithms and the LVRT capability in the Spanish case, although an extrapolation to other international grid codes can be easily carried out. The latter is a good alternative in order to be able to test the control algorithms embedded in a real microcontroller with its own resources, without losing the physical meaning of the behavior of the power system and avoiding the risks associated to an energized real power plant.