100% found this document useful (1 vote)
681 views82 pages

PSpice 17.2 MATLAB Interface User Guide (PSP - Matlab - Ug) PDF

Uploaded by

Nancy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
681 views82 pages

PSpice 17.2 MATLAB Interface User Guide (PSP - Matlab - Ug) PDF

Uploaded by

Nancy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 82

PSpice MATLAB Interface User Guide

Product Version 17.2-2016


April 2016
Document Last Updated: March 29, 2017
© 2006–2015 Cadence Design Systems, Inc. All rights reserved.
Portions © Apache Software Foundation, Sun Microsystems, Free Software Foundation, Inc., Regents of
the University of California, Massachusetts Institute of Technology, University of Florida. Used by
permission. Printed in the United States of America.
Cadence Design Systems, Inc. (Cadence), 2655 Seely Ave., San Jose, CA 95134, USA.
Product PSpice contains technology licensed from, and copyrighted by: Apache Software Foundation,
1901 Munsey Drive Forest Hill, MD 21050, USA © 2000-2005, Apache Software Foundation. Sun
Microsystems, 4150 Network Circle, Santa Clara, CA 95054 USA © 1994-2007, Sun Microsystems, Inc.
Free Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA © 1989, 1991, Free
Software Foundation, Inc. Regents of the University of California, Sun Microsystems, Inc., Scriptics
Corporation, © 2001, Regents of the University of California. Daniel Stenberg, © 1996 - 2006, Daniel
Stenberg. UMFPACK © 2005, Timothy A. Davis, University of Florida, ([email protected]). Ken Martin, Will
Schroeder, Bill Lorensen © 1993-2002, Ken Martin, Will Schroeder, Bill Lorensen. Massachusetts Institute
of Technology, 77 Massachusetts Avenue, Cambridge, Massachusetts, USA © 2003, the Board of Trustees
of Massachusetts Institute of Technology. All rights reserved.
Trademarks: Trademarks and service marks of Cadence Design Systems, Inc. contained in this document
are attributed to Cadence with the appropriate symbol. For queries regarding Cadence’s trademarks,
contact the corporate legal department at the address shown above or call 800.862.4522.
Open SystemC, Open SystemC Initiative, OSCI, SystemC, and SystemC Initiative are trademarks or
registered trademarks of Open SystemC Initiative, Inc. in the United States and other countries and are
used with permission.
MATLAB and SimuLink are registered trademarks of MathWorks.
All other trademarks are the property of their respective holders.
Restricted Permission: This publication is protected by copyright law and international treaties and
contains trade secrets and proprietary information owned by Cadence. Unauthorized reproduction or
distribution of this publication, or any portion of it, may result in civil and criminal penalties. Except as
specified in this permission statement, this publication may not be copied, reproduced, modified, published,
uploaded, posted, transmitted, or distributed in any way, without prior written permission from Cadence.
Unless otherwise agreed to by Cadence in writing, this statement grants Cadence customers permission to
print one (1) hard copy of this publication subject to the following conditions:
1. The publication may be used only in accordance with a written agreement between Cadence and its
customer.
2. The publication may not be modified in any way.
3. Any authorized copy of the publication or portion thereof must include all original copyright,
trademark, and other proprietary notices and this permission statement.
4. The information contained in this document cannot be used in the development of like products or
software, whether for internal or external use, and shall not be used for the benefit of any other party,
whether or not for consideration.
Disclaimer: Information in this publication is subject to change without notice and does not represent a
commitment on the part of Cadence. Except as may be explicitly set forth in such agreement, Cadence does
not make, and expressly disclaims, any representations or warranties as to the completeness, accuracy or
usefulness of the information contained in this document. Cadence does not warrant that use of such
information will not infringe any third party rights, nor does Cadence assume any liability for damages or
costs of any kind that may result from use of such information.
Restricted Rights: Use, duplication, or disclosure by the Government is subject to restrictions as set forth
in FAR52.227-14 and DFAR252.227-7013 et seq. or its successor.
PSpice MATLAB Interface User Guide

Contents

1
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Understanding Various MATLAB-related flows ................................. 8

Part A: Working with PSpice - MATLAB Interface for Advanced


Waveform Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9

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

April 2016 3 Product Version 17.2-2016


© 1999-2016 All Rights Reserved.
PSpice MATLAB Interface User Guide

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

Part B: Working with the PSpice Simulink Co-Simulation


Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37

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

April 2016 4 Product Version 17.2-2016


© 1999-2016 All Rights Reserved.
PSpice MATLAB Interface User Guide

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

April 2016 5 Product Version 17.2-2016


© 1999-2016 All Rights Reserved.
PSpice MATLAB Interface User Guide

April 2016 6 Product Version 17.2-2016


© 1999-2016 All Rights Reserved.
PSpice MATLAB Interface User Guide

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.

PSpice Simulink Co-Simulation, which is co-simulation of PSpice and Mathworks® Simulink,


