Raspberry Pi Design and Hardware Implementation of Fuzzy-PI Controller for Three-Phase Grid-Connected Inverter

: A photovoltaic system is one of the major sources of renewable energy. The grid-connected inverter controllers play an important role in the conversion and transmission of solar energy. Therefore, they must be improved to meet the demands for grid interconnection. This article introduces the design and hardware implementation of the intelligent fuzzy-PI controller of the inverter part of the grid-connected photovoltaic system. First, the paper discusses the design of the three-phase grid-connected fuzzy-PI controller. Next, the paper describes the implementation of a Matlab graphical user interface (GUI) to design any grid-connected inverter and size the photovoltaic systems. The code generation of the fuzzy-PI controller of the system is accomplished by using Matlab Simulink simulation software. The hardware components of the PV system are implemented experimentally. In the hardware implementation, a 70 W prototype is realized to test the functionality of the controller, such that one can develop a realistic controller without taking risks or falling into security concerns in the case of performing experiments on high-power systems. The prototype proves that the controller model can be directly transformed from Simulink to the control device. It also shows that the fuzzy-PI controller is working properly in the 70-watt prototype. The achieved performance parameters of the proposed fuzzy-PI controller are satisfactory. The proposed method to design and implement the fuzzy-PI controller does not require complicated programming, where a Matlab coder is proposed to transform the Simulink controller into C code that can be directly utilized as a software control program loaded in the microcontrollers embedded in the hardware of the controller. The main result is that the fuzzy-PI controller for the three-phase grid-connected systems can be implemented using low-cost reconﬁgurable microcontrollers.


