PV Systems Control Using Fuzzy Logic Controller Employing Dynamic Safety Margin under Normal and Partial Shading Conditions

: Because of the unpredictable activity of solar energy sources, photovoltaic (PV) maximum power point tracking (MPPT) is essential to guarantee the continuous operation of electrical energy generation at optimal power levels. Several works have extensively examined the generation of the maximum power from the PV systems under normal and shading conditions. The fuzzy logic control (FLC) method is one of the effective MPPT techniques, but it needs to be adapted to work in partial shading conditions. The current paper presents the FLC-based on dynamic safety margin (DSM) as an MPPT technique for a PV system to overcome the limitations of FLC in shading conditions. The DSM is a performance index that measures the system state deviation from the normal situation. As a performance index, DSM is used to adapt the FLC controller output to rapidly reach the global maxima of the PV system. The ability of the proposed algorithm and its performance are evaluated using simulation and practical implementation results for single phase grid-connected PV system under normal and partial shading operating conditions.


Introduction
The main two factors motivating energy demand are the population and financial growth. The growing demand for energy and the environmental impact of fossil fuels has increased the need for clean and renewable energy sources. In the last decade, solar energy technologies have become less expensive and more efficient. Moreover, it is a more environmentally friendly energy source than traditional ones like fossil fuels, coal, and nuclear energy. Therefore, the share of photovoltaic (PV) systems among other renewable energy sources has increased. The PV system can be connected directly as a stand-alone system to the load or indirectly as a grid-connected PV system via the electric grid. The gridconnected system is preferable in the presence of multiple sources of electric energy [1,2]. Since the PV system's output power depends primarily on environmental conditions, in particular irradiation and temperature, the PV system requires a maximum power point tracking (MPPT) controller to maintain the service at the global maxima [3,4], such that the maximum output power can always be delivered by the PV system.
During normal weather conditions, the PV system has only one global maximum, which the MPPT controller tries to follow, whereas the PV system in partial shading has multi-maximum points, local and global peaks. Hence, if the MPPT controller is not sufficiently resilient, the MPPT may struggle to locate the real maximum point and be stuck at a local maximum [5]. In this circumstance, the PV system's output power would be significantly decreased. This can take place due to a passing cloud, obstructions caused by tall buildings, trees, poles, towers, etc., or even damage to one or more modules in the PV array [6,7]. A shunt-connected bypass diode is used to protect the module from hot-spot damage when a section of the PV module is shaded. However, by using this diode, the output power is decreased greatly, since the power produced from the shaded module is quite unusable. Furthermore, conduction losses occur as the current passes through the bypass diode which can contribute to a further deterioration in device performance [8,9].
Different MPPT techniques and algorithms of PV under partial shading conditions are scattered throughout the literature. They can be classified into new MPPT optimization algorithms, hybrid algorithms, modeling techniques, and converter topologies [10]. The proposed work belongs to the MPPT algorithm type rather than the modeling and converter topologies. Various MPPT algorithms are implemented in the literature. Some of these algorithms employ artificial intelligence (AI) methods such as fuzzy logic controller (FLC) [11,12], artificial neural networks, and neuro-fuzzy algorithms [13]. Most of them depend on a power-voltage (P-V) scan of the PV and store the state at each observed shading condition. Other methods such as partial swarm optimization (PSO) [14,15], Harris hawk optimization [16], bat algorithm [17], or implementing soft computing optimization techniques [10,18] have been proposed before. The main limitations of these techniques are their computational complexity, initial condition dependency, cost, and slow tracking. They may also cause voltage and MPP oscillations.
The MPPT controller based on FLC is a successful and robust algorithm to work with different weather conditions [11,12], mainly for its fast response under rapid changes, which makes it a good tool to avoid the conventional MPPT problems such as oscillations around the MPP. However, MPPT controllers based on FLC sometimes fail to track the global maxima under shaded conditions. Thus, modified FLC algorithms have been presented in the literature. An integration of FLC with differential flatness control is introduced in [19] and compared with PSO. An adaptive neuro-fuzzy system-based MPPT is implemented in [13]. Both techniques depend on P-V scan methods and require more time to attain a stable maximum operating point. A type-2 FLC-based MPPT under partial shading is suggested in [20]. In this technique, the fuzzy membership function is asymmetrical, and each membership has lower and upper boundaries to overcome the uncertainties of generated power due to the shading. The main difficulty of this technique is how to deduce the type-2 membership function. Moreover, most of these techniques are complex with a high computational burden. In addition, they apply a P-V scan technique which interrupts the delivered power during the scanning and affects the grid stability.
The adaptation of FLC for MPPT is also addressed in [21] by adjusting the FLC output based on the deviation of the PV voltage and nominal open circuit voltage, V OC . This technique is simple and robust, but it fails in some situations to work effectively under partial shading. Hence, the main target of this paper is to design and implement an adaptive FLC technique based on other criteria to work probably in partial shading conditions and overcome the limitation of other FLC-based MPPT.
An adaptive FLC based on a performance index called the dynamic safety margin (DSM) is proposed. The DSM based controller has the advantage to sustain a specified safety margin during transient and disturbance behaviors [22,23]. Moreover, it can greatly aid the performance recovery in some situations of operational deviation. The safety region of the PV is chosen to contain all the possible maximum operating points at different weather conditions without shading. This means that once the safe operation region has been determined, the monitoring operating point with respect to the safe region indicates the abnormal behavior either due to shading or malfunction. The deviation of the operating points from the safe operation region is used as a performance index to evaluate how far the operation mode from the normal behavior is and to adapt the MPPT controller to track the global maximum. Therefore, the contributions of this article are summarized as: (1) determine the safe operating region of the PV system and calculate DSM; (2) design an adaptive FLC based on DSM as a robust MPPT controller to overcome the shading conditions of a grid-connected PV system, and (3) implement the proposed technique on a single-phase multi-stage grid-connected system as a case study.
The partial shading effect on the PV model will be illustrated in Section 2. The proposed MPPT technique is explained in Section 3 and the case study description and configuration are illustrated in Section 4. The analysis of the simulation results and the experimental verification of the proposed system are carried out in Sections 5 and 6, respectively. The conclusions are presented in Section 7.

