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

Document Type: Tutorial
NI Supported: Yes
Publish Date: Feb 24, 2009


Feedback


Yes No

Related Categories

Related Links - Developer Zone

Related Links - Products and Services

How to Create a LabVIEW Based Virtual Instrument for NI Multisim

10 ratings | 3.40 out of 5
Read in | Print | PDF

Overview

The interactive simulation features of Multisim are designed to help hardware design gain a better understanding of circuit behavior. However, the quality of simulation results is highly dependent on the applied signals as well as the methods of analyzing and displaying simulation data. To help close the traditional gap between design and test, Multisim offers the possibility to implement and use custom instruments based on NI LabVIEW together with your SPICE-based circuit, turning an ordinary schematic into a virtual prototype. You can now connect to real-world signals from inside Multisim, output data to drive real-world circuitries, or display simulation data in a way more suitable to your needs.

System Requirements

The current version of Multisim is NI Multisim 10.1.1. This version of Multisim supports LabVIEW instruments created in LabVIEW 8.2.1 and LabVIEW 8.5.1. You can find compatibility files for other versions of Multisim and other versions of LabVIEW in the Tutorial: Assure Compatibility of LabVIEW Based Instruments Across Different NI Multisim Versions.

 

Things to Consider

 

  • You can build either an input instrument (Multisim inputs data to an instrument based on LabVIEW) or an output instrument (an instrument based on LabVIEW outputs data to Multisim).
  • Input instruments continuously receive data from Multisim while the simulation is running. If you plan to build or use instruments that connect to real-world I/O (for example, DAQ, GPIB, Serial, File, and so on) take into consideration that you deal with simulation time (related to SPICE Tmax, complexity of your schematic, CPU speed, and so on) versus "real time."
  • Output instruments cannot transfer data to Multisim while the simulation is running. This means that data acquisition,generation,and so on has to take place before you start a SPICE simulation (for example, first record data with the microphone and than start the simulation).
  • Instruments based on LabVIEW are built out of a LabVIEW project; therefore, you need NI LabVIEW 8.0 or later to create new instruments.
  • You need only LabVIEW to create the instrument. LabVIEW does not need to be installed on the machine where you intend to run Multisim.

In the tutorial, you will see references to the Samples folder and to the LVInstruments folder. There are several possible locations for these folders in your computer directory, having one or any other option depends on what version of Multisim you have along with the version of Windows (Vista vs. non-Vista). The possible locations are:

In Windows 2000 and XP:
C:\Documents and Settings\All Users\Documents\National Instruments\Circuit Design Suite 10.1\samples\LabVIEW Instruments
C:\Documents and Settings\All Users\Documents\National Instruments\Circuit Design Suite 10.1\LVInstruments

In Windows Vista:
C:\Users\Public\Documents\National Instruments\Circuit Design Suite 10.1\samples\LabVIEW Instruments\
C:\Users\Public\Documents\National Instruments\Circuit Design Suite 10.1\LVInstruments

Otherwise, you can look in Multisim under the Options»Global Preferences»Paths, look for User LabVIEW Instruments Path, this will give you an idea of where in your file directory are the folders located.

 

Creating a New Instrument

Creating an input or output instrument is nearly the same process. In this tutorial, we will create a new input instrument that takes a signal from a SPICE circuit and compares it against an upper and lower limit. Differences to creating an output instrument will be explained.

Note: DO NOT delete any of the front panel controls or block diagram code. Everything the template comes with is required for communication between Multisim and an instrument based on LabVIEW.

Step 1: Copy and Rename a Template Project

  1. Copy the folder ...samples\LabVIEW Instruments\Templates\Input to a new directory.
  2. Rename the folder ..\Input to ..\In Range.
  3. Rename the file ..\In Range\StarterInputInstrument.lvproj to In Range.lvproj.
  4. Double-click on ..\In Range\In Range.lvproj to open the project file in LabVIEW.
  5. Right-click on the Starter Input Instrument.vit and select Save As. Follow the dialogs and rename the template to In Range Instrument.vit.
  6. Repeat the same process to rename Starter Input Instrument_multisimInformation.vi to In Range Instrument_multisimInformation.vi (Note: Independent of the name you choose for the sub VI, you have to keep the extension "_multisimInformation.vi" to enable Multisim to load the instrument).
  7. Save your project.


[+] Enlarge Image


[+] Enlarge Image

 

