Fixed Point Implementation of Grid Tied Inverter in Digital Signal Processing Controller

Power inverters are one of the devices of great importance used in power grids to convert DC to AC, especially for grids with attached solar panels or wind turbines. The world is getting warmer due to coal-and oil-based power generation. So human existence is threatened due to the increased amount of carbon-dioxide in the air. As a result, integration of renewable energy sources (RESs) with the grid became mandatory. So, the demand of grid-connected inverters is increasing as more RESs are connecting with the grid; this necessitates developing a low-cost grid connected inverter system. This paper presents a comprehensive study and hardware implementation of a grid tied inverter. In this research, we have demonstrated a cost-efﬁcient grid tied inverter design using low cost DSP controller applying ﬁxed point arithmetic. The ﬁxed-point arithmetic and Digital Signal Processing (DSP) implementation results in superior performance over conventional methods of calculation. This paper also proposes a hardware model of such a bi-directional grid tied inverter. A current controlled Voltage Source Inverter(VSI) is used in the paper and a PI controller is suggested for current error compensation. To generate gating pulse for appropriate voltage, Space Vector Pulse Width Modulation (SVPWM) technique is employed. Synchronous Reference Frame Phase Locked Loop (SRF-PLL) is chosen for performing grid synchronization. The feasibility of the hardware model is veriﬁed by performing simulations on Simulink


I. INTRODUCTION
Inverters are the most salient part of a grid for integrating renewable energy sources (RESs). They play a crucial role in DC to AC conversion. Electrical energy is usually stored as DC in energy storage systems (ESSs). To recover the stored energy, it is necessary to convert it into AC to feed to the utility grid for consumption. A grid tied inverter differs from a conventional inverter to a few extents. Grid tied inverters continuously maintain synchronization with the grid as well as control real and reactive power. Two systems are said to be synchronized when the voltages are in phase with each other and the frequency is the same. So, when inverters are synchronized to the grid, it means that the inverter output voltage and the grid voltage should have a phase difference of 0 • and the two voltages should have the same frequency.
The associate editor coordinating the review of this manuscript and approving it for publication was Ramazan Bayindir . Solar panels or wind turbines used as sources in grids produce DC voltage which needs to be converted to AC voltage for supplying to utility. For grids focused on photovoltaic (PV), several grid-connected inverter models have been proposed. A soft switched inverter consisting of reduced component size and power switches are demonstrated in [1]. An improved cascade-type control scheme is proposed in [2] to achieve fast transient response and low total harmonic distortion (THD). It was noticed in [3] that parasitic capacitors between PV panels and the earth causes leakage current in cascaded-multilevel inverters. To mitigate such problems, filter-based solutions have garnered popularity. A single phase LLCL filter based Aalborg inverter [4] can vary its input DC value for a wide range and save the total inductance for the conventional voltage source inverter (VSI). Transformerless inverters have recently paved their way into the field because of their light weight and low cost. A modular buck-boost transformer less inverter is represented in [5] for low voltage solar panels. Current control mode is used to control the inverter for the purpose of shaping current to adjust power delivery. A modified multilevel cascaded H-Bridge inverter has been designed and implemented [6] for PV systems. Another compact three phase multilevel inverter has been designed in [7] using a single DC source in each phase for generating multiple level output voltages. This is suitable for low and medium voltage applications, including grid integration of renewables or energy storage systems.
The contributions of this paper are to manifest a costefficient grid-tied inverter using fixed point arithmetic and digital signal processing and to implement a small-scale hardware prototype grid tied inverter. A current controlled VSI is used in the paper and a PI controller is suggested for current error compensation. To generate gating pulse for appropriate voltage, Space Vector Pulse Width Modulation (SVPWM) technique is employed. Synchronous Reference Frame Phase Locked Loop (SRF-PLL) is chosen for performing grid synchronization. The feasibility of the hardware model is verified by performing simulations on Simulink. The schematic diagram of the proposed system is illustrated in Figure 1.
Similar works have been performed by many researchers as numerous attempts have been made to improve inverters for grid connection for renewable energy penetration. For instance, in 2012, Abdalrahman et al have demonstrated a comprehensive simulation and implementation of a threephase grid-connected inverter using the PSIM simulation package [8]. In 2014, Al-Durra et al have presented a threephase grid tied DC/AC inverter with active and reactive power (VAR) control for medium size renewable and distributed DC energy sources [9]. In 2018, Sevilmiş et al have simulated an experimental three-phase grid tied inverter controlled by SVPWM method for RESs [10]. A compact three phase multilevel inverter for low and medium power PV systems has been explored in [7]. Inverters are a relatively new subject in the field of power electronics, and are under continual development. This study is a humble attempt at enriching that branch with an updated and improved technology.
The rest of the paper is organized as follows: Section II presents the modelling of the proposed system using relevant equations. Section III represents the real and reactive power control methods of the inverter and involves derivation of the different transformation and control techniques for grid tied inverter with simulation results. Section IV explains the grid synchronizing process using SRF-PLL system and the generation of the gating pulses using SVPWM method. Section V discusses the fixed-point arithmetic and how it is used in the proposed system to calculate the PLL angle. Section VI analyses the experimental results and demonstrates the integrated hardware implementation. Section VII draws out the conclusion to the paper.