combines the best-in-class software tools to provide unmatched design simulation
environment for electrical and physical system together. PSpice Simulink Co-Simulation
Interface allows you to substitute electronic blocks in PSpice, while the rest of the design is
simulated using MATLAB or Simulink. As a result, you can now use a single prototype to co-
simulate the electrical and mechanical systems. Co-simulation environment allows to
simulate whole system with more realistic element models before trial manufacturing.

April 2016 7 Product Version 17.2-2016


© 1999-2016 All Rights Reserved.
PSpice MATLAB Interface User Guide
Introduction

Understanding Various MATLAB-related flows


This guide is categorized in two parts: Part A and Part B. The following table explains the
various flows that this guide covers:

Flow Covered Description


PSpice - MATLAB PSpice - MATLAB Interface is PSpice-driven flow, where you can
Flow (Page 9) export the trace data to MATLAB using PSpice. MATLAB is only
required for advanced plotting and visualization. For using
measurement functions and MATLAB function in the behaviorial
expression, MATLAB works in the background and you will not have
to launch MATLAB User Interface. For more details on how to start
with PSpice - MATLAB Interface for Advance Waveform Analysis, see
the following chapters:
❑ 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
MATLAB - PSpice PSpice Simulink Co-Simulation Interface is a MATLAB-driven flow,
flow (Page 37) where you can drive the PSpice block from MATLAB. For more details
about how to start with the PSpice Simulink Co-Simulation interface,
see the following chapters:
❑ 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

April 2016 8 Product Version 17.2-2016


© 1999-2016 All Rights Reserved.
PSpice MATLAB Interface User Guide

Part A: Working with PSpice - MATLAB


Interface for Advanced Waveform
Analysis

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

April 2016 9 Product Version 17.2-2016


PSpice MATLAB Interface User Guide
Part A: Working with PSpice - MATLAB Interface for Advanced Waveform Analysis

April 2016 10 Product Version 17.2-2016


PSpice MATLAB Interface User Guide

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

April 2016 11 Product Version 17.2-2016


© 1999-2016 All Rights Reserved.
PSpice MATLAB Interface User Guide
Introducing the Advanced Waveform Analysis

Advanced Waveform Analysis


PSpice has been used to simulate analog-ony, mixed analog/digital, and digital-only circuits
for a long time. Now, PSpice capabilities as a simulation software has been enhanced further
with the integration of new PSpice - MATLAB Interface.

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.

License and Software Requirements for the Advanced


Waveform Analysis
To run various flows using the PSpice - MATLAB interface, you need to have
OrCAD_PSpice_Systems_Option (PA4500)or Allegro_PSpice_Systems_Option
(PO4500)license and should have the following combinations of the Cadence or OrCAD
products installed on your system:
➤ The Mathworks products (2015b or later)

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

c. Allegro Design Entry CIS

d. Allegro Design Entry HDL


Install the following simulator:

a. PSpice A/D

April 2016 12 Product Version 17.2-2016


© 1999-2016 All Rights Reserved.
PSpice MATLAB Interface User Guide

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

April 2016 13 Product Version 17.2-2016


© 1999-2016 All Rights Reserved.
PSpice MATLAB Interface User Guide
Setting Up the PSpice - MATLAB flow for Advanced Waveform Analsysis

Setting Up the MATLAB Path


Before you export the traces to MATLAB, set the MATLAB path in PSpice using Tools –
MATLAB – Set MATLAB Path. The MATLAB path should end at the bin folder, such as
<MATLAB installation>\bin.

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.

Running the MATLAB Engine


You need to start the MATLAB engine for smooth first launch of the MATLAB command
window. If you have not started the MATLAB engine before exporting the trace data, the first
launch of the MATLAB command window is delayed by few seconds. To run the MATLAB
engine, choose Tools – MATLAB - Start MATLAB Engine in PSpice.

April 2016 14 Product Version 17.2-2016


© 1999-2016 All Rights Reserved.
PSpice MATLAB Interface User Guide
Setting Up the PSpice - MATLAB flow for Advanced Waveform Analsysis

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.

April 2016 15 Product Version 17.2-2016


© 1999-2016 All Rights Reserved.
PSpice MATLAB Interface User Guide
Setting Up the PSpice - MATLAB flow for Advanced Waveform Analsysis

April 2016 16 Product Version 17.2-2016


© 1999-2016 All Rights Reserved.
PSpice MATLAB Interface User Guide

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.

The PSpice - MATLAB flows covered in this chapter are:


■ Using MATLAB Visualization Capabilities in PSpice on page 18
■ Calling the MATLAB function in PSpice on page 24
■ Using the MATLAB-based Measurement Function in PSpice on page 26

April 2016 17 Product Version 17.2-2016


© 1999-2016 All Rights Reserved.
PSpice MATLAB Interface User Guide
Understanding Advanced Waveform Analysis Flows

Using MATLAB Visualization Capabilities in PSpice


The new PSpice - MATLAB interface provides some of the best capabilities of MATLAB for
speciliazied plotting. You can export the PSpice trace data to MATLAB and generate various
plots, such as polar plots, 3D Plots.

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.

In the Export to MATLAB window, you can:


■ Select one or more traces that you want to be exported to MATLAB for advanced plotting
and visualization.
■ List the simulation output variable as Flat or Hierarchical. The following screenshot
illustrates the hierarchical structure of the simulation output variables:

