The software design of the single-phase inverter is mainly divided into the following parts: First, the equivalent mathematical model of the single-phase inverter is given, and then the software design of the inverter control part based on this model is introduced, followed by the modulation Part of the selection, and finally combined with the simulation results to make an overall introduction to the design of the control system software.

Ⅰ. Mathematical model of single-phase inverter
The topological structure of a single-phase inverter is shown in Figure 1. The inverter bridge is connected to the grid through a filter composed of L1L2C. When the inverter is working, the direction of current flows from the inverter bridge to the grid as shown in Figure I1. The current part I2 flows back to the inverter bridge via the capacitor C. So the voltage and current vectors of the inverter are shown in Figure 2.

Figure 1 Topological structure of single-phase inverter
Figure 2 Voltage and current vector diagram of inverter operation

Vector relationship:

(1)

When designing a circuit, generally L1=L2=L, the value of I1 is much larger than I2, R1=R2=R and they are very small, the above formula can be simplified to:

(2)

It can be seen from the vector relationship of the inverter work that the amplitude and phase of the grid-connected current can be controlled as long as the amplitude and phase of the inverter bridge output voltage Uab are changed.

Converting the vector relationship into the time domain can get the mathematical model of the inverter in the time domain:

(3)

Ⅱ. Design of control method of single-phase inverter
The control of the single-phase inverter generally adopts a double-loop control structure, the outer loop is a voltage loop, and the inner loop is a current loop. Among them, the output of the voltage loop is used as the setting of the inner loop. In practical applications, according to the inverter input voltage, the setting of the MPPT voltage loop is also different. The goal of grid-connected inverter control is to deliver the current quality to the grid as high as possible, which can improve the distortion of the grid while meeting relevant standards. Therefore, the design of the current loop is relatively important. The controller is designed with a control strategy combining PI control, voltage feedforward control and repetitive control. The control block diagram is shown in Figure 3.

Figure 3 Single-phase inverter control block diagram

①The design of the current feedforward part
The experiment measured that only using the PID of the grid-connected current to adjust the grid-connected current can not track the current command value well. Well and there is a phase difference between the current and the grid voltage, the PID adjustment ability has a certain limit. Therefore, it is necessary to introduce current feedforward regulation. The current feed-forward link is divided into current feed-forward amplitude adjustment and current feed-forward phase adjustment, that is, using real-time sampling of the grid-connected current signal, analyze its phase difference with the voltage and the amplitude difference with the current command value, and generate a compensation signal Act on the PWM modulation wave to offset the difference with the current command value. The feedforward link always plays a role in the whole process of grid connection.

②Design of repeated control part
Due to the dead zone, the asymmetry of the drive circuit, the periodic disturbance of the grid voltage and other non-linear factors, it is difficult for a pure PI regulator to meet the requirements of the grid-connected current total eye rate of change (THD). In order to reduce the influence of periodic disturbances, repetitive control is introduced. Experiments show that THD can be reduced by 1 to 3 percentage points after adding repetitive control, and the effect is more obvious in the low power section.

The repetitive control based on the internal model principle can effectively eliminate the command error and disturbance error of the grid-connected current, and provide high-quality steady-state waveforms. The principle of internal model points out that if a control system has a good ability to track commands and eliminate disturbance errors, a model describing the dynamic characteristics of external input signals must be included in the feedback control system. This model is the internal model. As shown in Figure 4, the repetitive control unit is mainly composed of two parts: a repetitive signal generator and an auxiliary compensator. The repetitive signal generator generates a periodic reference signal, where Q(z) is a first-order low-pass filter, which is generally taken as a constant less than 1. The auxiliary compensator is to provide phase compensation and amplitude compensation to increase the stability margin of the system. Generally take C(z)=KrZkS(z), Kr is the control gain, take a constant less than 1, Zk compensates the phase lag caused by the inverter itself and S(z). S(z) is designed as a second-order filter to attenuate the high frequency band and reduce the resonance peak.

Figure 4 Repetitive control structure diagram

Ⅲ. Modulation method of single-phase inverter
Single-phase inverters generally use SPWM modulation. SPWM modulation can be divided into unipolar modulation and bipolar modulation. The choice of the modulation method has an impact on the design of the drive circuit, the design of the filter, the efficiency of the inverter system, the current distortion rate, and the leakage current of the system. The following is a brief introduction to the two commonly used modes, which can be selected separately according to different application environments.

①Unipolar modulation
The concept of unipolar modulation and harmonic analysis will not be discussed here. Modulation is a comparison between the modulating wave and the carrier wave, and the PWM duty cycle is controlled by the comparison result. In the digital controller, the carrier can be easily realized by the timer. There are several ways to choose the modulation wave, which is illustrated by the control of the single-phase inverter bridge switching device in Figure 5. Figure 6 shows the single-phase inverter bridge waveform.

Figure 5 Control of single-phase inverter bridge switching devices
Figure 6 Modulation waveform of single-phase inverter bridge

As shown in Figure 6, the unipolar modulation wave and carrier wave are both positive, and the control loop must have commutation logic during the inverter process. In practical applications, four switches are used to reduce switching losses and improve the conversion efficiency of the inverter. Generally, there are one or two modulating switching states working in high frequency, and the other switching tubes working in power frequency switching state. The following two types are generally used. The driving sequence in Fig. 7 and Fig. 8 is T1- T3-T2-T4.

Fig. 7 Switch state 1 of unipolar modulation

It can be seen from the driving waveform that the second switching state tube has fewer switching times. Most of the time, only one tube is switching. Therefore, the switching loss of this method is the smallest, but in the open loop state, this modulation is due to The filter capacitor is always charged for half a week, and the measured waveform is close to a square wave, and a sine wave can only be obtained when a certain load is applied. In off-grid inverters, the first modulation mode is generally selected.

Figure 8 Switch state of unipolar modulation 2

②Bipolar modulation
In the bipolar modulation mode, the four switching tubes all work in the high-frequency switching state. The two tubes of the same bridge arm are complementary. The two diagonal tubes can be driven the same, or the phase difference can be 180° The modulation wave and the carrier wave are compared to produce two different drives. The modulated waves of the two modes are shown in Figure 9 and Figure 10.
Figure 9 Bipolar modulation wave 1

Figure 9 Bipolar modulation wave 1
Figure 10 Bipolar modulation wave 2

Ⅳ. Digital simulation
Based on the above control strategy, a SIMULINK simulation model as shown in Figure 11 is built, and its waveform is shown in Figure 12.

Figure 11 Single-phase inverter control system simulation model
Figure 12 Voltage and current waveforms