Main Content

Convert a SPICE Netlist to Simscape Blocks

R2026b

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.

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

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

  3. Build the library using sscbuild 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 +subcircuit_name_simscape_functions, where subcircuit_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>)
where the 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:

SuffixNameScale
TTera1e12
GGiga1e9
MEGMega1e6
KKilo1e3
MMilli1e-3
MIL--25.4e-6
UMicro1e-6
NNano1e-9
PPico1e-12
FFemto1e-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

NameSPICE FunctionSimscape Function
Absolute valueabssimscape.function.abs(x,ZC)
Minimumminsimscape.function.minm(x,y,n,epsilon)
Maximummaxsimscape.function.maxm(x,y,n,epsilon)
Signsgnsimscape.function.sign(x,ZC)

Trigonometry

NameSPICE FunctionSimscape Function
Sinesinsin
Inverse sineasinsimscape.function.asinm(x,warn)
Hyperbolic sinesinhsimscape.function.sinhm(x,maxAbsX,warn)

Inverse hyperbolic sine (since R2025a)

asinhsimscape.function.asinhm(x,maxAbsX,warn)
Cosinecoscos
Inverse cosineacossimscape.function.acosm(x,warn)
Hyperbolic cosinecoshsimscape.function.coshm(x,maxAbsX,warn)

Inverse hyperbolic cosine (since R2025a)

acoshsimscape.function.acoshm(x,maxX,warn)
Tangenttansimscape.function.tanm(x,flag,epsilon,x0,warn)
Inverse tangentatanatan
Four-quadrant inverse tangentatan2atan2
Hyperbolic tangenttanhtanh

Inverse hyperbolic tangent (since R2025a)

atanhsimscape.function.atanhm(x,maxAbsX,warn)

Exponents and Logarithms

NameSPICE FunctionSimscape Function
Powerx**y, pwr(x,y), or pwrs(x,y)simscape.function.powerRational(x,y,flag,epsilon,warn)
Exponentialexpsimscape.function.expm(x,xl,xh,warn)
Natural logarithmln or logsimscape.function.logm(x,x0,warn)
Base-10 logarithmlog10simscape.function.log10m(x,x0,warn)
Square rootsqrtsimscape.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:

NameSPICE FunctionSimscape Function
If conditionifif else
Limitlimitsimscape.function.limitm(x,a,b,n,epsilon)
Current through deviceii
Voltage across devicevv
Step functionstpif x>0, 1 else 0 end
Derivative (see Limitations)ddtder
Tabletabletablelookup

List of Simscape Functions

This function returns the absolute value of the input argument, x.

You can enable or disable zero crossing by setting the input argument ZC to true or false.

This function returns the smallest argument, x or y. The input argument, n, sets the order of the smoothing function.

The epsilon argument determines the start of the transition and is the absolute error of the function when x is equal to y.

This function returns the largest argument, x or y. The input argument, n, sets the order of the smoothing function.

The epsilon argument determines the start of the transition and is the absolute error of the function when x is equal to y.

This function returns the sign of the input argument, x.

You can enable or disable zero crossing by setting the input argument ZC to true or false.

This function returns the inverse sine of x, asin(x), for -1x1, 0 for x>1, and π for x < -1.

Use this function to protect against small numerical incursions into the invalid input range for asin(x).

This function returns the hyperbolic sine of x, sinh(x), when x ranges between -maxAbsX and maxAbsX. Otherwise, the function uses linear extrapolation with gradient matching at the boundary.

Use this function to avoid the numerical issues associated with sinh(x) for large negative or large positive input arguments.

This function returns the inverse hyperbolic sine of x, asinh(x), when x ranges between -maxAbsX and maxAbsX. Otherwise, the function uses linear extrapolation with gradient matching at the boundary.

Use this function to avoid the numerical issues associated with asinh(x) for large negative or large positive input arguments.

This function returns the inverse cosine of x, acos(x), for -1x1, 0 for x>1, and π for x < -1.

