subcircuit2ssc

Convert SPICE subcircuit to custom Simscape components

Description

example

subcircuit2ssc(filename,target) reads the SPICE netlist specified by filename and converts every subcircuit into one or more Simscape™ files in the folder specified by target.

The function lists SPICE commands not supported by the conversion process in the comments of the corresponding Simscape files. After conversion, review the generated Simscape files and make manual edits for any unsupported items. You can also obtain a list of unsupported commands by using an optional output argument, described below.

For a detailed explanation of supported conversions, see Converting a SPICE Netlist to Simscape Blocks.

subcircuit2ssc(___,subcircuit1,...,subcircuitN) converts only the subcircuits with the specified names.

subcircuitArray = subcircuit2ssc(___) returns an array of objects containing the subcircuit information.

[subcircuitArray,unsupportedCommands] = subcircuit2ssc(___) returns an array of objects containing the subcircuit information and a struct array containing the subcircuit names and SPICE commands found in the converted subcircuits that are not supported by the conversion process.

Examples

collapse all

Create a SPICE netlist named rcsubcircuit.cir that contains a simple RC subcircuit.

.SUBCKT RC1      1
*
R1	1	2	1k
C1	2	0	0.32mF
*
.ENDS

Convert all SPICE subcircuits in rcsubcircuit.cir to equivalent Simscape files and place them in a package directory called mylibrary.

subcircuit2ssc('rcsubcircuit.cir','+mylibrary');
Netlist converted. Review files and make manual edits for any
unsupported items before building the Simscape library located
at: +mylibrary.

Check the comments at the beginning of the generated component file rc1.ssc in the mylibrary package to verify that no manual conversion is required.

Generate the Simscape library using ssc_build.

ssc_build mylibrary;
Generating Simulink library 'mylibrary_lib' in the current directory

Open the generated library mylibrary_lib.slx to access the RC component as a Simscape block.

Create a SPICE netlist named temperatureresistor.cir that contains a resistor with temperature dependence.

TEMPERATURERESISTOR.CIR - TEMPERATURE RESISTOR SUBCIRCUIT
*
.SUBCKT TemperatureResistor     p n
*
R1 p n 1k TC=0.01,-0.002
*
.ENDS

Convert all SPICE subcircuits in temperatureresistor.cir to equivalent Simscape files and place them in a package directory called mylibrary.

subcircuit2ssc('temperatureresistor.cir','+mylibrary');
Netlist converted. Review files and make manual edits for any
unsupported items before building the Simscape library located
at: +mylibrary.

Check the comments at the beginning of the generated component file temperatureresistor.ssc in the mylibrary package to identify required manual conversions.

component temperatureresistor
% temperatureresistor
% Component automatically generated from a SPICE netlist for subcircuit TEMPERATURERESISTOR.
%   MATLAB version: 9.7.
%   Simscape Electrical version: 7.1.
%   Simscape code generated on: 11-Dec-2018 09:45:20
%
% Users should manually implement the following SPICE commands in order to
% achieve a complete implementation:
%    R1: tc 0.01 -0.002

The comments suggest that you must manually convert the temperature coefficients TC.

In the components section of the component file, replace the resistor with a SPICE resistor, which models temperature dependence:

components(ExternalAccess=observe)
    R1 = ee.additional.spice_passives.res(...
        R={(1*1000),'Ohm'},...
        TC1={(0.01),'1/K'},...
        TC2={(-0.002), '1/K^2'});
end

Generate the Simscape library using ssc_build.

ssc_build mylibrary;
Generating Simulink library 'mylibrary_lib' in the current directory

Open the generated library mylibrary_lib.slx to access the resistor with temperature dependence component as a Simscape block.

Input Arguments

collapse all

Name of the SPICE network file to read. This file must be on the path.

Example: 'SpiceSubcircuits.cir'

Data Types: char | string

Name of the folder where the Simscape language files are generated. To allow the building of custom block libraries, specify a package directory with the '+' precursor. If the specified folder does not exist, the function creates it in the current folder.

Example: '+SimscapeSubcircuits'

Data Types: char | string

Names of the SPICE subcircuits to convert to Simscape language files.

Example: 'Subcircuit1','Subcircuit2'

Data Types: char | string

Output Arguments

collapse all

Array of objects containing the subcircuit information.

A struct array containing the subcircuit names and SPICE commands found in the converted subcircuits that are not supported by the conversion process.

Limitations

  • The netlist must be written in Cadence® 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.

Introduced in R2018b