You are on page 1of 6

DEPARTMENT OF CHEMICAL ENGINEERING

University of California, Santa Barbara

ChE 152B Winter 2016

Simulink Guide

Getting Started

1. Open MATLAB. Type the word simulink into the command window and hit enter.

2. The Simulink Library Browser will appear. Click FileNewModel. Or click the white
document icon directly below File.

3. The window that appears is where you will build your Simulink model. You can drag
blocks from the Simulink Library Browser to the model window and they will appear there.

Building a Model

Simulink is used to build and simulate block diagram models. For this class, the following types
of blocks will be useful. Once you place a block in your model, you can double click it to change
its settings.

1. Sources: Source blocks provide inputs to your block diagram. To access these blocks, click
on Sources in the left panel of the Simulink Library Browser. Important source blocks are:
a. Constant: Use this to provide a constant input (ex. a constant set point).

b. Step: Use this to do a step test in set point or disturbance. Once you place the block
in your model, you can double click it to change the settings.
2. Continuous: The blocks under this category are useful for simulating continuous transfer
functions and controllers (such as the ones studied in this class). To access these blocks,
click on Continuous in the left panel of the Simulink Library Browser. Important blocks
are:
a. Transfer Function: Use this block to add any transfer function block (process,
disturbance, measurement device, etc). After double clicking the block, follow the
instructions to enter your specific transfer function. For example, to enter the
transfer function 5/(2s+1) you would enter [5] as the numerator coefficient and [2
1] as the denominator coefficients.
b. PID Controller: While you should be able to create a PID controller using transfer
function blocks, you can also use this block as a shortcut. Once you place the block,
double click it to enter the controller parameters. BE CAREFUL that you look at
the equation for the controller and make sure to find what P, I, and D correspond to
in terms of the controller parameters we are familiar with (hint: look at the Laplace
domain form of the PID controller).

c. Transport Delay: You may have noticed that the transfer function block has no
place to put delays. To add a delay to your transfer function, you will need to use
the transport delay block. This block can be placed before or after the transfer
function. Double click the block to change the length of the delay.

3. Math Operations: This category of blocks provides addition and multiplication of signals.
Blocks you will need from this category:
a. Add: This block can be used to add or subtract two inputs. By default it adds them,
but you can double click the block and change the second sign to a minus sign to
subtract the second input from the first. This block is useful when implementing a
feedback control loop (you need to subtract the measurement from the set point).
b. Gain: This block multiplies the input signal by a constant value. You can use this
block if a transfer function that you want to enter is a constant value (ex. Gv=5 in
problem 16.1 of the textbook). You can also use this block for a proportional-only
controller by entering Kc into the gain block.

4. Sinks: These blocks are used to provide an outlet for your simulation results. Useful blocks
here are:
a. Scope: Scope will provide a real-time plot of a signal as the simulation runs. These
are useful for quickly viewing the results of the simulation, but should not be used
as final plots to submit with homework or lab reports.

b. To Workspace: This block will send the signal to the workspace. Double click the
block to change the name of the variable that will appear in the workspace. There
are two recommended types of save format.
i. Array: This will save the signal in an array but will not include the time.

ii. Structure with Time: This will save the signal in a structure along with the
corresponding time. The actual signal will be under simout.signals.values
and the time will be under simout.time. Note that simout is replaced with
whatever variable name you choose.

Example of a Complete Model

This is an example of a complete model in Simulink.


Running a Simulation

Once your model is complete, you can run the simulation. Change the length of the simulation in
the toolbar next to the play and stop buttons (where it says 60 in the above example). The time
units are the same as the units of the time constants you have used. For example, if your time
constants are in minutes, then the time units are in minutes, so the above simulation would run for
a simulated 60 minutes (will only take seconds to run in reality).

To run the simulation, click on the play button. If you have a scope and want to see the results as
the simulation is running, double click on the scope and have its window visible before pressing
play. The scope from running this simulation is shown on the next page.

Tips and Tricks

To connect blocks, click and drag from the output port of one block to the input port of the
next block.
To make a branch off of an existing connection (such as between the Add1 block and the
Scope in the above example) hold control while clicking on the line and drag to where you
want the signal to go (for example, the To Workspace block in the example above).
To reverse the direction of a block, click on the block and then press CTRL+I. This is how
the Transfer Fcn1 block is reversed in the above diagram.
Click the binoculars icon on the scope to autoscale to the data.
To combine two signals into one (for example, to display two signals in the same scope)
use the Mux block, which is under the Signal Routing category.
Switches are useful blocks if you want to switch between different inputs without having
to connect and disconnect blocks over and over again. Use the Manual Switch under the
Signal Routing category for this purpose. Double click the block to change which input
will pass through. An example of Mux and Switch blocks is shown below.

You might also like