A DC motor torque equation is governed by
Here I f and I a are field current and armature current respectively. So, the torque of a DC motor can be controlled precisely using a standard PI controller, which works robustly on DC quantities of I f and I a . However, a PI controller inherently cannot maintain zero steady state error for sinusoidal reference. The integral action removes the error if reference value is constant in steady state. So, to control the sinusoidal output current, it is convenient to transform the sinusoidal or alternating current or voltage into DC quantities through dq transform. Thus, the model in dq frame is derived from three phase a-b-c frame. The conversion process comprises of two steps: firstly, from abc frame to αβ frame by means of Clarke Transformation, and then from αβ frame to the dq frame using Park Transformation.
The basic circuit for a three-phase grid tied inverter is depicted in Figure 2. The sinusoidal three phase output voltage of inverter is as follows Here, A is the amplitude of voltage, ω is the angular frequency and v ia , v ib , v ic are three phase inverter side voltages. The generic equation for a single phase is derived as The equation matrix for three phase stationary frame is The equation for the transformation of three phase stationary (abc) to two phase stationary (αβ) would be Now, So, the electrical dynamics of inverter in d-q synchronous frame is derived as The resistance R can be practically neglected and the differential equation of synchronous frame becomes d dt The equation describes that the dynamics of one axis current is dependent on the other axis current. This is analogous to the electric machine where direct axis flux produces quadrature axis back EMF. The control scheme is illustrated in Figure 3.
To control the currents i d andi q , a PI controller is proposed. Thus, the inverter input reference voltage would be Here, the asterisk ( * ) sign indicates the reference variable.

