Academic Company Events NI Developer Zone Support Solutions Products & Services Contact NI MyNI

Reference Design for Automating Simulation using Multisim and LabVIEW

0 ratings | 0.00 out of 5
Print

Overview

Through the unique integration between Multisim and LabVIEW, engineers are able to acquire simulation data as easily as real measurements within the LabVIEW environment.

By uniting real and simulated measurements in a single interface, engineers are able to proactively improve their design flow by correlating both sets of data, to validate the behavior of physical prototypes.

With the LabVIEW Multisim Connectivity Toolkit (beta), available for free download from ni.com/labs, you can fully automate the acquisition of simulation results from Multisim in LabVIEW. These standard VIs, provide 80+ functions to make integrating circuit design and test easier.

Introduction

The LabVIEW Multisim Connectivity Toolkit is a set of wrappers for the Multisim Automation API. All the various functions such as opening, closing, and viewing a circuit, as well as running, pausing and stopping simulation have been organized into VIs. 

This toolkit therefore allows the engineer to utilize standard LabVIEW programming practices to build powerful, and effective applications to automate simulation in Multisim.

Throughout the rest of this reference design, we will investigate the design of a LabVIEW application to:

  1. Open a pre-defined Multisim schematic
  2. View a Multisim schematic within LabVIEW
  3. Configure a simulation
  4. Change component settings for Multisim components from within LabVIEW
  5. Run a transient analysis.

 

Application

This discussion is based upon the attached reference design. The design can be used to automate transient simulation within LabVIEW, and can be modified to perform additional tasks.

The design is attached within the zip file named 7825_lv_and_multisim.zip.

Within this folder you will find:

    • MultisimExample.llb: This is the example application you will be able to use
    • RLCCircuit.ms10: This is the demonstration circuit to be simulated through the LabVIEW application.
    • SineWithNoise.lvm: This is a data file containing a real measurement. This real measurement can be used as a stimulus to the Multisim schematic easily through the automation API.

 

Design Strategy

There are a number of ways in which to consider the development of LabVIEW code for the purposes of automation. As you link from LabVIEW to the Multisim automation engine, there are a number of factors to consider. 

For example the designer must consider how a simulation event is handled, how the state is registered, and how the user will ultimately interact with an analysis within LabVIEW.

There are three common methods in which to build a LabVIEW application for Multisim automation:

  1. Busy-Wait Strategy: The busy-wait methodology is based upon waiting for data from Multisim to be sent to LabVIEW. With this design you must constantly pause the LabVIEW program flow to acquire data when it becomes available from the simulation engine. This method is not recommended for larger programs, particularly those that will also be automating real measurements. The pause time  may potentially affect other processes such as: user interface, hardware acquisitions, and so on. For very simple programs or short simulation wait times it is quick to implement.
  2. Polling: The basic polling concept requires you to have the application poll Multisim periodically to check if data has become available. If data is available then you fetch the data from Multisim. Using this type of structure allows your program to handle other tasks while at the same time checking for data available.
  3. Loop Event: The Loop Event is the recommended structure to utilize in building a LabVIEW application for Multisim. This is due to its ability to effectively leverage the resource-management benefits of LabVIEW. Using this type of structure allows your program to handle other tasks and react to events as they happen. We will explore this methodology further throughout this reference design.

 

Loop Event

As stated above it is recommended that you utilize the loop-event based approach to design with Multisim and LabVIEW. This approach (pictured in the figure below) is based upon an event handler waiting for Multisim to deliver “blocks” of simulated data to LabVIEW to be viewed and/or analyzed. This is the recommended structure due to it being able to benefit from resource-management tools in LabVIEW. Using this type of structure allows your application to handle other tasks and react to events as they occur.