Partial Shading Mode
Two groups of PV cells linked in series within a module could model a partially shaded module. Different levels of irradiance are received by each group. The module consists of r series-connected cells, in which s shaded cells receive irradiance G 1 , and (r − s) shaded cells receiving irradiance G 2 . The PV parameters can be represented as (1)-(4) [8,9]: where the subscripts 1 and 2 refer to the cells receiving irradiance of G 1 and G 2 respectively, I ph is the solar-generated current. Considering the existence of a single bypass diode for each PV module, the output current and voltage at the array terminal can be obtained by solving the following Equations (5) and (6): where A is the diode ideality factor, G is the operating irradiance level (W/m 2 ), K is the Boltzmann constant, G r is the nominal irradiance level (W/m 2 ), N s is the number of seriesconnected cells, T k is the operating temperature (K), V PV is the output voltage, I o1 is the diode saturation current, V PVm is the PV module output voltage, I PV is the PV output current and R s is the series-connected resistance. During partial shading, a segment of the PV cells, which obtains uniform irradiance, still perform at the optimum efficiency. Although the current flow is naturally constant through each cell in a series configuration, the shaded cells need to perform with a reverse bias voltage to provide a current such as the illumined cells. However, the resulting polarity of the reverse power contributes to power consumption and the decrease in the maximum output power of the partially shaded PV module. It is important to realize that the features of a bypass diode array vary from the one without such diodes, as the bypass diodes provide an alternate current path during the shaded mode. The cells of a module no longer carry the same current. Therefore, different maxima are established by the P-V curve. It is a crucial issue to present multiple maximum points in the PV characteristics, and most conventional MPPT algorithms may not differentiate between local and global maximum points. Figure 1 outlines the circuit diagram of a PV array consisting of two modules with series connected bypass diodes. while the second module has shading, and its irradiation is 800 W/m 2 . The system has two maxima operating points. Thus, the MPPT algorithm must operate the PV at the global peak. More investigation on different modules and shading conditions will be illustrated in Section 3.