III. REAL POWER AND REACTIVE POWER CONTROL
There are two control strategies for three phase Voltage Source Inverters (VSI): current control and voltage control. Voltage controlled VSI uses the phase difference between the inverter output voltage and grid voltage to control the power flow. Current-controlled VSI provides high-accuracy control of instantaneous current, protection from peak-current, overload mitigation, and superior dynamics [11]. In the past few years, many current control strategies have been developed. The major types of pulse width modulation (PWM) based current control strategies are linear and non-linear. VOLUME 8, 2020  Predictive controller has a very good steady-state performance and provides a good dynamic performance. However, its performance is sensitive to system parameters. The hysteresis controller has fast transient response, non-complex implementation and an inherent current protection. However, the hysteresis controller has some drawbacks such as variable switching frequency and high current ripples. These cause poor current quality and introduce difficulties in the output filter design [12], [13].
The main principle of current control is to force the controller current to follow the reference signal. In case of current control strategy, active and reactive components of the current injected into grid are controlled separately using PWM techniques. The proposed model of inverter operates in linear current control mode because the grid controls the operating voltage and frequency. The inverter has nothing to do with voltage and frequency as it is connected with infinite bus. The controller sets the current reference by which it controls real and reactive power as shown in Figure 3. A prominent advantage is that current control is less sensitive to distorted grid voltage and its response is faster. For these reasons, current control has advantages over voltage control methods. Thus, for grid connected application, current control is recommended. The current controller for controlling current in the grid connected inverters are vastly classified according to Figure 4. Table 1 summarizes the advantages and disadvantages of three principle current controllers: hysteresis current controller, predictive current controller and linear PI current controller. Based on these judgements, the linear PI control algorithm is found to be the best choice to implement the grid connected inverter [14], although PI controllers also have some problems, such as limited bandwidth, poor disturbance rejection and introduction of delay into the control loop [?].
The equations for calculation of current reference are deduced as follows. As all the calculations are in the d-q axis, thus the real and reactive power equations of inverter are respectively governed by Solving the equations, we can get the reference direct axis (I d ) and quadrature axis (I q ) current reference value These reference currents represent i dref and i qref in Figure 3, which are fed into the PI Controller to push real and reactive power into the grid. The PI current control offers an excellent steady-state response, low current ripple, constant switching frequency and well-defined harmonic content. Moreover, the controller is insensitive to system parameters since the algorithm does not need system models [15]. In this system, PI controllers are used to compensate the current vector components that are defined in synchronous reference frame. Because of coordinate transformations, i d and i q are DC components, and therefore reduce the error(s) between the reference current I * d (I * q ) and the actual current I d (I q ) to zero [12]. PI controller performs better in stationary systems as d-q components of current represent the AC parameters as dc quantities. The equation of the PI controller is After Laplace transformation, it becomes The equations can be shown in block diagram as shown in Figure 5. When the PI controller reaches the actuator limit, then the actuator becomes saturated. In this situation, the system effectively operates in open loop. To limit the integral windup, Figure 5 shows a significant anti-windup control scheme [16]. In the figure, three PI loops are used to control three interactive variables independently. The implementation is conventional and includes the term (Kc.Excess) to limit integral windup. Excess is calculated by subtracting the unlimited output (U ) and limited output (Out). The term Kc multiplies the Excess and limits the accumulated integral portion (Sum). The pseudocode of the modified PI controller becomes: Modified PI Controller pseudocode: Typical closed loop systems use PI controller through feedback mechanism to maintain the desired result. PI controllers can easily track DC quantities in low bandwidth condition. In the system, 3 phase AC quantities cannot be directly tracked by PI controller.
Thus, mathematical transformations such as Clarke and Park transformation provide an aid to convert the quantities into corresponding d-q components. Clarke Transformation converts three-phase AC signals as shown in Figure 6(a) into two-phase quadrature signals as shown in Figure 6(b). The equation for converting a, b, c frame into α, β frame is governed by the equation For a balanced 3 phase system So, the Clarke transformation reduces into   Here, k p and k i are the proportional and integral constants respectively, and e(t) is the error function of the input signal r(t); and y(t) is the output signal.
Similarly, f β (t) reduces into The Park transformation results in DC quantities (d and q components) which can follow PI controller reference signal easily. The Park transformation of three-phase AC signals in Figure 6(a) results into the DC signals shown in Figure 6(c). The value of f d and f q can thus be derived from the predetermined value of f α (t) and f β (t) using the following equation The advantage of the reduced equations (30) and (31) is that it requires lesser number of multiplications than the equation (26). So, the transformation can be easily implemented into the dsPIC33F family microcontroller. These equations also dictate that only two phases (phase a and b) of voltage or current are needed to be sampled for the transformation.

