You can convert SPICE components into Simscape™ equivalents using the SPICE conversion assistant. Often this conversion is automatic. However, because SPICE is a rich language, it is not always possible to perform a full conversion without some manual intervention.
To convert SPICE subcircuits into equivalent Simscape components, follow these steps.
Use the subcircuit2ssc
function to generate Simscape language component files from a SPICE netlist file. You can use
the optional subcircuit1,…,subcircuitN
input arguments to
specify which subcircuits to convert.
Make any necessary manual conversions to the generated Simscape component files. To identify the required manual conversions,
check the comments at the beginning of the generated Simscape component files. You can use the optional
unsupportedCommands
output argument to generate a
struct
array that lists unsupported SPICE commands for
each subcircuit.
Build the library using ssc_build
or add individual
components to your model using Simscape Component
blocks.
There are many different SPICE simulators with variations in syntax and syntax interpretation. The conversion assistant uses the same syntax as Cadence® PSpice and, where such differences exist, complies with PSpice.
The SPICE conversion assistant supports these commands:
.FUNC
— Reusable function
.PARAM
— Definable parameter
.MODEL
— Set of reusable component parameters
.SUBCKT
— Subcircuit
.LIB
— Directive to include models from an external
netlist
.INC
— Directive to include contents of external
netlist
The conversion assistant implements .FUNC
SPICE commands using
Simscape functions. These functions are placed inside a package sublibrary named
+
,
where subcircuit_name
_simscape_functionssubcircuit_name
is the name of the subcircuit being
converted.
Specify the .MODEL
syntax for resistors, capacitors, and inductors,
as
.MODEL <model name> res(r=<value>) .MODEL <model name> cap(c=<value>) .MODEL <model name> ind(l=<value>)
r
, c
, and l
values are
scaling factors for the value specified on the component declaration. This behavior
complies with PSpice, but is not consistent across all simulators.The conversion assistant does not automatically convert initial conditions specified
using the .IC
statement. However, you can specify initial conditions
for capacitors and inductors using the syntax IC=<value>
. Also,
you can manually convert any .IC
statements from the generated
Simscape component files.
Because the purpose of the conversion assistant is to help convert SPICE subcircuits
into Simscape blocks, simulation commands, such as .TRAN
, are
ignored.
The conversion assistant supports these numeric SPICE suffixes:
Suffix | Name | Scale |
---|---|---|
T | Tera | 1e12 |
G | Giga | 1e9 |
MEG | Mega | 1e6 |
K | Kilo | 1e3 |
M | Milli | 1e-3 |
MIL | -- | 25.4e-6 |
U | Micro | 1e-6 |
N | Nano | 1e-9 |
P | Pico | 1e-12 |
F | Femto | 1e-15 |
The conversion assistant supports these basic mathematical functions used in SPICE and MATLAB.
Name | SPICE Function | MATLAB Function |
---|---|---|
Absolute value | abs | abs |
Smallest element | min | min |
Largest element | max | max |
Sign function | sgn | sign |
Name | SPICE Function | MATLAB Function |
---|---|---|
Sine | sin | sin |
Inverse sine | asin | asin |
Hyperbolic sine | sinh | sinh |
Cosine | cos | cos |
Inverse cosine | acos | acos |
Hyperbolic cosine | cosh | cosh |
Tangent | tan | tan |
Inverse tangent | atan | atan |
Four-quadrant inverse tangent | atan2 | atan2 |
Hyperbolic tangent | tanh | tanh |
Name | SPICE Function | MATLAB Function |
---|---|---|
Power | ** or pwr | ^ or power |
Exponential | exp | exp |
Natural logarithm | ln or log | log |
Base-10 logarithm | log10 | log10 |
Square root | sqrt | sqrt |
The conversion assistant interprets log()
as the
natural logarithm rather than the base-10 logarithm. Not all SPICE simulators are
consistent in this regard, so ensure that this interpretation is congruent with your
SPICE model.
In addition, the conversion assistant supports these SPICE functions:
Name | SPICE Function |
---|---|
If condition | if |
Saturation | limit |
Current through device | i |
Voltage across device | v |
Step function | stp |
Derivative (see Limitations) | ddt |
Table | table |
The conversion assistant recognizes these SPICE symbols:
+
at the start of a line indicates line continuation
from the previous line
*
at the start of a line indicates that the entire line
is a comment
;
within a line indicates the beginning of an inline
comment
The notation for SPICE commands in this section follows these rules:
<argument>
refers to a required item in a command
line
<argument>*
refers to a required item in a
command line that occur one or more times
[argument]
refers to an optional item in a command
line
[argument]*
refers to an optional item in a command
line that occur zero or more times
This list shows the full set of supported SPICE components, and their supported SPICE
netlist notations. You can specify only the .MODEL
parameters that
differ from SPICE default values.
Independent voltage source
V<name> <+ node> <- node> [DC] <value> V<name> <+ node> <- node> exp(<v1> <v2> <td1> <tc1> <td2> <tc2>) V<name> <+ node> <- node> pulse(<v1> <v2> <td> <tr> <tf> <pw> <per>) V<name> <+ node> <- node> pwl(<<tj> <vj>>*) V<name> <+ node> <- node> sffm(<voff> <vampl> <fc> <mod> <fm>) V<name> <+ node> <- node> sin(<voff> <vampl> <freq> <td> <df>)
Independent current source
I<name> <+ node> <- node> [DC] <value> I<name> <+ node> <- node> exp(<i1> <i2> <td1> <tc1> <td2> <tc2>) I<name> <+ node> <- node> pulse(<i1> <i2> <td> <tr> <tf> <pw> <per>) I<name> <+ node> <- node> pwl(<<tj> <ij>>*) I<name> <+ node> <- node> sffm(<ioff> <iampl> <fc> <mod> <fm>) I<name> <+ node> <- node> sin(<ioff> <iampl> <freq> <td> <df>)
Current-controlled voltage source
H<name> <+ node> <- node> <voltage source name> <gain> H<name> <+ node> <- node> VALUE={<expression>} H<name> <+ node> <- node> POLY(<value>) <voltage source name>* <coefficient>* H<name> <+ node> <- node> TABLE {<expression>}=< <input value>, <output value> >* H<name> <+ node> <- node> <voltage source name> TABLE=< <input value>, <output value> >*
Voltage-controlled voltage source
E<name> <+ node> <- node> <+ control node> <- control node> <gain> E<name> <+ node> <- node> VALUE={<expression>} E<name> <+ node> <- node> POLY(<value>) <<+ control node> <- control node>>* <coefficient>* E<name> <+ node> <- node> TABLE {<expression>}=< <input value>, <output value> >* E<name> <+ node> <- node> <+ control node> <- control node> TABLE=< <input value>, <output value> >*
Current-controlled current source
F<name> <+ node> <- node> <voltage source name> <gain> F<name> <+ node> <- node> VALUE={<expression>} F<name> <+ node> <- node> POLY(<value>) <voltage source name>* <coefficient>* F<name> <+ node> <- node> TABLE {<expression>}=< <input value>, <output value> >* F<name> <+ node> <- node> <voltage source name> TABLE=< <input value>, <output value> >*
Voltage-controlled current source
G<name> <+ node> <- node> <+ control node> <- control node> <gain> G<name> <+ node> <- node> VALUE={<expression>} G<name> <+ node> <- node> POLY(<value>) <<+ control node> <- control node>>* <coefficient>* G<name> <+ node> <- node> TABLE {<expression>}=< <input value>, <output value> >* G<name> <+ node> <- node> <+ control node> <- control node> TABLE=< <input value>, <output value> >*
Behavioral source (The <expression> does not need to appear in braces {})
B<name> <+ node> <- node> V=<expression> B<name> <+ node> <- node> I=<expression>
Resistor
R<name> <+ node> <- node> [model name] <value> .MODEL <model name> res(r=<value>)
Capacitor
C<name> <+ node> <- node> [model name] <value> [IC=<value>] .MODEL <model name> cap(c=<value>)
Inductor
L<name> <+ node> <- node> [model name] <value> [IC=<value>] .MODEL <model name> ind(l=<value>)
Inductor coupling
K<name> <inductor name> <inductor name>* <value>
Voltage-controlled switch
S<name> <+ node> <- node> <+ control node> <- control node> <model name> .MODEL <model name> sw(ron=<value>, roff=<value>, vt=<value>, vh=<value>)
Current-controlled switch
W<name> <+ node> <- node> <voltage source name> <model name> .MODEL <model name> csw(ron=<value>, roff=<value>, it=<value>, ih=<value>)
Diode
D<name> <+ node> <- node> <model name> [area] .MODEL <model name> d(is=<value>, rs=<value>, n=<value>, cjo=<value>, vj=<value>, +m=<value>, fc=<value>, tt=<value>, revbrk=<value>, bv=<value>, ibv=<value>, +xti=<value>, eg=<value>)
Bipolar junction transistor (BJT)
NPN
Q<name> <collector node> <base node> <emitter node> [substrate node] <model name> <area> .MODEL <model name> npn(bf=<value>, br=<value>, cjc=<value>, cje=<value>, cjs=<value>, +eg=<value>, fc=<value>, ikf=<value>, ikr=<value>, irb=<value>, is=<value>, isc=<value>, +ise=<value>, itf=<value>, mjc=<value>, mje=<value>, mjs=<value>, nc=<value>, ne=<value>, +nf=<value>, nr=<value>, rb=<value>, rbm=<value>, rc=<value>, re=<value>, tf=<value>, +tr=<value>, vaf=<value>, var=<value>, vjc=<value>, vje=<value>, vjs=<value>, vtf=<value>, +xcjc=<value>, xtb=<value>, xtf=<value>, xti=<value>)
PNP
Q<name> <collector node> <base node> <emitter node> [substrate node] <model name> <area> .MODEL <model name> pnp(bf=<value>, br=<value>, cjc=<value>, cje=<value>, cjs=<value>, +eg=<value>, fc=<value>, ikf=<value>, ikr=<value>, irb=<value>, is=<value>, isc=<value>, +ise=<value>, itf=<value>, mjc=<value>, mje=<value>, mjs=<value>, nc=<value>, ne=<value>, +nf=<value>, nr=<value>, rb=<value>, rbm=<value>, rc=<value>, re=<value>, tf=<value>, +tr=<value>, vaf=<value>, var=<value>, vjc=<value>, vje=<value>, vjs=<value>, vtf=<value>, +xcjc=<value>, xtb=<value>, xtf=<value>, xti=<value>)
Junction field-effect transistor (JFET)
N-Channel
J<name> <drain node> <gate node> <source node> <model name> [area] .MODEL <model name> njf(beta=<value>, cgd=<value>, cgs=<value>, fc=<value>, is=<value>, +lambda=<value>, m=<value>, n=<value>, rd=<value>, rs=<value>, vto=<value>, xti=<value>)
P-Channel
J<name> <drain node> <gate node> <source node> <model name> [area] .MODEL <model name> pjf(beta=<value>, cgd=<value>, cgs=<value>, fc=<value>, is=<value>, +lambda=<value>, m=<value>, n=<value>, rd=<value>, rs=<value>, vto=<value>, xti=<value>)
Metal-oxide-semiconductor field-effect transistor (MOSFET)
N-Channel (only level-1 and level-3 are supported)
M<name> <drain node> <gate node> <source node> <bulk node> <model name> +[L=<value>] [W=<value>] [AD=<value>] [AS=<value>] [PD=<value>] [PS=<value>] [NRD=<value>] +[NRS=<value>] [M=<value>] .MODEL <model name> nmos(cbd=<value>, cbs=<value>, cgbo=<value>, cgdo=<value>, +cgso=<value>, cj=<value>, cjsw=<value>, delta=<value>, eta=<value>, fc=<value>, +gamma=<value>, is=<value>, js=<value>, kappa=<value>, kp=<value>, lambda=<value>, +ld=<value>, level=<value>, mj=<value>, mjsw=<value>, n=<value>, neff=<value>, nfs=<value>, +nss=<value>, nsub=<value>, nrd=<value>, nrs=<value>, pb=<value>, phi=<value>, rd=<value>, +rs=<value>, rsh=<value>, theta=<value>, tox=<value>, tpg=<value>, ucrit=<value>, +uexp=<value>, uo=<value>, vmax=<value>, vto=<value>, xj=<value>)
P-Channel (only level-1 and level-3 are supported)
M<name> <drain node> <gate node> <source node> <bulk node> <model name> +[L=<value>] [W=<value>] [AD=<value>] [AS=<value>] [PD=<value>] [PS=<value>] [NRD=<value>] +[NRS=<value>] [M=<value>] .MODEL <model name> pmos(cbd=<value>, cbs=<value>, cgbo=<value>, cgdo=<value>, +cgso=<value>, cj=<value>, cjsw=<value>, delta=<value>, eta=<value>, fc=<value>, +gamma=<value>, is=<value>, js=<value>, kappa=<value>, kp=<value>, lambda=<value>, +ld=<value>, level=<value>, mj=<value>, mjsw=<value>, n=<value>, neff=<value>, nfs=<value>, +nss=<value>, nsub=<value>, nrd=<value>, nrs=<value>, pb=<value>, phi=<value>, rd=<value>, +rs=<value>, rsh=<value>, theta=<value>, tox=<value>, tpg=<value>, ucrit=<value>, +uexp=<value>, uo=<value>, vmax=<value>, vto=<value>, xj=<value>)
Subcircuit
X<name> [node]* <subcircuit name> [PARAMS: < <name>=<value> >*]
After you generate the Simscape component files, inspect each file header for messages regarding unsupported SPICE commands. For example, the conversion assistant does not support the implementation of temperature coefficients for resistors:
R1 p n 1k TC=0.01,-0.002
The generated Simscape component file contains all the supported conversions, and this header, which identifies the temperature coefficients of the resistor for manual conversion:
component test % test % Component automatically generated from a SPICE netlist (11-Dec-2018 09:34:57). % Users should manually implement the following SPICE commands in order to % achieve a complete implementation: % R1: tc 0.01 -0.002
subcircuit2ssc
.
The netlist must be written in PSpice format and be syntactically correct. The conversion assistant does not check for proper PSpice syntax.
Only a subset of the PSpice netlist language is supported. However, unsupported PSpice commands are identified at the top of the corresponding Simscape component file to facilitate manual conversion.
To build generated Simscape components into Simscape blocks, parameter values must conform to Simscape constraints. For example, capacitance of a fundamental capacitor and inductance of a fundamental inductor must be nonzero.
The conversion assistant does not support the use of the derivative SPICE
function, ddt
, inside a function call.