The Proposed MPPT Algorithm
Different algorithms have been used to overcome the partial shading problem of the PV systems as discussed in the Introduction. Most of these techniques are complex with a high computational burden and have a bad impact on the grid stability due to the power interruption during P-V scanning. To overcome the problem of partial shading, a new MPPT algorithm based on FLC that can boost the output power when partial shading occurs is proposed. The proposed MPPT technique has been designed to adapt the FLC based on DSM, so the classical fuzzy MPPT and DSM are presented in detail in the following Sections 3.1 and 3.2. The FLC employing DSM is illustrated in Section 3.3.

Fuzzy Logic Controller (FLC)
The fuzzy controller is one of the AI methods that is widely used in industrial applications. Using FLC as an MPPT controller provides multiple merits of enhanced efficiency, reliability, and simple design [24,25]. Figure 3 shows the general structure of FLC for MPPT application, which has two inputs and one output. The two FLC input variables are the error E and change of error CE at sampled times j defined by (7)-(9): where P PV , I PV , V PV are the PV power, current, and voltage, respectively, at instant j. Figure 4 shows the variables' membership functions. In the literature, some authors prefer to implement the FLC using five linguistic variables [26,27] or seven linguistic variables [28,29]. The difference between them is not significant, so in this paper, the implementation of the FLC will be made using five linguistic variables as in [2,21,[30][31][32].  The overall configuration of the classical MPPT based on FLC for a given PV system is explained and implemented as a standalone system in [21] or grid-connected in [2,[30][31][32]. The configuration of FLC is suitable for different PV system applications either power generation as in [2,21] or power quality improvement as in [32]. Therefore, normalized FLC membership functions are preferred [33], as illustrated in Figure 4, to generalize the FLC structure and parameters for different PV system power rating and applications. The general rule base structure of FLC is shown in Table 1 [2]. Hence, the general FLC of a normalized FLC membership functions as in Figure 4 and the fuzzy inference rule base in Table 1 can be implemented for the different PV systems. The FLC parameters are addressed, in more detail, in [30,34], such as the number and types of membership functions, rule base, fuzzification, etc. To avoid the FLC redesign for different PV system configurations and ratings, a general FLC structure for MPPT will be employed with normalized membership functions and a fixed rule base. It is only required to determine the input and output scale factor of the FLC according to the PV system rating.

