Advanced SIMPLIS Training

To download the examples for Module 6, click Module_6_Examples.zip

6.1.2 Constant Current Subcircuit

In this Topic Hide

What You Will Learn

  1. How to create a constant current subcircuit load using a Piecewise Linear (PWL) Resistor.

  2. How to calculate a parameter value using if/else branching constructs.

  3. PWL resistors require the first and last segments to have positive resistance.

Model Requirements

The constant current load should:

  1. Model a constant current for voltages above a minimum saturation voltage.

  2. Allow users to optionally add a parasitic shunt resistance to the load.

  3. Limit the valid parameter values, including the calculated parameter values, to a range of values.

  4. Include a tabbed parameter editing dialog.

  5. Be self-contained in a schematic component file.

Model Design Procedure

The design procedure for this model is broken into three logical parts.

Part #1: Add PWL Resistor and Rename Constant Resistance Load File

You will start the model by opening the constant_resistance_load.sxcmp file you created in the 6.1.1 Constant Resistance Subcircuit topic. You will then add a voltage-controlled PWL resistor symbol and save this schematic component to a new file.

  1. Open the constant_resistance_load.sxcmp schematic component created during the 6.1.1 Constant Resistance Subcircuit. If you haven't created this file, open the "answer" file : 6.1.1_constant_resistance_load_answer.sxcmp.

  2. Select R1, and press the Delete key to delete the resistor symbol.

  3. On the Schematic Editor window, click on the Search located in the upper right hand corner of the window.
    Result: The search dialog appears:

  4. Enter pwl in the Search box.
    Result: The list of SIMPLIS compatible devices containing the text string pwl (case-insensitive) is displayed below the Search field:

  5. Select the last item, the VPWL Resistor, and place it on the schematic where the Z-shaped resistor was located. The schematic should appear as follows:

  6. From the Schematic Editor menu, select File Save As...

  7. Enter constant_current_load.sxcmp in the File name field and click Save to save the schematic component.

A point to remember: When you save a schematic component file using the Save As... menu option, only the schematic portion is saved and the symbol is discarded. In this case, you do not want to retain the graphical portions of the symbol, so this makes sense. To rename and save a schematic component file including the symbol, use the File Save Special... menu option, and check the Complete component including symbol checkbox.

Part #2: Parametrize the PWL Resistor

In this part, you will define the PWL resistor points using parameter values. The constant current load requires four parameters which the user will enter on the parameter editing dialog. These parameter names and the default values are shown in the table below:

Parameters Passed via Symbol
Parameter Description Parameter Name Default Parameter Value
The constant load current in amps DC_CURRENT 1
The load saturation voltage in volts SAT_VOLTAGE 0.2
The parallel, or shunt resistance in ohms RSHUNT 10Meg

A boolean flag to use the parallel resistance in the circuit

USE_RSHUNT 1

There are several ways to add these parameters to the actual PWL resistor. For this model you will define parameters calculated in the F11 window in addition to the parameters passed into the subcircuit through the symbol. In addition to the four parameters passed into the subcircuit through the symbol, the following four calculated parameters will be used:

Calculated Parameters Defined in the F11 Window
Parameter Description Parameter Name

Third voltage point

VOLTAGE_3

Third current point

CURRENT_3

Fourth voltage point

VOLTAGE_4

Fourth current point

CURRENT_4

The resulting V-I curve for the load with the parameters annotated is shown below. Each voltage-current pair is annotated in (x,y) format. How the four additional parameters are calculated will be covered in Part_3:_Define_Calculated_Parameters.

Notice the last segment in the resistor has a positive slope. SIMPLIS requires all PWL resistors to have positive slope for both the first and last PWL segment, and this model allows users to define the load as a ideal current source. If you did not add this third segment, the model would produce an error message because the slope of the last segment would be zero. This segment is placed at a voltage which is well beyond the operating voltage range of the load, preventing the final segment from effecting the normal operation of the load.

