Optimal design of proportional-resonant controller and its harmonic compensators for grid-integrated renewable energy sources based three-phase voltage source inverters

This paper proposes new analytical and optimal design procedures of the proportional-resonant (PR) controller and its harmonic compensators (HCs) for three-phase grid-connected voltage source inverters (VSIs) powered by renewable energy resources. The modeling and analysis based on stationary reference frame are performed for VSIs collaborated with an L-type ﬁlter. The theoretical veriﬁcation and simulation validation of the proposed design guidelines are done to approve its effectiveness and robustness. Particle swarm, grey wolf and Harris hawks’ optimization techniques are applied and compared for a proper selection of the parameters of the proposed PR controller and its HCs. To accomplish this study, multi-objective error functions are employed and compared to minimize the total harmonic distortion of the grid output current. The proposed PR controller and its HCs are tested, using MATLAB/Simulink, along with the allowable changes of inverter output active and reactive powers, and also under the grid voltage distortion. Moreover, their performance is evaluated according to IEEE and IEC harmonics standards, and compared with the conventional PI controller based on reference frame. Fur-thermore, the experimental validation for the proposed controllers is done based on the hardware-in-the-loop real-time simulator using C2000TM-microcontroller-LaunchPadXL-TMS320F28377S


INTRODUCTION
Nowadays, traditional energy shortages and pollution of the environment are the main issues affecting the world. Renewable energy resources (RERs) have become the best promising solution with the benefits of zero-emissions and low prices [1,2]. All countries have focused on the integrating of wind turbines (WTs), photo-voltaic panels (PVPs) and fuel cells (FCs) to the utility power network. The power electronic converters in renewable energy conversion systems (RECSs) are the most significant part, which is used to achieve power conditioning to satisfy specific requirements of various applications. This paper introduces two control approaches for three-phase grid-integrated current-controlled voltage source inverters (VSIs). The first approach is based on PI current controller in the synchronous reference frame, while the second depends on the proportional-resonant (PR) current controller with its harmonics compensators (HCs) in the stationary reference frame. Harmonics produced by these VSIs constitute a significant problem for power quality, particularly as the amount of these grid-connected RECSs is continuously growing. This implies that the controlling of these harmonics is essential to restrict their harmful impacts on the power quality of the utility power network. Several previous works were focused on using the multi-level inverters to minimize the harmonics of RECSs, as in [3][4][5][6]. This increases the cost and complexity of the system. The authors of [7] proposed the applying of PR current controller with its 3 rd , 5 th and 7 th HCs for single-phase PV inverters collaborated with an LCL-filter. In this reference, the design procedure depends mainly on MATLAB's SISO IET Gener. Transm. Distrib. 2021;15:1371-1386.
wileyonlinelibrary.com/iet-gtd Design Tool. Gui Y. et al. have suggested PR controllers for the energy storage system to regulate the frequency and voltage in the micro-grid [8]. PR voltage and current controllers with 5 th , 7 th , and 11 th HCs to suppress the voltage harmonics of the micro-grid integrated with a non-linear load are presented in [9]. In this reference, the design procedure is based on the bode diagrams of the sensitivity transfer function of the system. The PR controller is highly suitable for controlling and tracking the sinusoidal signals because it has very high gain at fundamental-frequency (resonant-frequency) and nearly no gains present at the other frequencies. Despite this, the output grid current of VSIs based on this controller is not immune from harmonics. This problem can be solved by adding HCs, which are tuned at the harmonics' frequencies.
The output grid current of VSIs contains harmonics caused by the inverter non-linearities in addition to harmonics that already exist in the utility power network [7]. This may violate the constraints of IEEE and IEC standards on the total harmonic distortion (THD) and individual harmonics magnitudes of output grid current for distributed generation systems. Therefore, in this paper, 5 th , 7 th , 11 th , 13 th and 17 th HCs are included with a PR controller to maintain the power quality of the output current within the standards along with the allowable range of output active and reactive power.
The PR current controllers based on the stationary reference frame offer several advantages over the conventional control methodologies, such as no decoupled and feed-forward parts are required. Furthermore, no ∕dq transformation, and vice versa are needed [9]. Moreover, the PR controllers can be provided by appropriate selection of HCs to suppress both the positive and negative sequence harmonics. In contrast to the traditional PI controllers, AC signals can be controlled and tracked to their references with zero steady-state error using PR controllers [8].
The main problem of the PR controller and its HCs is how to choose their parameters accurately to achieve good dynamic performance. The conventional procedure is time-consuming, depending on trial and error processes and the design process is ineffective [15]. Consequently, the main focus of that work is to introduce new modified analytical and optimal design guidelines for these parameters. The proposed methods are applied to three-phase grid-connected current-controlled VSIs cooperated with L-type filter and powered by RERs such as WTs, PVPs and FCs. The proposed procedures ensure the desired high dynamic performance with reducing the required time for design.
The theoretical verification of the proposed analytical design procedure of the PR controller and its HCs is introduced using the bode diagrams to confirm its effectiveness and robustness. The artificial intelligence-based optimal design is employed for the parameters of PR controller and its HCs to be appropriately selected. The proposed design procedures aim to obtain good dynamic response and stability, and also to minimize the total harmonic distortion of the output grid current. In order to evaluate the validation of the designed parameters, the pro-posed system is modelled and simulated in MATLAB/Simulink. This system is tested under both the normal operation and the grid voltage distortion. Moreover, the proposed system is experimentally elaborated using Hardware-in-the-loop (HIL) real-time simulator (RTS) based on C2000-microcontroller-LaunchPadXL-TMS320F28377S kit. The detailed discussion for the HIL simulator is presented in Section 6. Finally, the simulated and experimental results are compared with various types of controllers. Figure 1 shows the proposed control strategy for VSI based on the PR controller with its HCs in the stationary reference frame. This control approach contains four feed-back control loops: two outer active and reactive power control loops, and two inner current control loops for the -axis and -axis currents to be accurately controlled. Based on Figure 1, the output grid current equations for the VSI in the abc stationary reference frame are represented by:

ANALYSIS AND MODELING OF PR CONTROLLER AND ITS HCS BASED THREE-PHASE VSI IN STATIONARY FRAME
where i ag , i bg and i cg are the output grid currents in abc-frame, V ai , V bi and V ci are the inverter side voltages in abc-frame, V ag , V bg and V cg are the grid side voltages in abc-frame, R f is the filter resistor and L f is the filter inductor. By applying Clark transformation to the above equations, set of Equation (1) can be rewritten as: Here, V i , V i , V g , V g , i g and i g are the inverter side voltages, grid side voltages and output grid currents in -frame, respectively. Equation (2) illustrates that the control of the system is not cross-coupled, in which the derivative of -axis output grid current i g involves only -axis variables and the same in -axis current i g . Therefore, in contradiction of the conventional control methodologies depended on the rotating dqframe, there is no need for the feed-forward or the decoupled FIGURE 1 Control approach of three-phase current-controlled grid-connected VSI-based on the proposed PR controller and its HCs in stationary -frame parts. Moreover, this control approach does not require Park or inverse Park transformations.
The instantaneous active and reactive powers based on frame can be defined as: Assuming that the grid voltage is pure without harmonics, the derivatives of the active and reactive powers can be expressed as: where the grid voltage is defined as V g = √ V 2 g + V 2 g . The control inputs and state variables can be defined as [ The state-space dynamic model of three-phase currentcontrolled VSI in -frame can be expressed as: Figure 1 displays the control approach for VSI based on the proposed PR controller and its HCs in stationary -frame. Based on Equation (2), the output of the -axis and -axis current controllers, shown in Figure 1, can be represented as: In order to obtain the transfer-function of PR controller G PR (S ), the integral term of the traditional PI controller can be shifted to both Here, K pc and K ic are the proportional and integral gains of the PI current controller, and K rc and o are the resonantgain and resonant-frequency of PR current controller. The resonant-frequency is tuned at the fundamental-frequency ( o = 2 (50) rad∕s). The PR controller expressed in Equation (7) is considered as an ideal one that may suffer from stability issues due to the infinite gain at the resonant-frequency. In order to overcome these issues, the PR controller can be made practical by adding the damped term as the following: where c1 is the resonant bandwidth (BW) around fundamentalfrequency. It can be observed that the proportional term K pc of PR controller is responsible for determining the system dynamic including the BW, gain margin and phase margin, while the resonant term is necessary to track the AC signals with roughly zero steady-state error. Moreover, both the positive and negative harmonics can be suppressed by adding the paralleled HCs to the PR controller. These HCs are tuned at the required frequencies of the harmonics to be suppressed. The transfer-function of the HCs can be expressed as: 7,11,13,17,.. K hc S S 2 + 2 ch S + (h o ) 2 (9) in which K hc and ch are the resonant gain and BW of the current HCs at the frequency of harmonic order h. In this paper, the BW around the fundamental-frequency can be chosen to cover ∓1.6% of the frequency variation, thus c1 can be equal to 2 (50) × 1.6% ≈ 5 rad∕s. While the design of the BW for the certain harmonic frequency of the HCs can be achieved according to Equation (10) as [16,17]: Here, ζ is the damping factor and c5 , c7 , ch are the BW around the frequencies of 5 th , 7 th and h th harmonics, respectively. The parameters design of PR current controller can be done by using the control block diagram presented in Figure 2. From this figure, the open-loop transfer function of three-phase current-controlled VSI based on PR controller can be expressed as: Here, G PWM (S ) and G f (S ) are the transfer functions of pulse width modulation (PWM) delays and the filter, respectively, K PWM , T s and T d are the PWM gain, sampling time and control delay, respectively, and T f is the filter time constant which is equal to L f ∕R f . In this paper, the gain of PWM is equal to 1 to simplify the analytical analysis.
If the HCs are included with the PR controller, the open-loop transfer function becomes, Substituting Equations (12), (13) and (8) into (11) yields: The analytical and optimal design procedures for designing the parameters of the PR current controller and its HCs will be discussed in detail in the next two sections based on Figures 1 and 2.

FIGURE 2
Block diagram of closed current loops for three-phase VSI-based on PR controller and its HCs in stationary -frame

ANALYTICAL DESIGN PROCEDURES OF THE PR CONTROLLER AND ITS HCS
The analytical guidelines for designing the parameters of the PR controller and its HCs parameters are based on the openloop model represented by Equation (15). The following two design procedures must be achieved to guarantee a stable, fast, and accurate tracking of the sinusoidal waveform.
a. Typically, the control BW frequency of the PR controller must be in the range from 5% to 10% of the switching frequency for achieving high transient response [18], which equals 1-2 kHz for the used switching frequency in this paper of 20 kHz. Furthermore, the resonant term of the PR controller is adjusted at fundamental-frequency (resonant-frequency); hence, it has a high ability for controlling and tracking the sinusoidal signal around this frequency. It provides very high gain at this frequency and approximately no gains provided at the other frequencies caused by the magnitude falling. Depending on this explanation, the design of the proportional term K pc can be achieved on the base of suitable phase margin (PM P = 40-60 • ) while the control BW frequency is within the range of 1-2 kHz. b. Additionally, a significant dropping in phase response can be noticed at the resonant-frequency; hence, it is necessary to guarantee that its lowest phase response around this resonant-frequency is remaining within the suitable phase margin, thus the design of the resonant term gain K rc must be proceeded based on this constraint.
Based on Equations (12) and (13), the required phase margin PM P at the zero dB magnitude crossover-frequency co can be calculated by: Thus, the cross-over frequency co is Subsequently, to guarantee the zero dB magnitude response at the crossover-frequency co , the proportional gain K pc can be designed using Equations (16)-(18) as: It can be observed from Equation (18) that the K pc is calculated based on the required PM P at the zero dB magnitude at the crossover-frequency, the computational and PWM delays T d , the filter resistance R f , and the filter inductance L f . If any parameter of these is varied, the determined K pc will be changed accordingly. As soon as the design of K pc is accomplished, the design of the resonant term gain K rc can be performed on the base of a suitable phase margin PM R around the tuned fundamental-frequency. It can be observed that the resonant term of PR controller gives the lowest phase response at the frequency of p = o + 2 c1 . Consequently, the design of the K rc must be achieved regarding the phase margin PM R at the frequency of p = o + 2 c1 . By The following equation is deduced from Equation (19) by performing many mathematical operations The phase response of the PR controller at p = o + 2 c1 can be derived from Equation (20) as: From which the K rc can be designed according to the following equation: In which the phase response ∅ R of the PR controller at p = o + 2 c1 can be defined by The accepted range of phase margin PM R at p = o + 2 c1 is from 40 • to 60 • .
Equation (22) illustrates that the K rc is determined by the proportional gain K pc , the filter resistance R f , the filter inductance L f , the computational and PWM delays T d , the phase margin PM R and the fundamental cut-off frequency c1 . Similarly, the resonant term gains of HCs can be derived by the same above procedure at frequencies ph = ch + h o for h = 5, 7, 11, 13, 17…and so on. The theoretical verification is done using the following Bode diagrams, based on the data illustrated in Table 5, to confirm the effectiveness and robustness of the above analytical design procedures. These plots are obtained by the open-loop transfer-function, described in Equation (15), using the adopted parameters of PR controller, which are calculated by Equations (18) and (22).   (15) with fixed PM P = 50 • , while various PM R = 40 • , 50 • and 60 • K rc = 976.85. It can be observed that the three cases have the same phase response, while the magnitude responses are not the same. Thus, these cases have unequal cross-over frequencies of 2529.35, 1780.25 and 1223.95 Hz with unequal phase margins at 40 • , 50 • and 60 • , respectively. Moreover, it can be noticed that the cross-over frequency of the first case is out of the desired control BW. However, the cross-over frequencies of the second and third cases are within this band-width of 1-2 kHz (5-10% of switching frequency). Furthermore, for the resonant term at fundamental-frequency, it can be seen that the magnitude responses for these cases at this frequency are nearby 56.3, 51.8 and 47.4 dB, respectively; thus the sinusoidal signal can be tracked accurately due to high magnitudes; also the phase response for three cases at this frequency guarantees the phase margin PM R = 40 • . Correspondingly, Figure 4 depicts the Bode plot of the open-loop transfer-function represented in Equation (15) with fixed PM P = 50 • , while various PM R = 40 • , 50 • and 60 • . The gains of the three cases, presented in Figure 4 , are designed by Equations (18) and (22) as, Case 1: PM R = 40 • , K pc = 21.9, K rc = 1606.55; Case 2: PM R = 50 • , K pc = 21.9, K rc = 782.77; Case 3: PM R = 60 • , K pc = 21.9, K rc = 437.73. It can be observed that the three cases have the same value of phase margin PM P = 50 • at the cross-over frequency co = 1780.25 Hz. Additionally, at the resonant-frequency, the three cases have unequal magnitudes of 51.8, 46.5 and 42.9 dB, also the phase margins at this frequency are 40 • , 50 • and 60 • , respectively. Finally, it can be concluded that the small value of PM R leads to obtain high magnitude value, which supports that the sinusoidal signal to be tracked with the superior elimination of error, however this may cause stability issues for closed-loop system because of the minimal value of phase margin. Thus, it is crucial to adjust properly both the phase margin and the magnitude response at the resonantfrequency 50 Hz to obtain the high performance and good sta- bility. Table 1 shows the adopted parameters of PR current controller with the variations of PM P and PM R . The THD of grid current is measured at the output active and reactive power of 20 kW and 0 kVAR, respectively. It can be seen that the smaller PM P gives the lower THD of output grid current regardless of value of PM R , as explained in Table 1.

OPTIMAL DESIGN PROCEDURES OF THE PR CONTROLLER AND ITS HCS
The artificial intelligence (AI) algorithms are employed for tuning the parameters of several controllers successfully. The authors of [19] used the grasshopper algorithm to search for the accurate gains of the voltage and frequency PI controllers in the micro-grid, while in [20], the authors applied the particle swarm optimization (PSO) on the same application. Furthermore, the optimum controller design for reactive power control in an islanded microgrid was achieved by using PSO and bacterial foraging optimization algorithm [21]. Up to the authors' knowledge, no previous studies that use these algorithms for the optimal design of PR controller with its HCs in any application have been done. All the literature focused on using these algorithms for PID controller parameters to be appropriately determined in several applications. Consequently, this paper introduces the optimal design of PR current controller and its HCs for minimizing the THD of the output grid current in three-phase current-controlled grid integrated VSIs. The PSO, grey wolf optimization (GWO) and Harris hawks optimization (HHO) techniques are applied and cooperated with four objective error functions including integral absolute error (IAE), integral square error (ISE), integral time absolute error (ITAE) and integral time square error (ITSE). This is to select the proper parameters of PR controller and its HCs that achieve the minimum values of both the THD and the individual harmonics magnitudes for the output grid current. The gains of PR current controller and its HCs, required to be optimized, are K pc , K rc , c1 , K h5 , c5 , K h7 , c7 , K h11 , c11 , K h13 , c13 , K h17 and c17 .
PSO was introduced in 1995 as a metaheuristic algorithm inspired by nature. It mimics the food search mechanism of swarms like birds and fish. The main steps of this algorithm can be found in [22]. GWO is another metaheuris-tic algorithm that was presented in 2014. The social hierarchy and hunting behaviour of grey wolves were mimicked in this algorithm. The mathematical model and pseudo code of GWO were discussed in [23]. HHO was recently proposed in 2019 as a new population-based, nature-inspired, metaheuristic algorithm. It was inspired by the cooperative behaviour and chasing strategies of Harris's hawks. The mathematical equations and pseudo code of HHO were reported in [24].
The proposed system, based on the optimal PR current controller and its HCs, is shown in Figure 1. Firstly, the THD of output grid currents of phase "a", phase "b" and phase "c" are measured and compared with the desired value of THD * to obtain the value of error e THD = THD * − THD. Secondly, the four types of objective error functions required to be minimized can be calculated as: ( e i c THD ) 2 dt (24) Besides the above calculated objective error functions, the other input parameters to AI algorithm should be adequately adjusted for obtaining the optimal solution. These parameters include the number of search agents, maximum iterations number, and upper and lower limits of the optimized variables. In this paper, the maximum number of iterations is 30, the number of search agents is 20, and the lower and upper limits of the parameters of PR current controller and its HCs, based on the analytical method, are:  (15), using the proposed analytical and optimal parameters of PR current controller and its HCs

FIGURE 6
Closed-loop response of the system, presented in Figure 2, with the proposed analytical and optimal parameters of PR current controller and its HCs Finally, each algorithm is applied individually with each type of the four objective functions, and then the results are compared to obtain the best of them. Moreover, each algorithm with each objective function was run 10 times to find the optimal statistical result. Figure 5 clarifies the magnitude and phase responses of the open-loop model, explained in Equation (15), using the proposed analytical and optimal parameters of PR current controller and its HCs. Figure 6 describes the closed-loop response of the system, shown in Figure 2, with the proposed analytical and optimal parameters of PR current controller and its HCs. Note that the baseline in Figures 5 and 6 is the PI controller. The parameters of PI controller are chosen according to the equations previously published in [18]. Table 2 illustrates the adopted parameters obtained by the optimal design procedure for the PR current controller and its HCs. It can be observed from this table that HHO collaborated with ITSE objective function has the lowest fitness function, which results in the lowest value of THD in output grid current. In this paper, the reference THD of the output grid currents is adjusted to minimal value, which is equal to 0.1 %. The optimal procedure was done under the grid voltage distortion with 5 th , 7 th , 11 th , 13 th , 13 th and 17 th harmonics. In this frame of work, the references for active and reactive power were set to 20 kW and 20 kVAR, respectively.

SIMULATION RESULTS AND DISCUSSIONS
The proposed system, shown in Figure 1 and based on the parameters listed in Tables 2 and 5, is modelled and simulated in MATLAB/Simulink tools to test the feasibility of the designed parameters of PR controller and its HCs. The performance is investigated according to IEC 61727, IEEE 1547 and IEEE 929 harmonics standards and compared with the previously published conventional PI current controller. Two proposed scenarios, based on the purity level of grid voltage, are discussed in the following two subsections.

Scenario I
In this scenario, the proposed system is tested under a pure grid voltage during the step change of real power. The system behaviour is evaluated and compared with the conventional PI controller. Figures 7 and 8 show the performance of three-phase VSI during the step change of active power from 50 to 100 kW in the cases of PI current controller under dq synchronous frame and optimal PR current controller included with its HCs under stationary frame, respectively. Figure 7(a) presents the dynamic response of both d-axis and q-axis currents compared to their reference values. Moreover, Figure 7(b) demonstrates the dynamic behaviour of both actual active and reactive powers compared to their reference values. It can be observed that the conventional PI current controllers suffer from undesirable oscillations in d-axis and q-axis currents, and the output active and reactive powers, as shown in Figure 7(a,b). However, the optimal PR current controller and its HCs have insignificant oscillations, as illustrated in Figure 8(a,b). The proposed controller and its HCs have a superior performance in minimizing the tracking errors for output currents and powers. The power oscillations are reduced from ±0.25% in the case of conventional PI controller to ±0.02% in the case of proposed PR controller and its HCs. Figures 7(c) and 8(c) describe the grid voltage and output grid current for the phase "a" in the cases of PI current controller and optimal PR current controller with its HCs, respectively. It is worth mentioning that Figures 7(d) and 8(d) depict the harmonics spectrum of the output grid current for conventional controller and proposed

Scenario II
In this scenario, the proposed system is tested under the distortion of grid voltage. The grid voltage is distorted by injecting the 5 th , 7 th , 11 th , 13 th and 17 th harmonics. The system performance is investigated based on harmonics standards and compared with the conventional PI controller. Only the case, in which active power equals 20 kW and reactive power equals 20 kVAR lead, is discussed in detail, but the other cases are listed as briefly results in Table 3. Figures 9 and 10 represent the simulated output grid current waveform and its fast Fourier transform (FFT) analysis in the cases of PI current controller in dqframe and PR controller without HCs in -frame, respectively, under grid voltage distortion at P = 20 kW and Q = 20 kVAR lead. It can be observed that the THD of the output grid current is decreased from 11.2% in the case of a PI current controller to 9.81% in the case of an analytical PR current controller without HCs. Figure 11(a-d) depict the simulated output grid current waveform and its harmonics analysis in the cases of analytical PR with 5 th HC, analytical PR with 5 th and 7 th HCs, analytical PR with 5 th , 7 th and 11 th HCs, and analytical PR with 5 th , 7 th , 11 th and 13 th HCs, respectively. It can be noticed that the THD of output grid current decreased from 8.4% in the case of analytical PR with 5 th HC to 6.22% in the case of analytical PR with 5 th and 7 th HCs to 4.96% in the case of analytical PR with 5 th , 7 th and 11 th HCs to 4.17% in the case of analytical PR with 5 th , 7 th , 11 th and 13 th HCs. Figure 12(a,b) displays the simulated output grid current and its harmonics spectrum in the cases of analytical PR with 5 th , 7 th , 11 th , 13 th and 17 th HCs and optimal PR controller with 5 th , 7 th , 11 th , 13 th and 17 th HCs, respectively. It can be observed that the THD of output grid current decreased from 3.97% in the case of analytical PR with its HCs to 2.94% in the case of optimal PR with its HCs. Table 4 provides the THD and individual harmonics magnitudes of output grid current in the cases of PI controller, analytical PR controller, analytical PR controller with HCs and optimal PR controller with HCs under the grid voltage distortion at P = 20 kW, Q = 20 kVAR lead. It can be noticed that the conventional PI current controllers have high THD of output grid current. Compared with PSO and GWO, the HHO technique is more effective in minimizing both the THD and the individual harmonics magnitudes of the output grid current. Table 3 gives the THD of the output grid current with the changes of the real and reactive power under different current controllers. It can be seen that, for the worst operating conditions, the THD of output grid current decreased from 14.61% in the case of conventional PI current controller and to 12.43% in the case of only PR FIGURE 7 Performance of three-phase VSI based on PI current controller under dq synchronous frame during the step change of active power from 50 to 100 kW: (a) The actual and reference of d-q output grid currents, (b) the actual and reference of active and reactive powers, (c) the grid voltage and output grid current for phase "a", and (d) the harmonics spectrum of the output grid current in the case of the pure grid voltage and the output active power is 50 kW (simulation result)

FIGURE 8
Performance of three-phase VSI based on the proposed optimal PR current controller and its HCs under stationary frame during the step change of active power from 50 to 100 kW: (a) The actual and reference ofoutput grid currents, (b) the actual and reference of active and reactive powers, (c) the grid voltage and output grid current for phase "a", and (d) the harmonics spectrum of the output grid current in the case of the pure grid voltage and the output active power is 50 kW (simulation result) controller and to 5.15% in the case of analytical PR controller with its HCs and to 3.84% in the case of optimal PR controller with its HCs. Under any operating conditions, the proposed controller with its HCs can maintain the THD of the output grid current within the allowable limits required by harmonics standards.

HIL REAL-TIME SIMULATOR AND EXPERIMENTAL RESULTS
The high complexity of advanced control systems forces researchers to implement and develop more effective, efficient, low-cost and accurate real-time simulators. HIL emulator is the most promising methodologies used to develop, test and validate the complicated control systems in a real-time platform in the laboratories. It is performed by hosting the model of the physical plant in the personal computer (PC). This model is run in real-time simulation and contains input and output signals that can interface and communicate with the external hardware of the control system or other targets. HIL needs for the cooperated operation and data exchange between the external hardware target and host-PC. It is considered a safe and convenient procedure utilized in the laboratories for faster testing of the prototypes of controllers under various operating loads and conditions. HIL simulator has more reliability and credibility than a numerical simulation that is run in ideal environments ignoring disturbance, communication delay, noise and other practical issues that may cause fatal damage. It offers some benefits of minimizing the hazard, reducing the time of development, and being well appropriate to risky and critical applications. HIL-based testing can be performed without causing the equipment to fail or endanger. Many challenges are confronted when carrying out the test procedures such as cost for testing, cost of failure, system variations, repeatability and availability. In this situation, HIL real-time simulator is a compelling strategy [25,26].
In this paper, HIL technique is employed to experimentally test, verify and validate the functionality of the proposed con-

FIGURE 11
Simulated output grid current waveform and its harmonics spectrum in the case of an analytical PR controller with HCs in fffi-frame under grid voltage distortion at P = 20 kW and Q = 20 kVAR lead trol system to ensure that it operates appropriately as planned. The models of PR controller and its HCs must be transformed from continuous s-domain used in MATLAB simulation to discrete z-domain for a real-time HIL simulator. The validation was done by simulation in MATLAB/Simulink tools to make sure that the results obtained from both domains are identical and coincident. Figure 13 shows the discrete zdomain models of PR controller and its HCs. The main components and signals flow of the HIL simulator for the suggested control system are illustrated in Figure 14. For implementing HIL test bench, the three-phase VSI with output Lfilter and distorted power grid are simulated and hosted in the PC, and the proposed control system is implemented on C2000 micro-controller LaunchPadXL TMS320F28377S kit. The data of VSI and grid is listed in Table 5. The control system executed on the target kit includes power calculator, transformations, current loops, and controllers and HCs. In this work, the host PC used in HIL simulation has a processor of Intel(R) Core(TM) i7-4510U CPU @ 2.00 GHz with installed memory (RAM) of 8.00 GB. The external target kit of TMS320F28377S has a processor of 200 MHz CPU + 200 MHz CLA with 164 KB of RAM (parity) and 1 MB of flash (ECC). The serial communication is required for the cooperated operation and data exchange between TMS320F28377S kit and host PC. This serial communication is provided by XDS100v2 onboard emulator using the mini-USB cable and a virtual COM port.
Consequently, the host PC transmits the measured grid voltages and currents as well as the controller type selection signal to the TMS320F28377S kit. These signals are received to the FIGURE 12 Simulated output grid current waveform and its harmonics spectrum for both analytical and optimal PR controller with HCs in fffi-frame under grid voltage distortion at P = 20 kW and Q = 20 kVAR lead

FIGURE 13
Discrete z-domain models of PR controller and HCs kit. Therefore, the output grid currents can be controlled by the proposed PR controller and its HCs. Finally, the control system implemented in F28377S kit gives six pulses required for applying to VSI in the next instant. Subsequently, these six switching pulses are received to host PC and fed the IGBTs of VSI. This process repeats every sample time. The controller type selection signal is used to select the controller type in the host PC side to be activated on the target side. Figures 15, 16 and 17 show the comparison between the experimental and simulated output grid current in the cases of analytical PR controller, analytical PR controller and its HCs, and optimal PR controller with its HCs, respectively, under the grid voltage distortion at P = 20 kW and Q = 20 kVAR lead. For the experimental results, the THD of output grid current is decreased from 11.76% in the case of PI controller to 10.27% in the case of analytical PR controller to 4.2% in the case of analytical PR controller and its HCs to 3.09% in the case of optimal PR controller with its HCs. Table 6 illustrates the comparison between the experimental and simulated results under the grid voltage distortion at P = 20 kW and Q = 20 kVAR leading. It can be observed that the experimental results are coincident with the simulation with tiny discrepancies. This is due to the well-structured test bench developed by the authors. This test bench had built based on selecting the most optimum baud rate, sampling time and data rate transition.

CONCLUSIONS
This paper presented new modified analytical and optimal design procedures of the PR controller and its HCs for gridintegrated RERs based three-phase VSIs cooperated with Ltype filter. The modelling and analysis of the proposed control approach for these VSIs have been introduced. This control methodology depends on the proposed PR controller and its HCs in stationary reference frame. HHO, GWO and PSO algorithms were employed and collaborated with four objective error functions, including IAE, ISE, ITSE and ITAE, in order to search for the optimal parameters of PR controller and its HCs. These optimal parameters achieve the minimum values of both the THD and the individual harmonics magnitudes for the output grid current. The designed parameters of the proposed controller and its HCs were theoretically verified using the bode plots to confirm its effectiveness. The proposed system has been modelled and simulated in MAT-LAB/Simulink. Its performance was investigated and compared with the previously published conventional PI current controller under both the pure and distorted grid voltage. It can be noticed that the conventional PI current controllers suf-  Analytical current HCs gains, K h5 , K h7 , K h11 , K h11 , K h17 10,000, 10,000, 10,000, 10,000, 10,000 Active and reactive power loop gains, K p , K i 0.2, 80 fer from high THD in the output grid current and undesirable oscillations in the output active and reactive powers. Compared with PSO and GWO, the HHO technique is more effective in minimizing both the THD and the individual harmonics magnitudes of the output grid current while the system stability is approximately maintained. For the worst operating conditions, the THD of the output grid current decreased from 14.61% in the case of conventional PI current controller to 12.43% in the case of only PR controller to 5.15% in the case of analytical PR controller with its HCs to 3.84% in the case of optimal PR controller with its HCs. Under any operating conditions, the proposed controller and its HCs can achieve the grid code requirements by IEC 61727, IEEE 1547 and IEEE 929 standards for the output grid current of distributed generation. Additionally, the experimental tests have been done using HIL simulation based on C2000 micro-controller Launch-PadXL TMS320F28377S kit to demonstrate the benefits of the proposed PR controller and its HCs. Both the experimental and simulated results are compared. It can be observed that there   should be replaced by the proposed optimal PR controller and its HCs for three-phase grid-connected current-controlled VSIs collaborated with L-type filter based commercial applications.