The basic structure of the code is therefore to:

    1. Connect to Multisim  and open a schematic file
    2. Register a stop event. With this procedure the Active-X based Multisim Automation API events are registered with the event handler in LabVIEW. This means that LabVIEW will be able to understand when simulation events occur in Multisim, and will call an appropriate “call-back” VI to process this element of the analysis.
    3. Enumerate the various outputs of the simulation, and set their values if necessary
    4. Enumerate the various inputs of the simulation, and set their values if necessary
    5. Event based handling of simulation. Effectively when simulating, the LabVIEW application will: 
      • Run a simulation in Multisim and deliver a “block” of simulation data to LabVIEW
      • Event handler processes the appropriate tasks
      • A pause in simulation is effectively the time that lapses when Multisim delivers a “block of data” to LabVIEW. As such, when a pause occurs, you simply receive the data and then continue simulating.
      • Else there can be a stop in simulation
    6. Disconnect the connection to Multisim simulation from LabVIEW. 

 

 

Working with Event Handling

We will be focusing upon the Event Structure of the reference design, and how this approach executes the design strategy mentioned above.

 

Event Structure

The Event Structure waits for an event to occur. Based upon this event, a case is selected and the appropriate algorithm is executed. Below we view the specific code segments that have been defined as an example how best to utilize LabVIEW, Multisim and the LabVIEW Multisim Connectivity Toolkit, for the design of an application.


 

Load File Case

