Mathworks SIMELECTRONICS 1 user guide

SimElectronics
User’s Guide
®
1
How to Contact The MathWorks
www.mathworks. comp.soft-sys.matlab Newsgroup www.mathworks.com/contact_TS.html Technical Support
suggest@mathworks.com Product enhancement suggestions
bugs@mathwo doc@mathworks.com Documentation error reports service@mathworks.com Order status, license renewals, passcodes
info@mathwo
com
rks.com
rks.com
Web
Bug reports
Sales, prici
ng, and general information
508-647-7000 (Phone)
508-647-7001 (Fax)
The MathWorks, Inc. 3 Apple Hill Drive Natick, MA 01760-2098
For contact information about worldwide offices, see the MathWorks Web site.
®
SimElectronics
© COPYRIGHT 2008–20 10 by The MathWorks, Inc.
The software described in this document is furnished under a license agreement. The software may be used or copied only under the terms of the license agreement. No part of this manual may be photocopied or reproduced in any form without prior written consent from The MathW orks, Inc.
FEDERAL ACQUISITION: This provision applies to all acquisitions of the Program and Documentation by, for, or through the federal government of the United States. By accepting delivery of the Program or Documentation, the government hereby agrees that this software or documentation qualifies as commercial computer software or commercial computer software documentation as such terms are used or defined in FAR 12.212, DFARS Part 227.72, and DFARS 252.227-7014. Accordingly, the terms and conditions of this Agreement and only those rights specified in this Agreement, shall pertain to and govern theuse,modification,reproduction,release,performance,display,anddisclosureoftheProgramand Documentation by the federal government (or other entity acquiring for or through the federal government) and shall supersede any conflicting contractual terms or conditions. If this License fails to meet the government’s needs or is inconsistent in any respect with federal procurement law, the government agrees to return the Program and Docu mentation, unused, to The MathWorks, Inc.
Trademarks
MATLAB and Simulink are registered trademarks of The MathWorks, Inc. See
www.mathworks.com/trademarks for a list of additional trademarks. Other product or brand
names may be trademarks or registered trademarks of their respective holders.
Patents
The MathWorks products are protected by one or more U.S. patents. Please see
www.mathworks.com/patents for more information.
Revision History
April 2008 Online only New for Version 1.0 (Release 2008a+) October 2008 Online only Revised for Version 1.1 (Release 2008b) March 2009 Online only Revised for Version 1.2 (Release 2009a) September 2009 O nline only Revised for Version 1.3 (Release 2009b) March 2010 Online only Revised for Version 1.4 (Release 2010a)
User’s Guide
Getting Started
1
Product Overview ................................. 1-2
Product Description Assumptions and Limitations Modeling Physical Networks with SimElectronics
Blocks
Getting Online Help
........................................ 1-3
............................... 1-2
....................... 1-2
............................... 1-3
Contents
Required and Related Products
Product Require ments Other Related Products
SimElectronics Block Libraries
Overview of SimElectronics Libraries Opening SimElectronics Libraries
Product Workflow
Example — Modeling a DC Motor
Overview o f DC Motor Example Selecting Blocks to Represent System Components Building the Model Specifying Model Parameters Configuring the Solver Parameters Running the Simulation and Analyzing the Results
Example — Modeling a Triangle Wave Generator
Overview o f Triangle Wave Generator Ex am ple Selecting Blocks to Represent System Components Building the Model Specifying Model Parameters Configuring the Solver Parameters Running the Simulation and Analyzing the Results
............................. 1-5
............................ 1-5
................................. 1-10
................................ 1-12
................................ 1-27
..................... 1-5
..................... 1-6
................. 1-6
.................... 1-6
................... 1-11
...................... 1-11
........................ 1-15
................... 1-21
......... 1-25
........................ 1-29
................... 1-37
...... 1-11
..... 1-22
..... 1-25
...... 1-25
..... 1-38
iii
Modeling an Electronic System
2
Modeling Electronic Components ................... 2-2
Parameterizing Blocks Additional Parameterization Workflows Adding SimElectronics Blocks to a Model Connecting Model Blocks Selecting the Output Model for Logic Blocks
............................. 2-2
............... 2-15
.............. 2-16
........................... 2-17
........... 2-18
Working with Simulink Blocks
Modeling Instantaneous Events Using Simulink Blocks to Model Physical Components
...................... 2-22
...................... 2-22
Simulating an Electronic System
3
Selecting a Solver ................................. 3-2
Available Solvers How to Select a Solver
Specifying Simulation Accuracy/Speed Tradeoff
Parameters that Affect Accuracy and Speed Determining Appropriate Accuracy/Speed Parameter
Values
Avoiding Simulation Issues
General Troubleshoo ting for Simscape Models Troubleshooting for Simscape Models that Include
SimElectronics Blocks
........................................ 3-3
.................................. 3-2
............................. 3-2
...... 3-3
............ 3-3
......................... 3-5
.......... 3-5
........................... 3-5
... 2-22
iv Contents
Running a Time-Domain Simulation
Running a Small-Signal Frequency-Domain
Analysis
Linearizing SimElectronics Models Analyzing Small-Signal Behavior Using Bode Plots
........................................ 3-7
................ 3-6
................... 3-7
...... 3-7
Examples
A
Examples ......................................... A-2
Index
v
vi Contents
Getting Started
“Product Overview” on page 1-2
“Required and Related Products” on page 1-5
“SimElectronics Block Libraries” on page 1-6
“Product Workflow” on page 1-10
“Example — Modeling a DC Motor” on page 1-11
“Example — Modeling a Triangle Wave Generator” on page 1- 2 5
1
1 Getting Started
Product Overview
Product Description
SimElectronics®software works with Simscape™ software and extends the physical modeling capabilities of the Simulink for modeling and simulating electromechanical and electronic systems. It contains blocks that let you model electromechanical and electronic systems at a speed and level of fidelity that is appropriate for system-level analysis. The blocks let you perform tradeoff analyses to optimize system design, for example, by testing various algorithms with different circuit implementations.
In this section...
“Product Description” on page 1-2
“Assumptions and Limitations” on page 1-2
“Modeling Physical Networks with SimElectronics Blocks” on page 1-3
“Getting Online Help” on page 1-3
®
product family with tools
1-2
Assumptions and Limitations
Use SimElectronics with Simscape to simulate electromechanical and electricalsystemsinthetimedomain. Itcontainsblocksthatyoucanuse with other Simscape blocks to simulate components at a system level. The library contains blocks that use either high-level or more detailed models to simulate components. SimElectronicsdoesnothavethecapabilityto:
Model large circuits with dozens of analog components, such as a complete
transceiver.
Perform either layout (physical design) tasks, or the associated
implementation tasks such as layout versus schematic (LVS), design rule checking (DRC), parasitic extraction, and back annotation.
Model 3-D parasitic effects that are typically important for high-frequency
applications.
For these types of requirements, you must use an EDA package specifically designed for the implementation of analog circuits.
Product Overview
Another MathWorks™ p roduct, SimPowerSystems™ software, is better suited for power system networks where:
The underlying equations are predominantly linear (e.g., transmission
lines and linear machine models).
Three-phase motors and generators are used.
SimPowerSystems has blocks and solvers specifically designed for these types of applications.
Modeling Physical Networks with SimElectronics Blocks
SimElectronics is part of the Simulink Physical Modeling family . Models using SimElectronics are essentially Simscape block diagrams. To build a system-level model with electrical blocks, use a combination of SimElectronics blocks and other Simscape and Simulink blocks. You can connect SimElectronics blocks directly to Simscape blocks. You can connect Simulink blocks through the Simulink-PS Converter and PS-Simulink Converter blocks from the Simscape Utilities library. These blocks convert electrical signals to and from Simulink mathematical signals. For more information about connecting different types of blocks, see “Connecting Model Blocks” on page 2-17.
For more information about basic principles to follow when building an electrical model with SimElectronics, see “Basic Principles of Modeling Physical Networks” in the Simscape documentation.
Getting Online Help
Using the MATLAB Help System for Documentation and Demos
The MATLAB®Help browser allows you to access the documentation and demo models for all the MATLAB and Simulink based products that you have installed. Consult “Overview of Help” in MATLAB documentation for more information about the Help system.
1-3
1 Gettin g Started
For...
List of blocks “Block Reference”
Advanced tutorials
Product demonstrations
What’s new in this product
See...
Examples
SimElectronics Demos
Release Notes
The MathWorks Online
Point your Internet brow ser to the MathWorks Web site for additional information and support at http://www.mathworks.com/products/simelectronics/.
1-4
Required and Related Products
Product Requirements
SimElectronics software is an extension of Simscape product, expanding its capabilities to model and simulate electronic and electromechanical elements and devices.
SimElectronics software requires these products:
MATLAB
Simulink
Simscape
Other Related Products
The SimElectronics product page at the MathWorks Web site lists the toolboxes and blocksets that extend the capabilities of MATLAB and Simulink. These products can enhance your use of SimElectronics software in various applications.
Required and Related Products
For more information about The MathWorks™ software products, see:
The online documentation for that product if it is installed
The MathWorks Web site at
www.mathworks.com
1-5
1 Gettin g Started
SimElectronics Block Libraries
In this section...
“Overview of SimElectronics Libraries” on page 1-6
“Opening SimElectronics Libraries” on page 1-6
Overview of SimElectronics Libraries
SimElectronics libraries provide blocks for modeling electromechanical and electrical systems within the Simulink environment. You can also create custom components either by combining SimElectronics components as Simulink subsystems, or by using the Simscape language.
Note SimElectronics follows the standard Simulink conventions where block inputs and outputs are called ports. In SimElectronics, each port represents a single electrical terminal.
1-6
A SimElectronics model can contain blocks from the standard SimElectronics library, from the Simscape Foundation and Utilities libraries, or from a custom library you create, using the Simscape language, based on the Simscape Foundation electrical domain. A model can also include Simulink blocks and blocks from other products, such as those described in “Required and Related Products” on page 1-5.
For more information on modeling physical and electrical components, see “Modeling Electronic Components” on page 2-2.
Opening SimElectronics Libraries
There are two ways to access SimElectronics blocks:
“Using the Simulink Library Browser to Access the Block Libraries” on
page 1-7
“Using the Command Prompt to Access the Block Libraries” on page 1-8
SimElectronics®Block Libraries
Using the Simulink Library Browser to Access the Block Libraries
You can access the blocks through the Simulink Library Browser. To display the Library Browser, click the Library Browser button in the toolbar of the MATLAB desktop or Simulink model window:
Alternative Then expand t
ly, you can type
simulink in the MATLAB Command Window.
he Simscape entry in the contents tree.
1-7
1 Gettin g Started
1-8
ore information on using the Library Browser, see “Library Browser” in
For m
imulink Graphical User Interface documentation.
the S
Using the Command Prompt to Access the Block Libraries
therwaytoaccesstheblocklibrariesistoopenthemindividuallyby
Ano
ng the command prompt:
usi
SimElectronics®Block Libraries
To open just the SimElectronics library, type elec_lib in the MATLAB
Command Window.
To open the Simscape library (to access the utility blocks, as well as
electrical sources, sensors, and other Foundation library blocks), type
simscape in the MATLAB Command Window.
To open the main Simulink library (to access generic Simulink blocks), type
simulink in the MATLAB Command Window.
The SimElectronics library window is showninthefollowingfigure. Each icon in the window represents a library. Some of these libraries contain second-level sublibraries. Double-click an icon to open the corresponding library.
1-9
1 Gettin g Started
Product Workflow
When you analyze an electronic or electromechanical system using SimElectronics software, your workflow might include the following tasks:
1 Create a S imulink model that includes electronic or electromechanical
2 Define component data by specifying electrical or mechanical properties
3 Configure the solver options.
components.
In the majority of applications, it is most natural to model the physical system using Simscape and SimElectronics blocks, and then develop the controller or signal processing algorithm in Simulink.
For more information about modeling the physical system, see “Modeling Electronic Components” on page 2-2.
as defined on a datasheet.
1-10
For more information about the settingsthatmostaffectthesolutionofa physical system, see Chapter 3, “Simulating an Electronic System”.
4 Run the simulation.
For more information on how the product performs time-domain simulation of an electronic system, see “Running a Time-Domain Simulation” on page 3-6.
Example — Modeling a DC Motor
In this section...
“Overview of DC Motor Example” on page 1-11
“Selecting Blocks to Represent System Components” on page 1-11
“Building the Model” on page 1-12
“Specifying Model Parameters” on page 1-15
“Configuring the Solver Parameters” on page 1-21
“Running the Simulation and Analyzing the Results” on page 1-22
Overview of DC Motor Example
In this example, you model a DC motor driven by a constant input signal that approximates a pulse-width modulated signal and look at the current and rotational motion at the motor output.
Example — Modeling a DC Motor
To see the completed model, open the Controlled DC Motor demo.
Selecting Blocks to Represent System Components
Select the blocks to represent the input signal, the DC motor, and the motor output displays.
The follow ing table describes the role of the blocks that represent the system components.
Block Description
Solver Configuration
DC Voltage Source Generates a DC signal.
Controlled PWM Voltage
H-Bridge
Defines solver settings that apply to all physical modeling blocks.
Generates the signal that approximates a pulse-width modulated motor input signal.
Drives the D C motor.
1-11
1 Gettin g Started
Block Description
Current Sensor Converts the electrical current that drives the motor
into a physical signal proportional to the current.
Ideal Rotational Motion Sensor
DC Motor Converts input electrical signal into mechanical
PS-Simulink Converter
Scope
Electrical Reference
Mechanical Rotational Reference
Converts the rotational motion of the motor into a physical signal proportional to the motion.
motion.
Converts the input physical signal to a Simulink signal.
Displays motor current and rotational motion.
Provides the electrical ground.
Provides the mechanical ground.
Building the Model
Create a Simulink model, add blocks to the model, and connect the blocks.
1 Create a model.
If you are new to Simulink, see the “Creating a Simulink Model” example for information on how to create a model.
1-12
2 Add to the model the blocks listed in the following table. The Library
column of the table specifies the hierarchical path to each block.
Block Library Path Quantity
Solver Configuration
DC Voltage Source
Simscape > Utilities
Simscape > Foundation Library > Electrical > Electrical Sources
1
1
Example — Modeling a DC Motor
Block Library Path Quantity
Controlled PWM Voltage
H-Bridge
Simscape > SimElectronics > Actuators & Drivers > Drivers
Simscape > SimElectronics > Actuators
1
1
& Drivers > Drivers
Current Sensor
Simscape > Foundation Library > Electrical > Electrical
1
Sensors
Ideal Rotational Motion
Simscape > Foundation Library > Mechanical > Mechanical Sensors
1
Sensor
DC Motor Simscape > SimElectronics > Actuators
1
& Drivers > Rotational Actuators
PS-Simulink
Simscape > Utilities
2
Converter
Scope Simulink > Commonly Used Blocks
Electrical Reference
Simscape > Foundation Library > Electrical > Electrical
2
1
Elements
Mechanical Rotational Reference
Simscape > Foundation Library > Mechanical > Rotational Elements
1
1-13
1 Gettin g Started
Note You can use the Simscape function ssc_new with a domain type of
electrical to create a Simscape model that contains the following blocks:
Simulink-PS Converter
PS-Simulink Converter
Scope
Solver Configuration
Electrical Reference
This function also selects the Simulink
3 Connect the blocks as shown in the following figure.
ode15s solver.
1-14
Now you are ready to specify block parameters.
Example — Modeling a DC Motor
Specifying Model Parameters
Specify the following parameters to represent the behavior of the system components:
“Model Setup Parameters” on page 1-15
“Motor Input Signal Parameters” on page 1-15
“Motor Parameters” on page 1-18
“Current Display Parameters” on page 1-19
“Torque Display Parameters” on page 1-20
Model Setup Parameters
The following blocks specify model inform ation that is not specific to a particular block:
Solver Configuration
Electrical Reference
Mechanical Rotational Reference
As with Simscape models, you must include a Solver Configuration block in each topologically distinct physical network. This example has a single physical network, so use one Solver Configuration block with the default parameter values.
You must include an Electrical Reference block in each SimElectronics network. You must include a M echanical Rotational Reference block in each network that includes electromechanical blocks. These blocks do not have any parameters.
For more information about using reference blocks, see “Grounding Rules” in theSimscapedocumentation.
Motor Input Signal Parameters
You generate the motor input signal using three blocks:
The DC Voltage Source block generates a constant signal.
1-15
1 Gettin g Started
The Controlled PWM Voltage block generates a pulse-width modulated
signal.
The H-Bridge block drives the motor.
In this example, all input ports of the H-Bridge block except the PWM port are connected to ground. As a result, the H-Bridge block behaves as follows:
When the motor is on, the H-Bridge block connects the motor terminals
to the power supply.
When the motor is off, the H-Bridge blo ck acts as a freewheeling diode to
maintain the motor current.
In this example, you simulate the motor with a constant current whose value is the average value of the PWM signal. By using this type of signal, you set up a fast simulation that estimates the motor behavior.
1 Set the DC Voltage Source block parameters as follows:
Constant voltage =
2 Set the Controlled PWM Voltage block parameters as follows:
PWM frequency =
2.5
4000
1-16
Example — Modeling a DC Motor
Simulation mode = Averaged
This value tells the block to generate an output signal whose value is the average value of the PWM signal. Simulating the motor with an averaged signal estimates the motor behavior in the presence of a PWM signal. To validate this approximation , use value of
PWM for this
parameter.
3 Set the H-Bridge block parameters as follows:
1-17
1 Gettin g Started
Simulation mode = Averaged
This value tells the block to generate an output signal whose value is the average value of the PWM signal. Simulating the motor with an averaged signal estimates the motor behavior in the presence of a PWM signal. To validate this approximation , use value of parameter to validate this approximation.
PWM for this
1-18
r Parameters
Moto
Configure the block that models the motor.
Set the Motor block parameters as follows, leaving the unit settings at their default values where applicable:
Electrical Torque tab:
Example — Modeling a DC Motor
- Model parameterization = By rated power, rated speed &
no-load speed
- Armature inductance = 0.01
- No-load speed = 4000
- Rated speed (at rated load) = 2500
- Rated load (mechanical power) = 10
- Rated DC supply voltage = 12
Mechanical tab:
- Rotor inertia = 2000
- Rotor damping = 1e-06
Current Display Parameters
Specify the parameters of the blocks that create the motor current display:
Current Sensor block
PS-Simulink Converter1 block
Scope1 block
Of the three blocks, only the PS-Simulink Converter1 b lock has parameters. Set the PS-Simulink Converter1 block Output signal unit parameter to indicate that the block input signal has units of amperes.
A to
1-19
1 Gettin g Started
Torque Di
Specify the parameters of the blocks that create the motor torque display:
Ideal Rotational Motion Sensor block
PS-Simulink Converter block
Scope block
Of the three blocks, only the PS-Simulink Converter block has parameters you need to configure for this example. Set the PS-Simulink Converter block Output signal unit parameter to has units of revolutions per minute.
Note You must type this parameter value. It is not available in the drop-down list.
splay Parameters
rpm to indicate that the block input signal
1-20
Example — Modeling a DC Motor
Configuring the Solver Parameters
Configure the solver parameters to use a continuous-time s olver because SimElectronics m odels only run with a continuous-time solver. Increase the maximum step size the solver can take so the simulation runs faster.
1 In the model window, select Simulation > Configuration Parameters
to open the Configuration Parameters dialog box.
2 Select
3 Enter 1 for the Max step size parameter value.
4 Click OK.
ode15s (Stiff/NDF) from the Solver list.
1-21
1 Gettin g Started
1-22
For more information about configuring solver parameters, see Chapter 3, “Simulating an Electronic System”.
Running the Simulation and Analyzing the Results
In this part of the example, you run the sim ulation and plot the results.
In the model window, select Sim ulation > Start to run the simulation.
To view the motor current and torque in the Scope windows, double-click the Scope blocks. You can do this before or after you run the simulation.
Example — Modeling a DC Motor
Note By default, the scope displays appear stacked on top of each other on the screen, so you can only see one of them. Click and drag the windows to reposition them.
The following plot shows the motor current.
Motor Current
1-23
1 Gettin g Started
The next plot shows the motor rpm.
1-24
Motor RPM
As expected, the motor runs at about 2000 rpm when the applied DC voltage is 2.5 V.
Example — Modeling a Triangle Wave Generator
Example — Modeling a Triangle Wave Generator
In this section...
“Overview of Triangle Wave Generator Example” on page 1-25
“Selecting Blocks to Represent System Components” on page 1-25
“Building the Model” on page 1-27
“Specifying Model Parameters” on page 1-29
“Configuring the Solver Parameters” on page 1-37
“Running the Simulation and Analyzing the Results” on page 1-38
Overview of Triangle Wave Generator Example
In this example, you model a triangle wave generator using SimElectronics electrical blocks and custom SimElectronics electrical blocks, and then look at the voltage at the wave generator output.
You use a classic circuit configuration consisting of a n integrator and a noninverting amplifier to generate the triangle wave, and use datasheets to specify block parameters. For more information, see “Parameterizing Blocks” on page 2-2.
To see the completed model, open the Triangle Wave Generator demo.
Selecting Blocks to Represent System Components
First, you select the blocks to represent the input signal, the triangle wave generator, and the output signal display.
You model the triangle wave generator with a set of physical blocks bracketed by a Simulink-PS Converter block and a PS-Simulink Converter block. The wave generator consists of:
Two operational amplifier blocks
Resistors and a capacitor that work with the operational amplifiers to
create the integrator and noninverting amplifier
1-25
1 Gettin g Started
Simulink-PS Converter and P S-Simulink Converter blocks. The function of
the Simulink-PS Converter and PS-Simulink Converter blocks is to bridge the physical part of the model, which uses bidirectional physical signals, and the rest of the model, which uses unidirectional S imulink signals.
You have a manufacturer datasheet for the two operational amplifiers you want to model. Later in the example, you use the datasheet to parameterize the SimElectronics Band-Limited Op-Amp block.
The follow ing table describes the role of the blocks that represent the system components.
Block Description
Sine Wave Generates a sinusoidal signal that controls the
resistance of the Variable Resistor block.
Simulink-PS Converter
Solver Configuration
Electrical Reference
Capacitor Works with an operational amplifier and resistor block
Resistor
Variable Resistor
DC Voltage Source
Voltage Sensor Converts the electrical voltage at the output of the
Converts the sinusoidal Simulink signal to a physical signal.
Defines solver settings that apply to all physical modeling blocks.
Provides the electrical ground.
to create the integrator.
Works with the operational amplifier and capacitor blocks to create the integrator and noninverting amplifier.
Supplies a time-varying resistance that adjusts the gain of the integrator, which in turn varies the frequency and amplitude of the generated triangular wave.
Generates a DC reference signal for the operational amplifier block of the noninverting amplif ier.
integrator into a physical signal proportional to the current.
1-26
Block Description
Example — Modeling a Triangle Wave Generator
PS-Simulink Converter
Scope
Band-Limited Op-Amp
Diode
Converts the output physical signal to a Simulink signal.
Displays the triangular output wave.
Works with the capacitor and resistor to create an integrator and a noninverting amplifier.
Limit the output of the Band-Limited Op-Amp block, to make the output waveform independent of supply voltage.
Building the Model
Create a Simulink model, add blocks to the model, and connect the blocks.
1 Create a model.
If you are new to Simulink, see the “Creating a Simulink Model” example for information on how to create a model.
2 Add to the model the blocks listed in the following table. The Library Path
column of the table specifies the hierarchical path to each block.
Block Library Path Quantity
Sine Wave Simulink > Sources
Simulink-PS
Simscape > Utilities
Converter
Solver
Simscape > Utilities
Configuration
Electrical Reference
Simscape > Foundation Library > Electrical > Electrical Elements
Capacitor Simscape > Foundation
Library > Electrical > Electrical Elements
1
1
1
1
1
1-27
1 Gettin g Started
Block Library Path Quantity
Resistor
Variable Resistor
DC Voltage Source
Voltage Sensor Simscape > Foundation
PS-Simulink Converter
Scope Simulink > Commonly Used Blocks
Band-Limited Op-Amp
Diode
Simscape > Foundation Library > Electrical > Electrical Elements
Simscape > Foundation Library > Electrical > Electrical Elements
Simscape > Foundation Library > Electrical > Electrical Sources
Library > Electrical > Electrical Sensors
Simscape > Utilities
Simscape > SimElectronics > Integrated Circuits
Simscape > SimElectronics > Semiconductor Devices
3
1
1
1
1
1
2
2
1-28
Note You can use the Simscape function ssc_new with a domain type of
electrical to create a Simscape model that contains the following blocks:
Simulink-PS Converter
PS-Simulink Converter
Scope
Solver Configuration
Electrical Reference
This function also selects the Simulink
ode15s solver.
Example — Modeling a Triangle Wave Generator
3 Connect the blocks as shown in the following figure.
Note Use Ctrl+R to rotate blocks so that their orientations match those
shown in the figure.
ou are ready to specify block parameters.
Now y
Spec
Spe com
“Mo
ifying Model Parameters
cify the following parameters to represent the behavior of the system
ponents:
del Setup Parameters” on page 1-30
1-29
1 Gettin g Started
“Input Signal Parameters” on page 1-30
“Triangle Wave Generator Parameters” on page 1-31
“Signal Display Parameters” on page 1-37
Model Setup Parameters
The following blocks specify model inform ation that is not specific to a particular block:
Solver Configuration
Electrical Reference
As with Simscape models, you must include a Solver Configuration block in each topologically distinct physical network. This example has a single physical network, so use one Solver Configuration block with the default parameter values.
You must include an Electrical Reference block in each SimElectronics network. This block does not have any parameters.
1-30
Input Signal Parameters
Generate the sinusoidal control signal using the Sine Wave block.
Set the Sine Wave block parameters as follows:
Amplitude =
Bias = 1e4
Frequency (rad/sec) = p i/5e-4
0.5e4
Example — Modeling a Triangle Wave Generator
Triangle Wave Generator Parameters
Configure the blocks that model the physical system that generates the triangle wave:
Integrator — Band-Limited Op-Amp, Capacitor, and Resistor blocks
Noninverting amplifier — Band-Limited Op-Amp1, Resistor2, and Variable
Resistor blocks
1-31
1 Gettin g Started
Resistor1
Diode and Diode1
Simulink-PS Converter and PS-Simulink Converter blocks that b ridge the
physical part of the model and the Simulink part of the model.
1 Accept the default parameters for the Simulink-PS Converter block. These
parameters establish the units of the physical signal at the block output such that they match the expected default units of the Variable Resistor block input.
2 Set the two Band-Limited Op-Amp block parameters for the LM7301 device
with a +–20V power supply:
The datatsheet gives the gain as 97dB, which is equivalent to
10^(97/20)=7.080e4. Set the Gain, A pa ra m eter to
7e4.
The datatsheet gives input resistance as 39Mohms. Set Input
resistance, Rin to
39e6.
Set Output resistance, Rout to
0 ohms. The datatsheet does not quote
a value for Rout, but the term is insignificant compared to the output resistor that it drives.
Set minimum and maximum output voltages to –20 and +20 volts,
respectively.
The datatsheet gives the maximum slew rate as 1.25V/μs. Set the
Maximum slew rate, Vdot parameter to
1.25e6 V/s.
1-32
Example — Modeling a Triangle Wave Generator
3 Set the two Diode block parameters for a 4.3V zener diode. To model a
BZX384-B4V3, set block parameters as follows:
On the Main tab, set Diode model to
Piecewise Linear Zener.This
selects a simplified zener diode modelthatismorethanadequatetotest the correct operation of this circuit.
Leave the Forward voltage as 0.6V — this is a typical value for most
diodes.
The datatsheet gives the forward current as 250mA when the forward
voltage is 1V. So that the Diode block matches this, set the On resistance to (1V – 0.6V)/250mA =
1.6 ohms.
The datatsheet gives the reverse leakage curre nt as 3μA at a reverse
voltage of 1V. Therefore, set the Off conductance to 3μA/1V =
3e-6 S.
Thedatatsheetgivesthereversevoltageas4.3V.OntheReverse
Breakdown tab, set the Reverse breakdown voltage Vz to
4.3 V.
1-33
1 Gettin g Started
Set the Zener resistance Rz to a suitably small number. The
datatsheet quotes the zener voltage for a re verse current of 5mA. For theDiodeblocktoberepresentativeoftherealdevice,thesimulated reverse voltage should be close to 4.3V at 5mA. As Rz tends to zero, the reverse breakdown voltage w ill tend to Vz regardless of current, as the voltage-current gradient becomes infinite. However, for good numerical properties, Rz must not be made too small. If, say, you allow a 0.01V error o n the zener voltage at 5mA, then Rz will be 0.01V/5mA = 2 ohms. Set the Zener resistance Rz parameter to this value.
1-34
Example — Modeling a Triangle Wave Generator
4 The Voltage Sensor block does not have any parameters.
5 Accept the default parameters for the Variable R esistor block. These
parameters establish the units of the physical signal at the block output such that they match the expected default units of the Variable Resistor block input.
6 Set the
Capaci
Initi
Seri
Capacitor block parameters as follow s:
tance =
al voltage =
alue starts the oscillation in the feedback loop.
This v
es resistance =
2.5e-9
0.08
0
1-35
1 Gettin g Started
7 Set the DC Voltage Source block parameters as follows:
Constant voltage =
8 Set the Resistor block parameters as follows:
Resistance =
10000
0
1-36
Example — Modeling a Triangle Wave Generator
9 Set the Resi
Resistance
10 Set the Resistor2 block parameters as follows:
Resistance =
11 Accept the default parameters for the PS-Simulink Conve rte r block. These
stor1 block parameters as follows:
=
1000
10000
parameters establish the units of the physical signal at the block output such that they match the expected default units of the Scope block input.
Signal D
isplay Parameters
Specify the parameters of the Scope block to display the triangular output signal.
Double-click the Scope block and then double-click the Parameters button
to open the Scope parameters dialog box. On the Data history tab, clear
the Limit data points to last check box.
Configuring the Solver Parameters
Configure the solver parameters to use a continuous-time s olver because SimElectronics models only run with a continuous-time solver. You also change the simulation end time, tighten the relative tolerance for a more accurate simulation, and remove the limit on the number of simulation data points Simulink saves.
1-37
1 Gettin g Started
1 In the model window, select Simulation > Configuration Parameters
to open the Configuration Parameters dialog box.
2 In the Solver category in the Select tree on the left side of the dialog box:
Enter
Select
Enter
Enter
3 In the Data Import/Export category in the Select tree:
2000e-6 for the Stop time parameter value.
ode23t (Mod. stiff/Trapezoidal) from the Solver list.
4e-5 for the Max step size parameter value.
1e-6 for the Relative tolerance parameter value.
Clear the Limit data points to last check box.
4 Click OK.
For more information about configuring solver parameters, see Chapter 3, “Simulating an Electronic System”.
Running the Simulation and Analyzing the Results
Run the simulation and plot the results.
In the model window, select Sim ulation > Start to run the simulation.
ToviewthetrianglewaveintheScopewindow,double-clicktheScopeblock. You can do this before or after you run the simulation.
1-38
Example — Modeling a Triangle Wave Generator
The following plot shows the voltage waveform. As the resistance of the Variable Resistor block increases, the amplitude of the output waveform increases and the frequency decreases.
Triangle Waveform Voltage
1-39
1 Gettin g Started
1-40
Modeling an Electronic System
“Modeling Electronic Components” on page 2-2
“Working with Simulink Blocks” on page 2-22
2
2 M odeling an Electronic System
Modeling Electronic Components
In this section...
“Parameterizing Blocks” on page 2-2
“Additional Parameterization Workflows” on page 2-15
“Adding SimElectronics Blocks to a Model” on page 2-16
“Connecting Model Blocks” on page 2-17
“Selecting the Output Model for Logic Blocks” on page 2-18
Parameterizing Blocks
SimElectronics software is a system-level simulation tool, which provides blocks with a commensurate level of fidelity. Block parame te rs are de signed, where possible, to match the data found on manufacturer datasheets. For example, the bipolar transistor blocks support parameterization in terms of the small-signal quantities usually quoted on a datashe et, and the underlying model is simpler than that typically used by specialist EDA simulation tools. The smaller number of parameters and simpler underlying models can support MATLAB system performance analysis better, and thereby support design choices. Following system design, you can perform validation in hardware or more detailed modeling and validation using an EDA simulation tool.
2-2
This section contains the following parameterization examples:
“Example 1 – Parameterizing a Piecewise Linear Diode Model” on page 2-3
“Example 2 – Parameterizing an Exponential Diode from a Datashee t”
on page 2-6
“Example 3 – Parameterizing an Exponential Diode from a SPICE Netlist”
on page 2-10
“Example 4 – Parameterizing an Op-Amp from a Datasheet” on page 2-13
Most of the time, datasheets should be a sufficient source of parameters for SimElectronics blocks (see Examples 1, 2, and 4). Sometimes, there is need for more information than is available on the datasheet, and data can be augmented from a manufacturer SPICE netlist. For example,
Modeling Electronic Components
circuit performance m ay depend on one or tw o critical components, and increased accuracy is needed either for parameter values or the unde r ly ing model. SimElectronics libraries contain a SPICE-compatible sublibrary to support this case, and this is illustrated by Example 3. If you ha ve many components that need to be modeled to a high level of accuracy, then Simulink cosimulation with a specialist circuit simulator may be a better option.
In mechatronic applications in particular, you may need to model input-output behavior of integrated circuits, such as PWM waveform generators and H-bridges. For these two examples, SimElectronics libraries contain abstracted-behavior equivalent blocks that you can use. Where you need to model other devices, possible options include creating your own abstracted model using the Simscape language, or using Si mulink blocks. For an e xample of using Simulink blocks, see the Modeling an Integrated Circuit demo.
When looking for a datasheet, make sure you have the originating manufacturer datasheet because some resellers abbreviate them.
Example 1 – Parameterizing a Piecewise L inear Diode Model
The Triangle W ave Generator demo model, also described in “Example — Modeling a Triangle Wave Generator” on page 1-25, contains two zener diodes that regulate the maximum output voltage from an op-amp amplifier circuit. Each of these diodes is implemented with the SimElectronics Diode block, parameterized using the model is sufficient to check correct operation of the circuit, and requires fewer parameters than the
Exponential option of the Diode block. However, when
specifyingtheparameters,youneedtotakeintoaccountthebiascondition that will be used in the circuit. This example explains how to do this.
Piecewise Linear Zener option. This simple
The Phillips Semiconducto r s datasheet for a BZX384–B4V3 gives the following data:
Working voltage, VZ(V) at I
Ztest
=5
4.3
mA
Diode capacitance, Cd(pF)
Reverse current, IR(μA) at VR=1V
Forward voltage, VF(V) at IF=5mA
450
3
0.7
2-3
2 M odeling an Electronic System
In the datasheet, the tabulated values for VFare for higher forward currents. This value of 0.7V at 5mA is extracted from the datasheet current-voltage curve, and is chosen as it matches the zener current used when quoting the working voltage of 4.3V.
To match the datasheet values, the demo sets the piecewise linear zener diode block parameters a s follows:
Forward voltage. Leave as default value of 0.6V. This is a typical
value for most diodes, and the exact value is not critical. However, it is important that the value set is taken into account w hen calculating the On resistance parameter.
On resistance. This is set using the datasheet information that the
forward voltage is 0.7V when the current is 5mA. The voltage to be d r opped by the On resistance parameter is 0.7V minus the Forward voltage parameter, that is 0.1V. Hence the On resistance is 0.1V / 5mA = 20 Ω.
Off conductance. This is set using the datasheet information on reverse
current. The reverse current is 3μA for a reverse voltage of 1V. Hence the
Off conductance should be set to 3μA/1V=3e-6S.
2-4
Reverse breakdown voltage Vz. This parameter should be set to the
datasheet working voltage parameter, 4.3V.
Zener resistance Rz. This needs to be set to a suitable small number.
Too small, and the voltage-current relationship becomes very steep, and simulation convergence may not be as efficient. Too large, and the zener voltagewillbeincorrect. FortheDiodeblocktoberepresentativeofthe real device, the simulated reverse voltage should be close to 4.3V at 5mA (the reverse bias current provided by the circuit). Allowing a 0.01 V error on the zener voltage at 5mA, R
Junction capacitance. This parameter is set to the datasheet diode
capacitance value, 450 pF.
will be 0.01V / 5mA = 2 Ω.
Z
Modeling Electronic Components
2-5
2 M odeling an Electronic System
2-6
Example 2 – Parameterizing an Exponential Diode from a Datasheet
Example 1 uses a piecewise linear approximation to the diode’s exponential current-voltage relationship. This results in more efficient simulation, but requiressomethoughttogointothesettingofblockparametervalues. Analternativeistouseamorecomplexmodelthatisvalidforawider range of voltage and current values. This example uses the parameterization option of the Diode block.
This model either requires two data points from the diode current-voltage relationship, or values for the underlying equation coefficients, namely the saturation current IS and the emission coefficient N. The BZX384-B4V3 datasheet only provides values for the former case. Some datasheets do not give the necessary data for either case, and you must follow the processes in Example 1 or Example 3 instead.
The two data points in the table below are from the BZX384-B4V3 datasheet current-voltage curve:
Exponential
Modeling Electronic Components
Diode forward voltage, V
F
Diode forward current, I
F
0.7V 1V
5mA 250mA
Set the exponential diode block parameters as follows:
Currents [I1 I2]. Set to [5 250] mA.
Voltages [V1 V2]. Set to [0.7 1.0] V.
Reverse breakdown voltage BV. Set to the datasheet working voltage
value, 4.3V.
Ohmic resistance. Leave at its default value of 0.01 Ω.Thisisan
example of a parameter that cannot be determined from the datasheet. However, setting its value to zero is not necessarily a good idea, because a small value can help simulation convergence for some circuit topologies. The default value has negligible effect at the working current of 5mA, the additional voltage drop being 5e-3 times 0.01 = 5e-5V. Physically, this term will not be zero because of the connection resistances.
Zero-bias junction capacitance CJ0. Set to the datasheet diode
capacitance value, 450 pF.
A more complex capacitance model is also available for the Diode component with the exponential equation option. However, the datasheet does not provide the necessary data. Moreover, the operation of this circuit is not sufficiently sensitive to voltage-dependent capacitance effects to warrant the extra detail.
2-7
2 M odeling an Electronic System
2-8
Modeling Electronic Components
2-9
2 M odeling an Electronic System
Example 3 – Parameterizing an Exponential Diode from a SPICE Netlist
If a datasheet does not provide all of the data required by the component model, another source is a SPICE netlist for the component. Components are defined by a particular type of SPICE netlist called a sub c ircu i t. The subcircuit defines the coefficients for the defining equations. Most component manufacturers make subcircuits available on their website s. The format is ASCII, and you can directly read off the parameters. The BZX384-B4V3 subcircuit can be obtained from P hilips Semiconductors http://www.nxp.com/models/index.html.
The subcircuit data can be used to parameterize the SimElectronics Diode block either in conjunction with the datasheet, or on its own. For example, the Ohmic resistance is defined in the subcircuit as RS = 0.387, thus providing the missing piece of information in Example 2.
An alternative workflow is to use the SimElectronics Additional Components/SPICE-Compatible Components sublibrary. The SPICE Diode block in this sublibrary can be directly parameterized from the subcircuit by setting:
2-10
Saturation current, IS to
Ohmic resistance, RS to 0.387
Emission coefficient, ND to 1.001
Zero-bias junction capacitance, CJO to 2.715e-10
Junction potential, VJ to 0.7721
Grading coefficient, MG to 0.3557
Capacitance coefficient, FC to 0.5
Reverse breakdown current, IBV to 0.005
Reverse breakdown voltage, BV to 4.3
Note that where there is a one-to-o ne correspondence between subcircuit parameters and datasheet values, the numbers often differ. One reason for this is that datasheet values are sometimes given for maximum values, whereas subcircuit values are normally for nominal values. In this example,
1.033e-15
Modeling Electronic Components
the CJO value of 271.5 pF differs from the datasheet capacitance of 450 pF at zero bias for this reason.
2-11
2 M odeling an Electronic System
2-12
Modeling Electronic Components
Example 4 – Parameterizing an Op-Amp from a Datasheet
The Triangle W ave Generator demo model, also described in “Example — Modeling a Triangle Wave Generator” on page 1-25, contains two op-amps, parameterized based on a datasheet for an LM7301. The National Semiconductor datasheet gives the following data for this de vi ce:
Gain
Input resistance
Slew rate
Bandwidth
The Band-Limited Op-Amp and Finite-Gain Op-Amp blocks have been designed to work from manufacturer datasheets. Implementing detailed
97dB = 7.1e4
39MΩ
1.25V/μs
4MHz
2-13
2 M odeling an Electronic System
op-amp device models, derived from manufacturer SPICE netlist models, is not recommended, because it provides more accuracy than is typically warranted and slows down simulations. The simple parameterization of the SimElectronics op-amp blocks allows you to determine the sensitivity of your circuit to abstracted performance values, such as maximum slew rate and bandwidth. Because of this behavior-based parameterization, you can determine which spe c if ication of op-amp is required for a given application. A circuit designer can later match these behavioral parameters, determined from the model, against specific op-amp devices.
Based on the datasheet values above, set the Band-Limited Op-Amp block parameters as follows:
Gain set to
Input resistance, Rin set to 39e6Ω
Output resistance, Rout se t to zero. The value is not defined, but will be
small compared to the 1000Ω load seen by the op-amp.
Minimum output, Vmin set to the negative supply voltage,
model
Maximum output, Vmax set to the positive supply voltage,
model
Maximum slew rate, Vdot set to
Bandwidth, f set to
Note that these parameters correspon d to the values for +-5 volt operation. The datasheet also gives values for +-2.2V and +-30V operation. It is usually better to pick values for a supply voltage below what your circuit uses, because performance is worse at lower voltages; for example, the ga in is less, and the input impedance is less. You can use the variation in op-amp parameters with supply voltage to suggest a typical range of parameter values for which you should check the operation of y our circuit.
7.1e4
-20Vinthis
20Vinthis
1.25/1e-6 V/s
4e6 Hz
2-14
Modeling Electronic Components
Additional Parameterization Workflows
There are several other ways to parameterize and validate your model:
“Validation Using Data from SPICE Tool” on page 2-15
“Parameter Tuning Against External Data” on page 2-16
“Building an Equivalent Model of a SPICE Netlist” on page 2-16
Validation Using Data from SPICE Tool
One way to validate a parameterized SimElectronics component is to compare its behavior to data from specialist circuit simulation tool that uses a manufacturer SPICE netlist of the device. If doing this, it is important to create a test harness for the component that exercises it over the relevant operating points and frequencies
2-15
2 M odeling an Electronic System
Parameter Tuning Against External Data
If you have lab measurements of the device, or data from another simulation environment, you can use this to tune the parameters of the equivalent SimElectronics component. For an example of parameter tuning, see the demo Solar Cell Parameter Extraction From Data.
Building an Equivalent Model of a SPICE Netlist
In Example 3, parameterization from a SPICE netlist is relatively straightforward because the netlist defines a single device (the diode) plus corresponding model card (the parameters). Conversely, a netlist for an op-amp may have more than ten devices, plus supporting model cards. In principle it is p oss ible to build your own equivalent model of a more complex device by making use of the SPICE-Compatible Components sublibrary, and connecting them together using the information in the netlist. Before embarking on this you should ensure that the SPICE-Compatible Components sublibrary has all of the component models that you need.
If the device models you wish to model are complex (hundreds of com ponents), then cosimulation with an external circuit simulator may be a better approach.
2-16
Adding SimElectronics Blocks to a Model
You can include blocks from the SimElectronics library in a Simulink model. For more information on the library and the SimElectronics blocks, see “SimElectronics Block Libraries” on page 1-6.
This section contains th e following topics:
“Required Blocks” on page 2-16
“How to Add SimElectronics Blocks to a Model” on page 2-17
Required Blocks
Each topologically distinct physical network in a diagram requires exactly one Solver Configuration block, found in the Simscape Utilities library. The Solver Configuration block specifies global environment information for simulation and provides parameters for the solver that your m odel needs before you can begin simulation. For more information, see the Solver Configuration block reference page.
Modeling Electronic Components
Each electrical network requires an Electrical Reference block. This block establishes the electrical ground for the circuit. Networks with electromechanical blocks also require a Mechanical Rotational Reference block. For more information about using reference blocks, see “Grounding Rules” in the Simscape documentation.
How to Add SimElectronics Blocks to a Model
To add Sim Electronics blocks to a Simulink model:
1 Type elec_lib attheMATLABprompttoopenthe SimElectronics library.
2 Navigate to the desired library or sublibrary.
3 Drag instances of SimElectronics blocks into the model window using the
mouse.
Note You can also access SimElectronics blocks and oth er Simulink blocks from the Simulink Library Brow ser win dow. Type prompt to open this window. Add blocks to the model by dragging them from this window and dropping them into the model window.
simulink at the M A TLAB
Connecting Model Blocks
You follow the same procedure for connecting SimElectronics blocks as for connecting Simulink blocks: click a port and drag the mouse to draw a line to another port on a different block. For more information on connecting blocks, see “Connecting Blocks in the Model Window” in the Sim ulink documentation.
You can only connect blocks that use the same type of signal. SimElectronics blocks use the same physical signals that Simscape blocks use. These signals are different than Simulink signals, and are represented graphically by a different port style. Therefore, you can freely connect pairs of SimElectronics blocks and other Simscape blocks.
However, you cannot directly connect SimElectronics blocks to Simulink blocks. Instead, you must use the Simscape PS-Simulink Converter and Simulink-PS Converter blocks to bridge them.
2-17
2 M odeling an Electronic System
The following topics in the Simscape documentation explain how physical ports w ork and how to bridge physical blocks and Simulink blocks.
“Connector Ports and Connection Lines”
“Connecting Simscape Diagrams to Simulink Sources and Scopes”
Selecting the Output Model for Logic Blocks
The blocks in the Logic sublibrary of the Integrated Circuits library provide a choice of two output models:
Linear — Models the gate output as a voltage source driving a series
resistor and capacitor connected to ground. This is suitable for logic circuit operation under normal conditions and when the logic gate drives other high-impedance CMOS gates. The block sets the value of the gate output capacitor such that the resistor-capacitor time constant equals the Propagation delay parameter value. The linear output model is shown in the following illustration.
2-18
Quadratic — Models the gate output in terms of a comple mentary
N-channel and P-channel MOSFET pair. This adds more fidelity, which becomes relevant if drawing higher currents from the gate output, or if exercising the gate under fault conditions. In addition, the gate input demand is lagged to approximate the Propagation delay parameter value. Default parameters are representative of the 74HC logic gate family. The quadratic output model is shown in the next illustration.
Modeling Electronic Components
Use the Output current-voltage relationship parameter on the Outputs tab of the block dialog box to specify the output model.
For most system models, MathWorks recommends selecting the linear option because it supports faster simulation. If necessary, you can use the more detailed output model to validate simulation res ults obtained from the simpler model.
Quadratic Model Output and Parameters
If you select the quadratic model, use the following parameters to control the block output:
Supply voltage — Supply voltage value (Vcc) applied to the gate in your
circuit. The default value is
Measurement voltage — The gate supply voltage for which mask data
output resistances and currents are defined. The default value is
LogicHIGHoutputresistanceatzerocurrentandatI_OH—Arow
vector [ R_OH1 R_OH2 ] of two resistance values. The first value R_OH1 is the gradient of the output voltage-current relationship when the gate is
5 V.
5 V.
2-19
2 M odeling an Electronic System
logic HIGH and there is no output current. The second value R_OH2 is the gradient of the output voltage-current relationship when the gate is logic HIGH and the output current is I_OH. The default value is
Logic HIGH output current I_OH when shorted to ground —The
resulting current when the gat e is in the logic HIGH state, but the load forcestheoutputvoltagetozero. Thedefaultvalueis
Logic LOW output r es ist ance at zero current and at I_OL —Arow
vector [ R_OL1 R_OL2 ] of two resistance values. The first value R_OL1 is the gradient of the output voltage-current relationship when the gate is logic LOW and there is no output current. The second value R_OL2 is the gradient of the output voltage-current relationship when the gate is logic LOW and the output current is I_OL . The default value is
Logic LOW output current I_OL when shorted to Vcc —Theresulting
current when the gate is in the logic LOW state, but the load forces the outputvoltagetothesupplyvoltageVcc.Thedefaultvalueis
[ 25 250 ] Ω.
63 mA.
[30800]Ω.
-45 mA.
Propagation delay — Time it takes for the output to swing from
LOW
to HIGH or HIGH to LOW after the input logic levels change. For quadratic output, it is implemented by the lagged gate input demand. The default value is
25 ns.
Protection diode on resistance — The gradient of the voltage-curre nt
relationship for the protection diodes when forward biased. The default value is
5 Ω.
Protection diode forward voltage — The voltage above which the
protection diode is turned on. The default value is
0.6 V.
The following graphic illustrates the quadratic output model parameterization, using the default parameter output characteristics for a +5V supply.
2-20
Modeling Electronic Components
2-21
2 M odeling an Electronic System
Working with Simulink Blocks
In this section...
“Modeling Instantaneous Events” on page 2-22
“Using Simulink Blocks to Model Physical Components” on page 2-22
Modeling Instantaneous Events
When working with SimElectronics software, your model may include Simulink blocks that create instantaneous changes to the physical system inputs through the Simulink-PS Converter block, such as those associated with events or discrete sampling. When you build this type of model, make sure the corresponding zero crossings are generated.
Many blocks in the Simulink library generate these zero crossings by default. For example, the Pulse Gener ator block produces a discrete-time output by default, and generates the corresponding zero crossings. To model instantaneous events, select Zero crossing control option under the model’s Solver Configuration Parameters to generate zero crossings. For more information about zero crossing control, see “Zero-crossing control” in the Simulink documentation.
Use local settings or Enabl e all for the
2-22
Using Simulink Blocks to Model Physical Components
To run a fast simulation that approximates the behavior of the physical components in a system, you may want to use Simulink blocks to model of one or more physical components.
The Modeling an Integrated Circuit demo uses Simulink to model a physical component. The Simulink Logical Operator block implements the behavioral model of the two-input NOR gate, as shown in the following figure.
Working with Simulink®Blocks
Using Sim lag somew first-o to repre is requi Founda
ulink in this manner introduces algebraic loops, unless you place a here between the physical signal inputs and outputs. In this case, a
rder lag is included in the Logic2Volts & Propagation Delay subsystem
sent the delay due to gate capacitances. For applications where no lag red, use blocks from the Physical Signals sublibrary in the Simscape tion Library to implement the d esired functionality.
2-23
2 M odeling an Electronic System
2-24
Simulating an Electronic System
“Selecting a Solver” on page 3-2
“Specifying Simulation Accuracy /Speed Tradeoff” on page 3-3
“Avoiding Simulation Issues” on page 3-5
“Running a Time-Domain Simulation” on page 3-6
“Running a Small-Signal Frequency-Domain Analysis” on page 3-7
3
3 Sim ulating an Electronic System
Selecting a So lver
In this section...
“Available Solvers” on page 3-2
“How to Select a Solver” on page 3-2
Available Solvers
SimElectronics software supports all of the continuous-time solvers that Simscape supports. For more information, see “Working with Solvers” in theSimscapedocumentation.
You can select any of the supported solvers for running a SimElectronics simulation. The variable-step solvers, for most applications because they run faster and copy better for systems with a range of both fast and slow dynamics. The solver that SPICE traditionally uses.
ode23t and ode15s, are recommended
ode23t solver is closest to the
3-2
To use Real-Time Workshop from your model, you must use the code generation, see “Generating Code” in the Simscape documentation.
®
software to generate standalone C or C++ code
ode14x solver. For more information about
How to Select a Solver
To specify a solver:
1 Open the Configuration Parameters dialog box from the Simulation
menu.
2 In the Solver pane (which opens by default), select the desired solve r from
the Solver list.
Specifying Simulation Accuracy/Speed Tradeoff
Specifying Simulation Accuracy/Speed Tradeoff
In this section...
“Parameters that Affect Accuracy and Speed” on page 3-3
“Determining Appropriate Accuracy/Speed Parameter Values” on page 3-3
Parameters that Affect Accuracy and Speed
To trade off accuracy a n d simulation time, adjust one or more of the followin g parameters:
Relative tolerance (in the Configuration Parameters dialog box)
Absolute tolerance (in the Configuration Parameters dialog box)
Max step size (in the Configuration Parameters dialog box)
Constraint Residual Tolerance (in the Solver Configuration block
dialog box)
Determining Appropriate Accuracy/Speed Parameter Values
In most cases , the default tolerance values produce accurate results without sacrificing unnecessary simulation time. The parameter value that is most likely to be inappropriate for your simulation is Max step size,becausethe default value, than on the amount by which the signals are changing during the simulation. If you are concerned about the solver’s missing significant behavior, change the parameter to prevent the solver from taking too large a step.
The Simulink documentation describes the following parameters in m ore detail and provides tips on how to adjust them:
“Relative tolerance”
“Absolute tolerance”
“Max Step Size”
auto, depends on the simulation start and stop times rather
3-3
3 Sim ulating an Electronic System
The Solver Configuration block reference page in the Simscape documentation explains when to adjust the Constraint Residual Tolerance parameter value.
3-4
Avoiding Simulation Issues
In this section...
“General Troubleshooting for Simscape Models” on page 3-5
“Troubleshooting for Simscape Models that Include SimElectronics Blocks” on page 3-5
General Troubleshooting for Simscape Models
If you experience a simulation issue, first read “Troubleshooting Simulation Errors” in the Simscape documentation to learn about general troubleshooting techniques.
Note As mentioned in the “Product Overview” on page 1-2, SimElectronics software does not have the ability to model large circuits with dozens of analog components. If you encounter convergence issue s when trying to simulate a model with more than a few tens of transistors, you may find that the limitations of SimElectronics software prevent you from achieving convergence w ith any set of simulation parameter values.
Avoiding Simulation Issues
Troubleshooting for Simscape Models that Include SimElectronics Blocks
There are a few techniques you can apply to any SimElectronics model to overcome simulation issues:
Add parasitic capacitors and/or resistors (specifically, junction capacitance
and ohmic resistance) to the circuit to avoid numerical issues. The Astable Oscillator demo uses these devices.
Adjust the current and voltage sources so they start at zero and ramp up to
their final values rather than starting at nonzero values.
“Working with Simulink Blocks” on page 2-22 describes how to avoid simulation errors in the presence o f specific SimElectronics model configurations.
3-5
3 Sim ulating an Electronic System
Running a Time-Domain Simulation
When you run a time-domain simulation, SimElectronics software uses the Simscape solver to analyze the physical system in th e Simulink environment. For more information about how Simscape simulation works, see “How Simscape Simulation Works” in the Simscape documentation.
3-6
Running a Small-Signal Frequency-Domain Analysis
Running a Small-Signal Frequency-Domain Analysis
In this section...
“Linearizing SimElectronics Models” on page 3-7
“Analyzing Small-Signal Behavior Using Bode Plots” on page 3-7
Linearizing SimElectronics Models
The Simulink commands linmod and dlinmod create continuous- or discrete-time linear time-invariant (LTI) state-space models from Simulink models. You can use these commands to generate an LTI state-space model from a model containing Simscape components .
For more information about linearizing models that contain blocks from the Simulink Physical Mode ling fa mily, se e “Linearizing at an Operating Point”.
After you linearize your model, you can perform small-signal analyses such as:
Bode
Step
Impulse
Nyquist
Note If you h ave Simulink®Control Design™ software installed, you can
use its Control and Estimation Tools Manager GUI to linearize models. For more information about using this software for linearization, see “Linearizing the Model”.
Analyzing Small-Signal Behavior Using Bode Plots
After you create an LTI state-space model from your SimElectronics model, you can create a Bode plot for small-signal analysis using one of the follow i ng approaches:
“Using MATLAB for Bode Analysis” on page 3-8
3-7
3 Sim ulating an Electronic System
“Using Control System Toolbox Softw are for Bode Analysis” on page 3-8
UsingMATLABforBodeAnalysis
You can write a MATLAB script to generate a bode plot of the frequency response of the model from the LTI state-space model. The demo Small-Signal Frequency-Domain Analysis uses a linear passive bandpass filter example to show how to use MATLAB to create a Bode plot from an LTI model. The demo shows how to use both the state-space and transfer-function forms of the LTI model.
Using Control System Toolbox Software for Bode Analysis
You can use the built-in analysis and plotting capabilities of Control System Toolbox™ to understand the behavior of a linearized model.
The toolbox function
ss converts the state-space model returned by linmod
to a continuous-time state-space model.
The toolbox function
linmod to a continuous-time transfer function model.
The toolbox function
tf converts the transfer function model returned by
ltiview opens the LTI viewer for LTI system response
analysis.
The following example shows how to create a Bode plot of the frequency-response of the model in the demo Small-Signal Frequency-Domain Analysis.
At the MATLAB prompt:
1 Type the following to create a LTI state-space model of elec_ss_analysis:
[A B C D] = linmod('elec_ss_analysis',[],[],[1e- 5 0 1]);
2 Type the following to create a LTI transfer function model of
elec_ss_analysis:
[num den] = linmod('elec_ ss_analysis',[],[],[1e-5 0 1]);
3-8
Running a Small-Signal Frequency-Domain Analysis
3 Type the following to plot both the state-space and transfer function models
on a Bode plot:
ltiview('bode',ss(A,B,C,D),'b',tf(num,den),'r-.');
The toolbox creates the following plot:
The bandpass filter frequency response for the state-space and transfer function representations are different far from the center frequency. These differences arise from numerical noise introduced when calculating the transfer function representation.
linmod implicitly derives a state-space
representation for a linearized model, and computes the transfer function representation from this state-space model.
3-9
3 Sim ulating an Electronic System
Note If you have Simulink Control Design software installed, you can use
its Control and Estimation Tools Manager GUI to analyze models. This software uses the Control System Toolbox LTI viewer to display and analyze the dynamic behavior of a model.
3-10
Examples
Use this list to find examples in the documentation.
A
A Examples
Examples
“Example — Model “Example — Modeling a Triangle Wave Generator” on page 1-25
ing a DC Motor” on page 1-11
A-2
Index
IndexA
accuracy
model p arameter values 3-3 model parameters that affect 3-3
adding physical and mathematical blocks 2-16
B
blocks
connecting 2-17 logic blocks output 2-18
C
connecting blocks
SimElectronics
Simulink 2-17
Simulink to SimElectronics
blocks 2-17
®
Physical blocks to
®
Physical
L
libraries
SimElectronics
®
1-6
M
model
adding SimElectronics simulating a SimElectronics
models
®
components to 2-16
®
3-2
SimElectronics
®
blocks 1-6
O
opening
block libraries 1-6
S
SimElectronics
required and related products 1-5
SimElectronics
how to open 1-6
solver
selecting for SimElectronics
speed
model p arameter values 3-3 model parameters that affect 3-3
®
®
libraries 1-6
®
model 3-2
T
troubleshooting electrical models 3-5 troubleshooting s imulation issues 3-5
W
workflow
SimElectronics
workflow example
SimElectronics SimElectronics
®
1-10
®
electrical 1-25
®
electromechanical 1-11
Index-1
Loading...