April 2016 18 Product Version 17.2-2016


© 1999-2016 All Rights Reserved.
PSpice MATLAB Interface User Guide
Understanding Advanced Waveform Analysis Flows

■ 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:

April 2016 19 Product Version 17.2-2016


© 1999-2016 All Rights Reserved.
PSpice MATLAB Interface User Guide
Understanding Advanced Waveform Analysis Flows

1. Select Tools – MATLAB – Export Selected Traces to export selected traces to


MATLAB after you have simulated the schematic design.
The Export to MATLAB window is displayed.
2. In the Export to MATLAB window, select the sections that you want to use to export the
trace data.
If you have mult-section simulation, you can select one or more sections from the Select
Section window.
3. Select the traces you want to export to MATLAB in the Export to MATLAB window.
A default function, plotTraces, is used in the Export to MATLAB window to plot the
selected traces in the MATLAB plot window.
Note: You can add your own custom plot function in the Export to MATLAB window. For
more information, see the Using Customized MATLAB Plotting Functions in PSpice
section.
4. (Optional) Enter the MATLAB variable name that will have all the exported trace data. In
case, you have not entered any variable name, a default MATLAB variable will be
generated.
5. Once you have selected the traces, click the Export button.
If you have not started the MATLAB Engine, you will see the MATLAB command window
getting displayed. Also, a MATLAB figure panel is displayed with trace plot of the selected
trace with respect to time.
Note: Once you export the trace data to MATLAB, a MATLAB variable is generated, such
as PSpiceData_<instance number> if you have not mentioned any in the MATLAB
variable field. The instance number gets incremented every time you export a new trace
data to MATLAB.
The following screenshots illustrates an example of plots generated using the default
plotTraces function:

April 2016 20 Product Version 17.2-2016


© 1999-2016 All Rights Reserved.
PSpice MATLAB Interface User Guide
Understanding Advanced Waveform Analysis Flows

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

April 2016 21 Product Version 17.2-2016


© 1999-2016 All Rights Reserved.
PSpice MATLAB Interface User Guide
Understanding Advanced Waveform Analysis Flows

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.

Using Customized MATLAB Plotting Functions in PSpice


Pspice allows you to add your customized MATLAB plotting functions and use them through
the Export to MATLAB window. Using customized MATLAB functions, you can visualize
different plots other than the default one created using the plotTraces function. For example,
you can use customized function to create a polar plot or 3D plot that can really help in
understanding the data in more detail. The Customized MATLAB function should be saved as
MATLAB Script (.m) file. The

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:

April 2016 22 Product Version 17.2-2016


© 1999-2016 All Rights Reserved.
PSpice MATLAB Interface User Guide
Understanding Advanced Waveform Analysis Flows

April 2016 23 Product Version 17.2-2016


© 1999-2016 All Rights Reserved.
PSpice MATLAB Interface User Guide
Understanding Advanced Waveform Analysis Flows

Calling the MATLAB function in PSpice


PSpice allows you to add various function for the behaviorial controlled devices. These
functions could be related to mathematical expressions, laplace tranformations, lograthmic
function and many more.

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:

MATLABFunction(<MATLAB_function>, <Parameter_1>, <Parameter_2>,


<number of parameters>)

The following screenshot illustrates an example of the MATLABFunction function. In this


example, there is a power Matlab function. V(%IN) and 2.3 are two parameters used in the
functon. 2 defines number of parameters used in <actual_MATLAB_Function>. :

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.

April 2016 24 Product Version 17.2-2016


© 1999-2016 All Rights Reserved.
PSpice MATLAB Interface User Guide
Understanding Advanced Waveform Analysis Flows

❑ The <number_of_parameters> argument is parameters that the actual MATLAB


function can take in the MATLABFunction function. If the MATLAB function used in
MATLABFunction has five arguments as parameters, the <number_of_parameters>
argument will be five.
❑ The parameter and return type of the <MATLAB_function> used in
MATLABFunction is constant, not an array or a matrix. The constant values can be
one of the following types: integers, double, and float. If parameters other than
constant are used, the MATLABFunction function will not simulate.

Once the function is simulated, you can see the simultion results in PSpice as shown in the
following screenshot:

April 2016 25 Product Version 17.2-2016


© 1999-2016 All Rights Reserved.
PSpice MATLAB Interface User Guide
Understanding Advanced Waveform Analysis Flows

Using the MATLAB-based Measurement Function in


PSpice
PSpice allows you to use various measurement functions to evaluate the characteristics of
the waveform generated after simulation is completed. For more information on various
measurement functions, see the Measurement Expressions chapter in PSpice USer
Guide.

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:

a. For matlabFunction1: First argument is Trace Name, second argument is the


MATLAB function. For example, matlabFunction1(V(out), risetime).

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).

April 2016 26 Product Version 17.2-2016


© 1999-2016 All Rights Reserved.
PSpice MATLAB Interface User Guide
Understanding Advanced Waveform Analysis Flows

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.

April 2016 27 Product Version 17.2-2016


