MATLAB Simulation of PID Control of Output Voltage of Flyback Switching Power Supply

Flyback is one of the most common circuits in switching power supplies. Such as mobile phone chargers, laptop power adapters, and electric vehicle chargers mostly use this circuit. The basic function is to reduce high-voltage direct current to low-voltage direct current.

The characteristics of the flyback circuit are simple in structure and small in size. The disadvantage is that the output power is difficult to achieve very large, generally only applicable to the situation below 150W.

Its basic circuit is as follows:

2af2ef91bf3b4743bc56817654682ced.png

 The working logic is to transfer the energy from the primary side of the transformer to the secondary side through the fast turn-on and cut-off of the switch tube Q1 to realize step-down.

A circuit similar to flyback is called forward. In some high-performance desktop power supplies, the forward type is often used, and the power of the forward type can be made larger. Its principle diagram is as follows

acc405405c304557acf26e20763ac4c1.png

The forward and flyback structures are very similar, the difference between the two is that the positions of the same name terminal of the transformer and the diode D1 are different.

Principle analysis of flyback circuit:

When the input voltage is turned on, the switching tube Q1 is in the off state, and the primary side of the transformer is disconnected.

Then we input a high-frequency PWM wave (tens of KHz) to the G pole of Q1 to control the switching state of Q1.

When Q1 is turned on, due to the existence of the inductance of the primary side of the transformer, the current of the primary side cannot change suddenly, but slowly increases from 0. The primary current becomes larger, and the primary coil excites a magnetic field with a larger magnetic field intensity B in the transformer core, and the changing magnetic field excites an induced voltage u in the secondary coil.

c394bab4ee4d43c3a90ea0988c858039.pngThe curve in the figure is a schematic diagram and does not represent the actual change curve. In fact, the current on the primary side does not rise with a linear function, and the voltage on the secondary side also changes.

If there is no diode D1, the secondary side should charge the capacitor C2 at this time, but the unidirectional conductivity of the diode D1 cuts off the voltage of the secondary side, and the current i cannot flow in the direction shown in the figure above, so there is no current in the secondary side.

When Q1 is off, the primary side of the transformer is open. Similarly, due to the existence of the inductance of the primary side of the voltage transformer, the current on the primary side cannot change abruptly, but has a process of decreasing. At this time, the current is released through R1, C1, and D2. The primary current decreases, and the primary coil still excites a changing magnetic field in the transformer core, but at this time the magnetic field intensity B becomes smaller, and the induced voltage on the secondary side of the transformer is reversed.

e4ceb4baf97f43dfab85bec2a8e74d91.png

At this time, the diode D1 is turned on, and the secondary side of the transformer charges the capacitor (or supplies power to the load at the same time).

Q1 is turned on again, the primary current rises, and the secondary diode D1 is cut off.

Q1 is turned off again, the current on the primary side drops, the diode D1 on the secondary side is turned on, and the capacitor is charged (or power is supplied to the load at the same time).

The above process is continuously cycled, and the energy at the output end is continuously transmitted to the output end.

Output voltage analysis:

Now let's analyze the output voltage in the open-loop state (the PWM duty cycle of driving Q1 is fixed, the frequency is fixed, and the output load is also constant)

First of all, we must know that every time Q1 is cut off, the secondary side of the transformer will output energy to the outside. The output voltage Vout will be equal to the capacitor voltage, so analyzing the output voltage is equivalent to analyzing the capacitor voltage.

If there is no load at the output terminal (that is, no load), the right side of the capacitor is in an open circuit state. Every time the capacitor is charged, its voltage will increase. As long as the charging times are sufficient, its voltage can rise to the maximum value of the secondary side of the transformer. The theory can be Reach gif.latex?Vin*%5Cfrac%7Bn2%7D%7Bn1%7D, (n1, n2 are the number of coil turns of the primary side and secondary side of the transformer respectively).

If there is a load R at the output end, when Q1 is cut off, in addition to charging the capacitor on the secondary side of the transformer, part of the current flows to the load R, so the capacitor voltage rises slower than when there is no load. When Q1 is turned on, the secondary side is turned off. At this time, the capacitor supplies power to the load, and the capacitor voltage will drop. When Q1 is turned off again, the capacitor is charged again, and the voltage rises; when it is turned on, it drops again.

ad7f3ac63c3546ed970fcdb35f8c3a05.png

The output voltage is in a dynamic process of rising and falling. If the rising amount Uup is more than the falling amount Udown in a single cycle (that is, a cycle of the PWM wave), then in a single cycle, the output voltage still increases by ΔU.

