PSpice 17.2 MATLAB Interface User Guide (PSP - Matlab - Ug) PDF
PSpice 17.2 MATLAB Interface User Guide (PSP - Matlab - Ug) PDF
Contents
1
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Understanding Various MATLAB-related flows ................................. 8
2
Introducing the Advanced Waveform Analysis . . . . . . . . . . . . . . . . 11
Advanced Waveform Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
License and Software Requirements for the Advanced Waveform Analysis . . . . . . . . . . 12
3
Setting Up the PSpice - MATLAB flow for Advanced Waveform
Analsysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Setting Up the MATLAB Path . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
Running the MATLAB Engine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
4
Understanding Advanced Waveform Analysis Flows . . . . . . . . 17
Using MATLAB Visualization Capabilities in PSpice . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
Using Customized MATLAB Plotting Functions in PSpice . . . . . . . . . . . . . . . . . . . . . 22
Calling the MATLAB function in PSpice . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
Using the MATLAB-based Measurement Function in PSpice . . . . . . . . . . . . . . . . . . . . . 26
5
Accessing Trace Data from the MATLAB Variable . . . . . . . . . . . . 29
What is the generated MATLAB variable? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
How to check if the MATLAB variable is generated or not? . . . . . . . . . . . . . . . . . . . . 31
How to launch the desktop version of MATLAB from the MATLAB command window? .
31
How to access the trace data from the MATLAB variable using customized MATLAB
scripts? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
How to access the previously generated MATLAB variabe in the current session of
MATLAB workspace? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
Where are various customized scripts stored in the Cadence hierarchy and how to use
them? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
6
Introducing PSpice Simulink Co-simulation . . . . . . . . . . . . . . . . . . . 39
Introducing the PSpice Simulink Co-Simulation Interface . . . . . . . . . . . . . . . . . . . . . . . . 40
Requirements for PSpice Simulink Co-Simulation Interface . . . . . . . . . . . . . . . . . . . . . . 40
Setting Up the PSpice Simulink Co-simulation solution . . . . . . . . . . . . . . . . . . . . . . . . . . 41
7
Creating a Schematic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
Creating a schematic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
Using OrCAD Capture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
Using Design Entry HDL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
Using PSpice A/D to Simulate Schematic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
Creating and Setting Up a Block Diagram Using MATLAB . . . . . . . . . . . . . . . . . . . . . . . 53
Creating a Block . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
Setting Up Block Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
Setting Up Simulink Analyses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
Simulating and Verifying Results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
Migrating existing PSpice SLPS designs to new PSpice Simulink Co-simulation design 60
8
Interfacing PSpice Designs in MATLAB . . . . . . . . . . . . . . . . . . . . . . . . 63
Using the Simulation Profile Window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
Data Exchange between Simulink and PSpice . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
Setting Simulink Simulations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
9
Analyzing Simulink Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
Running a simulation from Simulink model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
Verifying results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
10
Simulation Settings Dialog Description . . . . . . . . . . . . . . . . . . . . . . . . 75
Data collection options for simulation profiles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
1
Introduction
PSpice is a simulation program that simulates any mix of analog and digital devices. Used
with design entry tools, OrCAD Capture or Design Entry HDL, you can think of PSpice as a
software-based breadboard of your circuit that you can use to test and refine your design
before manufacturing the physical circuit board or IC.
PSpice - MATLAB Interface extends the PSpice visualization capabilities to the next level. In
just one click, the interface allows you to export all or selected trace data to MATLAB, where
you can analyse and visualize the data in more enhanced way. You can visualize simulation
results on various different plots, such as Polar Plots and 3D plots. You can also customize
the processing on waveform using customized MATLAB® scripts on the exported trace data.
The chapters in part A introduce you to PSpice - MATLAB interface and describes the various
tools involved in working with PSpice -MARLAB interface for advance waveform analysis. The
chapters also describe how to do advanced waveform analysis in PSpice project using
MATLAB.
■ Introducing the Advanced Waveform Analysis on page 11
■ Setting Up the PSpice - MATLAB flow for Advanced Waveform Analsysis on page 13
■ Understanding Advanced Waveform Analysis Flows on page 17
■ Accessing Trace Data from the MATLAB Variable on page 29
2
Introducing the Advanced Waveform
Analysis
This chapter introduces the new PSpice - MATLAB Interface and lists the requirements to run
various flows for Advanced Waveform Analysis.
■ Advanced Waveform Analysis on page 12
■ License and Software Requirements for the Advanced Waveform Analysis on page 12
Various different visualization and plotting capabilities of MATLAB use plotting functions and
measurement functions in the PSpice-MATLAB interface to generate new plots and graphs
using the PSpice trace data.
a. MATLAB
➤ Cadence OrCAD products (HotFix 009 of R17.2-2016 or later) or Cadence Allegro
products (HotFix 009 of R17.2-2016 or later)
Install one of the following schematic designer tools:
a. Capture
b. Capture CIS
a. PSpice A/D
3
Setting Up the PSpice - MATLAB flow for
Advanced Waveform Analsysis
This chapter explains how to set up PSpice - MATLAB flow for Advance Waveform Analysis.
It also covers details about running the MATLAB engine.
■ Setting Up the MATLAB Path on page 14
■ Running the MATLAB Engine on page 14
Note: Remember the following points related to setting up the MATLAB path:
❑ The MATLAB path need to be set only once in the Set MATLAB Path window. Once
the path is set, you do not have to set it again on Capture relaunch.
❑ You have to set MATLAB path again, only if you have installed MATLAB or moved
MATLAB to new location in your system.
❑ Once the MATLAB path is set, it gets saved in the PSpice.ini file.
Note: You need to specify the MATLAB path before you run the the MATLAB engine. As the
Start MATLAB Engine option will be displayed only if you have entered the MATLAB path.
4
Understanding Advanced Waveform
Analysis Flows
The following flows are targeted for those users, who have electronics components as large
part of a design. For all the following flows, simulation will happen in PSpice only and you will
not be required to see MATLAB until you want to export PSpice trace data to MATLAB for
specialized plotting.
Before you start using the MATLAB visualization capabilities in PSpice, ensure that you have
set the MATLAB path and started the MATLAB engine. To know more about the setting the
MATLAB path and starting the MATLAB engine, see the Setting Up the PSpice - MATLAB flow
for Advanced Waveform Analsysis chapter.
■ Use the default MATLAB-based function, plotTraces, to plot traces with respect to
time in a figure panel.
■ Provide a different name, such as TRAN, MyVAR, to the generated MATLAB variable
instead of the default PSpiceData_<instance_number>. To do that, enter the
variable name in the MATLAB variable field of the Export to MATLAB window
Note: If you name the MATLAB variable using the MATLAB variable field, ensure that
the first character of the MATLAB variable is an alphabet.
■ Select one or more sections from the multi-section simulation data using the Select
Section option.
Note: It is recomended to select Export Selected Traces option to select a set of traces, if
the PSpice data file size is more than 800 MB.
Perform the following steps to export a set of selected traces to MATLAB for Advanced
Waveform Analysis:
The MATLAB variable generated is a structured array, which can be used further in
MATLAB using various custumized functions.
Note: Few customized MATLAB Scripts, which can be used to access the PSpice trace
data from the MATLAB variable, are at the following path: <Cadence
Installation>\tools\pspice\tclscripts\prPSPMatlab\MatlabScripts. For more
information on how to access the trace data from the generated MATLAB variable, see
the Accessing Trace Data from the MATLAB Variable chapter.
Caution
It is recommended to save your data in MATLAB before you exit MATLAB
command window. Else all the trace data, including variables generated,
will be lost.
To use the customized MATLAB plotting functions in PSpice, do the following steps:
1. Create a.m file for the plot you want to see in MATLAB, such as polar plot.
2. Save the file, such as polarPlotBH.m.
3. Open the file location in the current workspace of MATLAB.
Type the desktop command to get desktop version of MATLAB. As MATLAB’s each
session is independent of another session, ensure that you are working in the correct
workspace.
4. (Optional) Change the parameter’s information or trace data information the MATLAB
script file.
5. Click Run in the Editor tab of MATLAB to run the script.
Once done, you will see the desired plot getting generated from the selected trace data
and displayed in a figure panel.
The following screenshot illustrates an example of polar plot that was generated using a
custumized MATLAB function:
Now, PSpice allows you to add a MATLAB function in the expression for the E and G
behaviorial controlled devices. Various MATLAB functions can be added using the following
syntax:
Important
Remember the following points before you use MATLABFunction:
❑ You should correctly spell the <MATLAB_function> used in MATLABFunction,
else simulation will abort or nothing will be displayed on the probe window. Similarly,
correctly mention the number of parameters in MATLABFunction, else you will get
an simulation error.
Once the function is simulated, you can see the simultion results in PSpice as shown in the
following screenshot:
Now using PSpice, you can use the MATLAB-based measurement functions to evaluate the
waveform. When these functions are used, MATLAB is used behind the scenes to evaluate
measurement functions. By default, the following three MATLAB-based functions have been
added in PSpice:
■ MATLABFunction1(<trace_name>, <MATLAB_function>)
You can use this function to call any MATLAB function that uses one argument and
returns a constant expression. The first argument must always be trace name.
■ MATLABFunction2(<trace_name1>, <trace_name2>, <MATLAB_function>)
You can use this function to call any MATLAB function that uses two arguments and
returns a constant expression. If <MATLAB_function> returns anything other than
constant, the result will be invalid. The first and second argument in this function must
always be trace name.
Perform the following steps to evaluate the characteristics of a waveform using the new
MATLAB-based measurement functions:
1. In PSpice, choose Trace – Evalute Measurement.
An Evaluate Measurement window is displayed.
2. In the Functions or Macros section of the Evaluate Measurement window, select any of
the two MATLAB- based measurement function.
Once you select the function, the Trace Expression field gets filled in with function’s
defination.
3. Add the details about arguments of the selected MATLAB-based measurement function:
b. For matlabFunction2: First and second arguments are Trace Names, and third
argument is the MATLAB function. For example, matlabFunction2(V(out), I(out),
risetime).
4. Click OK.
The measurement function is diplayed in the Measurement Results window of the
PSpice probe.
5. Select the measurement function from the Measurement Results window.
The value evaluated is displayed.
Note: Ensure the following things before you evaluate a MATLAB-based measurement
function in PSpice:
❑ The MATLAB function name is correct.
❑ The number of arguments mentioned are correct.
5
Accessing Trace Data from the MATLAB
Variable
This chapter explains about the generated variable, how to extract data from the generated
variable, and how to use the data in MATLAB to generate various plots. Following topics are
covered in this chapter:
■ What is the generated MATLAB variable? on page 30
■ How to check if the MATLAB variable is generated or not? on page 31
■ How to launch the desktop version of MATLAB from the MATLAB command window? on
page 31
■ How to access the trace data from the MATLAB variable using customized MATLAB
scripts? on page 31
■ How to access the previously generated MATLAB variabe in the current session of
MATLAB workspace? on page 31
■ Where are various customized scripts stored in the Cadence hierarchy and how to use
them? on page 32
The following diagram illustrates the tree structure of the generated MATLAB variable:
Once done, you will see the name of the variable getting displayed in the MATLAB command
window if it is generated. The following screenshot illustrates that two variables, MyVAR and
PSpiceData_1, are currently present in the current MATLAB command window session:
How to access the trace data from the MATLAB variable using customized
MATLAB scripts?
As the trace data is saved as a structured array in the MATLAB variable, you can access the
trace data using the custumized scripts shipped with the Cadence hierarchy or using various
MATLAB commands.
If you want to access the currently generated MATLAB variable again, you need to save the
workspace as .mat file. To save a MATLAB current workspace as .mat file, click the Save
Workspace option in the Home tab of MATLAB. Once you save the workspace, you can re-
use the generated MATLAB variable in the new MATLAB workspace session by opening the
saved the .mat file.
Following MATLAB scripts can be used to access the trace data stored in the generated
MATLAB variable:
■ getPspiceData
■ getPrimaryParamData
■ getPrimaryParamName
■ getSecondaryParamData
■ getSecondaryParamName
■ listPSpiceDataStructAccess
■ listPSpiceDataStructAccessAll
getPspiceData
Use this customized MATLAB script to get the trace data of the MATLAB variable
Syntax
Parameter Description
varName – name of variable created in MATLAB
traceName - trace name. Ennclose in single quotes.
analysisName - Analysis name. Enclose in single quotes.
getPrimaryParamData
Use this customized MATLAB script to get the trace data of the MATLAB variable’s primary
parameter.
Syntax
Parameter Description
varName – name of variable created in current session of the MATLAB command window
analysisName - Analysis name. Enclose in single quotes.
getPrimaryParamName
Use this customized MATLAB script to get the name of the MATLAB variable’s primary
parameter.
Syntax
Parameter Description
varName – name of variable created in current session of the MATLAB command window
analysisName - Analysis name. Enclose in single quotes.
getSecondaryParamData
Use this customized MATLAB script to get the trace data of the MATLAB variable’s secondary
parameter.
Syntax
Parameter Description
varName – name of variable created in current session of the MATLAB command window
analysisName - Analysis name. Enclose in single quotes.
getSecondaryParamName
Use this customized MATLAB script to get the name of the MATLAB variable’s secondary
parameter.
Syntax
Parameter Description
varName – name of variable created in current session of the MATLAB command window
analysisName - Analysis name. Enclose in single quotes.
listPSpiceDataStructAccess
Use this customized MATLAB script to list a specific trace information in a log file. The
generated log file will be stored at the same location as the .dat file.
Syntax
listPSpiceDataStructAccess(<varName>, ‘<matlabVarName>’,
‘<traceName>’)
Parameter Description
varName – name of variable created in current session of the MATLAB command window
matlanVarName - Same as varName. Enclose in single quotes.
traceName - trace name. Ennclose in single quotes.
listPSpiceDataStructAccessAll
Use this customized MATLAB script to list information of all traces in a log file (.log). The
generated log file will be stored at the same location as the .dat file.
Syntax
listPSpiceDataStructAccessAll(<varName>, ‘<matlabVarName>’)
Parameter Description
varName – name of variable created in current session of the MATLAB command window
matlanVarName - Same as varName. Enclose in single quotes.
The chapters in part B introduce you to PSpice Simulink Co-Simulation interface and
describes the various tools involved in working with PSpice Simulink Co-Simulation. The
chapters also describe how to prepare a PSpice project for simulation and work with CIR files.
■ Introducing PSpice Simulink Co-simulation on page 39
■ Creating a Schematic on page 43
■ Interfacing PSpice Designs in MATLAB on page 63
■ Analyzing Simulink Models on page 71
■ Simulation Settings Dialog Description on page 75
6
Introducing PSpice Simulink Co-
simulation
This chapter introduces the PSpice Simulink Co-Simulation interface and lists the
requirements to run it:
■ Introducing the PSpice Simulink Co-Simulation Interface on page 40
■ Requirements for PSpice Simulink Co-Simulation Interface on page 40
PSpice is a SPICE-based simulator used for simulating electrical and electronic circuits, and
The Mathworks tools are used for system designing. PSpice Simulink Co-Simulation interface
integrates these two simulators to provide a simulation flow that can be used to design any
kind of system with electronic sub-systems.
a. MATLAB
b. Simulink
➤ Cadence OrCAD products (R17.2-2016 SPB17.20.011 or later) or Cadence Allegro
products (R17.2-2016 SPB17.20.011 or later)
Install one of the following schematic designer tools:
a. Capture
b. Capture CIS
a. PSpice A/D
You can set the PSpice Simulink Co-simulation solution automatically by performing the
following steps in PSpice:
■ Set Matlab Path using the Set MATLAB Path option from Tools – MATLAB – Set
MATLAB Path.
■ Launch MATLAB using Tools – MATLAB – Co-simulation.
The the MATLAB path settings will be done automatically.
To set the PSpice Simulink Co-simulation solution path manually, do the following:
■ Set the PSpice Simulink Co-simulation path to the PSpice installation in MATLAB. Set
the PSpice Simulink Co-simulation path path as
<Cadence_Installation>\tools\pspice\pspCosim (In the MATLAB window,
Choose File – Set Path). For example, if the installation path is
C:\Cadence\SPB_17.2, the path should be set to
C:\Cadence\SPB_17.2\tools\pspice\pspCosim.
■ Set the PSpice Simulink Co-simulation path as
<Cadence_Installation>\tools\bin in the PATH variable to run PSpice Simulink
Co-Simulation - MATLAB flow.
7
Creating a Schematic
This chapter explains how to create and edit a schematic using either OrCAD Capture or
Allegro Design Entry HDL, simulate the schematic using PSpice, and then create and setup
a block diagram using MATLAB:
■ Creating a schematic on page 44
■ Using PSpice A/D to Simulate Schematic on page 50
■ Creating and Setting Up a Block Diagram Using MATLAB on page 53
Creating a schematic
You can use either OrCAD Capture or Allegro Design Entry HDL to create and edit
schematics.
OrCAD Capture is a schematic design tool set for the Windows environment. With Capture,
you can draft schematics and produce connectivity and simulation information for printed
circuit boards and programmable logic designs.
Design Entry HDL helps you capture the design of a Printed Circuit Board (PCB) in the
schematic form. Design Entry HDL organizes schematic information into pages. It captures
and displays only one page of schematic information at a time. Design Entry HDL is a by-
reference editor because it references all parts in the schematic from various libraries that
reside at the reference or local area. To know more about Design Entry HDL, refer to the
Allegro Design Entry HDL User Guide.
Important
PSpice Simulink Co-simulation uses files created with OrCAD Capture and Allegro
Design Entry HDL, so you cannot directly assign net lists created with applications
other than Capture or Design Entry HDL. But you can use Capture to convert a
SPICE net list to a symbol and incorporate it into a circuit. After inserting the
symbolized net list into a circuit, perform transient analysis with PSpice, and then
assign it to PSpice Simulink Co-simulation. Refer to the chapter Designing for other
EDA applications of the online OrCAD Capture User’s Guide on how to incorporate
a SPICE netlist into a circuit. Refer to the Transient analysis chapter of the online
PSpice User’s Guide on how to perform transient analysis using PSpice.
You will use the New Project dialog box, as shown in the Figure 7-1, of OrCAD Capture to
create a new project.
You can enter the name of the project in the Name text box. You can also select the purpose
of the new project from the options under Create New Project Using. The Location text box
allows you to specify a work directory to save your files.
The project window and schematic page is displayed as shown in Figure 7-3.
You have created the project, now you can create a schematic. Create the circuit as shown
in Figure 7-4. This circuit is comprised of a MOSFET, resistors, and voltage sources.
The input signal of the circuit for verifying operation is a 0.5µ wide 1-shot pulse. Attach the
node name "OUT" to the drain node. You will use this name to specify output voltage from the
PSpice block later. Use the following libraries in creating the schematic:
Library Component
pwrmos.olb M2N6800
analog.olb R
source.olb VSRC
Note: Refer to OrCAD Capture User’s Guide to learn more about creating schematics using
Capture.
Choose File – Save to save the schematic after creating it. You can now use PSpice to
simulate the schematic.
2. In Project Manager, choose File - New - New Design. The New Project Wizard
appears. You can also click the Create Design Project icon to open the New Project
Wizard.
3. In the Name text box, enter the name of the project mosckt.
Note: In Design Entry HDL, project can contain only lower-case characters, numbers,
and the underscore symbol ‘_’.
4. In the Location text box, enter the path to the directory where you want to create the
project.
5. Click Next. The Project Libraries dialog box appears.
6. Select the required libraries from the list of Available Libraries, and click Add. The
libraries are added to the Project Libraries list.
In Project Manager, click on the Design Entry icon to invoke Design Entry HDL.
Note: Refer to Allegro Design Entry HDL User Guide or Allegro Design Entry HDL Tutorial to
learn more about creating schematics using Design Entry HDL.
Before using PSpice A/D to simulate your design, you need to set up analyses.
Note: PSpice is referred to as PSpice Simulator in Design Entry HDL. As a result, in Design
Entry HDL, the PSpice menu is called PSpice Simulator.
To set up analyses:
1. Choose PSpice – New Simulation Profile in Capture or PSpice Simulator – New
Simulation Profile in Design Entry HDL to open the New Simulation dialog box, as
shown in the Figure 7-5.
You have set up the analyses. Now choose PSpice – Run to run the simulation. PSpice A/D
opens and displays an empty plot window. You can now place a marker to display a waveform
on the schematic. Choose PSpice – Markers – Voltage Level on the MOSFET drain node,
as shown in Figure 7-7, to display a drain voltage waveform.
The drain voltage waveform is displayed on the PSpice A/D window, as shown in Figure 7-8.
Note: If a schematic diagram or settings are changed with Capture, you must execute
analysis once using PSpice A/D in order for the changes to be reflected in PSpice Simulink
Co-simulation.
Creating a Block
To create a block:
1. Start MATLAB
2. Set the current MATLAB directory to be the work directory where PSpice files are saved.
3. From the MATLAB command window, choose File – New – Model to create a new
model.
4. Do one of the following to insert a PSpice block in Simulink models:
5. From the MATLAB command window run the pspiceLib command to insert a new
PSpice library block.
Note: A warning might be displayed about inexact match when you run pspiceLib.
However, you can ignore this warning and use PSpice if the PSpice block library is
displayed at the pspIceLib command of the MATLAB command window.
Important
If an error is displayed because pspiceLib is not found, choose File - Set Path.
Set the path to <installation_directory>\tools\pspice\pspCosim.
6. Create a block diagram, as shown in Figure 7-9, using the blocks Repeating Sequence/
Sources and Scope/Sinks.
Important
You can place only one PSpice block in a single Simulink model. If you want to
incorporate multiple circuits, use Capture to create multiple circuit diagram pages
within a project, and connect all the data lines in the Simulink model, which need to
be connected to the circuit, to a single PSpice block.
Now that you have created a block and saved it, you will specify the block parameters.
Note: If you need to replace the old block inside legacy SLPS simulink models to new PSpice
block, do the following steps:
1. Open the Simulink Library Browser using View – Library Browser or using the library
browser icon.
2. Select the PSpice block from the Simulink Library Browser.
3. Drag and place the new PSpice block inside the Simulink model.
4. Replace the old block with the new PSpice block.
Double-click the PSpice block in the MATLAB command window to open the Simulation
Profile window as shown in Figure 7-11.
Enter the capture project file MOSCKT.opj into the Capture Project file text box. You can also
use the Browse button to specify the project file.
You can click the Select button under Input Sources to display the power sources in a circuit
in the IN/OUT select dialog box. You can then select the power source that you want to
designate as the source for the PSpice block. In this example, select the source V1.
Note: At least one input must be designated for PSpice Simulink Co-simulation, but you may
want to assign a circuit with only output to PSpice Simulink Co-simulation (i.e. an oscillator).
In this case, create a dummy circuit (for example, with a power source and resistance) within
the circuit diagram page, do not connect it with the original circuit, and allocate some data to
this power source.
To specify an output for the PSpice block click the Select button under Outputs. In this
example, select V(OUT) from the list displayed in the IN/OUT select dialog box.
After specifying the input sources and output, you can specify data saving options for PSpice
in the PSpice Option Parameter Settings dialog box. To open the dialog box, click Option
Parameters in the Co-simulation Settingswindow. In this example, specify the PSpice Data
Saving Option as Selection Only.
Tip
If you select any option other than none from the PSpiceData Saving Option list, the
analysis speed will be slower. Therefore, it is not recommended to change this
option unless you need it.
You can specify global parameters using the Global Parameter Settings dialog box, if the
target design has PARAMS. To open the dialog box, click Global Parameters. You can
specify one global parameter.
After completing the settings, click OK to close the Cos-mulation Settings window. You can
now set up Simulink analyses.
Save the file after setting up the parameters: choose File - Save.
To simulate using Simulink, choose Simulation - Start. When analysis is finished, double-click
Scope to display the waveform and perform Autoscale. The waveform that appears in
Simulink, shown in Figure 7-13,is similar to the one displayed PSpice.
If you selected any option other than none in the PSpiceData Saving Option in Simulation
Profile window, you can display the PSpice Simulink Co-simulation results using PSpice A/D.
To display the PSpice Simulink Co-simulation simulation results in PSpice, perform the
following tasks:
1. From PSpice A/D, choose File – Open
2. Select the file c:\Work\MOSCKT-PSpice File\SCHEMATIC\Cosim_tran.dat
3. Choose Trace – Add Trace to open the Add Trace dialog box.
4. Select V (M1:d) from the Add Trace dialog box.
The PSpice Probe window displays the PSpice Simulink Co-simulation simulation result, as
shown in Figure 7-14:
5. Replace the old SLPS block with the new PSpice block.
8
Interfacing PSpice Designs in MATLAB
This chapter explains how to prepare PSpice circuits by creating CIR files and describes the
various options of the Simulation Profile window. It also explains the data exchange between
Simulink and PSpice:
■ Using the Simulation Profile Window on page 64
■ Setting Simulink Simulations on page 68
The Co-simulation Settings window allows you to various parameters for the PSpice block.
Following are the elements of this window:
■ Project file: Designates a Capture project file (*.opj) containing a PSpice schematic to
be assigned.
■ Open Project: Opens the designated project in Capture. If a project has not been
designated, Capture will start without a project. You cannot use this button to open a
designated project if Capture has already started. You can either close Capture before
clicking this button, or manually open the designated project from Capture.
Note: If Capture is already open when you start Capture by pressing Open Capture from
Simulation Profile Settings, you cannot open a project.
■ Reload: Updates information about changes in the schematic.
■ Clear All: Clears the items in the Simulation Profile window.
■ PSpice Simulation Profile: Lists all simulation profiles in the project specified in the
Capture Project file text box.
■ Use PSpice simulation profile: Uses the default simulation profile settings.
■ Customize simulation profile: Allows you to use the customized simulation settings.
■ Simulation Options: Allows you to customize the simulation settings using the simulation
settings dialog box. For more information on simulation settings dialog box parameters,
see the Simulation Settings Dialog Description chapter.
■ Enable Simulink Major Step:
■ Input Sources: Designates the voltage source (V*) and current source (I*) for supplying
input data (from Simulink to the PSpice block) into the circuit. If a voltage source is
selected, the input data will be supplied to the circuit as a voltage value, and if a current
source is selected, it will be supplied as a current value. The sequence listed here is the
sequence of input signals to the PSpice block. At least one input source must be
specified.
■ Input Select: Lists all power sources contained in the circuit referenced by the CIR file
specified in the PSpice Circuit file box.
■ Add/Move/Delete buttons for Input: Adds, changes sequence, and deletes items,
respectively, from the Input box.
■ Outputs: Designates data in the circuit to be output from the PSpice block to Simulink.
The sequence listed here is the sequence of output signals to Simulink.
You can set node voltage, current passing through a device, and dissipation of a device
as values for PSpice Simulink Co-simulation output. The specification format for output
values corresponds to that of PSpice.
❑ Node voltage: Specified by the syntax, V([NODENAME]) where NODENAME is the
name of the node in the circuit.
❑ Current passing through a device: Specified by the syntax, I ([DEVICENAME]),
where DEVICENAME is the reference name of the device. The sign of current
passing through a device conforms to PSpice. The direction from Pin 1 to Pin 2 of
the device is defined as positive, as shown in Figure 8-2.
■ Outputs Select: Lists all output variables in the PSpice Simulation profile in the PSpice
Simulation Profile box.
■ Add/Up/Down/Remove buttons for Input: Adds, changes sequence, and deletes items,
respectively, from the Input box.
■ Global Parameters: If any global parameters defined in the design.
Data exchange between Simulink and PSpice A/D via PSpice Simulink Co-simulation is
shown below.
In Simulink, you cannot check an internal property of PSpice that has a smaller time step than
that of Simulink. In addition, there are also some Simulink minor steps for which data is not
exchanged with PSpice, as you can see from the figure above.
To check the internal results of PSpice, designate one of the items other than None under
Data Saving Option in the Simulation Settings window. Then use PSpice A/D to open the
PSpice data file Cosim_***.dat after completing an analysis.
PSpice Simulink Co-simulation can use any one of the items fixed, variable-step, and all, from
the Type list under Solver options.
Because PSpice Simulink Co-simulation data exchange only operates with each Simulink
step, in order to avoid overlooking phenomena from the PSpice circuit, Simulink’s maximum
step size (Simulink’s fixed step size when fixed step is selected) must be a sufficiently small
value. The value, however, should not be smaller than is needed, or Simulink’s overall
analysis may become slow.
As you can see from Figure 8-4, you cannot obtain the correct waveform if the maximum step
size is set to a large value.
PSpice internal
value
Calculation result within PSpice
Time T
0 1 2 3 4 5 6 7 8
Time T
0 1 2 3 4 5 6 7 8
If you want to see a waveform within PSpice in order to determine the step size, check it by
starting PSpice A/D and opening the PSpice data file, though it will not be displayed in
Simulink.
Note: When the PSpice block is inserted in the feedback loop, calculation in the PSpice block
is performed by PSpice, which operates in a different memory space than that of Simulink. In
principle, a delay of one Simulink cycle step will occur between the PSpice block's input and
its output. To minimize this effect, Simulink’s time steps must be sufficiently small.
9
Analyzing Simulink Models
This chapter explains how to analyze a Simulink model, change parameters to avoid
convergence errors, and verify results using PSpice:
■ Running a simulation from Simulink model on page 72
■ Verifying results on page 72
If a convergence error occurs within PSpice during analysis with Simulink, increase the option
parameter ITL4 of PSpice up to the value specified in ITL4 Max in Simulation Settings, and
retry analysis. However, if PSpice cannot get a result a Convergence Error message is
displayed.
You can recalculate convergence by changing the analysis options using the Simulation
Settings dialog box.
After you change these parameters, click OK. PSpice will continue with the calculation using
the changed analysis options.
Normally, if a convergence error occurs during analysis, set the value of ITL4 to a large value,
such as 1000. As a result, you can improve convergence without changing analysis accuracy.
Verifying results
You can verify Simulink model analyses results by two methods. You can:
■ check the output of PSpice Simulink Co-simulation using the scope in Simulink.
■ verify the results obtained in Co-simulation by opening the PSpice data file in PSpice.
This will display the waveform in the PSpice A/D window, as shown in Figure 9-1:
When you call PSpice from PSpice Simulink Co-simulation to perform an analysis, PSpice
creates a data file (*.dat) and an output file (*.out). A PSpice data file stores calculation data
within PSpice Simulink Co-simulation, either for the entire circuit or for the part selected as
PSpice Simulink Co-simulation output. If you select none as the PSpice Data Saving Option
in the Simulation Profile window, PSpice will create an empty data file. The output file contains
information, such as the analysis log, in text format and is used to verify internal errors that
might occur during analysis., The data file and the output files are created in the directory
designated for the CIR file.
10
Simulation Settings Dialog Description
Use the Options tab of the Simulation Settings dialog box to fine-tune how PSpice performs
calculations for PSpice Simulink C-Simulation, as well as what information to save to the
simulation output file (*.OUT):
Use the Analog Simulation settings to fine-tune analog simulation accuracy, set iteration
limits, set operating temperature, and specify MOSFET parameters.
The option names shown in the text box correspond to the option names used in the PSpice
.OPTIONS command. For more information about this command, refer to the PSpice
Reference Guide.
The following tables defines all the options in the tab for the Analog Simulation category:
Use the Analog Simulation settings to enter values for the total transient iteration limit, relative
magnitude for matrix pivot, and absolute magnitude for matrix pivot.
The option names shown to the right of each text box correspond to the option names used
in the PSpice .OPTIONS command. For more information about this command, refer to the
PSpice Reference Guide.
Click this… To do this…
General Enter values for speed level, tolerances, and minimum
conductance.
Bias Point Suggest relaxed limits for various options that PSpice can
modify during a simulation to achieve convergence.
Transient Enter values for the default drain area, default source area,
default length, and default width.
The following tables defines all the options in the tab for the Analog Advanced category:
Use the Gate Level Simulation settings to set timing, I/O levels for interfaces, drive strength,
and error message limits.
Click this button… To do this…
General Enter values to set delay or initiali state in flip-flops or latches.
Advanced options Enter values for the minimum output drive resistance, maximum
output drive resistance, overdrive ratio, default delay
calculation, and error message limits.
The following tables defines all the options in the tab for the Gate Level Simulation category:
Use the Output File settings to select the types of information PSpice saves to the simulation
output file.
The following table defines all the options in the tab for the Output file category: