Page tree
Skip to end of metadata
Go to start of metadata

Where To Find This Example

Select Help > Open Examples... from the menus and type either the example name listed above or one of the keywords below.

Or in Version 13 or higher you can open the project directly from this page using this button. Make sure to select the Enable Guided Help before clicking this button.

Design Notes

Subcircuit Parameter Interface

This example illustrates how to create an interface for subcircuits using input parameters and how to create dynamic subcircuit architectures.

Defining Subcircuit Parameters

Subcircuit interface parameters are defined via equations using the "<<" operator. Their properties can be modified by right-clicking on the equation and selecting Properties.  User must set the Default Value for each parameter, which is the value that the parameter will have when the first time a subcircuit is placed in a system diagram.  User can also enter a Description for the parameter, and select various Unit Types and Data Types. 

To see examples of interface parameters, open subcircuit FunctionSelect from the Project Tree. It contains two parameters, Function and N. N is a simple parameter, which is a real scalar.  Its default value is set to 1. The parameter Function is an enumerated parameter; this is defined under the Data Type option and its description should include the labels of the enumeration, placed between braces and separated by commas, e.g.:

            Parameter description {Selection 1, Selection 2, Selection 3}

This will display "Selection 1", "Selection 2" and "Selection 3" as the available values for this parameter, and will return 0, 1 or 2 depending on the selection.

To see an illustration of other types of parameters, open subcircuit SourceSelect from the Project Tree.  Here, parameter Frequency is defined as a Frequency type parameter.  In this case, the Unit Type is set to Frequency, and the Default Value is automatically scaled by the frequency units defined in Options/Project Options/Global Units/Frequency. When this subcircuit is placed in another system diagram, the value of the Frequency parameter will be scaled by the frequency units of the project. As with other parameters in VSS, if a variable is used to define this parameter, it will default to the base frequency units, which is Hz.

Passing Subcircuit Parameters

Subcircuit SourceSelect invokes subcircuit SourceSine and passes its parameters to the latter. Parameters of subcircuit SourceSine are defined similarly in order to illustrate parameter passing. The, they are also defined using the variables SourceType and Frequency. Please note that either subcircuit may contain more parameters that are not common to both.

The Main System Diagram invokes subcircuit SourceSelect.  User can define the parameters of subciruit SourceSelect at the Main level and they are passed internally all the way down to subcircuit SourceSine.

Dynamic Configuration of Subcircuit Architecture

VSS allows system diagrams to invoke different subcircuits based on parameter settings. To illustrate this, we have created three types of source subcircuits: SourceSine, SourceSquare and SourceSAW, and three subcircuits that implement various functions: MultiplyByN, IncreaseByN and DecreaseByN. We have also created two "top-level" subcircuits that select the appropriate source implementation and function implementation based on the user selection.

Subcircuit SourceSelect allows the user to select the source type by using the parameter SourceType; the latter is defined as an enumerated parameter with options for Sine, Square and SAW waveforms. The appropriate subcircuit is selected based on the setting of the parameter SourceType. The main steps to create this architecture are described below:

1. Create a system diagram, name it SourceSelect.

2. Add an equation: SourceType << 0. Right-click on the equation, change Data Type to Enumeration; in the Description filed add parameter description and its enumerated values as: Source type {Sine, Square, SAW}

3. Insert one of the optional subcircuits, in this case SourceSine. Add an output port and connect it to the output of SourceSine.

4. Create a series of equations that define a string variable based on the selection of SourceType:

           

            SCname = "SourceSine"

            SCname = if(SourceType==1,"SourceSquare",SCname)

            SCname = if(SourceType==2,"SourceSAW",SCname)

5. Change the NET field of the inserted subcircuit from "SourceSine" to SCname (without quotes).

6 Add additional interface parameters or functionality as needed.

This approach was also used for implementing the FunctionSelector subcircuit.

Click Run Simulation button.  The values of each parameter are displayed inside the subcircuits and the source signal and the processed output signal are displayed on the graph. Changing the SourceType and/or Function parameters via their respective drop-down menus will yield different source and output signals. Changing the value of the parameters Frequency and/or N will also change the results; open the Tuner box and change the value of N while the simulation is runninng to see its effect on the output signal. You can also change the SourceType while the simulation is running and the subcircuit architecture will change to reflect this change. To verify this, open the Main System Diagram, right-click on the SourceSelect subcircuit and select Edit Subcircuit. The value of SCname variable should match the selection of the SourceType. Right-click on the subcircuit at this level and select Edit Subcircuit again. This will now lead you to the subcircuit that matches the SourceType parameter selection from the Main System Diagram. You can go out of this level and change the SourceType parameter value and verify again that the subcircuit architecture has changed accordingly.

System Diagram - Main System Diagram

Graph - Graph 1