Converting a SPICE Netlist to Simscape Blocks
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 optionalsubcircuit1,…,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 astruct
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.
Commands
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 namespace 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.
Numeric Suffixes
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 |
Mathematical Functions
The conversion assistant supports these basic mathematical functions used in SPICE and Simscape. These basic mathematical functions might not be continuous or smooth and can cause numerical problems during the simulation. To solve these issues, these functions might require smoothing.
The subcircuit2ssc
function automatically turns on the smoothing
parameters when converting a SPICE subcircuit. To disable the smoothing option, inside
the block mask of the generated Simscape component block, set the Specify
function smoothing parameters parameter to
No
.
Elementary Math
Name | SPICE Function | Simscape Function |
---|---|---|
Absolute value | abs | simscape.function.abs(x,ZC) |
Smallest element | min | simscape.function.minm(x,y,n,epsilon) |
Largest element | max | simscape.function.maxm(x,y,n,epsilon) |
Sign function | sgn | simscape.function.sign(x,ZC) |
Trigonometry
Name | SPICE Function | Simscape Function |
---|---|---|
Sine | sin | sin |
Inverse sine | asin | simscape.function.asinm(x,warn) |
Hyperbolic sine | sinh | simscape.function.sinhm(x,maxAbsX,warn) |
Cosine | cos | cos |
Inverse cosine | acos | simscape.function.acosm(x,warn) |
Hyperbolic cosine | cosh | simscape.function.coshm(x,maxAbsX,warn) |
Tangent | tan | simscape.function.tanm(x,flag,epsilon,x0,warn) |
Inverse tangent | atan | atan |
Four-quadrant inverse tangent | atan2 | atan2 |
Hyperbolic tangent | tanh | tanh |
Exponents and Logarithms
Name | SPICE Function | Simscape Function |
---|---|---|
Power | x**y , pwr(x,y) , or
pwrs(x,y) | simscape.function.powerRational(x,y,flag,epsilon,warn) |
Exponential | exp | simscape.function.expm(x,xl,xh,warn) |
Natural logarithm | ln or log | simscape.function.logm(x,x0,warn) |
Base-10 logarithm | log10 | simscape.function.log10m(x,x0,warn) |
Square root | sqrt | simscape.function.sqrtm(x,flag,epsilon,warn) |
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.
Other
In addition, the conversion assistant supports these SPICE and Simscape functions:
Name | SPICE Function | Simscape Function |
---|---|---|
If condition | if | if else |
Saturation | limit | simscape.function.limitm(x,a,b,n,epsilon) |
Current through device | i | i |
Voltage across device | v | v |
Step function | stp | if x>0, 1 else 0 end |
Derivative (see Limitations) | ddt | der |
Table | table | simscape.tablelookup([x1,x2,…xn],[y1,y2,…yn],x,interpolation=linear,extrapolation=nearest) |
List of Simscape Functions
simscape.function.hyp(x,epsilon) — Function with positive output
simscape.function.abs(x,ZC) — Absolute function
simscape.function.expm(x,xl,xh,warn) — Exponential function
simscape.function.coshm(x,maxAbsX,warn) — Hyperbolic cosine function
simscape.function.sinhm(x,maxAbsX,warn) — Hyperbolic sine function
simscape.function.acosm(x,warn) — Inverse cosine function
simscape.function.asinm(x,warn) — Inverse sine function
simscape.function.limitm(x,a,b,n,epsilon) — Limit function
simscape.function.logm(x,x0,warn) — Natural logarithm function
simscape.function.log10m(x,x0,warn) — Base-10 logarithm function
simscape.function.maxm(x,y,n,epsilon) — Maximum function
simscape.function.minm(x,y,n,epsilon) — Minimum function
simscape.function.powerRational(x,y,flag,epsilon,warn) — Power function
simscape.function.sign(x,ZC) — Signum function
simscape.function.sqrtm(x,flag,epsilon,warn) — Square root function
simscape.function.tanm(x,flag,epsilon,x0,warn) — Tangent function
Symbols
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
Components
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.
Sources
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>
Passive Devices
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>
Switches
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>)
Semiconductor Devices
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>)
Subsystems
Subcircuit
X<name> [node]* <subcircuit name> [PARAMS: < <name>=<value> >*]
Performing Manual Conversions
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
.Parasitics Values
For passive devices such as capacitors and inductors, to introduce parasitic values in the generated Simscape component files, set the Specify parasitics values parameter to Yes. Then specify the value of the Capacitor parasitic series resistance or Inductor parasitic parallel conductance parameters.
Limitations
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.
See Also
Functions
subcircuit2ssc
|ssc_build
|ee.spice.semiconductorSubcircuit2lookup
|ee.spice.diodeSubcircuit2lookup