Boost Converter – Simulink Model Using MATLAB Embedded Function

In this post, I am going to talk about modelling dc-dc power converters using MATLAB’s user defined function block. Doing so saves a lot of time and it’s much more easier as compared to the Buck converter model in which each dynamical equation is implemented using blocks. Doing so is not only time consuming, but tracking back and finding out errors is hard especially when the system becomes larger. In this model, I have used as few blocks as possible.

The Boost converter circuit is shown in fig.1. I have accounted for the parasitic resistance in passive components as well as the ON resistance for active device.

Fig. 1: Boost converter circuit

Inputs the converter model are:

  • Input voltage V_g
  • Voltage control (duty cycle) d
  • Load current i_{out}

Converter outputs:

  • Capacitor voltage v_C
  • Inductor current i_L
  • Output voltage V_{out}
  • Input current I_g

Step 1:

  • Start Simulink either using the MATLAB command window or by clicking the Simulink button on the toolbar
  • Create a new Simulink model file and save it as boost.mdl
  • From the Simulink place 3 instances of constant block located under “commonly used blocks”. Also place a subsystem block as well a scope block.

At this point your model file will look something like fig. 2. Notice that I have renamed the blocks to identify their respective characteristic.

Fig. 2: Initial set up for Boost converter model

Step – 2:

  • Open the Boost converter subsystem block by double clicking on it.

Notice the default connection between in1 and out1. Delete this connection.

  • Add 2 more instances of In1 and 3 more instance of Out1 found under commonly used block
  • Add an instance of subsystem, mux, and demux found under commonly used block
  • Navigate to user-defined functions and add a MATLAB Function block to your model file
  • Go to the continuous library and add 2 instances of integrator block to your model file.

Make the connections as shown in fig.3 and rename your blocks appropriately. Notice that by default mux block has 2 inputs and demux has 2 outputs. This can be changed by double clicking on the respective blocks and changing the number of inputs/outputs

Fig. 3: Boost converter subsystem block

Step – 3:

  • Open the PWM system block, and delete the default connection between In1 and Out1
  • Add a repeating sequence block found under Sources
  • Go to Math library and add a subtract block
  • Finally from the discontinuous library add a relay block and make the necessary connection as shown in fig. 2

Fig. 4: PWM subsystem block

Open the repeating sequence block by double clicking. This block lets you set up switching frequency for the converter as well as the amplitude V_M for the PWM signal. Rather than setting it to some default value, this parameters can be set as variables so that the user has control over changing them for different design.

Fig. 5: Setting parameters in repeating sequence block

Step – 4:

Going back to the user defined function, this is where we will enter the converter state equations. You can refer to the boost converter post to get an in-depth view of how these equations are derived.

When the MOSFET M_1 is on, the behavior of the converter can be captured by the following equations,

v_L = V_g - I_L\left(R_L + R_{on}\right)

i_C = - i_{out}

I_g = i_L

V = v_C - R_{ESR}i_{out}

Similarly, when MOSFET switches off, the equations are

v_L = V_g - I_LR_L - V

i_C = I_L - i_{out}

I_g = i_L

V = v_C + R_{ESR}\left(I_L - i_{out}\right)

Over one switching period T_s, the equations can be combined and represented as follow:

Inductor voltage,

v_L = \left[V_g - I_L\left(R_L + R_{on}\right)\right]*D + \left(V_g - I_LR_L - V\right)\left(1 - D\right)

Capacitor current,

i_C = -i_{out}*D + \left(I_L - i_{out}\right)\left(1 - D\right)

Input current,

I_g = I_L*D + I_L*\left(1 - D\right)

Output voltage,

V = \left[v_C - R_{ESR}i_{out}\right]*D + \left[v_C + R_{ESR}\left(I_L - i_{out}\right)\right]*\left(1 - D\right)

Solving them, the equations simplify to,

v_L = V_g - V\left(1 - D\right) - I_L\left(R_L + R_{on}D\right)

i_C = I_L\left(1 - D\right) - i_{out}

I_g = i_L

V = v_C + R_{ESR}\left[I_L\left(1 - D\right) - i_{out}\right]

The above equations can be entered directly to our MATLAB function. The 5 inputs via mux are stored in an array format. The code should look something as follow:

function y = CCMBoost(u,L,C,RL,Ron,Resr)

% Inputs:
% u = [Vg D iout v_C i_L]
%
% Parameters:
% L, RL, C, Resr, Ron
%
% Outputs:
% y = [dv_C/C di_L/L Vo ig]

Vg = u(1);                  % Input voltage
D = u(2);                   % Switch control
iout = u(3);                % Load current
vC = u(4);                  % Capacitor voltage
iL = u(5);                  % Inductor current

dbar = 1-D;

% State equations
Vo = vC + Resr*((iL*dbar) - iout);          % Output voltage
Ig = iL;                                    % Input current
iC = (iL*dbar) - iout;                      % Capacitor current
vL = Vg - (Vo*dbar) - iL*((Ron*D) + RL);    % Inductor voltage

% Output
y = [iC/C vL/L Vo Ig];

Save the MATLAB function. Now we want the parameters be set as variables so that the user can change them. In order to do so, select edit data/ports under tools as shown in fig. 6

Fig. 6: User function parameters

In the next window, select you will find a list of your I/O ports as well as the parameters specified in the function file. Select the input port u and change it’s size to 5 so that it matches the input array.

Fig. 7: Changing data port u property

Also, change the scope of L, C, R_L, R_{ESR}, and R_{ESR} from input to parameter. This can be done simply by clicking on the respective input and selecting parameter from the drop down menu. At the end, your port manager window should look as follow:

Fig. 8: Port/Data Manager

Going back to the Boost subsystem block, you can set up initial conditions for the inductor current and capacitor voltage. In order to do so, open the capacitor integrator block, and type in a variable name under the initial condition field. Do the same for inductor integrator block as well. I have named them as vC_0 and iL_0.

Fig. 9: Configuring initial condition variable

Now, go back to the starting, open the scope block and open the scope parameters. Under general settings for scope parameters, change the number of axes to 4. Then under history uncheck limit data points to last. Click apply and connect the scope inputs to the boost converter outputs.

Fig. 10: Changing scope setting

Fig. 11: Final connections

Right click on the Boost subsystem block, and select mask subsystem. This will open mask editor where you can create a UI for the user to change the boost converter variables and parameters. In the mask editor, click on parameters tab. Then add all the variables via the add button. Make sure that the variable name matches the ones used within the subsystems. Your final mask window should look something as follow,

Fig. 12: Mask editor

Apply your settings and close the editor window. Now if you try and open the Boost converter subsystem block you will see a dialog box as follow,

Fig. 13: Setting parameters

I have set the parameters as follow:

Input voltage: V_g = 12 V

Required output voltage is 30 V. Hence,

Duty cycle, D = 1 - \frac{V_g}{V} = 1 - \frac{12}{30} = 0.6

Load resistance, R = 50 \Omega

Load current, i_{out} = \frac{V}{R} = \frac{30}{50} = 0.6 A

Switching frequency, f_s = 100 kHz

Inductance L = 120 \mu H

Inductor series resistance R_L = 10 m\Omega

Capacitance C = 50 \mu F

Capacitor series resistance R_{ESR} = 1 m\Omega

Switch on resistance, R_{on} = 10 m\Omega

PWM amplitude V_M = 1

Initial inductor current i_L(0) = 1.5 A

This value for inductor current was obtained using the fact that the average inductor current in a boost converter is given by I_L = \frac{V}{\left(1 - D\right)R}

Initial capacitor voltage v_C(0) = 30 V

You can even leave the initial condition set to 0.

Now that all the parameters are configured, its time to simulate and verify that our model produces the expected result. Save your design and go to configure parameters under simulation. I have set the stop time to 100 ms and step size to 1 \mu s.

Fig. 14: Simulation parameter

Now run the simulation. If everything works out properly, then you will get the following result.

Fig. 15: Simulation result

I hope that it all works out for you. In case it didn’t then you can download this file and rename the extension from Boost.pdf to Boost.mdl and re-run the simulation or figure out your error.

Advertisements

Fundamental of Boost Converter

Among the dc-dc power converters, boost converter topology is used to step-up the input voltage. Depending upon the conversion ratio, the output voltage is either equal to the input or higher than the input. Fig.1 shows the circuit for a boost converter.

Fig. 1: Boost converter circuit

