Example Code

VirtualBench: Acquire Analog and Digital Signals With the MSO

Products and Environment

This section reflects the products and operating system used to create the example.

To download NI software, including the products shown below, visit ni.com/downloads.

    Hardware

  • VirtualBench All-in-One Instrument

Code and Documents

Attachment

Description

Overview
This example automates acquiring analog and digital signals with the VirtualBench mixed signal oscilloscope (MSO).


[+] Enlarge Image

Steps to Run Program

    1. Download the example program on the right under downloads.
    2. In LabVIEW software, open the program by going to File » Open… and navigating to the file.
    3. Connect the VirtualBench device.
    4. Select the correct VirtualBench device from the drop-down menu of the VirtualBench Device control. Adjust the channel settings as desired.
    5. Scroll down in the left pane to view and set timing and trigger information.
    6. Click the Run button to begin acquiring data.
    7. The data acquired will display on the graphs.
    8. Click the Stop button to end the program.

 

As a reminder, the detailed help for each VI specifies allowable values for each input. Below is an excerpt from the MSO Configure Analog Channel VI as an example:

 

Program Explained

 


[+] Enlarge Image

 

    • Initialize Session
      • A new session to the MSO is initialized by passing the VirtualBench device information from the VirtualBench Device control into the MSO Initialize VI.
    • Configure Instrument
      • Channel Settings
        • Instrument and error information are passed into the MSO Configure Analog Channel VI. Analog channels, vertical coupling, probe attenuation, vertical range, and vertical offset information is passed from controls on the front panel to the VI. The analog channels specified are enabled using a Boolean true constant.
        • Instrument and error information are passed into the MSO Enable Digital Channels VI. The digitals channels to be viewed are passed from the front panel to the VI, and these channels are enabled using a Boolean true constant.
      • Timing Settings
        • Instrument and error information are passed into the MSO Configure Timing VI. Sample rate, acquisition time, and pretrigger time are passed from the front panel controls to the VI, and the sampling mode is set to sample. Sample mode acquires the first point from each sample interval, discarding the others. The other option peak detect determines the highest and lowest values for each sample interval then displays all the samples between the two values. Sample mode delivers the highest accuracy for timing interval measurements; peak detect is useful at slower sampling rates to see any extremes that occurred during the sample interval. 
      • Trigger Settings
        • Instrument and error information are passed into a Case structure. The trigger type specified on the front panel is used as the case selector. Select the down arrow next to the case name to select a different case to view.
          1. Immediate Trigger case: Instrument and error information are passed into the MSO Configure Immediate Trigger VI. In this case, the trigger will immediately activate after the pretrigger time has expired. 
          2. Digital Start Trigger case: Instrument and error information are passed into the MSO Configure Digital Edge Trigger VI. The digital trigger source and edge information is passed from the front panel controls to the VI. In this case, the trigger will activate on a digital source when the edge reaches the specified slope (rising, falling, or either). 
          3. Analog Start Trigger case: Instrument and error information are passed into the MSO Configure Analog Edge Trigger VI. Trigger source, slope, level, and hysteresis information is passed into the VI from the front panel. In this case, a trigger will activate on an analog source when the analog edge reaches the specified levels. A hysteresis window is used to improve measurement accuracy.
          4. Pattern Trigger case: Instrument and error information are passed into the MSO Configure Digital Pattern Trigger VI. The trigger source and the pattern are passed from the front panel into the VI. In this case, a trigger will activate on the digital source when the specified pattern occurs.
    • Perform Operation
      • Instrument and error information are passed out of the Case structure and into a While Loop.
      • The instrument and error information are passed into the MSO Run VI to start the MSO; auto trigger is enabled or disabled as specified on the front panel. This VI is in the While Loop so the program will look for another trigger occurrence after the first loop iteration.
      • The instrument and error information are passed into the MSO Read  VI. This VI outputs the digital and analog waveforms; these are then bundled together and displayed on the mixed signal graph Analog Data on the front panel. This VI also outputs the reason for the trigger: normal, forced, or auto.
      • As indicated by the While Loop, this program will repeatedly acquire and display the waveforms.
      • The error wire is then unbundled in order to determine the status. This information is then passed through an OR with the state of the Stop button into the conditional terminal of the While Loop. If either an error has occurred or if the user clicks the Stop button, the While Loop will finish executing.
    • Close Session
      • The instrument and error information are passed out of the While Loop and into the MSO Close VI. This closes the MSO session and deallocates any resources for the next time a session is created with the instrument.
    • Handle Errors
      • Finally, the error information is passed into the Simple Error Handler VI. If an error has occurred, a dialog box will open to notify the user.

 

Additional Resources

 

VirtualBench Examples

 

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.