Introduction
Solar energy is one of the major sources of renewable energy. This fact means that converting it into electricity is a very important research topic. A photovoltaic system can be defined as a system used for the transformation of solar energy into electrical energy. High cost and low efficiency are among the defects of photovoltaic systems. This event motivates scientists to investigate how to maximize the efficiency of renewable energy resources. Considerable attention is given to photovoltaic (PV) power generation systems as one of the most promising energy generation systems that can alternate with fossil fuel power generation [1]. The PV industry has expanded rapidly in the last 20 years [2]. It can also be seen that the installation of photovoltaic technology is increasing by 20-25% annually, mainly due to cost reduction. The cost reduction is driven by the improvement of solar cell efficiency, the improvement of production technology, and the development of economies of scale.
An inverter is required to transform the DC electricity coming from a photovoltaic generator into AC electricity [3,4]. One of the most important electronic components of a grid-connected PV inverter is the DC/AC inverter controller [5]. Therefore, it received intensive research to optimize its performance. There are different types for the regulation of the controlling action of the controller. The conventional methods are based on proportional integral differential methods PID.
A PI controller is proposed as a solution for three-phase grid-connected inverter control. The proposed solution is simulated using PSIM and implemented in hardware to validate the results [6]. A detailed description of the hardware implementation of the PI controller is presented in [7]. The hardware uses a dsPIC microcontroller to control the inverter and produce a voltage that is synchronized with the grid voltage. The purpose of that research is to show a practical implementation of a control system for a gridconnected inverter (GCI) by using a dsPIC microcontroller. It is found that the conventional PI controllers are relatively slow and have more steady-state errors and more ripples compared to the fuzzy controllers [7].
In [8], a fuzzy controller, which is based on a special choice of a combination of inputs and outputs, is used. The selection of input and output, as well as fuzzy rules, is based on the principle of mathematical analysis of the derived function (slope) in order to find the best value. It can also be observed that by employing only three sets of linguistic variables to deconstruct the membership functions of the fuzzy controller's inputs and outputs, the best results and answers from the photovoltaic system may be achieved [8]. The fuzzy controllers can be also used for the maximum power point tracking in DC/DC converters of the PV generators. However, in partial shading, classical fuzzy MPPT fails to obtain the global maxima. [9]. In order to overcome the FLC problem under shading conditions [9], FLC is based on dynamic safety margin (DSM), similar to the MPPT algorithm of photovoltaic systems. The simulation results show that the proposed MPPT algorithm can detect the peak value at the global maximum point and manage the photovoltaic system. A two-fuzzy logic controller scheme [10] is proposed to control the DC/DC converter and the inverter in a three-phase grid-connected inverter. The proposed scheme improves the power quality of the system. However, the research article presents a simulation study only.
The control strategy of the photovoltaic (PV) system in [11] utilized a single-phase gridconnected inverter with low voltage ride-through (LVRT) capability which is controlled by a fuzzy logic controller. In reference [12], a DC-DC boost converter is used to boost the DC voltage generated by a solar cell with an output voltage of 18 volts. In order to obtain good transient and steady-state performance, a typical 54 V fuzzy controller is suitable for DC-DC converters, and 24 V is suitable for DC-AC converters. They found that the created controller provided fast response and good performance. [12].
In addition, a fuzzy logic controller for a three-phase grid-connected inverter has been designed and implemented in hardware [13]. The fuzzy controller (FLC) was tested using a 260-watt photovoltaic system. Their results show that the FLC performs better with the PI controller [13].
A fuzzy controller for controlling a grid inverter for 22 KV distribution systems was proposed. The experimental results showed that the intelligent controller increased the stability of the output voltage [14].
In [15], smart fuzzy was proposed to provide active and reactive power control for efficient low-voltage ride-through (LVRT) capabilities during grid faults. The logic proposed by fuzzy is based on an improved reactive and active power control strategy by injecting reactive current to stabilize the grid voltage. In addition to the fuzzy strategy of inverter control, the algorithm of a 1 kW solar photovoltaic grid-connected system was verified in real time on the hardware.
A research paper [16] described an optimized fuzzy controller for grid-connected photovoltaic systems. The proposed controller is optimized using a nature-inspired optimization algorithm called LSA. In order to demonstrate the functioning of the proposed algorithm, a hardware prototype was realized [16].
Ngoc-Tung Nguyen et al. [17] introduced a fuzzy-PI controller to control a gridconnected inverter where they tuned the PI by fuzzy logic for various advantages such as being less expensive, covering a larger variety of operating circumstances, and improving the quality factor. Despite disturbances of the load and variations of input, the gain of the PI controller is tuned by the fuzzy algorithm [17].
Regarding regulation of the inverter with a simplified fuzzy-PI controller (SFPIC) [18], a linear control surface proposes a single input of fuzzy controller with its fuzzification and defuzzification processes. The proposed controller was shown to produce a comparable performance to its standard fuzzy-PI controller but with a significant reduction in computational time. A hardware implementation was realized to compare the simplified fuzzy-PI performance controller and the traditional fuzzy-PI controller [18].
An interactive grid-connected inverter controlled by fuzzy-PI was developed and deployed [19]. The PI controller's proportionate and complete gains were determined according to the system operating point by the FLC. A self-adapting PI controller was realized, which can adapt to the fast transient response due to different operating conditions such as grid disturbances and natural influences. Both simulation and experimental results show that the system proposed has rapid dynamic responses with low overshoot and short adjustment times. The proposed inverter system was also compared to the conventional PIcontrolled system [19]. In a previous work [20], a comparison between different controllers was worked out. It showed the superior performance of the fuzzy-PI controller. This motivated the researchers to develop a fuzzy-PI controller for their PV system [20].
The main objective of this work is to introduce the design and hardware implementation of an intelligent controller (fuzzy-PI) for grid-connected photovoltaic generators in an average household. In terms of hardware implementation, the researchers used a 70 W prototype to test the controller for the sake of safety and cost issues. The proposed methodology does not need complex programming, as a Matlab control code is transformed to a C-control code for operating the electronic hardware design of the controller. Finally, the hardware setup is developed for verifying the simulation model of the system realized in Matlab.
The paper is organized as follows: Section 2 describes the Simulink components of the PV system in detail. Section 3 provides Simulink results. Section 4 provides a GUI for system design and sizing for all components of the system modules. Section 5 introduces a design and hardware implementation of an intelligent controller (fuzzy-PI) for the inverter part of a grid-connected PV system, code generation, and experimental results. In the hardware implementation, the researcher works with a 70 W prototype to test the controller. Section 6 provides a conclusion and future work.

Complete Descriptions of the Simulink Components of PV System
This section presents a full description of the Matlab Simulink system that is built to test the fuzzy-PI controller. Figure 1 shows the complete Simulink model for the system. On the left, there is a DC voltage source along with two decoupling capacitors. The idea is to model the effect of a PV panel source along with a converter. An exact model is not needed for the PV panel because the researcher concentrates on the inverter controller part. The output of the DC voltage along with decoupling capacitors goes through a two-level bridge inverter. The control signal of the two-level bridge inverter comes from the fuzzy-PI controller. The three-phase output of the inverter is input to the measurement block and then input to the LC filter. The LC filter is responsible for eliminating the disturbance from the three-phase signals. The LC filter output is connected to an AC load that has two options (high load and low load). On the other side, there are the grid and the measurement and display blocks.