We will make following assumptions while analyzing fig.2 circuit:

  • The converter operates in steady state
  • Inductor current is always positive meaning that the converter operates in continuous conduction mode (CCM)

Circuit when the MOS switch M_1 is ON, is shown in fig. 2 (top). Application of Kirchoff’s voltage and current laws yields following equations:

-V_g + V_L + I_L\left(R_L + R_{on}\right) = 0

V_L = {V_g} - I_L\left(R_L + R_{on}\right)

i_c = -\frac{V}{R}

Fig.2: Top – MOS switch ON (diode in reverse bias)
Bottom – MOS switch OFF (diode conducting)

When the MOS switch is OFF, as shown in fig. 2 (bottom), the energy stored in inductor is getting transferred to the capacitor.

-V_g + V_L + I_LR_L + V = 0

V_L = V_g - V - I_LR_L

i_c = I_L - \frac{V}{R}

Using capacitor charge balance, we know that the average capacitor current over one period in steady state is zero. That is,

\left<i_C\left(t\right)\right>_{avg} = 0

\frac{-V}{R} DT_s + \left(I_L - \frac{V}{R}\right)\left(1-D\right)T_s = 0

Solving the above algebraic equation gives us the average value of the inductor current over one cycle in steady state.

I_L = \frac{V}{\left(1-D\right)R}

Once again applying inductor-volt second balance, we know that the average inductor voltage over one cycle in steady state is zero. That is,

\left<v_L\left(t\right)\right>_{avg} = 0

\left[V_g - I_L\left(R_L + R_{on}\right)\right]DT_s + \left[V_g - V - I_L R_L\right]\left(1-D\right)T_s = 0

V\left(1-D\right) + I_L\left(R_{on}D + R_L\right) = V_g

Substituting for I_L and solving for the output voltage V yields

V = \frac{V_g}{\left(1-D\right) + \frac{R_{on}D + R_L}{\left(1-D\right)R}}

Notice that, if the MOS and inductor are considered to be ideal, then we get the ideal conversion equation:

V = \frac{V_g}{1-D}

Fig. 3: Relationship between duty cycle and output voltage

Fig. 3 shows a plot of duty cycle vs. output voltage using the ideal conversion equation. Here’s the input voltage V_g is taken to be 1V. Notice that when the duty cycle is zero, the output voltage is equal to that of the input voltage. As the duty cycle increases, the output voltage increases as well. Ideally, the output voltage can reach infinity.

Fig. 4: Inductor current waveform (Steady State)

We can now determine the ripple in inductor current as well as the output voltage. As shown in Fig. 4, in steady state, the inductor current changes from I_{min} to I_{max} for 0 \leq t \leq DT_s. The relationship for inductor ripple current is simply given by the line-segment, that is,

2\Delta i_L = (slope)*DT_s

\Delta i_L = \frac{1}{2L}\left[V_g - \frac{V}{\left(1-D\right)R}\left(R_L + R_{on}\right)\right]*DT_s

\Delta i_L = \frac{D}{2Lf_s} \left[V_g - \frac{V\left(R_L + R_{on}\right)}{\left(1 - D\right)R}\right]

Above relationship can be used to determine the inductance L during the design process, if the inductor current ripple constraint is known. The criteria that the converter operates in CCM is that the minimum inductor current stays positive, that is

I_{L,min} \geq 0

I_L - \Delta i_L \geq 0

\frac{V}{\left(1 - D\right)R} \geq \frac{D}{2Lf_s}\left[\frac{V_g\left(1 - D\right)R - V\left(R_L + R_{on}\right)}{\left(1 - D\right)R}\right]

L_{min} \geq \frac{D}{2Vf_s}\left[V_g\left(1 - D\right)R - V\left(R_L + R_{on}\right)\right]

The above relationship determines the minimum value for the inductance such that the converter operates in CCM. Usually, the choosen value of inductance is at least 15 to 20 % greater than L_{min}. This is just to ensure that the converter doesn’t enter into discontinuous mode in the presence of disturbances.

Last but not the least is the output voltage ripple. Using the equations for i_C, we get the plot for capacitor voltage v_C as shown in Fig. 5

Fig. 5: Capacitor voltage waveform (Steady state)

Capacitor voltage ripple = slope * time period