Dynamic Safety Margin (DSM) for PV
In general, the design objective of control systems is to achieve a specified constrained output. The DSM is a performance index whose independent variable is the distance from a predefined safety boundary. The idea of the DSM is introduced in [22,23]. Let x be the state space in n , and Φ ⊆ x be subspace that defines the safe operation region for some system state variables x ∈ m . Φ can be specified by a set of inequalities, > 0 is the unsafe operation as shown in Figure 5, and ∂Φ = {x|ϕ i (x) = 0, i =1, . . . , q} ⊂ Φ is the boundary of the safe region, where variable q is the number of defined inequalities and m is the number of state variables relevant to safety. Notice that m ≤ n, where n is the dimension of the state-space. The system trajectory starts from the initial condition, x 0 , to the operating point x s crossing the state space with varying distance to the safety boundary as shown in Figure 5. In this subspace of state variables, DSM is defined as the instantaneous shortest distance, δ(t), between the current state vector, x, and ∂Φ. Therefore, the DSM can be obtained by solving the following quadratic programming optimization problem: subject to x p ∈ ∂Φ and the DSM is: where x po is the solution of the previous optimization problem and: , if x into the region of safe operation −1, if x out of the region of safe operation As a result, in the case of the PV system, the state variable relevant to the safety boundary is chosen to be PV voltage and power, x = [V PV P PV ] T , and the safe operation region, Φ, is selected to be the subspace that includes the state corresponding to the maximum power points for all possible circumstances of weather conditions, temperature and irradiation. If the PV operating point, which corresponds to a certain PV power, is beyond Φ, the extracted power from the PV system will not reach the maximum power leading to a lower performance of the PV system. The safe region of a PV module can be determined by one of the following methods: (1) offline, based on the power and voltage (P-V) manufacture characteristic of the module. However, it requires to have accurate data about the PV modules and their connection; (2) online, by recording the maximum power point that has been obtained by FLC without shading conditions. This method does not require prior accurate data about the modules type or connection, but it may take a long time to record the boundary of the safe region; (3) by integrating both methods, offline and online. In the case of offline technique, the boundary of Φ is determined by grouping all the possible maximum power at different irradiation and temperature. To illustrate the idea, consider a real PV module of KYOCERA KC200GT type of 200 W rated power and 30 V open circuit voltage. By analysing the P-V characteristic, the safe region will be an elliptic shape, convex set, as shown in Figure 6. In the case of a multi-module PV system, the safe region will be determined by combining the characteristics of modules based on the series and parallel connection. In the case of series connection, the total safe region, Φ s , of n s modules connected in series is determined by: where Φ is the safe region of a single module, x = [V PV P PV ] T is the state vector of a single PV module, and x s ∈ R 2 , x s = [V s P s ] T is the state variable of new string voltage and power.
In the case of parallel connection, the total safe region, Φ p , of n p modules connected in parallel is determined by: where A p = 1 0 0 n p , x p ∈ R 2 , x s = [V p P p ] T is the state variable of the new parallel combination voltage and power. The most appropriate technique to determine the safe region of a single module is the third one by integrating the offline and online methods to gain the advantages of both. Therefore, it is necessary to determine the basic safe region offline to start the algorithm and this region will be adapted based on real online observation.
In this study, KYOCERA KC200GT PV modules will be used to simulate and test the MPPT algorithm. Without loss of generality, this safe operation region can be approximately specified by a set of linear inequalities constraints as a polytope, as shown in Figure 6, in the form of Φ = {x|ϕ i (x) ≤ 0, i = 1, . . . , 4}, where: where a i T ∈ 2 and c i ∈ are constant, ϕ i (·) = 0 is a subspace of state vector boundary, ∂Φ. These constraints can be combined in a matrix form as follow: where: For the given KYOCERA KC200GT PV module type, the corresponding parameters of (15) are determined for the characteristic shown in Figure 6 such as: The boundary of the safe region is ∂Φ(x p ) = {x p |A x p = c}. Since the boundary has four linear segments represented by the matrix equation, then: The minimum distances between the current state x and a boundary segment number i (δ i (t)) are given by [23]: All boundaries distance vector for d(t) = [δ 1 (t), δ 2 (t), . . . , δ q (t)] T can be calculated using: where c ∈ q , d c ∈ q , D a ∈ q×n , and D ia ∈ q×q . Since Φ is convex and the boundary constraints are linear, the safe region is a polytope, and the DSM, δ(.), is the minimum element in d(.) [23], such as: Therefore, the determination of the safe region, Φ, of a PV system and the DSM can be summarized in the following steps: (1) Determine the safe region of a single PV module offline from the datasheet of the PV manufacture as illustrated in Figure 6.  (12) and (13). (4) Compute the online DSM by solving the optimization problem (10) subject to constraints (17). The solution of problem (10) with constraints (17) can be obtained by applying Equations (18) and (20). (5) Record the observed maximum point at normal conditions and update the safe region boundary of step 3 if necessary, to overcome the approximation in steps 1 and 2.

FLC Employing DSM
Adapting FLC can be implemented by regulating the fuzzy output based on a certain criterion. This idea is addressed in [21] by enhancing the FLC output based on the deviation of the PV voltage and PV open circuit voltage but it fails to work probably in partial shading conditions. Therefore, an adaptation criterion based on DSM is proposed. The general configuration of the PV system consists mainly of (1) PV modules, (2) converter subsystem, either DC-DC or DC-AC, based on the application, and (3) direct load and/or grid connection based on the PV mode, standalone or grid connected as shown in Figure 7. The main function of the MPPT controller is to determine the gate signal of the PV converter. Accordingly, the value of the DSM can be used to regulate the FLC output as shown in Figure 7 to obtain the suitable gating signal duty cycle of the PV converter subsystem. The adaptation of FLC based on DSM is carried out according to the following steps: (1) The measured voltage and current of the PV are manipulated as explained in Section 3.1 to obtain the FLC output. and: s g (t) = 0, if x within the safe operation region k, if x out of the safe operation region where Duty is the duty cycle of the PWM to control the converter of the PV, k ∈ [0, 1] is the adaptation gain and δ(t) is the instantaneous DSM. In the case of partial shading, the operating point traverses to the unsafe mode. Then DSM will enhance the FLC to move to another maximum point located in Φ or near to it. (5) During the adaptation, maximum operating points are recorded, and the DSM based FLC will adjust the converter to operate at the global maximum point.