© 1999-2016 All Rights Reserved.
PSpice MATLAB Interface User Guide
Understanding Advanced Waveform Analysis Flows

April 2016 28 Product Version 17.2-2016


© 1999-2016 All Rights Reserved.
PSpice MATLAB Interface User Guide

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

April 2016 29 Product Version 17.2-2016


© 1999-2016 All Rights Reserved.
PSpice MATLAB Interface User Guide
Accessing Trace Data from the MATLAB Variable

What is the generated MATLAB variable?


Whenever you export the traces to MATLAB, either a default MATLAB variable is generated
in the MATLAB command window, such as PSpiceData_N, where N is a digit; or a
customized MATLAB variable is generated in the MATLAB command window, such as
MyVAR.

The MATLAB variable is a structured array that contains


■ full path of the trace data file (.dat),
■ name of the trace data file, and
■ trace data in the Analysis struct variable.

The following diagram illustrates the tree structure of the generated MATLAB variable:

April 2016 30 Product Version 17.2-2016


© 1999-2016 All Rights Reserved.
PSpice MATLAB Interface User Guide
Accessing Trace Data from the MATLAB Variable

How to check if the MATLAB variable is generated or not?


To check if the MATLAB variable is generated in the MATLAB command window, type who
on the command prompt of the MATLAB command window.

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 launch the desktop version of MATLAB from the MATLAB


command window?
Type desktop on the MATLAB command window’s prompt to launch MATLAB’s desktop
version.

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.

How to access the previously generated MATLAB variabe in the current


session of MATLAB workspace?
You can not access previously generated MATLAB variables in the current session of the
MATLAB workspace unless you have saved the previous MATLAB workspace seesion. As
MATLAB workspace sessions are independent of each other, therefore all the trace data is
lost after you close them.

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-

April 2016 31 Product Version 17.2-2016


© 1999-2016 All Rights Reserved.
PSpice MATLAB Interface User Guide
Accessing Trace Data from the MATLAB Variable

use the generated MATLAB variable in the new MATLAB workspace session by opening the
saved the .mat file.

Where are various customized scripts stored in the Cadence hierarchy


and how to use them?
To access the customized MATLAB scripts from the Cadence hierarchy, browse the following
location in the MATLAB’s Current Folder window: <Cadence
Installation>\tools\pspice\tclscripts\orPSPMatlab\MatlabScripts.

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

getPspiceData(<varName in MATLAB workspace>, ‘<analysisName>’,


‘<traceName>’)

Parameter Description
varName – name of variable created in MATLAB
traceName - trace name. Ennclose in single quotes.
analysisName - Analysis name. Enclose in single quotes.

April 2016 32 Product Version 17.2-2016


© 1999-2016 All Rights Reserved.
PSpice MATLAB Interface User Guide
Accessing Trace Data from the MATLAB Variable

getPrimaryParamData

Use this customized MATLAB script to get the trace data of the MATLAB variable’s primary
parameter.

Syntax

getPrimaryParamData(<varName in MATLAB workspace>, ‘<analysisName>’)

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

getPrimaryParamName(<varName in MATLAB workspace>, ‘<analysisName>’)

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

getSecondaryParamData(<varName in MATLAB workspace>,


‘<analysisName>’)

April 2016 33 Product Version 17.2-2016


© 1999-2016 All Rights Reserved.
PSpice MATLAB Interface User Guide
Accessing Trace Data from the MATLAB Variable

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

getSecondaryParamName(<varName in MATLAB workspace>,


‘<analysisName>’)

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.

April 2016 34 Product Version 17.2-2016


© 1999-2016 All Rights Reserved.
PSpice MATLAB Interface User Guide
Accessing Trace Data from the MATLAB Variable

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.

April 2016 35 Product Version 17.2-2016


© 1999-2016 All Rights Reserved.
PSpice MATLAB Interface User Guide
Accessing Trace Data from the MATLAB Variable

April 2016 36 Product Version 17.2-2016


© 1999-2016 All Rights Reserved.
PSpice MATLAB Interface User Guide

Part B: Working with the PSpice Simulink


Co-Simulation Interface

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

April 2016 37 Product Version 17.2-2016


PSpice MATLAB Interface User Guide
Part B: Working with the PSpice Simulink Co-Simulation Interface

April 2016 38 Product Version 17.2-2016


PSpice MATLAB Interface User Guide

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

April 2016 39 Product Version 17.2-2016


PSpice MATLAB Interface User Guide
Introducing PSpice Simulink Co-simulation

Introducing the PSpice Simulink Co-Simulation Interface


PSpice Simulink Co-Simulation Interface is an interface tool that links PSpice to the
MATLAB® modeling tool and also to Simulink® system simulator, provided by The
Mathworks.

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.

Requirements for PSpice Simulink Co-Simulation


Interface
To be able to use PSpice Simulink Co-Simulation Interface, you need to acquire either
Allegro PSpice Systems Option (PA4500) or OrCAD PSpice Systems Option
(PO4500) license from Cadence, and should have the following combination of The
Mathworks and Cadence OrCAD products installed on your system:
➤ The Mathworks products (64-bit 2015b or later)

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