Input Voltage
The basic components of the Simulink model consist of the following:

•
There is a use of a simplified I-V curve model introduced in other papers [21]. • In this Simulink model, the researcher is concerned with the inverter controller. The researcher uses the value of the voltage at the MPPT generated by the boost converter. • There is a model of a PV array and a boost converter with a single voltage source parallel with two series capacitors. • The paper [21] shows that the voltage source model approximates the real photovoltaic panel operation.

Fuzzy-PI Controller
The controller of the inverter consists of a current regulator and a voltage regulator. The internal components of the current regulator are discussed here.
The researchers suggest that the algorithm illustrated in Figure 2 is a fuzzy-PI controller. Figure 2 shows the fuzzy-PI controller. First, the Id direct and Iq quadrature currents are subtracted from the Id and Iq reference values to obtain the error. The logic blocks of the fuzzy control the error. The Vd and Vq signals are then added to the controlled signals, which create the control signal to the V d and V q direct and quadrature voltages on the complete system. The input of the fuzzy logic is the calculated error that is used to obtain the gains of the PI controller. On an FLC that is adjusted to the input data is the nonlinear mapping of the output scalar data. FLC consists of three phases: fuzzification, the rules table, and defuzzification [22]. In most nonlinear applications, the conventional controller does not work well. Therefore, the fuzzy logic control (FLC) was an efficient nonlinear application solution.
Fuzzification is the process that is used to convert the input crisp values into the fuzzy variable values by using input gains and normalized membership functions. Defuzzification is the process that is used to convert the fuzzy variable values into crisp values by using output gains and normalized membership functions.
Two blocks of fuzzy logic are used: one for voltage control and the other for current control. The fuzzy controller design consists of the design of the membership functions and the design of the rules table. By using the Matlab Fuzzy Toolbox, the researcher can build the FLC [20].
Each fuzzy element in Figures 3 and 4 is the meaning of each language connected to five uniform membership functions. Fuzzy logic control is used for tracking currents (Id and Iq), while a phase-locked loop (PLL) is used for park transformation synchronization (ABC-DQ) [22,23].
The block of fuzzy logic has two inputs, the change of error (∆∆e) and the error (∆e) that generates the PI controller gains, which are defined as integral gain (Ki) and proportional gain (Kp). In accordance with variations in the temperature and the irradiance, the proposed fuzzy-PI controller varies gain values (Ki and Kp). The (Ki and Kp) values are multiplied by the error before being passed to the discrete-time integrator and zero-order hold. The membership functions of direct and quadrature Id and Iq output currents for fuzzy inverter control with Ki gain between 14.5 to 15.5 and Kp gain between 2.5 to 3.5 are illustrated in Figures 5 and 6, where a rule table is used to minimize the current error and the transient response to perform FLC [24].

•
The two-level bridge is connected to a DC power supply.

•
The bridge output is connected to the three-phase LC filter. • Use a three-phase measurement block after the three-phase LC filter.
For three-phase voltage and current calculations, a measuring tool is used, as shown in Figure 1.
Review of inverters in photovoltaic applications [25]: Inverters are required to tie PV generators to the utility grid. They convert the DC power generated by PV to AC power used by the grid. Electricity is kept at a constant voltage in only one direction for DC power, and passive filters are usually employed to filter out harmonics generated from the inverter switching, yielding almost a clean voltage with a reduced harmonic distortion, which can be fed into the power grid.
The general-principle diagram of the three-phase inverter and its operating instructions [26]: Figure 7 shows three identical half-bridge converters that make up the three-phase, two-level inverter. The DC sides of the three half-bridge converters are connected in parallel to a single DC-side voltage source. Each half-bridge converter has one phase of a three-phase (A, B, and C) AC system wired to its AC-side terminal. The alternating current system could be passive, such as an RLC load, or active, such as a synchronous machine (electrical power grid).

Three-Phase Loads
In the simulation model, the RLC module is used to model the three-phase load. The RLC branch is a block with a resistance value (R) related to (active power) and a capacitor (C) and coil (L) related to reactive power. RLC is a Matlab Simulink block of the RLC branch with active load power P = 70 W and reactive load power = 0.

Total Harmonic Distortion
Total harmonic distortion (THD) is a measure of how a signal (voltage or current) is distorted by the harmonics in the signal.

•
The main measurement results obtained from Simulink prove that the fuzzy-PI controller works in theory, and then the experimental result is total harmonic distortion.