Case Study
To illustrate the implementation of the proposed FLC based on DSM, a single-phase grid connected PV system is used as a case study. It has been compared with previous work in [2,30,31]. The advantages and limitations of the case study configuration are addressed in [2]. The case study employing the MPPT controller based on DSM is illustrated in Figure 9. It includes a PV array with a flyback converter followed by a current-controlled voltage source inverter. The flyback converter has been chosen for several reasons. For instance, the voltage is converted down to a value determined by the turns' ratio during the off phase. This allows to choose a diode with smaller capacitances and therefore higher switching speed, a MOSFET with a much lower ON resistance can be used. Consequently, the power losses could be reduced leading to higher efficiency. Also, it has a wide input voltage range and provides isolation between the grid and PV due to the presence of a high-frequency transformer [35]. Moreover, no need to use a bulky transformer after the inverter to step up the voltage to the grid voltage. Besides, it does not have many components, thus it is inexpensive compared to other topologies and provides DC-DC at one stage instead of using multiple stages. However, it has a higher ripple current and higher input and output capacitance. Also, its efficiency is typically between 75% to 80% [36]. The voltage source inverter feeds current into the single-phase grid and local singlephase loads. The V refDC , V DCLink , V Grid , V AB, and i ac are DC-link reference voltage, DC link voltage, grid voltage, inverter voltage, and grid current respectively [37]. From the sensed V PV and current I PV at the subsystem block, the E and CE are deduced as shown in Figure 9. Then, the deduced E and CE are manipulated by the FLC to produce the PWM of the flyback converter [38,39]. FLC works efficiently under normal conditions of the PV system in terms of fast performance and accurate MPPT without oscillation as seen in [21,31]. However, for the partial shading situation, the power is decreased due to the trapping of the local MPP instead of the global one which will be illustrated in Section 5.

Simulation Results
The simulation of the proposed technique has been carried out using the MAT-LAB/SIMULINK environment for the PV KYOCERA KC200GT module in different situations. The simulation results are presented to investigate the effectiveness of the proposed model and control algorithms of the single-phase grid-connected PV system. The PV power curves for a different number of modules at normal weather of 25 • C and 1000 W/m 2 , and partial shading conditions are shown in Figure 10. The proposed technique will be applied for the given case study based on the criteria in Section 3.

FLC Configuration
A normalized FLC is utilized as explained in Section 3.1 with two inputs, E and CE, and one output, duty cycle, as shown in Figure 11. The input scale factors, K e and K ce will be changed based on the number of modules connected in series, such that K e = k o /n and K ce = k co /n, where n is the number of modules, and k o and k co are the nominal scales for a single module and both are equal to 1. E and CE are computed from (8) and (9), while the number of membership functions and the rule base were illustrated in Figure 4 and Table 1, respectively.

DSM Computation
The safe region, Φ, of each module, is deduced based on the datasheet of the module as explained in Section 3.2 with the same parameters of Figure 6. For two or more modules connected in series, the overall safe region will be obtained by (12). Then the parameters of (15) will be (22) for two modules, (23) for three modules, and (24) for four modules: Then by measuring the PV system state, x = [V PV P PV ] T , the online DSM can be computed by solving the optimization problem (10) subject to constraints (17) with the parameters (22), (23), or (24), based on the number of modules. The solution of problem (10) with constraints (17) can be obtained by applying (18) and (20). The observed maximum point under normal condition is recorded to update the safe region boundary (22), (23), and (24) if necessary, to overcome the approximation of the computed region of a single module.

