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.
Inputs the converter model are:
- Input voltage
- Voltage control (duty cycle)
- Load current
- Capacitor voltage
- Inductor current
- Output voltage
- Input current
- 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.
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
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
Open the repeating sequence block by double clicking. This block lets you set up switching frequency for the converter as well as the amplitude 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.
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 is on, the behavior of the converter can be captured by the following equations,
Similarly, when MOSFET switches off, the equations are
Over one switching period , the equations can be combined and represented as follow:
Solving them, the equations simplify to,
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
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.
Also, change the scope of and 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:
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.
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.
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,
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,
I have set the parameters as follow:
Required output voltage is . Hence,
Inductor series resistance
Capacitor series resistance
Switch on resistance,
Initial inductor current
This value for inductor current was obtained using the fact that the average inductor current in a boost converter is given by
Initial capacitor voltage
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 and step size to .
Now run the simulation. If everything works out properly, then you will get the following 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.