•
Simulink uses the THD block to measure the total harmonic distortion of the inverter output signal. Figure 8 shows that one phase of the grid voltage is in phase with the inverter current, so P.F. = 1. This kind of simulation is called low load simulation. It means that the grid and inverter both feed the load, and this event is the cause of having an inverter current and three-phase current separately, as shown in Figure 9.  Figure 10 shows the synchronization between inverter voltage and the grid voltage for the fuzzy-PI controller of low load. Consequently, Figure 10 shows that both are synchronized together, which means that the controller is working fine in the simulation phase. The AC output inverter, grid, and low load power for low-load fuzzy-PI controller are shown in Figure 11. The PV power is feeding load power and the remaining power is injected into the load. The result of the calculation of the overshoot = 5.94%, settling time(s) = 0.121, peak time(s) = 0.076, and average THD of inverter current = 0.744% are shown in Table 1. Table 1. The specifications of the fuzzy-PI controller are shown in Figure 11.

Parameters Values
Settling This work achieves a lower THD for the fuzzy-PI controllers than [16,27,28] are shown in Table 2. Table 2. The THD comparison between the works in the literature and the work presented in this article.

GUI for System Design and Sizing for All Components of the System Modules
Matlab GUI is used for the sizing of a complete PV system (sizing of PV array, sizing of the boost converter and sizing of the inverter), shown in Figure 12. For example, load power = 9200 W.

Sizing for Inverter
This work uses a two-level bridge inverter that has two switches off in one branch. The inverter output three-phase voltage = 240 V. Max. power flow in the inverter = 9200 W and DC-link voltage = 700 V; Therefore, IGBT switch rating current = 9200 700 = 13.1 A (2)

Sizing for Boost Converter
Output average voltage (V o ) = 700 V, duty cycle = 0.5, thus the gain = 2.

Sizing for PV Array
The module type is "SunPower SPR-305E-WHT-D" at standard irradiation = 1000 W/m 2 . The output voltage of the characteristics of one module at MPPT = 54.7 V, and the output current of each module at MPPT = 5.58 A as shown in Table 3. Therefore No. of parallel modules = Total current of all modules / Output of eachmodule = 30 5.58 = 5.3≈ 6 modules (14) Total no. of modules = no. of series modules X no. of parallel modules = 7 × 6 = 42 modules (15)

Hardware Implementation of Fuzzy-PI Controller for Grid-Connected Inverter, Code Generation, and Experimental Results
In this hardware experiment, a Matlab coder is used to convert the controller Simulink code into C code for use with the controller. It is necessary to write a general code that combines the controller generated from Simulink with the other hardware components. The complete block diagram of the controller blocks is shown in Figure 13. In the hardware, a Raspberry Pi processor (microcomputer) executes the algorithm. An Arduino controller is used to read the signals from the voltage sensing circuit and generate a duty cycle signal for the pulse width modulation block (PWM) inside the Arduino controller.
The communication protocol between the Raspberry Pi and the controller is I2C, as shown in Figure 14. In this section, there is a description of the hardware components of the setup used to implement the three-phase grid-connected fuzzy-PI inverter controller, as shown in Figure 15.

Sensing Circuits
The sensing circuits setup consists of a voltage-sensing circuit and a current-sensing circuit.

Voltage Sensing Circuit
The first step in the hardware experiment is to sense the grid voltage to synchronize inverter output with the grid. This synchronization is performed inside the controller. A use of single-supply op-amps is provided; this circuit generates a full-wave rectifier, as shown in Figure 16. Therefore, the first step is using a transformer to transform the input grid voltage to a legible form by the controller, as shown in Figure 17. The sensor-integrated circuit is LM358 (dual, 30 V, 700 kHz operational amplifier) [29]. Figure 18 shows rectified signal sensed from the grid (input).   The output of the full-wave rectifier in Figure 16.

•
In the hardware experiment, three current sensors are used to sense the current.

•
The sensor circuit is an HW-872 card with an ACS712 integrated circuit installed [30].

Controller
A Raspberry Pi controller is used to set the controlling blocks. This idea is to take advantage of the high processing power of the microcomputer. An Arduino controller is used because it has a built-in analog to digital converter (ADC) and PWM circuits. A communication protocol is used to connect a Raspberry Pi and an Arduino in order to transform the data read by the ADC in the Arduino to the Raspberry Pi controller; the C code for the fuzzy-PI controller downloaded on the Raspberry Pi, then, evaluates the duty for controlling the inverter switches. This duty cycle is transformed to the Arduino controller by the communication protocol between the microcontroller and a Raspberry Pi. The communication delay time in the communication between Arduino and Raspberry Pi = 100 µs. Figure 19 shows the output of the controller. It can be seen that the duty cycle of the produced pulse width modulation signal is changing with time, as there are around six edges on the right.