c. Allegro Design Entry CIS

d. Allegro Design Entry HDL


Install the following simulator:

a. PSpice A/D

b. Allegro PSpice Simulator

April 2016 40 Product Version 17.2-2016


PSpice MATLAB Interface User Guide
Introducing PSpice Simulink Co-simulation

Setting Up the PSpice Simulink Co-simulation solution


There are two following ways to setup the new PSpice Simulink Co-simulation solution:
■ Automatic Setup
■ Manual Setup

Automatic Setup of the PSpice Simulink Co-simulation solution

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.

Manual Setup of the PSpice Simulink Co-simulation solution

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.

April 2016 41 Product Version 17.2-2016


PSpice MATLAB Interface User Guide
Introducing PSpice Simulink Co-simulation

April 2016 42 Product Version 17.2-2016


PSpice MATLAB Interface User Guide

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

April 2016 43 Product Version 17.2-2016


PSpice MATLAB Interface User Guide
Creating a Schematic

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.

The following section explains how to create schematics.

Using OrCAD Capture


You need to perform the following steps to create a schematic using Capture:
1. Create a project in OrCAD Capture
2. Create the schematic

You will use the New Project dialog box, as shown in the Figure 7-1, of OrCAD Capture to
create a new project.

April 2016 44 Product Version 17.2-2016


PSpice MATLAB Interface User Guide
Creating a Schematic

Figure 7-1 New Project dialog box

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.

Perform the following steps to create a new project:


1. Start OrCAD Capture
2. Choose File – New – Project to open the New project dialog box.
3. Enter MOSCKT into the Name text box.
4. Select Analog or Mixed A/D under Create New Project Using group box.
5. Specify the work directory in the Location text box. For this example, create a directory,
Work in the C drive.
6. Click OK.
The Create PSpice Project dialog box, shown in Figure7-2, will be displayed since you
had selected Analog or Mixed A/D under Create New Project Using group box.

April 2016 45 Product Version 17.2-2016


PSpice MATLAB Interface User Guide
Creating a Schematic

Figure 7-2 Create PSpice Project dialog box


7. Select Create a Blank Project and click OK.

The project window and schematic page is displayed as shown in Figure 7-3.

Project window Schematic page

Figure 7-3 Project window with schematic page

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.

April 2016 46 Product Version 17.2-2016


PSpice MATLAB Interface User Guide
Creating a Schematic

Figure 7-4 Circuit with 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.

April 2016 47 Product Version 17.2-2016


PSpice MATLAB Interface User Guide
Creating a Schematic

Using Design Entry HDL


You need to perform the following steps to create a schematic using Design Entry HDL:
1. Create a project in Project Manager
2. Create the schematic

To create a new project:


1. Invoke Project Manager.

April 2016 48 Product Version 17.2-2016


PSpice MATLAB Interface User Guide
Creating a 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.

April 2016 49 Product Version 17.2-2016


PSpice MATLAB Interface User Guide
Creating a Schematic

7. Click Next. The Design Name dialog box appears.


8. In the Design Name text box, enter the name of the top level design.
9. Click Next. The Summary dialog box displays the project details.
10. Click Finish to create the project.

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.

Using PSpice A/D to Simulate Schematic


PSpice A/D simulates analog-only, mixed analog/digital, and digital-only circuits. PSpice A/
D’s analog and digital algorithms are built into the same program so that mixed analog/digital
circuits can be simulated with tightly-coupled feedback loops between the analog and digital
sections without any performance degradation.

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.

Figure 7-5 New Simulation dialog box


2. Enter the name of the simulation profile into the Name text box. For the example used in
this chapter, enter the name as Tran.

April 2016 50 Product Version 17.2-2016


PSpice MATLAB Interface User Guide
Creating a Schematic

3. Select none from the Inherit From list.


Click Create.
The Simulation Settings dialog box appears as shown in Figure 7-6.

Figure 7-6 Simulation Settings dialog box


4. In the Simulation Settings dialog box:
❑ Specify the Analysis type as Time Domain (Transient)
❑ Specify the Run to time as 3u (3u seconds).
❑ Click OK.
Note: To learn more about the Simulation Settings dialog box options, see Chapter 8, Setting
Up Analyses and Starting Simulations, of the PSpice User’s Guide.

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.

April 2016 51 Product Version 17.2-2016


PSpice MATLAB Interface User Guide
Creating a Schematic

Figure 7-7 Voltage level on MOSFET

The drain voltage waveform is displayed on the PSpice A/D window, as shown in Figure 7-8.

Figure 7-8 Drain Voltage waveform

April 2016 52 Product Version 17.2-2016


PSpice MATLAB Interface User Guide
Creating a Schematic

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 and Setting Up a Block Diagram Using MATLAB


In this section, you will learn how to use MATLAB to create a block, set PSpice Simulink Co-
simulation block parameters, set up Simulink analyses, and simulate using both PSpice and
Simulink.

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.

April 2016 53 Product Version 17.2-2016


PSpice MATLAB Interface User Guide
Creating a Schematic