e086b2103fc64cd585d6af13df281fdf.png

After the voltage rises, the current flowing through the load R will increase, so its power is equivalent to an increase. When Q1 is turned off, the load will consume more energy, and the energy obtained by the capacitor will be less, so the amount of its voltage rise will be reduced; when Q1 is turned on, the capacitor will discharge to the load, because the voltage is high, So its discharge capacity is more, and the amount of voltage drop will be less. The ascending amount decreases and the descending amount becomes larger. As long as enough cycles have passed, the voltage of the capacitor will rise in a certain cycle by the same amount as the drop, that is, a balance will be reached, and this balance will always be maintained. That is, the output voltage has reached a dynamic and stable state.

4214d34470504ab39ba3d6ab2533da61.png

It can be concluded that no matter how big the load R is, as long as enough time passes, the output voltage can reach stability. But the smaller R is, the smaller the average value of the output voltage after stabilization is.

From the above analysis, the size of the output voltage is related to the size of the load. In practical applications, we hope that the voltage can be stabilized at a certain value, no matter how the load changes. Therefore, we need to introduce a closed-loop control of the output voltage.

Closed loop control of output voltage:

The so-called closed-loop control is to feed back the output value (that is, the output voltage) to the regulation system, and the regulation system controls the input quantity (PWM duty cycle), so as to realize the closed-loop control of the output voltage.

05437e8c5cc64dcbb899f253eb2de5de.png

 Why can the output voltage be adjusted by adjusting the PWM duty cycle of Q1?

It can be understood that the output voltage is actually a representation of the energy transfer density of the transformer. The more energy transferred from the primary side of the transformer to the secondary side per unit time, the higher the output voltage will be (the reason why it is called a trend is because the output voltage is related to the load. If the load remains unchanged, the output voltage will be higher. ), or the greater the power.

For the primary side of the transformer, it is equivalent to an inductor, and its power satisfies the "ampere-second balance".

ac3b6e48b9d44c1da98bcd4b3575638f.png

The figure above is a schematic diagram of the driving PWM wave of Q1. The height of the shadow can be equivalent to the average current (assuming that the average current is I1 when it is on and I2 when it is off), and the width is equivalent to time.

When Q1 is turned on, the transformer stores energy, and the stored energy value is equivalent to the shaded area S1; when Q1 is turned off, the transformer releases energy, and its value should be less than or equal to the stored energy (the ideal state is equal, if Q1 is turned on, the transformer If the magnetic core is saturated, it will be less than that, which is not considered here), assuming that the released energy is equivalent to the area S2, then S1=S2, that is, I1*t1=I2*t2.

When Q1 is turned on, the average current of the primary side is basically unchanged, so, I2= gif.latex?I1*%5Cfrac%7Bt1%7D%7Bt2%7D= gif.latex?I1*%5Cfrac%7BT*D%7D%7BT-T*D%20%7D= gif.latex?I1*%5Cfrac%7BD%7D%7B1-D%7D. (D is the duty cycle)

Therefore, it can be deduced that the larger D is, the larger I2 is, the larger the energy transferred to the secondary side is, and the larger the output voltage is.

Here only a simple analysis is carried out, in fact the relationship between the energy transfer mode and the corresponding function is more complicated.

It should be noted that the duty cycle of the flyback circuit is not greater than 50% to avoid saturation of the transformer core.

Note: There are two ways to change the duty cycle: one is to keep the PWM frequency unchanged, and change the on time and off time at the same time; the other is to keep the on time unchanged, and change the off time, that is, the frequency will change.

PID control

PID control is the most commonly used control method in automatic control. It has a wide range of applications, such as the temperature control of inverter air conditioners, the control of servo motors, the automatic driving of aircraft, and even the attitude maintenance of rockets, etc.

PID refers to three links:

P: Proportional link, the output of the proportional link is proportional to the amount of time. Laplace transform is performed on the differential equation of the proportional link to get: C(s)=KR(s). The proportional link cannot eliminate the static error. When the parameter of the proportional link is too large, the system will be unstable and oscillate.

I: Integral link, the output of the integral link is proportional to the time integral value of the input quantity, and the integral link can eliminate the static error in the control system, which can be considered as the supplement of the proportional link. If its value is too large, it will cause system shock. 

D: The differential link, the output of the differential link is proportional to the derivative value of the input quantity to the time variable, which can predict the changing trend and respond in advance. If its value is too large, it will also cause system oscillation.

Only the proportional and integral links are used in this system.