IV. GRID SYNCHRONIZATION
The voltage amplitude and the frequency of the inverter and the grid need to be synchronized with each other when they are connected [17]. In the traditional synchronous generator system, the generator output voltage and frequency are the governing parameters to synchronize with the grid. After proper matching of amplitude and frequency, the generator synchronizes with the grid at the Point of Common Coupling (PCC). It needs to be continuously tracked on-line whether or not the synchronization is continually maintained. The condition of synchronization determines the firing signals for the inverter [18]. A grid tied inverter mimics the behavior of synchronous generators. So, to inject power into the grid,  it has to synchronize with the grid frequency and amplitude. There are several techniques for synchronization, such as [19]: • Duplicate grid voltage output so that the output current reference has the same phase as the grid voltage • Synchronous Reference Frame (d-q) PLL (SRF PLL) SRF-PLL is used widely in ideal grid conditions for three-phase grid-connected power converters for its simple implementation and fast and accurate estimation of the phase/frequency [20]. Phase Locked Loop (PLL) is the heart of a grid tied inverter system, keeping track of the grid frequency and phase. More accurately, the role of PLL in a three-phase system is to estimate the angle measuring the instantaneous voltage waveform. The control of the grid tied inverter mainly depends on the synchronization algorithm. PLL synchronization techniques are prominently used in practical applications. A detailed discussion on PLL techniques can be found at [21]. Suppose, the PLL estimated angle is θ, then the a-b-c to d-q transformation can be described as Using trigonometric identity, the equation reduces to Under ideal grid conditions, the determined phase angle (θ) is equal to the phase angle of the grid (ωt) and as can be seen from the following equations; while v q is equal to zero. The block diagram of the SRF-PLL system is illustrated in Figure 7. It is mandatory to assume that PLL is in locked mode during PLL design which means input signal and feedback signal are in phase and same frequency. When PLL angle is close to instantaneous voltage vector angle, (ωt − θ) is small or close to zero. The term can be linearized for controlling using PI controller.
Thus, it can be concluded that, for balanced three-phase system, the q axis component V q is close to zero when PLL angle is locked [22]. So, the q axis property is used in SRF-PLL as phase detector (PD) and low pass filter/PI controller is then used to eliminate steady state error and output is fed to voltage-controlled oscillator (VCO) which generates the angle and sine wave. The transfer function of the PLL circuit is given by We choose T s = 0.04 and ζ = 1/ √ 2. So, the parameters of the PI controller can be calculated as where, the natural frequency is given by Figure 8 shows the three phase AC signals and the PLL angles for the signals. All the necessary algorithms to implement grid tied inverters have been presented previously. This segment aims to present the PWM technique for generating output signal of inverter. There are many methods for generating PWM signals. In this application, Space Vector PWM (SVPWM) technique is implemented for its robustness [23].
The SVPWM subroutine can be implemented in three steps. In the first step, the sectors are calculated from the PLL angle. Secondly, the time durations t 0 , t 1 and t 2 are to be calculated. After that, the duty cycle for different sectors can be easily determined according to the flowchart of Figure 9.
As shown in the figure, the first step to implement the SVPWM subroutine is to determine the sector from the PLL angle. That is done by comparing the extracted grid phase   angle with angle range of each sector, as illustrated in Figure 10. Table 2 demonstrates the duty cycles of the three upper switches of the inverter in the six different sectors.
The software implementation dsPIC controller is explained in the flowchart shown in Figure 11. The grid voltage and the current injected to the grid will be sensed firstly through ADC module of the dsPIC controller. Then the grid angle is extracted by the PLL algorithm. After that, the PI controller is executed for the current control loop. Finally, SVPWM subroutine is executed.
The second step to implement the SVPWM subroutine is to calculate the modulation index (m) and the time duration T 1 , T 2 , T 0 that can be determined by the following equations where u ref is the amplitude of desired output fundamental component, u DC is the available dc-bus voltage, T s is the sampling period, and s is the phase angle of the grid voltage that extracted by PLL. The gating signals are generated when PWM module interrupts. The interrupt service routine for the PWM module is shown in Figure 12. In this routine, the duty cycle for each pair of PWM output (PWMxH/PWMxL) is loaded in its associated PWM duty cycle register (PDCx). After implementation of the SVPWM subroutine, the waveshapes of the three phases are represented in the simulation diagram shown in Figure 13.
As all the calculations are in 16 bits. So, 32 bits output saturated into 16 bits.

VI. EXPERIMENTAL RESULTS
The proposed work is an assembly of several experimental steps. The successive development of the proposed model has been presented below through simulation diagrams. It is noteworthy that all the results obtained have been taken in fixed point arithmetic format and thereby, all the graphical results produced are scaled in the Q1.15 format along the vertical axis. Here are the in short description of how we captured all the hardware results. We capture all the data using serial terminal. As serial terminal communication is low, so we used internal buffer for the variables. When buffer was full, data was sent through the serial terminal.