To parameterize the PWL resistor,

  1. Double click on the PWL resistor R1.
    Result: The Define VPWL Resistor: R1 dialog opens:

  2. Stretch the Voltage and Current columns to approximately twice the default width.

    1. Position the mouse between the Voltage and Current Columns on the title bar row.
      Result: The mouse cursor changes to two vertical bars, indicating the columns are ready to be resized.

    2. Press and hold the left mouse button and drag the column to resize.

    3. Repeat for the Current column by moving the mouse cursor to the right of the Current column, and repeating step B.

  3. Starting at the second data point, enter {SAT_VOLTAGE} in the Voltage column and {DC_CURRENT} in the Current column. Double-click the left mouse button to change table cells, and once in a table cell, you can select all text with the keyboard shortcut Ctrl+A.
    Result: The dialog at this point appear as follows:

    CAUTION: Spelling errors here will have disastrous consequences later on. Whenever you enter text by hand, double check the spelling. A good way to avoid spelling errors is to copy and paste the text from this document.
  4. Repeat Step #3 entering {VOLTAGE_3} and {CURRENT_3} in the third row and {VOLTAGE_4} and {CURRENT_4} in the fourth row.
    Result: The final dialog is configured as follows:

  5. Click Ok to save the changes.

At this point, the PWL resistor uses six parameters - two are passed in from the symbol, and the other four are calculated from the passed-in parameters. In the next part, you will define the four calculated parameters in the F11 window of the constant_current_load.sxcmp schematic component.

Part #3: Define Calculated Parameters

The first two data points which define the PWL resistor are either constants or passed into the subcircuit from the symbol. The third and fourth points are either constant, or calculated from the parameters passed into the subcircuit. In this part, you will define these parameters in the F11 window of the schematic component.

Using the F11 window of the schematic component to define local parameters is good modeling technique. These local parameters can be constants, or calculated from the parameters passed into the subcircuit. Once a parameter is defined in the F11 window, it can be used in other calculations which occur later in the same F11 window. You can think of the parameters which are passed into the subcircuit through the symbol as being at the very top of the F11 window. These parameters can be used anywhere in the F11 window to define new parameters.

  1. Press F11 to open the command (F11) window.

  2. Select all text in the F11 window and delete it.

  3. The third voltage point is set by parameter VOLTAGE_3 and should be placed well above the normal operating voltage for the load. A voltage of 10,000V would be comfortably above the maximum operating voltage for the load for most purposes. This is an example of a constant parameter defined in the F11 window. Enter the following text in the F11 window of the schematic:

    .VAR VOLTAGE_3 = 10000

  4. Next, the CURRENT_3 parameter needs to be calculated. The value of CURRENT_3 depends on the USE_RSHUNT parameter. If the USE_RSHUNT parameter is a logical true (non-zero), the CURRENT_3 parameter includes the RSHUNT parameter. If the USE_RSHUNT parameter value is zero, the load models a pure current source with infinite output impedance over the operating voltage range of VSAT_VOLTAGE to VOLTAGE_3. The following .IF/.ELSE/.ENDIF construct can be used to define the CURRENT_3 parameter value. Enter the following text in the F11 window of the schematic:

    .IF { USE_RSHUNT }
         .VAR CURRENT_3 = { DC_CURRENT + ( VOLTAGE_3 - SAT_VOLTAGE ) / RSHUNT }
    .ELSE
         .VAR CURRENT_3 = { DC_CURRENT }
    .ENDIF

  5. Finally, the values of last voltage and current pair are defined to add a 1Ω positive slope. These parameters are a function of the VOLTAGE_3 and CURRENT_3 parameters. Enter the following text in the F11 window of the schematic:

    .VAR VOLTAGE_4 = { VOLTAGE_3 + 1 }
    .VAR CURRENT_4 = { CURRENT_3 + 1 }

Note that the parameters are dependent on previous parameters in the same F11 window. The first parameter defined is VOLTAGE_3. Depending on the value of the USE_RSHUNT parameter, the value of CURRENT_3 can depend on the value of VOLTAGE_3. The values of both CURRENT_4 and VOLTAGE_4 are then dependent on the values of CURRENT_3 and CURRENT_4. The ability to define parameters which are dependent on previous parameters is one of the key benefits to using the F11 window to define calculated parameters.

At this point, all PWL resistor points are defined, but no error checking has been added. In the next step, Part_4:_Check_Passed_Parameter_Values_With_dot_error, you will add error checking for the parameter values.

Part #4: Check Passed Parameter Values With .ERROR

