1. System Requirements
The current version of Multisim is NI Multisim 12. This version of Multisim supports LabVIEW instruments created in LabVIEW 2010 and newer.
2. 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.
To properly install the LabVIEW instrument in the correct folder 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.
3. 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
- Copy the folder ...samples\LabVIEW Instruments\Templates\Input to a new directory.
- Rename the folder ..\Input to ..\In Range.
- Rename the file ..\In Range\StarterInputInstrument.lvproj to In Range.lvproj.
- Double-click on ..\In Range\In Range.lvproj to open the project file in LabVIEW.
- Right-click on the Starter Input Instrument.vit and select Save As. Follow the dialogs and rename the template to In Range Instrument.vit.
- 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).
- Save your project.
Step 2: Specify Interface Information
Double-click on Open In Range_multisimInformation.vi to open it.
- Change to the block diagram of the VI (press Ctrl-E, or navigate to Window > Show Block Diagram).
- Enter the following information:
- Instrument ID = "InRange" (Unique used to communicate between Multisim and LabVIEW)
- Display name = "In Range" (the name that will appear in Multisim?s instrument toolbar list
- Number of pins = "1" (this sets the number of inputs pins offered by the instrument)
- Input pin names = "In" (pin name that will be used in a SPICE netlist or netlist report)
- 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.
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
Double-click on In Range Instrument.vit to open it.
- Select the front panel and change it as shown in the graphic below.
- Move (but DO NOT delete) all controls that a user should not see
- Right-click on the front panel and add a Horizontal Pointer Slide from the numeric controls
- Rename the control to Upper Limit
- Right click the slider and select Data Range and enter the following values
Repeat the steps to create a slider named Lower Limit but set the default value to -5
- Place a Square LED from the Boolean Control palette and rename it In Range
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
- 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.
- Enlarge the space in the case structure (press Ctrl and draw a rectangle with the left mouse button)
- Place "Index array" from the array palette to select the data for pin number 1 (your input pin)
- Place "Get waveform components" from the waveform palette to extract Y-data from your wire
- Place "In Range and Coerce" from the comparison palette and wire your front panel controls to the upper and lower limit terminals
- 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?"
- Save your VI and close front panel and block diagram
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.
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
- Expand the Build Specifications and double-click on Source Distribution to open it.
- Select the category "Distribution Settings"
- Change the Distribution Directory to ...\In Range\Build\In_Range.llb
- Press the Build button
- Press Done after the build process is completed.
- Save Project (File > Save Project) and close LabVIEW.
4. 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.
- 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\.
- Start Multisim.
- 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).
- Build a simple circuit to test the instrument's behavior.
- Place a Function Generator
- Place the new In Range Instrument and connect it to the + pin of the Function Generator
- Place Ground and connect it to the Ground pin of the Function Generator
- Double-click the Function Generator symbol to open its interface and enter the following values
- Waveform: Sine Wave
- Frequency: 60 Hz
- Amplitude: 10 Volts
- Double-click the In Range instrument symbol to open its interface
- Start the simulation and verify the instruments behavior.