Figure 7-9 Block diagram using Repeating Sequence/Source and Scope/Sinks


7. Specify the repeating sequence parameters as shown in Figure 7-10.

Figure 7-10 Repeating Sequence parameters


8. Save the model with the file name mosckt.mdl in the current directory.

April 2016 54 Product Version 17.2-2016


PSpice MATLAB Interface User Guide
Creating a Schematic

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.

Setting Up Block Parameters


You will use the Simulation Profile window to specify the following block parameters:
■ the Capture project file
■ the input sources and outputs for the PSpice block
■ the PSpice data saving options

Double-click the PSpice block in the MATLAB command window to open the Simulation
Profile window as shown in Figure 7-11.

April 2016 55 Product Version 17.2-2016


PSpice MATLAB Interface User Guide
Creating a Schematic

Figure 7-11 Simulation Profile window

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.

April 2016 56 Product Version 17.2-2016


PSpice MATLAB Interface User Guide
Creating a Schematic

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.

Setting Up Simulink Analyses


You can use the Simulation Settings dialog box, shown in Figure 7-12, to set up a Simulink
analyses. To open the Simulation Parameters dialog box, choose Simulation – Model
Configuration Parameters from the model window menu.

April 2016 57 Product Version 17.2-2016


PSpice MATLAB Interface User Guide
Creating a Schematic

Figure 7-12 Simulation Parameters dialog box

In the Simulation Parameters dialog specify the following parameters:


■ Under Simulation time, enter 3e-6 (3usec) into the Stop time text box.
■ Under Solver Options:
❑ In the Type list boxes specify Fixed-step and discrete.
❑ In the Fixed step size list box, specify 1e-9.

Save the file after setting up the parameters: choose File - Save.

Simulating and Verifying Results


You can now simulate the analyses using Simulink and then verify the PSpice block results
from both Simulink and PSpice.

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.

April 2016 58 Product Version 17.2-2016


PSpice MATLAB Interface User Guide
Creating a Schematic

Figure 7-13 The waveform in the Scope window

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:

April 2016 59 Product Version 17.2-2016


PSpice MATLAB Interface User Guide
Creating a Schematic

Figure 7-14 PSpice Simulink Co-simulation simulation result in PSpice

Migrating existing PSpice SLPS designs to new PSpice


Simulink Co-simulation design
PSpice Simulink Co-simulation allows you to easily migrate the existing PSpice SLPS designs
(.mdl) to new PSpice Simulink Co-simulation designs (.mdl). To use the existing designs in
the new solution, we need to only replace the existing SLPS block with the new PSpice block.
Once done, the existing designs will smoothly run in the new solution.To replace the old SLPS
block in existing designs, do the following:
Note: Before you migrate the old simulink designs to new PSpice Simulink Co-simulation
solution, remove all the existing PSpice SLPS solution path from the MATLAB’s path settings.
1. Open the Simulink file (.mdl) in Simulink.
2. Open Simulink Library Browser in the model window using View – Library Browser.
3. Select the PSpice block from Simulink Library Browser.
4. Drag and drop the PSpice block from Simulink Library Browser to the simulink design.

April 2016 60 Product Version 17.2-2016


PSpice MATLAB Interface User Guide
Creating a Schematic

5. Replace the old SLPS block with the new PSpice block.

April 2016 61 Product Version 17.2-2016


PSpice MATLAB Interface User Guide
Creating a Schematic

April 2016 62 Product Version 17.2-2016


PSpice MATLAB Interface User Guide

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

April 2016 63 Product Version 17.2-2016


PSpice MATLAB Interface User Guide
Interfacing PSpice Designs in MATLAB

Using the Simulation Profile Window


You can open the Simulation Profile window by double-clicking the PSpice block in a MATLAB
command window, as shown in Figure 8-1.

Figure 8-1 Co-simulation Settings window

April 2016 64 Product Version 17.2-2016


PSpice MATLAB Interface User Guide
Interfacing PSpice Designs in MATLAB

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

April 2016 65 Product Version 17.2-2016


PSpice MATLAB Interface User Guide
Interfacing PSpice Designs in MATLAB

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.

Figure 8-2 Device positive current direction


❑ Pin inflow current: Specified by the syntax I[PINNAME]([DEVICENAME]) where
PINNAME is the pin name of the element. For pin inflow current, the direction flowing
into the pin is regarded as positive, as shown in Figure 8-3.

Figure 8-3 Pin positive current direction


❑ Power dissipation of device: Specified by the syntax W([DEVICENAME]). Power
dissipation is calculated as I*V. However, since the absolute value of current is
taken, the current directions do not matter.

April 2016 66 Product Version 17.2-2016


PSpice MATLAB Interface User Guide
Interfacing PSpice Designs in MATLAB

■ 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


When a PSpice block is placed in a Simulink model, two different analysis engines are used
for simulation, where transient analysis will be done at their respective time step.

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.

April 2016 67 Product Version 17.2-2016


PSpice MATLAB Interface User Guide
Interfacing PSpice Designs in MATLAB

Setting Simulink Simulations


