Download as pdf or txt
Download as pdf or txt
You are on page 1of 82

SIMULINK

SIMULINK

SIMULINK





Subsystems
simulink Debugger
Simulink Accelerator

S-function
S-function M-files
S-function C++ codes

SIMULINK
: Simulink

Simulink
.
simulink



simulink
.
SIMULINK Model-Based Design

nonlinear
.
Demo
.
simulink graphical user interface
)(GUI


S-function .
simulation
simulation non-real time
real time
Xpc Target Real Time Workshop .
Simulation
Simulation
Toolboxs .

: Building a Model

signal generator
signals
square wave.
Transfer function

Scope
Simulation

Mux block
signal scope
:


::
simulink
:

>>simulink



Signal generator

simulink

sources

signal generator


: scope
1 simulink 2 sinks3 scope

: transfer function
simulink
continuous
transfer function

:: Mux block
simulink
Signal Routing
Mux

::


::

node


ctrl
.

:


+
+
.


Configuring the Model

:: double click signal generator


::


Transfer function


Simulation

simulation 10

: start simulation :


start simulation double click Scope
Simulation square
wave 10

:
.
.



Block Diagram

(nonvirtual block and virtual blocks) .

.

" "time-based block diagram


1 )(state variables block diagram time
step .
2 .3 .

1 built-in blocks2 custom blocks User-defined

States


states : Discrete continuous
.
intervals .
States

continuous states :
Integrator


State-Space

State-Space
Transfer Fcn

transfer function
Zero-Pole

transfer function
zero-pole-gain S .

Continuous States


.
.
Discrete States


update functions
.

Modeling Hybrid Systems

.
Block Parameters
Parameter
Parameters .
.
A tunable parameter
recompiling
parameters .

Block Sample Times


continuous sample time .



implicit sample time

fundamental sample time of the inputs

.
An implicit discrete sample time
.
Systems and Subsystems
subsystem
virtual and nonvirtual
Subsystems
.
Block Methods

:
Outputs

Update

Derivatives

::
BlockType.MethodType


Start Simulation

Model Compilation
executable form
:
1 block parameter expressions
2 3 attribute propagation
4 optimizations
5 hierarchy
6 block sorted order
7 Sample Time
: Link Phase

: Simulation Loop Phase

:
1- Loop Initialization phase

2- Loop Iteration phase

1 2-

3 zero-crossing detection
( (
4 .


successive states

solvers

1- Fixed-step solvers
step
size step size .
2- Variable-step solvers

.
Solvers
1- Continuous solvers

.
2- Discrete solvers

Zero-Crossing Detection


.


.

.

Algebraic Loops


direct feedthrough
:
The Math Function block
The Gain block
The Integrator block's initial condition ports
The Product block

The State-Space block when there is a nonzero D matrix


The Sum block
The Transfer Fcn block when the numerator and denominator are of the same
order
The Zero-Pole block when there are as many zeros as poles
algebraic loop
direct feedthrough
:

z = u z z = u/2

Algebraic Constraint
algebraic loop

Modeling and Simulating Discrete


Systems


) (sampled data (multirate
)systems - ) (hybrid systems ::

1- SampleTime block parameter


block parameter Sample Time explicit implicit
implicit .
2- Sample-time inheritance

.

Determining Step Size for Discrete Systems


step size
sample time hits
fundamental sample time
fundamental sample time sample time:
sample times 0.25 0.5
fundamental sample time 0.25

solver

variable-step discrete
fixed-step
fixed-step simulation step size fundamental sample time
variable-step solver step size sample time
hits.
:

Sample Time Propagation



::

gain
::
1 2

Constant Sample Time

::

::
1 parameters nontunable2 ) (inf .



Tunable Parameters
Sample Time Propagation

::
.mdl
::

Model Editor
::

1- Menu Bar


2- Toolbar



3- Canvas
block diagram

4- Status Bar

Updating a Block Diagram


signal
data types sample times Updating a
Block Diagram

Edit Update Diagram
Ctrl+D ..

Format
Port/Signal Displays



ode45


ode3
:: M-file
:

function new_model(arab_eng)
% NEW_MODEL Create a new, empty Simulink model
% NEW_MODEL('MODELNAME') creates a new model with
% the name 'MODELNAME'. Without the 'MODELNAME'
% argument, the new model is named 'my_untitled'.
% the model name is arab_eng
if nargin == 0
arab_eng = 'arab_eng';
end
% create and open the model
open_system(new_system(arab_eng));
% set default screen color
set_param(arab_eng, 'ScreenColor', 'blue');
% set default solver
set_param(arab_eng, 'Solver', 'ode3');
% set default toolbar visibility
set_param(arab_eng, 'Toolbar', 'off');
% save the model
save_system(arab_eng);



Format Foreground color
Background color Screen color

set_param


RGB

::

::
:

;)'set_param(arab_eng, 'ScreenColor', 'blue

)']set_param(arab_eng, 'ScreenColor', '[0.3, 0.9, 0.5


Sample Time

Format Sample Time Colors


Update Diagram Edit .

Annotating


Annotation
Properties ::

M function Annotation

Using TeX Formatting Commands in


Annotations
TeX Formatting

1 annotation Enable
TeX Commands ::

TeX
::


\alphara\beta-\iteng


Creating Subsystems

simulink & ports
subsystems subsystem ::

::

::

input
outport

::

::



create subsystem

::

Model Navigation Commands



Simulink Model Browser
::
Open Block

edit open block ::

Open Block In New Window



::

Go To Parent


::

Window Reuse


File Preferences Window reuse
type ::

::

Controlling Access to Subsystems




subsystem's parameter

::

Read/Write permissions
ReadOnly
NoReadOrWrite
ReadWrite

Creating Conditionally Executed


Subsystems

control signal

Enabled Subsystems
Triggered Subsystems.
Triggered and Enabled Subsystems
A control flow subsystem

::: Enabled Subsystems



scalar vector



sine wave

Enable block Ports & Subsystems


subsystem :



::


::

Output when disabled



Held

Reset
Initial
output .

Enable block ::

States when enabling


Held

Reset


Outputting the Enable Control Signal.
scope
Zero-Crossing Detection

Triggered Subsystems
Trigger
trigger input

Trigger
Rising

Falling

Either

:


trigger .
trigger R F
3 trigger


ports & subsystems
trigger
:

trigger
:

triggered subsystems
enabled subsystems


Function-Call Subsystems
S-function
.
::
Trigger
) (-1

.
::

trigger

:: Triggered and Enabled


Subsystems

trigger
enabled ::


::

::


sine wave trigger step
input
.
pulse 10
50% duty cycle
enable
trigger

sine trigger
.

Creating Alternately Executing


Subsystems
merge

full-wave rectifier
:

::

Conditional Execution Behavior



Switch Multiport Switch

)conditional execution (CE


behavior.
:

simulation format
Block displays
sorted order ::

simulation
:

X:Y
X layer
X=0
Y :


Pulse generator
constant subsystem gain scope X
Y
1- Pulse generator
2- constant
3- subsystem
4- gain
5- scope
subsystem } 0:2{1

::

1:0


subsystem
Subsystem parameters


Propagate execution context across subsystem boundary


gain

:

constant gain

1- constant
2- subsystem
3- gain
Conditional Execution Behavior
CE behavior

Propagating Execution Contexts

execution context
.

execution context .
execution context
:
1 2

3 testpoint
4 execution context
5 multirate block6 sample time execution context
execution context

Switch

execution context

.

:: conditional
execution behavior
Configuration Parameters Optimization
Conditional input branch execution
::
Propagate execution context across subsystem boundary
triggered subsystem


subsystem's execution context


Propagate
execution context
format Block Displays
Execution Context Indicator

Referencing Models
.
model
simulink

Ports & subsystems


instance
.
S-function the referenced
model's simulation target .

simulation target .
Referencing Referencing
root model
- model parent
parent Referencing

Global data
global data
.
Model Referencing Subsystems
Model Referencing Subsystems .
1- Modular development

2- Inclusion by reference

.
3- Incremental loading
.
4- Incremental code generation
Real-Time Workshop
stand-alone applications binaries
binaries .
Subsystems Model Referencing
.
Model Reference

Creating a Model
Reference

set path
::
Inline parameters optimization

simulation
configuration parameters
optimization Inline parameters

model

ref1 :

model
::

ref1
solver
Fixed step

edit model reference parameters
step scope
::



global tunable parameters


global tunable parameters.
.

Using Model Arguments


Model Arguments
reference
Counter reference
:
1- Declare model workspace variables that determine the
model's behavior as model arguments
workspace workspace

global nontunable parameters
global tunable parameters
2- Assign values to the model arguments in each reference to
the parameterized model

Model Arguments
view
model explorer
::

model workspace ::

workspace
workspace add MATLAB
variable

counter
1
::

Model Arguments
::

Model block's parameter


edit
Model Argument ::

::
counter
!
Model Block Sample Times


simulation target

1 ) )2 3 4 fixed-step solver fixed step size5 sample time propagation triggered sample
time
6

Triggered subsystem
Function call
iterator subsystem


.
Blocks That Preclude Sample-Time Inheritance


simulation target
simulation target
default

Discrete-Time Integrator
)From Workspace (if it has input data that contains time
)Probe (if probing sample time
Rate Limiter
Sine Wave

::
model

Referenced Model I/O
model:
Bus I/O Limitations
bus
1 bus object2 bus object workspace
3 bus Bus Creator blockIndex I/O Limitations

:

0 - or 1- based indexing

for
:

0- or 1-based indexing


Matching I/O Rates
rate
Building Simulation Targets
Simulation Targets S-function

simulation targets
updating the model's diagram edit slbuild .

.
targets
.

slprj
Simulink Accelerator Real-Time Workshop

Function-Call Models

Function-Call Generator
function-call model.

trigger trigger function
call Model
function call controller
ports & subsystem
model
simulation configure parameters
solver fixed step
Periodic sample time constraint
Ensure sample time independent
scalar
:

Browsing Model Reference Dependencies



Tools Model Reference Graph

view_mdlrefs

Converting Subsystems to Model References



Convert to Model Block atomic subsystem

You might also like