Prev Next

OpAmp Circuit Simulation Example

For this example, we walk through the creation of a SysPhS model for a simple electronic circuit, and then use a simulation to predict and chart the behavior of that circuit.

Prerequisites

Running this simulation requires either:

  • OpenModelica or
  • MATLAB's  Simulink and Simscape

Circuit Diagram

The electronic circuit we are going to model is illustrated in this figure, using standard electronic circuit notation.

The circuit in this example will include a sine wave signal source, an earth, two resistors, and an OpAmp amplifier integrated circuit. The next figure shows the resulting diagram, as generated from a SysML diagram using SysPhS, into an external application - in this case Modelica.

Create SysML Model

This table shows how we can build a complete SysML model to represent the circuit, starting at the lowest level types and building up the model one step at a time.

Component

Action

Blocks

In SysML, using SysPhS, the circuit and each of the component-types are represented as Blocks.

In a Block Definition diagram (BDD), create a circuit component Block. The circuit has five parts: an OpAmp, a signal source, a signal to voltage converter, a ground, and a resistor. These parts are of different types, with different behaviors.

The key Blocks, including the OpAmp, Ground and Resistor, are accessible as pre-defined Blocks, using the SysPhS Component Patterns. However, for clarity, we will run over their creation from scratch.

Create a SysPhS Block for each of the Part types. The parts of the Circuit Internal Block Definition (IBD), will be connected through Ports, which represent electrical pins. These are defined in the BDD. The resistor has a positive and a negative pin. The ground has only one pin, which is positive. Electricity (electric charge) is transmitted through the pins. The two Ports are named 'p' (positive) and 'n' (negative), and they are of type ChargeFlowElement.

This figure shows the BDD, with Blocks defining the type of components used. This includes a signal source sine wave, a signal voltage converter, a Ground, a Resistor-type and an OpAmp-type.

Note: These Blocks are created from the SysPhS Toolbox using either Modelica Blocks or Simulink Blocks. You can type each Block to both tools. For more information see the Setting Blocks as Both Modelica and Simulink Help topic.

Phs Ports

The Value Types used for the Ports are pre-defined in the SysPhS Simulation Libraries. The two key quantities used are the ChargeFlowElement and the RealSignalInElement ValueTypes,

This figure shows the OpAmp Block in the Block Definition diagram, with the Ports on the OpAmp Block set to the ChargeFlowElement ValueType, and where this is referenced in the Browser window.

The Import connector to the Common Types Package shows how these must be set. For more information on the Package Import (circled), see the Referencing the SysPhS Simulation Libraries Help Topic.

Phs Constants

Both the Resistor and the Sine Wave Blocks have properties defined in their respective components in MATLAB and Modelica.

Let's use the resistor as an example. For these components, in their respective tools, we need to set a value of the resistance in Ohms. For most circuits there might be multiple resistor-parts that are derived from this Resistor Block, modeled as Parts in the IBD or Parametric diagrams. Hence, their value (in Ohms), will be set in the IBD, Parametric diagram or possibly in the simulation Datasets.

To set the property defining the resistance we need to create a Phs Variable 'r'. The initial value is left unset.

Note: The SysPhS Patterns include a Block of type Resistor that is already constructed.

For setting the resistance values in each individual component (Part), see the Initial Values row in this table, which shows the Blocks set with the Ports and Phs Constants.

Internal Structure

For the internal structure we create a Block with a child IBD diagram.

  • Create a Block for an inverting OpAmp circuit
  • Under this create an Internal Block Diagram (IBD) using the context menu option:
    Create New Child Diagram | Internal Block Definition diagram
  • Double-click to open the IBD
  • Set the diagram to only show the Port's name, using:
         -  F5 | Element | Element Appearance
  • Unset these two options:
         -  Show Stereotypes
         -  Show Property Type
    This will then show only the Port and Type

On the IBD, create Parts and connect them:

  • From the Browser, drag the Blocks onto the IBD as Parts (Properties)
  • To view the Parts in compartments, delete them from the diagram
    Note: Set the Paste option 'Structural Elements to 'ALL'
  • Otherwise, in the Features view, for the 'Interaction' tab click on the All button, and for the 'Parts / Properties' tab click on the All button.
  • Add properties for the Source signal, converter, 2 Resistors, OpAmp and Ground, typed by the corresponding Blocks

Bindings

To model the wiring up of these components:

  • Set the connections between the Ports with connectors of type Connector.

Notice that this follows the same structure as the original circuit diagram, but the symbols for each component have been replaced with properties typed by the Blocks we have defined.

Initial Values

As there are two Resistors, the input resistor (RIn) and the feedback resistor (Rf) must be created as two different Properties (Parts) in the IBD, sourced from the Resistor Block, as each of them will have different values. The values must be set in the Properties window, 'Property' tab, 'Initial' field.

For the InputControllingSignal, initial values are required for the amplitude and frequency.

On returning to the BDD you should now have the InvertOpAmp Block shown as:

Configure Simulation Behavior

This table shows the detailed steps of the configuration of SysMLSim.

Step

Action

Create a SysMLSimConfiguration Artifact

  • Open the Block Definition diagram
  • Click on the open space in the diagram
  • Press the Spacebar
  • From the 'Artifacts' sub-menu, select 'SysMLSim Configuration'
    This creates a new SysMLSim Configuration Artifact:

Set the Package

  • Double-click on the SysMLSim Configuration Artifact
    This opens the Configure SysML Configuration window
  • In the 'Package' field click on the [...] button and select the Package containing the SysML diagram:

Set Modelica or Simulink

In the top drop-down you can select which simulation tool to use:

  • Modelica
  • Simulink

For more details on these settings, see the Configure SysML Simulation Help topic.

Set the Block to Simulate

  • In the left-hand list, under 'Name', find 'InvertOpAmp'
  • In the 'Value' column, click on the drop-down and select 'SysMLSimModel'

Select Properties to Plot

You can now select the Properties to be plotted:

  • In the right-hand pane, select the Ports to plot

Run Simulation

On the 'Simulation' tab, click on the Solve button. This example shows a plot generated in Modelica:

In the legend you can see LM741.out.v  and 'Signal.v that are plotted, and match them with the two properties selected under Properties to Plot.

View the Model in Modelica or Simulink

To view the generated model in the external applications, Modelica or Simulink, see the View the Model in Modelica or Simulink Help  topic, along with tips for debugging any issues in the generated code.

Learn More