You can use the Simulink Parameters dialog box to specify the settings for the Simulink
simulations. To open the Simulation Parameters dialog box, in the Simulink model window,
choose Simulation – Model Configuration parameters.

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

SLPS output value


When maximum step size of Simulink is set to 2
When maximum step size of Simulink is set to 1

Time T

0 1 2 3 4 5 6 7 8

April 2016 68 Product Version 17.2-2016


PSpice MATLAB Interface User Guide
Interfacing PSpice Designs in MATLAB

Figure 8-4 Waveform with large maximum step size value

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.

April 2016 69 Product Version 17.2-2016


PSpice MATLAB Interface User Guide
Interfacing PSpice Designs in MATLAB

April 2016 70 Product Version 17.2-2016


PSpice MATLAB Interface User Guide

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

April 2016 71 Product Version 17.2-2016


PSpice MATLAB Interface User Guide
Analyzing Simulink Models

Running a simulation from Simulink model


You can start a simulation to analyze a Simulink model containing an PSpice block. To do so,
choose Simulation - Start from the Simulink model menu.

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:

April 2016 72 Product Version 17.2-2016


PSpice MATLAB Interface User Guide
Analyzing Simulink Models

Figure 9-1 Waveform displayed in PSpice window

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.

April 2016 73 Product Version 17.2-2016


PSpice MATLAB Interface User Guide
Analyzing Simulink Models

April 2016 74 Product Version 17.2-2016


PSpice MATLAB Interface User Guide

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):

Analog simulation options

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.

Click this button… To do this…


General Enter values for speed level, tolerances, and minimum
conductance.
AutoConverge Suggest relaxed limits for various options that PSpice can
modify during a simulation to achieve convergence.
MOSFET options 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 Simulation category:

Flag option Meaning


ADVCONV Enables all convergence algorithms, such as Pseudo Tran,
STEPGMIN, and step sources. ON by default.
AutoConverge Suggest relaxed limits for various options that PSpice can modify
during a simulation to achieve convergence.

April 2016 75 Product Version 17.2-2016


© 1999-2016 All Rights Reserved.
PSpice MATLAB Interface User Guide
Simulation Settings Dialog Description

Flag option, Meaning, continued


Restart Restart the convergence calculation
PREODER Presorts the matrix diagonal by Markowitz counts.

Options Description Units Default


General
section..
SPEED_LEVEL increases simulation performance by - 3
optimizing switching behavior of models. If
increase in simulation performance is not
needed, set SPEED_LEVEL=0.
RELTOL relative accuracy of V and I 0.001
VNTOL best accuracy of voltages volt 1.0 uV
ABSTOL best accuracy of currents amp 1.0 pA
CHGTOL best accuracy of charges coulomb 0.01 pC
GMIN minimum conductance used for any branch ohm-1 1.0E-12
Auto Converge
section..
ITL1 Maximum number of iterations of 150.0
convergence calculation during bias point
analysis
ITL2 Maximum number of iterations of convergence 20
calculation during DC analysis
ITL4 Maximum number of iterations of convergence 10
calculation at each time step during transient
analysis
TNOM Nominal Temperature value Celsius 27 degrees
Celsius
THREADS maximum number of threads. Set to 0 for Number of
engine default. THREADS=1 implies single- cores/2
thread.

April 2016 76 Product Version 17.2-2016


© 1999-2016 All Rights Reserved.
PSpice MATLAB Interface User Guide
Simulation Settings Dialog Description

Options Description Units Default


PIVTOL absolute magnitude required for pivot in matrix 1.0E-13
solution
MOSFET
Section..
DEFAD MOSFET default drain area (AD). meter2 0.0
DEFAS MOSFET default source area (AS). meter2 0.0
DEFL MOSFET default length (L). meter 100.0 u
DEFW MOSFET default width (W). meter 100.0 u

Analog Advanced options

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:

Flag option Meaning


NOGMINI Specifies not to add GMIN across current sources.
BRKDEPSRC Sets automatic break-points for behavioral sources.
CONVAID Generates .1OP file for debugging purpose when convergence fails.

April 2016 77 Product Version 17.2-2016


© 1999-2016 All Rights Reserved.
PSpice MATLAB Interface User Guide
Simulation Settings Dialog Description

Flag option, Meaning, continued


STEPGMIN Enables GMIN stepping. This causes a GMIN stepping algorithm to be
applied to circuits that fail to converge. GMIN stepping is applied first,
and if that fails, the simulator falls back to supply stepping.
NOSTEPSRC Do not run source stepping algorithm for bias point convergence.
NOSTEPDEP Do not step dependent sources during source stepping algorithm for
bias point convergence.
GMINSRC Enables step GMIN inside source-stepping
PSEUDOTRAN Uses Pseudo-Transient Method.

Options Description Units Default