In this part you will use the .IF/.ENDIF and .ERROR constructs to check if the parameter values are within the ranges allowed by the model.

  1. The first error message is similar to the one you used in 6.1.1 - Part 3. This tests that the DC_CURRENT parameter is greater than zero. Copy the following three lines of text and paste into the F11 window.

    .IF { DC_CURRENT <= 0 }
        .ERROR "The dc load current parameter (DC_CURRENT) for the constant_current_load subcircuit must be greater than 0."
    .ENDIF

  2. Next, the shunt resistance parameter RSHUNT is checked to ensure the parameter value is greater than zero. Copy the following three lines of text and paste into the F11 window.

    .IF { RSHUNT <= 0 }
        .ERROR "The shunt resistance parameter (RSHUNT) for the constant_current_load subcircuit must be greater than 0."
    .ENDIF

  3. Finally, the saturation voltage parameter SAT_VOLTAGE is checked to see if it is greater than zero volts and less than 10k volts. This .IF statement uses the logical OR operator - two pipe characters "||", to test if the parameter is either less than or equal to 0V or greater than or equal to 10k volts. Copy the following three lines of text and paste into the F11 window.

    .IF { SAT_VOLTAGE <= 0 || SAT_VOLTAGE >= VOLTAGE_3 }
        .ERROR "The saturation voltage parameter (SAT_VOLTAGE) for the constant_current_load subcircuit must be greater than 0 and less than 10k volts."
    .ENDIF

Symbol Design Procedure

As in section 6.1.1 Symbol Design Procedure, the symbol design procedure is broken into two parts:

Part #1: Assign and Edit a Symbol

At this point, the subcircuit load has a complete schematic but no symbol. Since the load is essentially a current source, you will assign a current source symbol to the load. The simplest way to do this is to copy the global symbol for the current source to the schematic component. You will then modify the graphical elements of the symbol to indicate that the underlying model is not the built-in current source.

  1. Press I to place an ideal current source on the schematic.

  2. Select I1, the ideal current source symbol you just placed.

  3. Right click and select Edit Symbol...
    Result: The global symbol for the current source opens in the symbol editor:

  4. It is very important to save this symbol to your schematic component file before you start to edit it. If you make edits to this symbol and inadvertently save them, those changes would be applied to the global current souce symbol used by other schematics. This could have disastrous effects in other schematics. To save the symbol to your schematic component file,

    1. Select the Symbol Editor menu File Save...
      Result: The Save Symbol dialog opens

    2. In the Save to radio button group, select Component file.

    3. Click the Browse... button to navigate the file system and select the schematic component file for the constant_current_load.sxcmp. The configured dialog will appear as follows:

  5. Delete unneeded symbol properties VALUESCRIPT and VALUE.

    1. Position the mouse over the *edit_dcsource text and left click once. This text is the property value of the VALUESCRIPT property.
      Result: The text changes color from black to blue, indicating the property is selected.

    2. Press the Delete key to delete the property.

    3. Repeat for the text 1m which represents the VALUE symbol property.
      Result: At this point the symbol editor should appear as follows:

  6. Edit the MODEL property, changing the property value to X. This will tell the netlister to instantiate a subcircuit model for this symbol.

    1. Position the mouse over the *I text and left click once.
      Result: The text changes color from black to blue, indicating the property is selected.

    2. Press F7 to edit the MODEL property.
      Result: The Edit Property dialog opens:

    3. Change the Value to X, and Click Ok.
      Result: The symbol editor now appears as follows:

  7. Change the REF property to LOAD?.

    1. Select the I? text and repeat Steps 6 A-C, changing the REF property to LOAD?
      Result: The symbol now appears as follows:

  8. Change the SIMULATOR property to SIMPLIS.

    1. Select the *DUAL text and repeat Steps 7 A-C, changing the SIMULATOR property to SIMPLIS.
      Result: The symbol now appears as follows:

  9. Next, you will modify the graphical representation so users will know this symbol does not represent the built-in current source model.

    1. Position the mouse over the N pin, then press and hold the mouse button while dragging the pin downwards two major grid ticks.
      Result: The N pin is now two grid ticks down from the original position.

    2. Repeat for the P pin, moving the pin up one grid tick. Unlike the resistor symbol you modified in the last topic, the pins on the current source symbol are already one grid tick further apart.
      Result: The P pin is now one grid tick up from the original location.

  10. Move the two circles and arrow down 1/2 a major grid tick to center the circles and arrow vertically between the pins.

    1. Press and hold the left mouse button and drag the mouse to draw a selection box over the two circles and the arrow in the middle of the symbol:

    2. Release the mouse button
      Result: The two circles and arrow change from green to blue indicating they are selected.

    3. Click on one of the blue circles and drag the selected items down 1/2 a major grid tick.
      Result: The two circles and arrow are centered between the two pins.

  11. Connect the pins to the circles and add a graphical box around the current source.

    1. Double click to start a graphical "wire" segment.

    2. Left click once to define a corner or end point.

    3. Right click to stop wiring.

    4. If you make a mistake, right click to stop wiring and press Ctrl-Z to undo.
      Result: The symbol should appear approximately as follows:

  12. Select the Symbol Editor menu File Save... to save the symbol to the schematic component file.

  13. Navigate to the SIMetrix/SIMPLIS Schematic Editor window. Select and delete the current source I1.