-2\Delta v_C = \frac{-V}{RC} * DT_s

\Delta v_C = \frac{V*D}{2RCf_s}

Above equation determines the selection of the capacitance. Notice that as the switching frequency increase, the capacitance goes down, which makes them ideal to be integrated into ICs.

Interfacing LED to Freescale 9S12

Interfacing LEDs to Freescale’s 9S12 16-bit controller family is quite simple. Here’s my version for it. I hope this is helpful. Click here to download the source code.

Schematic:

System Schematic

Buck Converter – Open Loop Simulink Model

Simulating is a big part of design verification, so this post will deal with creating a model of an open loop synchronous buck converter using MATLAB and Simulink, which can be used to perform transient analysis. The equations governing the operation of a synchronous buck converter shown in fig. 1 are:

\frac{di_L}{dt} = \frac{1}{L}\left(V_g*d - i_L*R_L - v_o\right)

\frac{dv_c}{dt} = \frac{1}{C}\left(i_L - i_o\right)

v_o = v_C + ESR\left(i_L - i_o\right)

Fig. 1: Synchronous Buck Converter

Modelling such a converter using Simulink is quite simple. As shown in fig. 2, the input to model are:

Input voltage,V_g

Duty cycle,d

Load current, i_{load} \left(i_o\right)

Whereas the outputs of the system are:

Voltage across the load, V_o

Inductor current, i_L

Fig. 2: Switching converter model (Fundamentals of power electronics, Robert Erickson)

Simulink Model:

Click my_syncbuck_ol to download the simulink model file, then change the file extension from .pdf to .mdl. From the top level view shown in fig. 3, you can change the values of input voltage, duty cycle, and load resistance according to your system parameters.

Fig. 3: Top Level View

Double clicking on the “Buck converter – open loop” block opens up another window with two more subsystem blocks. Clicking on any of these subsystems will allow you to change their respective parameters. In order to access the underlying lower levels, right click on the block and select “Look under mask” from the menu.

Fig. 4: Mid-level subsystems

  • PWM Subsystem:Allows you to change the switching frequency as well as the amplitude of the PWM ramp signal.

Fig. 5: PWM Subsystem

  • Buck converter Subsystem: Allows you to change the values for inductance and capacitance, along with their parasitic resistances. This is the block where we implement the system equations described earlier.

Fig. 6: Buck Converter Subsystem

Once you have all the parameters setup, you can run the simulation. Fig. 7 shows a screenshot of the simulation result, which can be accessed from the scope block located in the top level view.

Fig. 7: Simulation Result

Fundamentals of Non-Isolated Buck Converter

In dc-dc power converters, buck converter topology is often used to provide a regulated dc voltage to the load. An ideal switch mode buck converter is as shown in Fig. 1

Fig. 1 - Ideal switch model for DC-DC Buck converter

We will make the following assumptions for our analysis:

  • All the components are ideal
  • The converter operates in steady state
  • Capacitor is large enough to hold the output voltage constant
  • Inductor current is always positive, meaning the converter operates in continuous conduction mode (CCM)

Ideal switch can be realized using a MOSFET and a diode as shown in Fig. 2. Once again we will assume that the MOSFET and diode are ideal.

Fig. 2: Switch realization using MOSFET and Diode (top)
MOSFET ON, Diode reverse biased (middle)
MOSFET OFF, Diode forward biased (bottom)

Case I: MOSFET is ON

The diode will be reversed biased. The input voltage appears across the LC filter. The inductor current starts building up and the energy is transfered to charge the capacitor to built an output voltage. Let’s assume that M_1 is ON for time DT_s and OFF for (1-D)T_s=D'T_s, where D is the duty cycle.

Applying KVL across the loop,

-V_g+V_L+V_o=0

V_L=V_g-V_0

L\frac{d}{dt} i_L(t)=V_g-V_0

\frac{d}{dt} i_L(t)=\frac{V_g-V_0}{L}

KCL at the output node gives,

i_L(t) = i_c(t) + \frac{V_0}{R}

i_c(t)=I_L - \frac{V_0}{R}

Case II: MOSFET is OFF

We know that the inductor current cannot go to 0 instantaneously. The energy stored in the inductor is used to keep the voltage constant across the capacitor. Here the diode is forward biased, and thus the loop can sustain the inductor current flow while discharging it. Applying KVL yields,