MPPT Algorithm Results
The DSM based FLC algorithm described in Section 3.3 is implemented in the case study for different module configurations. Figure 12 shows the PV power for a different number of modules operating at normal conditions, while Figure 13 illustrates the PV power for the DSM based FLC at partial shading situations. The results in Figure 12 are similar for both controllers at normal operations. By comparing the global maximum in Figure 10 with the results in Figure 13 during partial shading conditions, the output power is the global maximum. For example, in the case of 4 modules, there are 4 peaks and the global one is about 450 W that has been obtained by the DSM based FLC, while the FLC has detected the first peak of 200 W. So, there is a considerable difference in the total output power for the FLC based on DSM compared to the normal FLC in the case of multiple modules.

Practical Case Study
To verify the proposed technique, a laboratory PV system is prepared as illustrated in Figure 15.  Figure 16 with a maximum power of 80 W at temperature and irradiation of 28 • C and 700 W/m 2 , respectively. In the beginning, the practical PV curve from the datasheet has been addressed to determine the safety region, Φ, as in Section 3.2.  After that, the test rig has been connected as illustrated in Figure 15, where the input signals, measured, are the actual PV voltage, DC bus voltage, and currents. The designed Simulink program has been coded and downloaded into the DSP. The DSP and PC are configured in a hierarchical two-level control structure; DSP as individual control, which is directly connected to the field, and PC as a supervisory controller. Both DSP and PC are connected through USP communication. Then the proposed algorithm is applied based on the current measurement to produce the suitable duty cycle of the flyback converter to change the operating point of voltage.
The classical FLC and DSM based FLC have been tested in normal and partial shaded modes, the results have been illustrated and compared. Figure 17 shows the V mpp signal measured by the DSP at the normal operation for DSM based FLC method. The result shows the system's ability to obtain an accurate maximum power from the PV module. Figure 18 shows the simulation results of a single module voltage of 17.8 V. It is almost the same voltage that has been obtained from the PV curve around 80 W in Figure 16. Figure 19 shows the PV curve at normal and partial shading conditions for the practical system, while Figures 20 and 21 show the extracted power from the PV module under partial shading conditions employing FLC with DSM and standalone FLC, respectively. In the case of FLC, the power was nearly 36 W, which represents the local peak in Figure 19 or the first peak. While for the DSM based FLC, the power was approximately the same as the global peak of 80 W in Figure 19.     By reviewing the simulation and practical results, it is clear that DSM based FLC is robust, fast, and can track the global maximum in the shading conditions. Moreover, it has less computational effort in comparison with other techniques that have been introduced in the introduction and Section 3. Finally, it does not require to make P-V scan of the PV system, which has a great impact on the grid stability.

Conclusions
A robust and fast MPPT technique is necessary for a PV system to generate the maximum allowable power in case of environmental conditions and load variations. The MPPT based on FLC is robust, fast, and easy to be implemented but it fails sometimes to track the global maxima under partial shading conditions. Therefore, it is necessary to adapt the FLC based on a certain performance criterion to be able to work properly during partial shading conditions. Then, an MPPT technique based on FLC employing DSM as a performance index is proposed for normal and partial shaded modes. The DSM is used to evaluate the PV system operation either at normal or abnormal conditions; abnormal covers either shading or malfunction operation. To determine the DSM, a safe operation region, normal operation mode, of the PV system must be determined. The DSM indicates the current PV state from the safety boundary for adapting the normalized FLC. The determination of the safety boundary of the PV system has been investigated and the relation between the safety region of the single PV module and the combination of different modules has been addressed. Additionally, the proposed DSM based FLC algorithm has been tested and compared with the classical FLC for a single-phase grid connected PV system as a case study. To guarantee the effectiveness of the proposed technique, a string of different series connections up to four PV modules have been employed. The simulation results ensure the proposed MPPT technique's ability to detect the peak and operate the PV system on the global maximum point, while classical fuzzy MPPT fails to get the global maxima in the case of partial shading. To validate the proposed method, it has been successfully implemented for a practical PV system and results demonstrate the fruitful operation of the proposed algorithm. Since the technique does not need to apply P-V scan, it has a good impact on the grid stability with a fast response. The key issue of the proposed approach is the determination of the safe operating region. Consequently, a safe region must be specified offline before implementing the proposed technique based on the manufacturing data, then it is updated or identified online based on the historical data. Funding: This work was partly supported by the Natural Science Foundation of China through the project with code 51850410515. Also, the experimental setup was co-funded by AASTMT.