From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Example Code

VirtualBench: Bode Analyzer With the FGEN and 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 outputs a waveform from the VirtualBench function generator (FGEN) to a device under test (DUT), and then measures the signal using the VirtualBench mixed signal oscilloscope (MSO). It then performs an impedance/Bode analysis and displays a Bode plot consisting of two graphs: gain versus the frequency and phase versus the frequency. 


[+] 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. Follow the connection instructions to correctly connect your DUT. 
    5. Select the correct VirtualBench device from the pull-down menu of the VirtualBench Device control.
    6. Specify the analog channel, trigger channel, DC offset, and amplitude in the Channel Settings panel. 
    7. Click the Run button to run the program.
    8. The Bode plot will display on the graphs.

 

Program Explained

 


[+] Enlarge Image

 

    • Initialize Session
      • The VirtualBench device information is passed into the FGEN Initialize VI to initialize a new session to the FGEN and passed to the MSO Initialize VI to initialize a new session to the MSO. 
    • Configure Instrument
      • Instrument and error information are passed into the FGEN Configure Standard Waveform VI. The waveform function is set to sine. The amplitude and offset information are passed into the VI from the controls on the front panel. The frequency is set to be e5; this is the starting frequency.
      • Instrument and error information are passed into the MSO Configure Analog Channel VI. The analog channel is passed to the VI from the control on the front panel and the channel is enabled using a Boolean true constant. 
      • Instrument and error information are passed into the MSO Configure Analog Edge Trigger VI. The trigger channel is passed to the VI from the control on the front panel, the trigger slope is set to rising, and the trigger slope is set to rising edge. As a reminder, the detailed help for each VI specifies allowable values for each input. Below is an excerpt from the MSO Configure Analog Edge Trigger VI: 
    • Perform Operation
      • Instrument and error information are passed to the FGEN Run VI.
      • Error information from the FGEN Run VI and the MSO Configure Analog Channel VI is then bundled together before being passed into the While Loop. The error wire enforces data flow and ensures that the instruments have been configured correctly before entering the While Loop.
      • Instrument information is also passed into the While Loop. The solid tunnels indicate that the information is passed into the For Loop without any additional manipulation.  The While Loop will not execute until all of the inputs are available.
      • There are three arrays that are passed into the While Loop to initialize the shift registers. The shift registers indicate that it will pass values from previous iterations through a loop to the next iteration. LabVIEW transfers the data stored in the right terminal of the shift register to the left terminal at the completion of a loop. 
      • Instrument and error information are passed into the FGEN Query Standard Waveform VI. The frequency information is passed out of the VI and then appended to the bottom array. This frequency array is then used to make the graphs on the front panel. 
        • The frequency is also multiplied by 10; the program will sample at ten times the frequency of the signal.  The valid range for the MSO sample rate is between 15260 Hz and 1 GHz; we compare the calculated frequency to make sure it is within this range. If not, we coerce it to either the maximum or minimum frequency. 
        • The frequency is also used to determine the acquisition time on the MSO. First, the inverse of the frequency is taken to determine the period. The period is multiplied by 5 so the MSO will capture five waveforms. 
      • Instrument and error information are passed into the MSO Configure Timing VI. The calculated sample rate and acquisition time are also passed into the VI. 
      • Instrument and error information are passed into the MSO Run VI to start the MSO acquisition. 
      • Instrument and error information are passed into the MSO Read VI. This VI outputs the signal. To work with channel 1 and channel 2 data separately, the signal is indexed. Since the index starts at 0, channel 1 is at index 0 and channel 2 is at index 1.
      • Instrument and error information are passed into the MSO Stop VI to end the acquisition. The error wire passes from the MSO Read VI to the MSO Stop VI and then to the index of the signals; this is to ensure these steps are done in the correct order. 
      • Channel 1 and channel 2 signals are then passed into two different Tone Measurements Express VIs along with error information. This VI pulls out the amplitude and phase of the two signals.  
        • The amplitude and phase are output as dynamic data. This is converted to a single scalar data type for better use in calculations.
        • Channel 1 amplitude is then divided by channel 2 amplitude to calculate the gain. The gain is then converted into dB by computing the base 10 logarithm of the gain and then multiplying by 20.
        • Channel 2 phase is subtracted from channel 1 phase. A phase correction needs to be applied if the calculation yields a negative phase. The delta phase is compared to -180. If the delta phase is less than -180, it will return a true value. In this case, the selector will output the delta phase plus 360 degrees. If the delta phase is greater than -180, it will return false. The selector will then output the delta phase. 
        • The phase is built into an array and used for the output phase graph. The gain is similarly built into an array and used for the output gain graph.  
      • After the signals are split into the two channels, the error information is bundled together and passed to the FGEN Configure Standard Waveform VI. The frequency input is calculated:
        • The FGEN should sweep through a range of frequencies increasing at a frequency of ex where x is the loop iteration count divided by 2. The iteration terminal provides the loop iteration indexed at 0. One is added to get the loop iteration count. 
        • The loop iteration count is divided by 2, then added to the initial value of five before computing the exponential. 
        • The VB-8012 frequency range is between 20 MHz and 0. The program compares the frequency to ensure it is between these two values and if not, it coerces the frequency value to either the minimum or maximum frequency.
      • The program will stop on three conditions:
        • If an error has occurred. 
        • If the gain is attenuated below -30 dB.
        • If the specified frequency for the FGEN is outside the allowable range. When the frequency is compared to the allowable frequency range, it outputs a true or false based on if the frequency is within range. The inverse is taken to determine if the frequency is out of range. 
      • The conditions are OR'd together and then passed into the stop terminal of the While Loop. 
      • A 500 ms Wait has been added and will be performed after every read. While Loops are designed to  execute as fast as possible, but this can take up a lot of processor resources. The Wait is added to prevent  unnecessary use of computing resources.
    • Close Session
      • The instrument and error information are passed out of the While Loop and into the FGEN Close VI and the MSO Close VI. This closes the FGEN and MSO sessions and deallocates any resources for the next time a session is created with the instruments.
    • 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.

Comments
DAntoAle
Member
Member
on

Hello, I'm a student from Lanciano, Italy. In our class V A Electronic, with my classmates, we studied the VI. We will suggest an improvement that will give to the VI the ability to always complete. Indeed in the actual implementation the component "MSO Read (VI)", sometimes doesn't return. This happens when the output signal, on the DUT, is too small. We solved the issue changing the default value of the "auto trigger" input terminal on the "MSO Run (VI)". You can see a screenshot that shows our proposed improvement.

Best regards, 

Alessio D'Antonio.

 

 

Immagine 2023-01-19 120204.png