V_L+V_0=0

V_L=-V_0

L\frac{d}{dt} i_L(t)=-V_0

\frac{d}{dt} i_L(t)=\frac{-V_0}{L}

 Applying KCL yields,

i_c(t)=I_L - \frac{V_0}{R}

The implication of assuming steady state condition is that the inductor current will be periodic. That is,

i(t_0+T)=i(t_0)

Inductor current,

i_L(t_0+T)=\frac{1}{L}\int^T_0 v_L (t) dt + i(t_0)

i_L(t_0+T)-i(t_0)=0=\frac{1}{L}\int^T_0 v_L(t) dt

Multiplying both sides by \frac{L}{T}

\frac{1}{T} \int^T_0 v_L(t) dt=0

Using inductor volt-second balance,

<v_L(t)>_{avg}=0

V_L*DT_s + V_L*(1-D)T_s=0

(V_g-V_0)*D + (-V_0)(1-D)=0

V_gD-V_0=0

V_0=DV_g

Conversion factor (Duty cycle),

D= \frac{V_0}{V_g}

Using capacitor charge balance,

<i_C(t)>_{avg}=0

(I_L-\frac{V_0}{R})*DT_s + (I_L-\frac{V_0}{R})*(1-D)T_s=0

(I_L - \frac{V_0}{R})*D + (I_L - \frac{V_0}{R}) - (I_L - \frac{V_0}{R})*D = 0

I_L-\frac{V_0}{R}=0

Thus, the average inductor current will be,

I_L=\frac{V_0}{R}

Let’s determine the ripple in the inductor current. We know that when M_1 is ON

\frac{d}{dt} i_L(t)=\frac{V_g-V_0}{L}

\frac{\Delta i_L}{\Delta t} = \frac{V_g-V_0}{L}

Since \Delta t corresponds to the time for which the MOSFET is ON, it can be replaced by DT_s. Thus the ripple in the inductor current is,

\Delta i_L=\frac{V_g-V_0}{L}DT_s=\frac{(1-D)V_0}{Lf_s}

Due to this ripple, the inductor current varies from a minimum to a maximum value

I_{L,max} = I_L + \frac{\Delta i_L}{2} = \frac{V_0}{R} + \frac{(1-D)V_0}{2Lf_s}

I_{L,min} = I_L - \frac{\Delta i_L}{2} = \frac{V_0}{R} + \frac{(1-D)V_0}{2Lf_s}

Fig. 3: Capacitor current waveform (top)
Inductor current waveform (bottom)

Similarly, the output voltage across the capacitor has a ripple imposed over it’s average value. This output voltage ripple is then determined using the charge equation for the capacitor. We know that the charge stored by a capacitor is given by,

q = C\Delta V

\Delta V = \frac{q}{C}

The change in capacitor voltage is attributed to the total positive charge stored by the capacitor. Looking at the capacitor current waveform in Fig. 3 we can determine the +ve charge stored by the capacitor, which is simply the area under the triangle.

\Delta Q = \left (\frac{1}{2}\right ) \left (\frac{\Delta i_L}{2}\right ) \left (\frac{T_s}{2}\right )

\Delta Q = \frac{1}{8} \left (\frac{(1-D)V_0}{Lf_s^2}\right )

Hence, the output voltage ripple is

\Delta V_0 = \frac{(1-D)V_0}{8LCf_s^2}

Using above equation we can make a good selection for the capacitance remembering that we want the capacitor to be as large as possible since its impedance will be negligible as compared to the load at higher operating frequencies, forcing majority of the inductor current ripple to bypass via the capacitor rather than the load. Similarly, we would want to choose inductor appropriate to required operation. One criteria that we might look at for CCM is that the inductor current must be positive. What if i_L goes to zero? In this case, we can write

I_{L,min} = 0

\frac{V_0}{R}=\frac{(1-D)V_0}{2L_{min} f_s}

L_{min} = \frac{(1-D)R}{2f_s}

The above result gives the minimum value of inductance so that the inductor current remains positive. In practice, one would like to choose inductance value 10 or 20 times higher than L_{min}. I will try to go over a design example for buck converter in upcoming posts.