Inverter
Printed circuit board (PCB) hardware for the inverter is implemented. The inverter consists of six switches along with a driving chip that transforms the signal output by the controller to equivalent driving voltages for the six switches. The inverter inputs are the controller that controls signal along with DC voltage. The output is filtered using the transforms that work as a filter. The schematic diagram of the inverter is given in Figure 20. As shown in the figure, six switches and driver chip IR2110 are used. The signals coming from the right are the six control signals that control the switches. Three current fuses are used for circuit protection. The Inverter PCB circuit is shown in Figure 21. The detailed description of the hardware components is shown in Table 4.     Table 4 shows a detailed description of the hardware components. Detailed Explanation of Inverter: Principles of Operation: Two switch cells in the phase make up the half-bridge converter. The S 1 and S 4 de note the upper and lower switch cells, respectively. Each switch cell is created by connecting an antiparallel connection of a fully controlled diode and unidirectional switch Node 0 represents the common point of the voltage source. This node is used as the voltage reference node and is referred to as the DC-side midpoint. As a result, the three AC-side terminal voltages are as follows: The preceding equations demonstrate that in order to obtain a balanced three-phase line current and a balanced three-phase AC-side voltage, and m a (t), m b (t), and m c (t) should be formed into a balanced three-phase signal, which is typically carried via a closed-loop control method [25,31].
The half-bridge converter operates by switches S 4 and S 1 alternately. The turn-on/off commands of S 4 and S 1 are delivered using the pulse-width modulator (PWM). The PWM is a modulation method and can be carried out in a variety of ways.
The most mutual PWM technique compares a high-frequency waveform of periodic triangular, known as the signal of the carrier, to a slow-varying waveform identified as the modulating signal. The signal of the carrier has a periodic waveform with time T s and fluctuates between −1 and 1 as in the equation 1, if the switch is commanded to conduct 0, if the switch is turned off (19) As shown in Figure 22, when the carrier signal is lower than the modulating signal, a turn-on command for S 1 is delivered, while the turn-on command for S 4 is canceled [25]. Figure 22. Schematic diagram of generating PWM gate pulses for S4 and S1. Figure 23 shows the waveforms of the switching functions S4 and S1, which depend on the output of the PWM diagram, that is, S1(t) + S4(t) = 1 [25].    There are two and a half divisions; each division = 10 V, therefore, V P = 25 V, and output phase voltage (V) (R.M.S) = 25/ √ 2 = 17.6 V. The specifications for the hardware design and power rating of the inverter as shown in Table 5. Matlab Simulink simulation. The three-phase peak voltage output from the inverter in experimental and simulation results (V P ) = 25 V, therefore the output phase voltage (V) (r.m.s.) = 25/ √ 2 = 17.6 V Figure 24 shows the final results generated by the inverter. As seen, the three-phase signal synchronized has the same peak-to-peak values. It can also be seen that the signal is smooth but with low total harmonic distortion (THD). This proves that the controller works experimentally and produces a voltage that is synchronized with the grid and that has a small total harmonic distortion.
A capacitor, CBB 22, 474J400 V, is used in each phase for smoothing the output threephase signals [32].

Conclusions and Future Works
In this work, the system uses GUI Matlab software to study the dimensions of inverters, boost converters, and photovoltaic arrays. In this paper, a design is introduced alongside the hardware implementation of a fuzzy-PI controller for the inverter part of a grid-connected PV system. In the hardware implementation, a 70 W prototype is used to test the controller. The proposed method does not need complex programming, as a Matlab compiler is proposed to transform the developed Simulink controller to a C code that can be utilized to operate the microcontrollers in the hardware of the grid-connected inverter. The experimental results show that the proposed methodology works well and produces the required C code of the controller. The experimental results show that the proposed fuzzy-PI controller achieves good performance with an inverter efficiency = 97.8%. The main conclusion is that the fuzzy-PI controller for a three-phase grid-connected system can be implemented using low-cost reconfigurable microcontrollers. In addition, the measured and simulated output current waveforms are similar, validating the correctness of our design and our method.
In future work, one may scale up the power of the grid-connected system to realistic value for the household power as in our Simulink model.

Conflicts of Interest:
The author's declare that they have no competing interests.