A. CLARKE TRANSFORMATION
The transformation from the abc-frame to the stationary αβ frame is represented by Clarke transform, which is shown in Figure 14. Only two of the three phase voltages are fed into a Clarke transform to convert them from a three-phase system (i a , i b , i c ) to a two-dimensional orthogonal system (i α , i β ). Note that it's not necessary to measure all three currents, since the sum of the three must equal unity (0). So, the third current must be the negative sum of the first two.

B. PARK TRANSFORMATION
The transformation from the stationary αβ frame to the synchronously rotating dq frame is represented by Park transform, which is shown in Figure 15. A Park transform is used to convert the two-axis stationary system (i α , i β ) to a twoaxis rotating system (i q , i d ). The main purpose to transform the three-phase instantaneous voltages and currents into the synchronously rotating reference dq frame is to make compu-  tations much easier. Besides, it allows the system operator to independently control the active (d-axis) and reactive (q-axis) components of the currents.

C. SVPWM
SVPWM is employed in this system to generate appropriate gating pulses for the inverter. SVPWM has been proven to be a better technique compared to the more commonly used PWM or sinusoidal PWM (SPWM) techniques. SVPWM is generates a more fundamental sine wave with a higher voltage, dominant harmonic reduction and lower total harmonic distortion (THD) when used in an inverter. The three phases implementation of the SVPWM subroutine in dspic33f microcontroller is shown in Figure 16.

D. INVERTER PHASES
The inverter takes input from the DC voltage source and converts it into three-phase AC voltage and feeds to the grid. For the experiment, a DC source is used instead of a solar array. The inverter converts the DC voltage into a three phase AC voltage. The three phases of the inverter output can be represented as the red, blue and green waveforms in Figure 17.

E. PLL
Phase locked loop (PLL) control is an indispensable part of the grid synchronization process. It helps to estimate the angular difference in the phase of the inverter output voltage and the grid voltage, based on which the VCO operates to control the frequency of the inverter output. Figure 18 represents the PLL angle of the inverter output voltage with respect to a certain phase of the grid. Figure 19 shows the simulation of the grid synchronization process. The simulation has been illustrated for one phase only. The red waveform is the grid voltage and the green waveform is the inverter output voltage; and it is evident that these two waveforms are perfectly in phase with each other, i.e. with a phase difference of 0 • . This implies that these two VOLUME 8, 2020   signals are matched in phase and therefore, the inverter output has been synchronized with the grid voltage.

G. HARDWARE IMPLEMENTATION
The components used in the hardware implementation of the proposed model has been presented as an image in Figure 20. The three-phase 400V, 50Hz AC signal output voltage of the inverter, which is fed to the grid, is sampled by a sensor board, which can be observed on the oscilloscope display, as shown in Figure 21. There is a control board and a switch board too. A serial converter aids to display the waveforms on the monitor. The monitor depicts the live control of the device, as shown in Figure 22. The monitor shows four waveforms: the PLL angles, and the three SVM phases, which are similar  to Figure 8 (bottom) and Figure 14. The complete hardware implementation setup is shown in the image of Figure 23. In the hardware implementation, a DC source is directly used instead of a PV system for the purpose of experimentation and convenience.

VII. CONCLUSION
In this paper, a grid tied inverter has been proposed which can be implemented using fixed point calculation and digital signal processing (DSP). The fixed point arithmetic and DSP implementation have been found to perform better than the conventional methods of calculation, yielding a low-cost inverter. A hardware model of such a grid tied inverter has also been implemented in this work. The current control strategy has been used for the voltage source inverter in the proposed system. PI controller has been used for the current control strategy. Space Vector Pulse Width Modulation (SVPWM) technique has been used for generating the gating pulses. For the purpose of grid synchronization, Synchronous Reference Frame Phase Locked Loop (SRF-PLL) has been employed. MATLAB/Simulink platform has been used for simulations and to assess the feasibility of the hardware model. Future works will include improvisation of the proposed system to make it more cost-effective and tolerant of intermittencies of renewable sources of energy by incorporating an energy storage system along with this system.