Using LabVIEW and Multisim: SPICE Netlist Simulation from LabVIEW

Publish Date: Sep 29, 2009 | 5 Ratings | 3.60 out of 5 |  PDF

Overview

This article was written by Nestor Sanchez, Product Support Engineer, at National Instruments. Nestor works with the NI Multisim and NI Ultiboard tools, and has developed example programs and applications with the NI Electronics Workbench Group R&D team.

Table of Contents

  1. Introduction
  2. SPICE Netlist File Analysis & Tutorial
  3. Tutorial Contents
  4.  Step 1 - Working with NI Multisim
  5. Step 2 - Working with LabVIEW
  6. Step 3 - Run the VI
  7. Step 4 - Simplifying Connectivity to Multisim with the ExpressVI
  8. Summary

1. Introduction

The following tutorial shows a simple way to simulate a SPICE Netlist from within the LabVIEW environment. Once you finish this tutorial you will see how easy and straight-forward it is to use the LabVIEW Multisim Connectivity Toolkit to call and control the Multisim simulation engine.

The LabVIEW Multisim Connectivity Toolkit (beta) takes advantage of the COM aware API which allows a programming language such as LabVIEW to automate a Multisim simulation. Such automation is important for engineers who need to use simulation and perform an analysis which is not readily available in an off-the-shelf product. By leveraging a programming language, an engineer has unlimited flexibility/creativity in order to develop an analysis for their specific design.

In order to be able to use the LabVIEW Multisim Connectivity Toolkit (beta), you have the following requirements:

  1. Multisim 10.1 higher. If you do not have Multisim, download a 30 day evaluation here.
  2. LabVIEW 8.6.1 or higher. If you do not have LabVIEW download a 30 day evaluation here
  3. LabVIEW Multisim Connectivity Toolkit (beta). Download here.

To access help documents about the LabVIEW Multisim Connectivity Toolkit, in LabVIEW select;

Help » Multisim Connectivity Toolkit Help.

 

Back to Top

2. SPICE Netlist File Analysis & Tutorial

One of the analysis capabilities that the toolkit exposes is the ability to simulate a SPICE netlist file. A SPICE netlist file contains the source SPICE code that not only describes the circuit but that also runs an analysis on it. Even though the code makes it look very simple, it is in fact intended for advanced users that are knowledgeable in SPICE commands. This file is referred to as a 'SPICE nutmeg command file'.


This tutorial will allow you to understand how to:

  1. Create and modify a netlist file from a Multisim circuit file
  2. Create and modify a SPICE nutmeg command file
  3. Use Multisim to figure out what nutmeg commands to issue
  4. Use LabVIEW to build a VI that will execute the SPICE nutmeg command file
  5. Display results from the simulation
  6. How to use the Multisim Connectivity ExpressVI in order to accomplish this task

There are many different use-cases for this type of simulation tailored for advanced SPICE users. Some applications include allowing you to access libraries of old SPICE files that you wish to simulate, creating a batch process to run a simulation across a complete collection of files, as well as dynamically modify netlist files or analysis parameters to see differences.

This tutorial assumes that the user has working knowledge of LabVIEW, Multisim and understands the basics of SPICE. If you do not have a knowledge of these topics, we recommend:

  1. Multisim Interactive Demonstration: Learn how to capture and simulate
  2. Tutorial - Introduction to the LabVIEW Multisim Connectivity Toolkit
  3. Reference Design - LabVIEW Multisim Connectivity Toolkit

 

Back to Top

3. Tutorial Contents

For this tutorial you will find attached a spice_example_5933.zip file. In this file you will find the following contents, which you will be able to use for various steps in this tutorial (if you choose not to create your own files):

  1. RLCCircuit.ms10 [Step 1 - Working with NI Multisim]
  2. RLCCircuit.cir [Step 1 - Working with NI Multisim]
  3. SPICENutmeg.cir [Step 1 - Working with NI Multisim]
  4. SPICE Netlist Command Line Demo.vi [Step 2 and Step 3]
  5. SPICE Express VI Demo.vi [Step 4 - Simplifying Connectivity to Multisim with the ExpressVI]

 

Back to Top

4.  Step 1 - Working with NI Multisim

In this first step you are creating a SPICE nutmeg command file. This will allow you to lever the graphical design environment of NI Multisim to generate a SPICE based command file that contains circuit information, as well as the specific of the analysis you will soon complete. 

 

1. Download the attached spice_example_5933.zip file.

Group all the files included in the folder of this demo script into a new directory. In this way you will be able to modify them without compromising the originals.

 

2. Load the circuit file.

Launch Multisim. Select File » Open Samples..., and select the RLCCircuit.ms10 file. Click Open to load the file and review it.

 

3. Create the netlist file.

Select Transfer » Export Netlist. Leave the default name for the file (RLCCircuit.cir) and browse to the directory location where you would like to place files. We suggest: C:\demo\

Click Save. You can open the file in the Notepad application if you wish to review the results of this export.

 

4. Create a sample SPICE nutmeg command file.

Select Simulate » Analyses » Transient Analysis. Select the Output tab, and confirm that V(Output) is listed under the Selected variables for analysis window.

Select the Summary tab, and expand the Representation as SPICE commands branch.

Launch Notepad or any other text editor in Windows, and type all command lines starting from begin-scope to end-scope. You should have in Notepad text similar to the following:

begin-scope page Transient Analysis
checknodes 3
save $output_0v_sp_node
iplot $output_0v_sp_node
set trtol = 7
set itl4 = 100
set convlimit
set rshunt = 1e+012
-param hrange 0 0.001
tran -env-options 0.001 0.001 0 0.001 auto_ic auto_tstep auto_tmax
if-error end-scope audit-log-show
write-and-destroy-iplot C:\DOCUME~1\<username>\LOCALS~1\TEMP\EWB_13.RAW
end-scope

In your Notepad window select File » Save. Enter the name SPICENutmeg.cir for the file and browse to the same directory as the netlist file in Step 3. Click Save.

Close the Multisim application.

 

5. Modify the SPICE nutmeg command file.

There are multiple things that we need to to, in order to modify from the nutmeg command file before we are able to simulate it properly in LabVIEW. 

First specify the source netlist file first. Enter the following line before the begin-scope line:

source "C:\demo\RLCCircuit.cir"

As you may have noticed, the V(Output) variable we selected in Multisim was renamed to $output_0v_sp_node, this is an internal convention used in the Multisim engine, but is not a standard convention for plain SPICE. Modify the two lines that use the variable name so they now look like the following two lines:

save $output
iplot $output

Specify the output results file line (write-and-destroy-iplot) so that it is located within the same directory as your *.cir files:

write-and-destroy-iplot C:\demo\demo.raw

 

The final nutmeg file should look like the following:

source "C:\demo\RLCCircuit.cir"
begin-scope page Transient Analysis
checknodes 3
save $output
iplot $output
set trtol = 7
set itl4 = 100
set convlimit
set rshunt = 1e+012
-param hrange 0 0.001
tran -env-options 0.001 0.001 0 0.001 auto_ic auto_tstep auto_tmax
if-error end-scope audit-log-show
write-and-destroy-iplot C:\demo\demo.raw
end-scope

 

Verify that your file looks the same as the previous code before you proceed. Save the changes and close Notepad.

This is the file that will execute the analysis commands, and the one that will be called from LabVIEW. This command file uses the source line to specify which circuit netlist file to load and to apply the analysis to. This command file also saves the analysis results the file specified in the write-and-destroy-iplot line.

Back to Top

5. Step 2 - Working with LabVIEW

6. Launch LabVIEW.

Confirm that you have the LabVIEW Multisim Connectivity Toolkit VIs, they should be located under the Connectivity and/or Addons palette menus. They should like the following:

 

7. Build your code.

For this particular piece of code you will need the following LabVIEW functions/blocks. You can find next to each table entry below, the appropriate palette (or group) in which the function is located.

 

VI (Virtual Instrument)

 

Palette / Image

 

