An Adaptive Digital Neural Network-Like-PID Control Law Design for Fuel Cell System Based on FPGA Technique

T his paper proposes an on-line adaptive digital Proportional Integral Derivative (PID) control algorithm based on Field Programmable Gate Array (FPGA) for Proton Exchange Membrane Fuel Cell (PEMFC) Model. This research aims to design and implement Neural Network like a digital PID using FPGA in order to generate the best value of the hydrogen partial pressure action (PH 2 ) to control the stack terminal output voltage of the (PEMFC) model during a variable load current applied. The on-line Particle Swarm Optimization (PSO) algorithm is used for finding and tuning the optimal value of the digital PID-NN controller (kp, ki, and kd) parameters that improve the dynamic behavior of the closed-loop digital control fuel cell system and to achieve the stability of the desired output voltage of fuel cell. The numerical simulation results (MATLAB) package along with the schematic design experimental work using Spartan-3E xc3s500e-4fg320 board with the Xilinx development tool Integrated Software Environment (ISE) version 14.7 and using Verilog hardware description language for design testing are illustrated the performance enhancement of the proposed an adaptive intelligent FPGA-PID-NN controller in terms of error voltage reduction and generating optimal value of the hydrogen partial pressure action (PH 2 ) without oscillation in the output and no saturation state when these results are compared with other controllers


INTRODUCTION
Recently, the world goes towards alternative sources of energy as a result of the pollution on the planet and climate change, as well as the diversity of sources that are sought by major energy companies. Therefore, many researchers are focusing on fuel cells because of their advantages as they operate as a battery or internal combustion engines, but with high efficiency up to two or three times (Al-Amir, et al., 2015; Al-Araji, et al., 2019). Although discovered in the 18 th century, it began to highlight on fuel cells in the 1960s when NASA used it in spacecraft launched into space (Spiegel, 2011). The principle of mechanism working for the fuel cell is simply the production of electrical energy because of the chemical reaction. There are many ways in which fuel cells are classified, the most important of which is by electrolyte and the most important types are Alkaline Fuel Cell (AFC), Phosphoric Acid Fuel Cell (PAFC), Molten Carbonate Fuel Cell (MCFC), Solid Oxide Fuel Cell (SOFC) and Proton Exchange Membrane Fuel Cell (PEMFC) (Barbir, 2012;Mekhilef, et al., 2012). The mostly used fuel is hydrogen as in PEMFC or carbon monoxide and natural gas. The anode is supplied with hydrogen and the cathode with oxygen in the fuel cells. The catalyst separates the hydrogen atoms in anode into protons and an electron. The membrane allows only the hydrogen protons Cross to the cathode. The hydrogen electrons are moving from outside the cell to the cathode. The chemical reaction occurs in the cathode between hydrogen atoms and oxygen with the help of the catalyst and produces water and heat. Electrical energy is produced as the resulting of the hydrogen electrons through the electrical circuit, which generates a DC voltage. A single fuel cell produces approximately 1.23 volt when the load is applied 0.6 to 0.7 volt (Daud, et al., 2017). The fuel cells can produce electric energy that may reach MW by forming it in a serial or parallel manner for obtaining the necessary energy. Grouping of cells is called a stack. This research will focus on PEMFC because of its great advantages. Also, the most important is that it can work in room temperature with low pressure and fast response quiet, does not have moving parts, and can be applied in portable applications, the domestic power or power stations (Dagher, 2018;Daud, et al., 2017 ;Al-Araji, et al., 2019). The fuel pressure, temperature, humidity, and applied current are factors affecting the fuel cell and making the fuel cell system generation nonlinear dynamical behavior (Rezazadeh, et al., 2011). The sensitivity of this system is very high because of its high current and low voltage, so it needs a controller that can minify this sensation by making the external voltage constant. Therefore, to obtain the greatest energy generation and more efficiency, many researchers resorted to using different types of linear controllers for tracking output voltage of fuel cells (Daud, et al., 2017). Because of the many variation parameters of fuel cell led to the nonlinear dynamical performance output voltage and the process of controlling inaccurate. So that, many other researchers have worked to use nonlinear methods and techniques to solve the variation parameters problems in the fuel cell such as sliding mode controller (Ali, et al. 2017) and adaptive back-stepping controller (Zuniga-Ventura, et al., 2018). While other researchers have resorted to using artificial intelligence algorithms to understand the phenomena involved in the generation process of fuel cells such as fuzzy logic control (Mammar and Chaker, 2009;Schumacher, et al., 2004), the fuzzy-PID controller (Beirami, et al., 2015), neural networks (Al-Amir, et al., 2015;El-Sharkh, et al., 2004;Mammar and Chaker, 2012) and nonlinear PID controller was proposed for fuel cell output voltage system (Al-Araji, et al., 2019). Besides, many types of intelligent evolutionary algorithms have been used to build the modeling of PEMFC and controlling it. Genetic algorithm (Rajasekar, et al., 2015), artificial Bees colony Optimization (Mostofi and Safavi, 2013), particle swarm optimization algorithm (Ren, et al., 2012; Dagher and Al-Araji, 2013), firefly optimization algorithm (Abdelaziz, et al., 2015) and hybrid Firefly-Chaotic Particle Swarm Optimization algorithm (Dagher, 2018). The on-line particle swarm optimization algorithm (Al-Araji, 2014). The motivation for this research is to obtain the best value of the hydrogen partial pressure action (PH2) for enhancement of the dynamical performance of a real-time nonlinear fuel cell output voltage during a variable load current applied. Therefore, the contribution of this work is to design and implement a digital neural network like PID control law to achieve the following properties:  A smooth value of the hydrogen partial pressure control action (PH2) which is generated using MATLAB simulation based on the proposed design of the digital neural network like PID control law.  An adaptive control algorithm based on the PSO technique is used in order to stabilize the output voltage of the fuel cell as well as to fast track the desired voltage with minimum tracking voltage error while changing the load current.  A FPGA Spartan-3E xc3s500e-4fg320 board with Verilog hardware description language for design testing is designed, implemented, and verified the digital neural network like PID control law.  A proposed continuous PID control law equation is replaced by the proposed adaptive digital PID control law equation in a real-time system. The organization of this is paper as follows: Section 2, describes the nonlinear fuel cell mathematical model. Section 3, explains the proposed digital neural network like PID control law. Section 4, shows the effectiveness of the digital controller through numerical simulation results in MATLAB. Section 5, illustrates the experimental work based on Xilinx Spartan-3E Starter Kit. Finally, the conclusions of this research are given in section 6.