Step 2: Specify Interface Information

  1. Double-click on Open In Range_multisimInformation.vi to open it.
  2. Change to the block diagram of the VI (press Ctrl-E, or navigate to Window > Show Block Diagram).
  3. Enter the following information:
    1. Instrument ID = "InRange" (Unique used to communicate between Multisim and LabVIEW)
    2. Display name = "In Range" (the name that will appear in Multisim?s instrument toolbar list
    3. Number of pins = "1" (this sets the number of inputs pins offered by the instrument)
    4. Input pin names = "In" (pin name that will be used in a SPICE netlist or netlist report)
  4. Save (File > Save) this VI and close the block diagram and front panel.

NOTE: A valid instrument can have either input pins or output pins, but not both. If you set number of input pins > 0 and number of output pins > 0, the instrument will not be treated as a valid LabVIEW/Multisim instrument.


[+] Enlarge Image

Note: If you create an output instrument, fill in the appropriate values for number of output pins and output pin names.

 

Step 3: Create Custom Instrument

The front panel of the VI In Range.vit will be the instrument interface a Multisim user sees and operates, the block diagram is where you add the graphical code for your instruments specific functionality.

Build The Fron Panel of Your Instrument
  1. Double-click on In Range Instrument.vit to open it.
  2. Select the front panel and change it as shown in the graphic below.
    1. Move (but DO NOT delete) all controls that a user should not see
    2. Right-click on the front panel and add a Horizontal Pointer Slide from the numeric controls
    3. Rename the control to Upper Limit
    4. Right click the slider and select Data Range and enter the following values
    5. Repeat the steps to create a slider named Lower Limit but set the default value to -5
    6. Place a Square LED from the Boolean Control palette and rename it In Range


[+] Enlarge Image

Note: The front panel also holds a control named "Sampling Rate [Hz]" with a default value of 10 kHz. This control determines the rate data are transferred from the simulation to the instrument based on LabVIEW. Change the default value or make the control accessible on the interface if changes to that control are necessary.

Finish the Block Diagram of Your Instrument
  1. Change to the Block Diagram (press Ctrl-E) and add the following graphical code to the case "Update data," located in the lower while loop.
    1. Enlarge the space in the case structure (press Ctrl and draw a rectangle with the left mouse button)
    2. Place "Index array" from the array palette to select the data for pin number 1 (your input pin)
    3. Place "Get waveform components" from the waveform palette to extract Y-data from your wire
    4. Place "In Range and Coerce" from the comparison palette and wire your front panel controls to the upper and lower limit terminals
    5. Place "Index array" from array palette and wire its input to the "In Range" terminal of the "In Range and Coerce" function. Wire the output scalar to front panel square LED "In Range?"
    6. Save your VI and close front panel and block diagram


[+] Enlarge Image

Note: If you create an output instrument, the process is very similar except that you wire all data you want to send to Multisim to control named Multisim output pins located in the case structure named Update Initial Output Data.


[+] Enlarge Image

Note: If you intend to save instrument data (settings, control values, and so on) with your circuit, you need to place the appropriate code in the cases "Serialize Data" and "Deserialize Data."

Step 4: Build a Custom Instrument

  1. Expand the Build Specifications and double-click on Source Distribution to open it.
    1. Select the category "Distribution Settings"
    2. Change the Distribution Directory to ...\In Range\Build\In_Range.llb
    3. Press the Build button
  2. Press Done after the build process is completed.
  3. Save Project (File > Save Project) and close LabVIEW.


[+] Enlarge Image


[+] Enlarge Image

Install and Use the Custom Instrument

Everything you need to use a custom instrument inside Multisim comes with the Multisim installer. If you would like to share a new instrument with colleagues or other Multisim users, just send the *.llb from your project's ..\Build folder.

  1. Navigate to project's build folder "...\In Range\Build\" and copy the new instrument "In_Range.llb" to the LabVIEW instrument folder inside the Multisim installation directory ... \lvinstruments\.
  2. Start Multisim.
  3. Access the new "In Range" instrument from the LabVIEW category of the Multisim instrument toolbar or from the Simulate menu (Simulate > Instruments > LabVIEW Instruments > In Range).
  4. Build a simple circuit to test the instrument's behavior.
    1. Place a Function Generator
    2. Place the new In Range Instrument and connect it to the + pin of the Function Generator
    3. Place Ground and connect it to the Ground pin of the Function Generator
    4. Double-click the Function Generator symbol to open its interface and enter the following values
      1. Waveform: Sine Wave
      2. Frequency: 60 Hz
      3. Amplitude: 10 Volts
    5. Double-click the In Range instrument symbol to open its interface
  5. Start the simulation and verify the instruments behavior.


[+] Enlarge Image

Additional Resources

Search ni.com for More Instruments Based on LabVIEW for Multisim

View the Tutorial: Assure Compatibility of LabVIEW Based Instruments across Different NI Multisim Versions 

See an Overview of Multisim Virtual Instruments

Learn More about LabVIEW

Downloads

in_range.zip

10 ratings | 3.40 out of 5
Read in | Print | PDF

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/).