ITL5 total repeating limit for all points for transient - 0.0
analysis
(ITL5=0 means ITL5=infinity)
PIVREL relative magnitude required for pivot in matrix - 1.0E-3
solution
PIVTOL absolute magnitude required for pivot in matrix - 1.0E-13
solution
SOLVER performance package solution algorithm - 1
(Solver = 0 selects the original solution
algorithm;
Solver = 1 selects the advanced solution
algorithm)
DMFACTOR Sets the relative factor for minimum delta. The
value specifies the relative value by which the
minimum time step size is changed. The value
should be less than or equal to 1 and a factor
of 10, such as .1, .001, or .0001.
WCDEVIATION worst case deviation. It can have double - Same as
values between 0 and 1. RELTOL

April 2016 78 Product Version 17.2-2016


© 1999-2016 All Rights Reserved.
PSpice MATLAB Interface User Guide
Simulation Settings Dialog Description

LIMIT the absolute voltage limit. The default, 0, - 0


specifies that there is no limit on data values.
You can modify it to a large value, such as
1e12, to eliminate overflow errors, especially
when using exponential sources.
DIODECJO Minimum value for Diode junction capacitance ohm 0
DIODERS Minimum value for Diode ohmic resitance ohm 0
BJTCJ minimum value for BJT Base-collector zero- farad 0
bias depletion capacitance (Cjc), Base-emitter
zero-bias depletion capacitance (Cje), and
zero-bias collector substrate capacitance (Cjs)
GMINSTEPS the GMIN stepping size in integer (any - Same as
positive value). Set to 0 for engine default. ITL1
ITL6 the number of steps of the source stepping - Same as
algorithm. Can have any positive integer ITL1
value. Set to 0 for engine default.
PTRANSTEP number of steps for a pseudo transient - Same as
analysis to find the operating point. Can be ITL1
any positive integer value. Set to 0 for engine
default.
method integration method - -
(values can be either TRAPEZOIDAL or
GEAR)
TRTOL tolerance for integration error calculated using - 7
transient analysis. It is a relative tolerance
where a higher TRTOL value results in bigger
time steps and reduced accuracy. The TRTOL
value should NOT be greater than 1/RELTOL.
CSHUNT shunt capacitance added from all nodes of the farad 0
design to GND. Recommended value is 1pF.
TRANCONV Enables alternate path search if transient
simulation fails.

April 2016 79 Product Version 17.2-2016


© 1999-2016 All Rights Reserved.
PSpice MATLAB Interface User Guide
Simulation Settings Dialog Description

Gate Level Simulation options

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:

Flag option Meaning


NOPRBMSG Suppresses simulation error messages in Probe data file.

Options Description Units Default


DIGMNTYMX default delay selector: 1=min, 2-typical, - 2.0
3=max, 4=min/max
DIGINITSTATE sets initial state of all flip-flops and latches in - 2.0
circuit: 0=clear, 1=set, 2=X
DIGIOLVL default digital I/O level: 1-4; - 1.0
DIGDRVF minimum drive resistance ohm 2.0
(Input/Output UIO type model, DRVH (high) and
DRVL (low) values)

DIGDRVZ maximum drive resistance ohm 20K


(UIO type model, DRVH and DRVL values)
DIGOVRDRV ratio of drive resistances required to allow one - 3.0
output to override another driving the same
node
DIGMNTYSCALE scale factor used to derive minimum delays - 0.4
from typical delays
DIGTYMXSCALE scale factor used to derive maximum delays - 1.6
from typical delays

April 2016 80 Product Version 17.2-2016


© 1999-2016 All Rights Reserved.
PSpice MATLAB Interface User Guide
Simulation Settings Dialog Description

DIGERRDEFAULT default error limit per digital constraint device - 20.0


DIGERRLIMIT maximum digital error message limit - 0

Output file options

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:

Flag option Meaning


ACCT Summary and accounting information is printed at the end of all the
analyses (refer to your PSpice User’s Guide for further information
on ACCT).
EXPAND Lists devices created by subcircuit expansion and lists contents of the
bias point file.
LIBRARY Lists lines used from library files.
LIST Lists a summary of the circuit elements (devices).
NOBIAS Suppresses the printing of the bias point node voltages.
NODE Lists a summary of the connections (node table).
NOECHO Suppresses a listing of the input file(s).
NOMODE Suppresses listing of model parameters and temperature updated
values.
NOOUTMSG Suppresses simulation error messages in output file.
NOPAGE Suppresses paging and the banner for each major section of output.
OPTS Lists values for all options.
NUMDGT Number of digits in printed values. This is 4 by default.
WIDTH same as the .WIDTH OUT= statement
(can be set to either 80 or 132)
Default is 80.

April 2016 81 Product Version 17.2-2016


© 1999-2016 All Rights Reserved.
PSpice MATLAB Interface User Guide
Simulation Settings Dialog Description

Data collection options for simulation profiles


Use the Data Collection tab of the Simulation Settings dialog box to restrict the captured
simulation data. This is especially useful for large circuit designs that produce more data than
you need for waveform analysis.

Data Collection Options


Option Description
All All data will be collected and stored. (This is the default setting.)
All but Internal All data will be collected and stored except for internal
Subcircuits subcircuits of hierarchical designs (top level data only).
At Markers Only Data will only be collected and stored where markers are
placed.
None No data will be collected.

April 2016 82 Product Version 17.2-2016


© 1999-2016 All Rights Reserved.

You might also like