You now have a symbol which will call the subcircuit based current source load model. The functionality of the underlying subcircuit is implied by the current source symbol, and the box around the current source suggests to the user that this is not a normal current source. At this point the symbol doesn't pass parameters to the underlying subcircuit, nor does the symbol have a parameter editing dialog. In the next part, Part_2:_Add_Parameters_and_Dialog_Properties, you will use a spreadsheet to add the required symbol properties.

Part #2: Add Parameters and Dialog Properties

Included in the Module_6_Examples.zip file is a pre-prepared dialog definition spreadsheet similar to the one used in the previous module. Like the spreadsheet used in 6.1.1 Part #2:_Add_RESISTANCE_Parameter_and_Dialog_Properties, this spreadsheet contains all script commands to add the properties to the symbol. The extracted file is located at: C:\Training\Module_6_Examples\6.1.2_constant_current_load_dialog_definition_worksheet.xlsx. The dialog definition creates the following dialog for the constant current load:

To add the symbol properties,

  1. Open the 6.1.2_constant_current_load_dialog_definition_worksheet.xlsx excel spreadsheet.

  2. Copy the 11 cells: B37-B47 to the windows clipboard.

  3. Navigate to the SIMetrix/SIMPLIS command shell window.

  4. Click the mouse in the command line entry located at the top of the command shell window:

  5. Press Ctrl+V to paste the commands in the command line.
    Result: the last command is partially visible in the command line.

  6. Press Enter or click the Ok Button on the command line.
    Result: The commands are executed in SIMetrix/SIMPLIS. Each AddSymbolProperty command adds a single symbol property to the symbol. As in previous exercises, the dialog definition properties are protected. All properties are hidden from view when the symbol is placed on the parent schematic.

  7. Select the Symbol Editor menu File Save... to save the symbol to the schematic component file.

The model and symbol are now complete and ready for testing.

Test the Model

Now that the model and associated symbol are completed, its time to start testing. A testbench schematic for the constant current load is located in the Module_6_Examples directory. After you place the load, this test schematic is ready to simulate. You will then run a few experiments on the model to verify it works as expected.

To start testing the model,

  1. Open the 6.2_test_constant_current.sxsch schematic.
    Result: The testbench schematic opens, this schematic has been specially prepared to test the load using three XY probes and a ramped voltage source. Each X-Y probe is configured to display one three PWL resistor operating segments.

  2. From the Schematic Editor menu select Hierarchy Place Component (Relative Path)...

  3. Select the constant_current_load.sxcmp component file from the Modeling Blocks directory.

  4. Place the load on the schematic where the opening below H1 is located.

  5. Press F9 to run the simulation.
    Result: The V-I curves for the load are generated on three tabs. The current tab displays the saturation characteristics of the load:

Each graph tab displays a different operating region for this load. The individual X-Y probes have been configured to set the graph X-values to a range appropriate to the default load parameters. For example, the default saturation voltage is 20mV. The saturation graph is displayed over a X range of 0 to 40mV. The vertical axis is auto scaled to fit the data. In this case, the actual curve extends to a load voltage of 10,001V, at which the current is approximately 2A. For this reason, the graph is auto scaled to a maximum Y-value of 2A.

Experiment #1: Test Dialog and Change Parameter Values

Whenever you pass parameters to subcircuits, it is important to test that the parameters are being passed properly and the simulation results reflect the actual parameter value. In this experiment, you will change the load parameters and verify the value changes in the simulation.

  1. Navigate to the Schematic Editor window.

  2. Double click on the subcircuit load symbol to edit the resistance parameter.
    Result: The parameter editing dialog opens.

  3. Change the DC Current value to 500m, and change the Saturation Voltage parameter to 30m and click Ok to accept the dialog. The dialog should appear as follows:

  4. Press F9 to run the simulation.
    Result: The green V-I curve for the load is generated with the new parameters.