Multisim Connect

 

Connection

Multisim New File

 

File

Multisim Do Command File

 

Simulation Control

Multisim Wait or Next Output

 

Simulation Control

Multisim Last Error Message

 

Error & Utility

Multisim Disconnect

 

Connection

 

You will also need the File Parser SubVI to create the code below. This is custom made SubVI allows you to parse the nutmeg command file in order to find where the results of the analysis are saved; it will then parse the results file to convert the data into a LV-ready XY graph.

In LabVIEW build the following virtual instrument (VI) that will allow you to execute the SPICE netlist. 

Error checking is not required, but is highly recommended, using the Multisim Last Error Message VI will allow you to troubleshoot and effectively manage errors in LV.

Finally make sure you place an XY Graph control in the front panel.

 

Back to Top

6. Step 3 - Run the VI

At this point you can also open the existing example, to see Multisim and LabVIEW run together for this tutorial.

8. Open the SPICE Netlist Command Line Demo.vi contained with the rest of the contents of this tutorial. 

The front panel for this particular VI will appear as the following:

In the Log File Path section of the front panel, enter:

C:\demo\logfile.log

In the Command File Path control, browse and select the SPICENutmeg.cir file, created in step 5.

Click on the Arrow button in the top left-hand corner of the front panel to run the VI

After a few seconds, the XY Graph control will be populated with the analysis data. Use the Zoom Controls of the Graph Palette to zoom into the data.

 

Back to Top

7. Step 4 - Simplifying Connectivity to Multisim with the ExpressVI

In the previous Implementation section you were able to see how easy it is to program with the LabVIEW Multisim Connectivity Toolkit. 

If you are just starting to learn LabVIEW, or you wish to quickly configure a SPICE analysis from within LabVIEW, you can also make use of the Express VI version of the Multisim Do Command Line VI.

The purpose of an Express VI is to assist you when trying to program in LabVIEW, it provides a pre-built framework that you can easily configure parameters for. In this Toolkit we have included an Express VI called the Multisim SPICE Command Line VI. In the next set of instructions you will learn how to implement the same example discussed previously but now with an Express VI.

 

a.) Repeat Step 1 - Working with NI Multisim. This will allow you to create your Multisim command line nutmeg file.

b.) Begin building your VI.

In LabVIEW, select File »New VI.

Switch the block diagram, <CTRL+E> or Window » Show Block Diagram.

c.) Place the Express VI.

Right-click anywhere in the block diagram and select the Connectivity » Multisim » Express palette.

Select the SPICE Cmd Line VI and place it in the diagram. 

 

d.) Configure the Express VI.

After you place the Express VI, the configuration window pops-up in a few seconds. Set the SPICE Command File Path as shown in the following figure or the location where you placed SPICENutmeg.cir from the previous exercise.

 

Click OK when ready. LabVIEW will now create the Express VI.

e.) Wire the diagram.

We suggest that you wire the block diagram as shown in the following figure. You’ll notice that all the Multisim VIs have now been replaced by a single Express VI node.

f.) Run the VI.

When the code is ready, you can run the VI. The results should be the same as the previous example; however, the amount of code to be created has been reduced to a single VI.

If you wish, you can open the attached SPICE Express VI Demo.vi. This contains the code above, and will allow you to view the ExpressVI in action.

 

Back to Top

8. Summary


This tutorial explained the simplest process to get a text-based SPICE netlist and nutmeg commands to simulate from LabVIEW. This is particularly important when you want to have advanced access to the Multisim simulation engine for analyses.


Your LabVIEW programs will most likely be far more complex than the ones presented here, however the purpose of the tutorial is to show the simplest and most basic way to connect to the Multisim engine and simulate the SPICE commands.
The File Parser SubVI was custom made for this application in particular, use it as reference as how a results file from nutmeg commands may be parsed and therefore export useful data for graphing or other tasks.

Back to Top

Bookmark & Share


Downloads

Attachments:

spice_example_5933.zip


Ratings

Rate this document

Answered Your Question?
Yes No

Submit