MATLAB
MATLAB is a commercial mathematical software produced by MathWorks in the United States . It is used in data analysis , wireless communication , deep learning , image processing and computer vision , signal processing , quantitative finance and risk management, robotics, control systems and other fields. It can be seen in academics, engineering or scientific research.

Circuit simulation is only a function of matlab.

In June 2020, Harbin Institute of Technology was included in the "Entity List" by the United States, and the matlab development company terminated all authorizations of Matlab Harbin Institute of Technology.

So how powerful this software is, I won’t say much here.

6a6b5343ecf64f2cbab13e6d6c56be9d.png

MATLAB will exit two new versions every year. The latest version is 2022b. Here I am using the R2020b version.

 Circuit simulation requires the Simlink module.

d6778ec8154f4ddd82e85a94251532e1.png

Create a new blank file, select the device in the Library browser, and build the circuit model as follows:

0b32facce628497bb15e63c097cfa760.png

b883d16195e84de9b735b4a426d9d69d.png

 

The basic design parameters of this circuit:

Rated input voltage: 300Vdc

Rated output voltage: 12Vdc

Rated output current: 12A

Rated power: 140W

About the choice of matlab modeling device:

All inductors, resistors and capacitors can choose Series RLC Branch

a76434b597854bc5b01fc2390ebe514d.png

Then select whether it is a single resistor or a single capacitor or other combinations in the Branch type, and then set its value.

ec610d068fb545daabf0280d052c2c10.png

 The positions of diodes and MOSFETs are as follows, and the names can be searched directly. c14b37c6cc2f4f6fbcb3cd548c36fecb.png

Both devices have an m port, which can be connected to an oscilloscope to view the voltage and current waveforms of the device. If you don't need it, you can also hide the port, as follows:

e02ec4647fb148e79f106e767e45f198.png

 Snubber resistance (snubber resistance) and Snubber capacitance (snubber capacitance) can be set to inf (infinity) and 0 respectively to simulate the ideal environment as much as possible.

 

 Transformer selection Linear Tramsformer (linear transformer), parameters can refer to the following:

Here I am using a 54:6 double-winding transformer, PQ3220 magnetic core, primary side inductance 700uH, secondary side 8.64uH.

141c3441d8fa47089597276f23972f5b.png

 The parameters of the transformer correspond to the model as follows (winding 3 is omitted):

a4abb909d7f84cc1824ed5bd04dccfd6.png

 Note:

1. In this transformer model, the values ​​of V1 and V2 do not represent the actual voltage, but actually represent the voltage ratio between the primary side and the secondary side, which can also be said to be the coil turns ratio. For example, the above V1=54, V2=6, if set to V1=9, V2=1, the effect is exactly the same. The inductance ratio (Lm: L2) of the primary side and the secondary side does not affect the voltage ratio of the primary side and the secondary side (this is inconsistent with the actual transformer characteristics).

2. Lm, Rm (magnetizing inductance, magnetizing resistance) respectively simulate the reactive power loss and active power loss of the transformer. Generally, L1 can be set to 0, Lm can be set to the inductance of the primary side, R1 can be set to the resistance of the primary side, and Rm can be set to a larger value.

3. I use the International System of Units (SI) for all the parameters here, and the Nominal power and frequency are invalid.

 PWM generator:54ad68535d054809b1b7c08d62067803.png

 PID controller

36bd0db0961540768a3c93d3343d4c86.png

 Voltage and current probes to measure voltage and current

27a955c6993b4ebb9eb8b1a7bb6c2010.png

 Adder, used to calculate the error value6a200b3c5681454e9580aff66d02b07e.png

The reference voltage is provided by the constant blockf6337addea334ad7ac5e86b5ba8d18cb.png

 Search "scope" to add an oscilloscope, and the number of channels and layout can be changed in the settings of the oscilloscope

72626829617b48c9a4c47b017620061d.png

Finally don't forget to add Powergui, you can't run your circuit simulation without it. You can also modify the parameters of the model in it. I will not modify them here, and the default is fine.

3dc045da6c6d4f789a72a916dba1e62c.png

Once the model is built, you can start

 

First explain the relevant simulation conditions:

Input voltage 300V, load 5 ohms (current 2.4A)

PWM frequency 50K,

The PID controller is set as follows, using PI control, the upper and lower limits of the output are limited to 0-0.5.

bdc65ededfb44dcda003c0adeb1195ba.png

c6ab7e152bfb4175b0e8bc1a6487c90e.png

After setting, if you do not change the proportional integral coefficient and run with the default value (the default value is 1), you will get the following waveform