Use this function to protect against small numerical incursions into the invalid input range for acos(x).

This function returns the hyperbolic cosine of x, cosh(x), when x ranges between -maxAbsX and maxAbsX. Otherwise, the function uses linear extrapolation with gradient matching at the boundary.

Use this function to avoid the numerical issues associated with cosh(x) for large negative or large positive input arguments.

This function returns the inverse hyperbolic cosine of x, acosh(x), when x ranges between 1 and maxX. When x is less than 1, the function returns 0. When x is greater than maxX, the function uses linear extrapolation with gradient matching at the boundary.

Use this function to avoid complex outputs for input arguments less than 1 and to avoid the numerical issues associated with acosh(x) for large positive input arguments.

This function represents the tangent function with input argument protection.

If the flag argument is 0, this function returns the tangent of x, tan(x), when x is equal to or -π/2. The epsilon argument determines the smoothness of the transition at these points.

If the flag argument is 1, this function returns the tangent of x, tan(x), when x ranges between -x0 and x0. Otherwise, the function uses linear extrapolation with gradient matching at the boundary.

1/epsilon is the maximum value of the output argument y.

This function returns the inverse hyperbolic tangent of x, atanh(x), when x satisfies -maxAbsXxmaxAbs and -1x1. When the magnitude of x is greater than maxAbsX but less than 1, the function uses linear extrapolation with gradient matching at the boundary. When x is less than or equal to -maxAbsX and less than or equal to -1, the function returns atanh(eps-1). When x is greater than or equal to maxAbsX and greater than or equal to 1, the function returns atanh(1-eps).

Use this function to avoid complex outputs for input arguments with a magnitude greater than 1 and to avoid the numerical issues associated with atanh(x) for input arguments with a magnitude close to 1.

This function represents the power function x^y, where y is rational, with input argument protection for negative x.

If the flag argument is 0, the function returns x^y for x≥0 and -(-x)^y for x < 0. If the flag argument is 1, this function applies the power function to simscape.function.hyp(x,epsilon).

The SPICE conversion assistant converts the pwr(x,y) SPICE function to simscape.function.powerRational(x,y,1,0,warn).

The SPICE conversion assistant converts the pwrs(x,y) SPICE function to simscape.function.powerRational(x,y,0,0,warn).

This function returns the exponential of x, exp(x), when x ranges between xl and xh. Otherwise, the function uses linear extrapolation with gradient matching at the boundary.

Use this function to avoid the numerical issues associated with exp(x) for very small or large input arguments.

This function returns the natural logarithm of x, log(x), when x is greater than x0. Otherwise, the function uses linear extrapolation with gradient matching at the boundary.

Use this function when x reaches a value close to 0 during simulation. Set x0 between 0 and 1.

This function returns the base-10 logarithm of x, log10(x), when x is greater than x0. Otherwise, the function uses linear extrapolation with gradient matching at the boundary.

Use this function when x reaches a value close to 0 during simulation. Set x0 between 0 and 1.

This function represents the square root function with input argument protection.

If the flag argument is 0, this function returns sqrt(x) for positive x and -sqrt(-x) for negative x. If the flag argument is 1, this function returns the square root of simscape.function.hyp(x,epsilon).

This function returns x limited between a and b. The input argument, n, sets the order of the smoothing function.

The epsilon argument determines the start of the transition and is the absolute error of the function when x is equal to a or b.

This function approximates max(x,0). The approximation uses hyperbolic smoothing to achieve output that is always positive and has a smooth derivative at x = 0.

The function returns x/2 + sqrt(x^2 + 4*epsilon^2)/2.

When the absolute value of x is much greater than epsilon, the result tends to:

  • x, for x > 0

  • 0, for x < 0

The epsilon argument determines the smoothness of the transition and is the absolute error of simscape.function.hyp(x,epsilon) when x = 0.

Use this function to avoid numerical issues like division by zero.

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
To complete the conversion, modify the Simscape component file to implement the missing components. For more information about performing manual conversions and this particular scenario, see 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

See Also

Topics