NONLINEAR FUEL CELL MODEL DESCRIPTION
In general, PEM fuel cells consists of three main components: anode, cathode, and electrolyte (Asl, et al., 2010). Anode typically displays a catalyst containing platinum, and cathode of a platinum catalyst. The electrolyte is a thin, solid polymeric sheet. The reactions of a PEMFC is shown in Fig. (1), when hydrogen is fed to an anode side the catalyst causes hydrogen atoms to become ( + ) ions (protons) and releases their electrons as Eq. (1). 2H → 4H + + 4 e − anode (1) The electrolyte membrane will only allow hydrogen protons to pass throws from the anode side to the cathode side, as shown in Fig. (1). The reaction in the cathode occurs as a result of hydrogen ions entering from the electrolyte to the cathode side with electrons from the outer circuit and oxygen supply from air the cell and produces water as in the Eq. (2). 4H + + 4 e − + 4O + → 2H 2 O + heat cathode (2) Under normal operation conditions, a single cell produces from 0.5 to 0.9 volts since a higher power is needed, and a number of cells are connected serially and as needed called a stack, and a stack arrangement can be up to hundreds of kilowatts. Generally, the polarization curve is used to express the performance of the whole cell and shows highly nonlinear properties between voltages and current (Dagher, 2018    where L is the thickness of the polymer membrane (cm).
A is an active cell area (cm 2 ). ρ m denotes membrane specific resistivity (Ω.cm) which computed as the following expression: Where ∅ is the ratio of the number of water moles for each sulfonic group in the membrane. V con can be expressed as follows: β is a parametric coefficient. J is the current density that passes through the cell (amp/cm 2 ). J max is the maximum current density that passes through the cell (amp/cm 2 ). It can be expressed as follows: J max = I max A (9) V act is the voltage drop (V) due to the activation of the anode and can be expressed as follows: V act = α 1 + α 2 . T + α 3 . T. In(C O2 ) + α 4 . T. In(I) (10) Where, α i are parametric coefficients. C O2 is the effective concentration of oxygen (mol/cm 3 ) and can be calculated as follows: The total output voltage of the stack can be determined by the Eq. (12)  To study the characteristic of the fuel cell, "output voltage against load current" at temperature 25C o and partial pressure of hydrogen and oxygen are 1, and 0.2 Atm, respectively, is shown in Fig. (2) where the output voltage of the fuel cell against a variable load current is seen. To study the effect of the losses voltage for the fuel cell, the polarization curve is shown in Fig. (3). To understand the effect of varying the hydrogen partial pressure from range 0.2 to 1 Atm with constant oxygen partial pressure is 0.2 Atm of the fuel cell at maximum load current is 30A is shown in Fig. (4).
To analyze the effect of the temperature variation of the fuel cell with a constant partial pressure of hydrogen and oxygen and with maximum load current is 30 A, as shown in Fig. (5).

DIGITAL NEURAL PID CONTROLLER DESIGN
In industrial applications, the traditional PID controller is considered one of the most popular control devices in terms of its simplicity and easy to understand the structure, which is consisted of three, terms proportional, integral, and derivative (Al-Araji, 2015). To solve the tuning limitation in the traditional PID controller (Al-Araji, et al., 2011), proposed an adaptive digital neural network PID controller with PSO on-line tuning parameters, which led to having a high dynamical characteristic and strong adaptation performance. Fig. (6) shows the proposed controller, which has the ability in terms of finding and tuning the optimal or near-optimal control parameters that will lead to fast reduce the tracking voltage error of fuel cell system through generating smooth and best control action. Where, kp is the proportional gain, ki integral gain, kd is the derivative gain, and e(k) error signal and u(t) is the controller action. There are many steps to design and implement the proposed digital NN-PID controller in FPGA: The first step is digitized the continuous control law PID as in Eq. (14) based on the backward ztransform, the digital control law become as in Eq. (15) (Al-Araji, 2017). net(k) = K p e(t) + K i (e(k) + e(k − 1)) + K d (e(k) − e(k − 1)) (15) O(k) = Lnet(k) (16) Where L demands liner Action function PH 2 (k) = O(k) + PH 2 (k − 1) (17) The second step in the design of the proposed controller is converting the neural networks like a digital PID controller for the PEM fuel cell with on-line tuning gain parameters, as shown in Fig.  (7).The net equation of the neural network represents as in Eq. (18). net(k) = K p * e(k) + K i * (e(k) + e(k − 1)) + K d * (e(k) − e(k − 1)) + PH 2 (k − 1) (18) The objective function in the on-line tuning is used as a mean square error function to evaluate the error between the desired output and the actual output of the fuel cell as in Eq. (19) (Zurada, 1992; Al-Araji, 2014; Al-Araji and Dagher, 2015).
Where, k: sample, t: iteration, p: is the number of population. e: is the error of each iteration. V FC : is the actual output voltage of the fuel cell of each iteration. V des : is the desired output voltage of each iteration.
The control gain parameters kp, ki and kd are tuned and obtained using the PSO algorithm in order to make the transient state of the control action is fast that leads to track the desired output fast with minimum error voltage, no overshoot, and without oscillation in the output voltage response of the fuel cell. The third step is PSO algorithm, (James Kennedy and Russell C. Eberhard in 1995) were the first to describe the PSO based on social-psychological principles as a stochastic algorithm inspired by simulation of social behaver such as birds flocking and fish schooling to solve real optimization problems (Al-Araji, 2014). The PSO is direct search methods which are derivativefree that they depend only on the evaluation of the cost function. PSO abbreviation to particle swarm optimization where features fast, easy to implement, don not need a gradient method to optimized function, and have a few parameters to adjust (Dagher, 2018). The proposed PSO tuning algorithm is used to find NN-PID weights (KP, Ki, and Kd) at the minimum cost function of Mean square error (MSE) in Eq. (19) at each sampling time to tuning on-line the system controller of PEMFC. According to simple mathematical formulas, the particles moving in the search-space over the particle's position and velocity. The particle's movement is influenced by its local best position, which is guided toward in the search-space to the best-known positions. Better positions are found updated by other particles. So the best solutions expected the swarm to move forward. The position and velocity of the particles at each time step are updated according to the equations. The step of PSO can give an explanation in the following steps: -Defining the PEMFC parameters such as the hydrogen partial pressure (PH2), the oxygen partial pressure (PO2), the temperature (T), the number of cells (Ncell), the maximum current (Imax), and the current of the cell (Icell). -Setting the maximum iteration number and initialize particles (Kp, Ki, and Kd) randomly.
-Finding the personal best for each particle PIDNN parameters according to Eq. (20) at first iteration the personal best it same the random initialize numbers where t is for iteration and i is particle number.
-Find the Global best for all particles by G best = max { P best,i t } (21) -Finding the velocity for all particles by Eq. (22) (Al-Araji et al., 2019).
Where, 1 and 2 are cognitive coefficients, and r1 and r2 are two uniform random numbers. x i t+1 = x i t + v i t+1 v (23) -Finding a better performance index (mean square error) -Updating the velocity and position of the particle.
-Updating the iteration counter. If one of the stopping criteria is satisfied, then stop, else loop to the first step. Fig. (8) shows a flowchart of the PSO algorithm. After each sampling time, the weights of the online NNPID are updated to minimize the error between the actual output voltage of the PEMFC model and the desired output voltage.
The fourth step is to convert the proposed digital NN-PID controller to the structure of FPGA, as shown in Fig. (9) by using the Xilinx development tool with ISE Ver.14.7 to design, implement, and verify the proposed FPGA-NN-PID controller. One of the important points in the FPGA design, the finite word length. The designer should determine the word length of all ICs used. Therefore, the finite word length of the proposed FPGA-NN-PID controller design is sixteen bits (Williamson, 1991; Khedker and Khade, 2017; Al-Araji, 2017) as follows: one bit for sign, Two bits for integer, and Thirteen bits for a fraction for all registers, adders/subtractions, and multipliers ICs. The FPGA-NN-PID controller consists of three modules, the Two's complement arithmetic module, an adaptive NN-PID control law module, and control unit module.  Two's complement arithmetic module: The proposed FPGA-NN-PID controller needs two's complement arithmetic that deals with signed-data that may appear as "error signal" so the two's complement module is designed as shown in Fig. (10-a) and it needed the following components ICs, as shown in Table 2.To verify the operation of the digital circuit of the two's complement arithmetic, the test bench waveform Verilog language is used as shown in Fig.  (10-b).    Fig. (11-a) and it needed the following components ICs, as shown in Table 3. To verify the operation of the digital circuit of adaptive NN-PID control law, the test bench waveform Verilog language is used, as shown in Fig. (11b).  Figure 11. An adaptive FPGA-NN-PID controller a-schematic design b-test bench waveform.

Journal of Engineering
 Control unit module: The adaptive FPGA-NN-PID controller is achieved by synchronizing and controlling the data flow in the two modules, the two's complement arithmetic module and an adaptive digital NN-PID control law module. The design of control unit consists of 32 bits Shift-Register and uses two 16-bits shift-register ICs through a serial connection and four comparators ICs in order to divide the maximum clock of the Spartan-3E board that is equal to 50 MHz to 1 Hz through generating a sequence of eight pulses during each sample where the sampling time is equal to 1 sec. Fig. (12-a) shows the control unit module, and it needed the following components ICs, as shown in Table 4. Fig. (12-b) shows investigating the operation of the control unit based on Verilog language simulation.  Finally, Fig. (13) shows the proposed an adaptive FPGA-NN-PID controller IC as the design of the overall module with control signals that it needed the following components ICs, as shown in

MATLAB SIMULATION RESULTS:
The MATLAB numerical simulation package is used to carry out the proposed digital NN-PID controller for the fuel cell system, as shown in Fig. (6) and used the physical parameters of the fuel cell, as shown in Table .1 with Eqs. (15) to (17). The on-line PSO algorithm is used to find and tune the weights of the adaptive NN like PID controller. Fig. (14) shows the investigating of the best number of particles and the number of iterations against the mean square error. The 38 numbers of particles (5 to 50 with step 5) and numbers of iterations (20 to 200 with step 20). So the best particles and iterations number are set to (20,100), respectively, because the mean square error is equal to 3.015 during 125 samples.

Figure 14.
The study best number of particle effects and the best number of iterations against MSE.
The parameters of the PSO algorithm is defined in Table 6. Based on the best parameter values that are taken from Fig. (14). Table 6. PSO algorithm parameters.
These parameters achieved a convergence to a global optimum of the PSO algorithm in terms of minimizing the objective function. To show the effectiveness of the proposed digital NN-PID controller with PSO tuning algorithm for the PEMFC system during 125 samples, the desired output voltage is changed in five phases (21, 22.5, 23.5, 21.5, and 22.5) volt with variation load current in five stages as (15, 10, 7, 15, and 10) Amp, as shown in Figs. (15-a) and (15-b), respectively. The actual output voltage of the fuel cell is a fast response to reach the desired output voltage without overshoots, no oscillation, and very small error occurred. Fig. (16) shows the fast response with a small swing of the hydrogen partial pressure control action of the proposed digital NN-PID controller in order to track the desired output voltage. Fig. (17) shows the on-line performance index of the mean square error for the adaptive digital NN like the PID controller based on the PSO algorithm. It has very small spikes in response when the desired output is changing. Figs. (18-a, b, c) show the on-line positive values of the parameters (kp, ki, and kd), respectively, of the proposed digital NN-PID controller based on the PSO tuning algorithm. It was compared with other types of controllers, as shown in

EXPERIMENTAL WORK
To carry out the proposed schematic design of the adaptive FPGA-NN-PID controller in Fig. (13a) is by using the real-time Spartan-3E Starter Kit with device xc3s500e-4fg320 in Fig. (19), Xilinx-ISE 14.7 package uses a sequence of operations (synthesize-XST, Implement Design, and Generate Programming File) for the proposed controller. After the design is synthesized and implemented successfully, it is shown in the summary report Fig. 20. The hardware description language functional model is generated Verilog file that is extracted to the black box using the Xilinx-system generator in the MATLAB Simulink. The black box with the ports Gateway In and Gateway Out that is given in Fig. (21) is tested with the overall fuel cell system under the MATLAB environment before downloading. This black box used to download the bitstream of the proposed FPGA-NN-PID controller on the Spartan-3E Starter Kit with device xc3s500e-4fg320 using the system generator through the JTAG (Joint-Test-Action-Group) as an interface and by the USB (universal serial bus) cable. The downloading process is done by using the hardware co-simulation mechanism. This mechanism enables the building of the hardware form for the designed controller. First, and from the HDL netlist, the chosen name for the used kit is selected. A compilation status was shown when starting the generating of a co-simulation block. Through the compilation process, a generating, performing, synthesizing, and running XFlow were done with no errors. After completing the compilation process successfully, a JTAG block was generating, as shown in Fig. (22).  The JTAG hwcosim (hardware co-simulation) interface block makes interaction with Spartan-3E Starter Kit with device xc3s500e-4fg320 during the system simulation running; it passes the incoming data from the system to the FPGA kit through the Gateway Ins while the FPGA kit sends the output (control signal) to the fuel cell system through the Gateway Out of the JTAG block. Therefore, the block diagram of the proposed FPGA-NN-PID controller for fuel cell model in realtime is represented in Figs. (23 a and b). PID controller in terms of fast reaching the desired output voltage. Journal of Engineering Volume 26 September 2020 Number 9 42 fuel cell system as shown in Figs. (24 and 25). In Fig. (25), it can be seen the fast response of the actual output voltage of the fuel cell in the five desired voltage steps with very small overshoots after 50 samples and steady-state error equal to zero that can be observed. Fig. (26) illustrates the performance effect of the hydrogen partial pressure control action of digital FPGA-NN-

CONCLUSIONS:
In this paper, an on-line adaptive FPGA-NN-PID controller with an intelligent PSO tuning algorithm for the Fuel Cell system had been designed and simulated for different desired output voltage with variable load current using MATLAB package. The Spartan-3E board with device xc3s500e-4fg320 and ISE for the Xilinx development tool was used to make the schematic proposed controller design, simulate and verify in the real-time