Experiment #2: Test USE_RSHUNT Logic

Next you will check the USE_RSHUNT logic is working properly.

  1. Double click on the LOAD1 symbol to edit the parameters

  2. Uncheck the Use Shunt Resistance? check box.
    Result: The Shunt Resistance parameter control is disabled (grayed-out), suggesting to the user that the Shunt Resistor will not be used in the model.

  3. Click on the Ok button to save your changes.

  4. Press F9 to run the simulation.
    Result: A third set of curves is overlaid on the graph viewer:

  5. Select the first tab with the over voltage characteristics:

  6. Zoom into the point at which the blue curve changes slope.

    1. While pressing and holding the left mouse button, drag a box selection around the point where the blue curve changes slope. This is the transition from the constant current segment to the over voltage segment.

    2. Release the left mouse button. You may need to zoom multiple times to get to a magnification which allows you to see the shunt resistance effect.
      Result: The graph clearly shows the current at the 10kV point is approximately 501mA, which is the 500mA DC Current plus the shunt resistance contribution. The shunt resistance contributes 10kV/10MegΩ or 1mA to the load current at the load voltage of 10kV.

Experiment #3: Test .ERROR Message

Testing the .ERROR message is slightly more difficult because the parameter editing dialog will not allow you to enter an invalid value. Instead you will manually edit the value using the Edit Properties dialog.

  1. Select the LOAD1 symbol.

  2. Right click and select the Edit/Add Properties... menu option.
    Result: The Edit Properties dialog opens:

  3. Change the DC_CURRENT, RSHUNT, and SAT_VOLTAGE properties to 0.

    1. Double click on each property. On the Edit Property dialog, change each property Value to 0, and click Ok on the Edit Property dialog to accept the changes.

    2. Repeat for each property.

    3. Click Ok on the Edit Properties dialog.

  4. Press F9 to run the simulation.
    Result: All three parameters are less than the minimum limit specified in the F11 window of the constant_current_load.sxcmp schematic, and each .ERROR statement is output to the command shell:

    *** ERROR *** (6.2_test_constant_current.net): Subckt def constant_current_load used by X$LOAD1:
    The saturation voltage parameter (SAT_VOLTAGE) for the constant_current_load subcircuit must be greater than 0 and less than 10k volts.
    *** ERROR *** (6.2_test_constant_current.net): Subckt def constant_current_load used by X$LOAD1:
    The shunt resistance parameter (RSHUNT) for the constant_current_load subcircuit must be greater than 0.
    *** ERROR *** (6.2_test_constant_current.net): Subckt def constant_current_load used by X$LOAD1:
    The dc load current parameter (DC_CURRENT) for the constant_current_load subcircuit must be greater than 0.

Experiment #4: Test Minimum Values Allowed by Dialog

In the previous experiment you set the load parameters to values less than the minimum allowed by the parameter editing dialog. In this short experiment you will verify the dialog prevents users from entering values less than the specified minimum value.

  1. Double click on the LOAD1 symbol to open the parameter editing dialog.
    Result: Although the three parameters were set to 0 in the last exercise, the dialog automatically changes the values to 1p, which is the minimum allowed value for each parameter. The 1p value is defined in the excel spreadsheet for this dialog definition.

  2. Press the up arrow button on the DC Current spinner control.
    Result: The DC Current value changes from 1p to 2p.

  3. Press the down arrow button twice on the DC Current spinner control.
    Result: The DC Current value changes from 2p to 1p, and on the second click, the minimum value of 1p is enforced.

Conclusions and Key Points to Remember

A PWL resistor can be used to define a very flexible constant current load. This load will simulate without producing numerical errors if the terminals are left open circuited.

Key points to remember are:

  1. You can define parameters local to the F11 window. These parameters can be constants or be defined in terms of the parameters passed into the subcircuit.

  2. You can further test the value of parameters passed into the subcircuit with the .IF/.ELSE statements to define new parameters.

  3. You can validate parameter values are within a range with the .ERROR statement. Any parameter can be checked, including calculated parameters.

  4. When parametrizing PWL resistors, make certain the first and last segments have a positive slope.

© 2015 simplistechnologies.com | All Rights Reserved