3b0f9de8fb634036a5c1d6e47930ff6c.png

 Measuring the output voltage, we can see that it oscillates at a frequency of 271Hz, which obviously does not meet our expectations, so the PID parameters need to be adjusted.

The basic sequence of PID parameter adjustment is first proportional and then integral (when adjusting the proportional coefficient, the integral coefficient needs to be adjusted to 0, and the proportional coefficient is adjusted from large to small until the output does not oscillate), then the proportional coefficient is not changed, and the integral is adjusted coefficient until the error quickly goes to 0 and no oscillation occurs.

Generally speaking, we hope that the larger the proportional coefficient and the integral coefficient, the better, but if these two values ​​are too large, the output will oscillate. So it is necessary to find an intermediate value that will neither oscillate nor respond quickly.


The waveform when P=1 and I=0 is the same as the previous one. It can be found that the duty cycle is quickly switched between 0.5 and 0. When the duty cycle is 0.5, the output voltage rises rapidly. When the voltage reaches 12V, it is too late for the duty cycle to respond, and the voltage exceeds 12V; then the duty cycle It will be 0 again, and the voltage drops rapidly. When the voltage reaches 12V, it is too late for the duty cycle to respond, and the voltage is lower than 12V. Going back and forth will cause the output voltage to fluctuate. The reason is that the proportional coefficient is too large and the duty cycle output is not soft enough.

8c8de9e992974610b69cf23b1505fd4c.png

 


We slowly reduce the proportional coefficient. When Kp=0.5 and Ki=0, you can see that the change of duty cycle is much softer, and the amplitude of output oscillation is also slightly slowed down, but it is not enough. Continue to reduce it.

29a17e4318024e82937fbd64c336f98a.png


 

This Kp=0.1,Ki=0:42de631395ae44739158aad8d3033fcc.png

At this time, the output will oscillate slightly twice at the beginning, and then it will be basically stable, and the duty cycle will be softer. But it is not enough, because the output voltage has an overshoot at the beginning of rising, although its value is only 10.517V, which is lower than 12V, but once the integration link is introduced, its value will exceed 12V. So continue to reduce the Kp value.


When Kp=0.01, Ki=0, the output basically does not overshoot.

4bf0d4a8b290442aa67b2f769e0aa38d.png

 But its voltage is only 2.043V, which is far lower than 12V. This is because there is a steady-state error in the single-proportion link, so the integral link needs to be introduced.

First set Ki to 1, try it out.


When Kp=0.01, Ki=1:

b1cd6b8e7f5d49ffb7e0e12c643f7617.png

It can be seen that the output voltage increases very gently to 12V, and the steady-state error is almost 0. But pay attention to the time scale, it takes nearly 0.2s for the output voltage to increase from 0 to 12V, which is obviously too slow, if it can be faster up to 12V, that's fine. So keep increasing Ki


Kp=0.01,Ki=5

a1fa703b2a9f40128ae406039b421151.png

It is found that at this time, the output voltage rises from 0 to 12V, and it only takes 0.02S. Of course, I wish he was a little faster. keep turning up


Kp=0.01,Ki=6

12a3f56d458e45dbaade53016c04326b.png

 It can be found that the time to reach 12V is shortened at this time, but there is a slight overshoot, which is obviously not what we want. If you continue to increase it, the overshoot will become more and more serious, so you need to adjust Ki smaller. Just now when Ki=5, there is no overshoot, so you only need to adjust Ki slightly, and it should be greater than 5.


When Kp=0.01, Ki=5.5:

9aaf62c83cdb4108b13831af3c5418a0.png

 At this point the waveform is almost perfect!

Look at the output voltage and current waveform:

f8371e79eff948dea67170eb7521f6e1.png

The curves are beautiful without any issues.

 

Let's try another load, R=10

f702aa8aab434be2b25ba585711c794d.png

aa6c2b8da4ce47dc9955707af792c775.png

There is no problem. It can be found that after R becomes larger, the time to rise to 12V is shortened.


Try another input voltage, Vin=400V, R=2

c2b93ebced714023a388bebd6c0e6798.png

Almost indistinguishable from the previous

In this way, the entire adjustment is completed, and the final parameters are: Kp=0.01, Ki=5.5

 

It should be noted that there is no best PID parameter, only better ones . As long as it meets the actual needs.

 

If the driving PWM wave of the MOSFET is sent by the microcontroller, how to realize the PID control in the microcontroller?

The next article will explain the implementation method of PID control of STM32 microcontroller.

 

 

 

 

 

 

 

 

 

Guess you like

Origin blog.csdn.net/qq_55203246/article/details/126962914