Within the Event structure is the Load File event case structure. Within this case structure is the algorithm to register the stop event (section 2 listed in the Design Strategy flow chart. This event is set to notice and register an event of a paused or stopped simulation. Since the Multisim Automation API is ActiveX based communication, LabVIEW does need to be able to register the events that are occurring within Multisim. Whenever a simulation event does occur, LabVIEW will execute a callback VI which will define the manner in which the event will be processed. For this application the name of the callback VI is _SimulationStopEventControl.

 

_SimulationStopEventControl

Within this case structure, again the Multisim Automation API is being checked for its simulation status. There are effectively three stages in which the simulation can be – stopped, running or paused.

 

This case identifies a stopped simulation, and as such is still waiting for action from the application.

If Multisim returns that it is running simulation, the application is placed into an idle state, and no information is being gathered or analyzed.

 

When simulation pauses, the aforementioned “block” of measurement data is transferred from Multisim to LabVIEW. This is when a Fetch Output algorithm is executed in order to gather information and showcase the measurements within the graphical LabVIEW front panel.

 

 

Application Code

The following documentation highlights some of the specific data on this application, and code that will be valuable for reuse for future applications.

 

Connect Case

One of the most significant events to handle is the connection of LabVIEW to the Multisim Automation API.  This case structure will connect to Multisim, check if the connection is successful, and then finally verify the version of Multisim that is being used (it is important to note that although Multisim 10.0 does have an Automation API – many features have been added to the latest edition of Multisim 10.1).

 

Once the connection is verified, the connection status on the front panel of the instrument is highlighted as connected.

 

 

Circuit Comps Tree & Apply Comp Value

After a circuit has connected, the attached reference design begins to load pertinent information into the interface.  In the case of the code below (Circuit Comps Tree), the case structure reads the various RLC values from the circuit. This functionality relates to the ability for you to change component values in the API provided in Multisim 10.1.

Based upon the component selected in the front panel, the application will extrudes the value of the RLC component from the circuit and populate the component family tree with its value.

 

For example, on selecting resistor R1, the Component Value of 50 is determined.

 

The Apply Comp Value case structure allows you to set the value of the selected component. This means that the value placed into the front panel (seen above as the defined New Value variable) will set the value of the component (in this case resistor R1) to the entered value.

 

This changed value will immediately cascade to the Multisim schematic.

 

 

Configure Signal and Load LVM

The Configure Signal and Load LVM case structures are identical algorithms, with the exception of the source of the input data. These case structures allow you to define the exact nature of the stimulus in the simulation process. The Configure Signal defines a custom signal, based upon user input. This includes signal type, amplitude, and frequency. These elements combine to input a specific signal into the simulation process.


[+] Enlarge Image             

The Load LVM, allows you to load a pre-saved file of real-measurement data from LabVIEW as the circuit stimulus.  This means that the stimulus of the circuit be a real signal such as a heartbeat, or noisy signal to improve the simulation model of a design. This ability to input a real signal through a LVM file can be automated. This means that the “Open LVM” subVI that can be currently seen, can be replaced with a direct input from a real source. LabVIEW can automate the acquisition of a real signal, and input it into the simulation flow. This is an example of virtual prototyping. This approach requires real signals to be used as a simulation stimulus. The real signal allows you to better approximate real-world conditions, and reduce design errors based upon real world noise etc… during the earliest stages of the design flow.

 

In both cases, the input signal is saved to an Inputs Array structure. 


 

Running Simulation

The previously analyzed case structure is connected to a case structure which holds the algorithm for the actual simulation. For this reference design, there is an actual “run” and “stop” button, however this code can again be modified, in order to completely automate simulation to run continuously until a particular event executes.

For the purposes of this reference design however, a case structure which is controlled by the preceding event structure acts as control for the simulation process.

The case structure can be seen below. Again select from the drop-down box the various execution case for the application. As with the event structure we will explore some of the most pertinent algorithms within this structure.

 

Set Input

In the previous event structure, we identified the configure signal and load LVM algorithms as key elements of automation process, as they set the stimulus for the circuit simulation. The Set Input algorithm takes the Inputs Array data (spoken about previously) and utilizes the Automation API to set the stimulus.

 

 

Run Simulation and Resume Simulation

Run Simulation and Resume Simulation both execute the same algorithm. Once the simulation is run, upon a time delay there is a check upon the status of the simulation. This status check provides the simulation status in the front panel.

 

 

Fetch Output

As previously mentioned when the simulation is paused within Multisim, LabVIEW can receive the ‘block’ of simulation data, which can then be transferred to LabVIEW to view. As such the code below, simply looks for the appropriate output variable from the circuit, and sends the data to a  LabVIEW graph to showcase the simulation.

 


[+] Enlarge Image

 

 


 

Using the Application

The application provided with this white paper contains all the code in order to be able to setup an automated Multisim simulation. To use this application you do require Multisim 10.1, LabVIEW 8.5+ and the LabVIEW Multisim Connectivity Toolkit.

  1. Open the MultisimExample.llb virtual instrument.
  2. In the LLB Manager, open the Multisim Application.vi.
  3. Run the LabVIEW virtual instrument.

 

  1. Click on the Connect button, to connect to Multisim.
  2. Notice that LabVIEW will connect to Multisim.

 

  1. Select a circuit file (you will need Multisim installed) and browse to the appropriate circuit. Browse to the RLCCircuit.ms10 which is available in the attached zip folder.
  2. Click on the Load Circuit button.

 

 

  1. Through the connectivity toolkit, the API will now showcase the circuit within a window.

 

  1. Click on the I/O Configuration tab.
  2. There are multiple inputs and outputs to analyze during the simulation.
  3. In the available inputs and outputs select (while holding down the CTRL key), V2 (which is the input to the circuit) and V(Output) nodes.
  4. Click on the >> button to select the inputs and outputs.
  5. Click on the Configuration Ready button.
  6. Hit the green Play button.
  7. You can now view the simulation in the LabVIEW window.

 

  1. Stop the simulation (the red stop button).
  2. You can now use the standard LabVIEW chart and graph tools to view and further analyze the data from the simulation.

 

Downloads

7825_lv_and__multisim.zip

0 ratings | 0.00 out of 5
Print

Reader Comments | Submit a comment »

 

Legal
This tutorial (this "tutorial") was developed by National Instruments ("NI"). Although technical support of this tutorial may be made available by National Instruments, the content in this tutorial may not be completely tested and verified, and NI does not guarantee its quality in any way or that NI will continue to support this content with each new revision of related products and drivers. THIS TUTORIAL IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND AND SUBJECT TO CERTAIN RESTRICTIONS AS MORE SPECIFICALLY SET FORTH IN NI.COM'S TERMS OF USE (http://ni.com/legal/termsofuse/unitedstates/us/).