Student’s Portion Introduction In this lab, you will learn about the basics of data acquisition. First, you will configure your data acquisition hardware in Measurement & Automation Explorer. Then, you will examine the data acquisition VIs in LabVIEW. Finally, you will develop analog input applications. Objective Learn the three DAQ device grounding modes. Learn the uses of Measurement & Automation Explorer. Differentiate between single-point acquisition, continuous acquisition, and buffered acquisition. Theory Measurement & Automation Explorer Introduction Measurement & Automation Explorer, or MAX, is a software interface that gives you access to all National Instruments DAQ, GPIB, IMAQ, IVI, Motion, VISA, and VXI devices connected to your system. The shortcut to MAX is placed on the desktop during installation of NI-DAQ. MAX is used primarily to configure and test National Instruments hardware, but it offers other functionality, such as checking to see if you have the latest version of NI-DAQ installed. The functionality of MAX is divided into four categories: • Data Neighborhood • Devices and Interfaces • Scales • Software 1 Data Neighborhood Data Neighborhood contains the virtual channels. The Data Neighborhood category shows you the currently configured virtual channels and provides utilities for testing and reconfiguring those virtual channels. Data Neighborhood also provides access to the DAQ Channel Wizard, which allows you to create new virtual channels. DAQ Channel Wizard The DAQ Channel Wizard is a software interface that lets you create new virtual channels. A virtual channel is a shortcut to a configured channel in the system. You can set up the configuration information for the channel and give the channel a descriptive name at the same time. Later, you can use the descriptive name to access that channel and its configuration information in LabVIEW. You can give the channel a description, decide what type of transducer the channel will use, set the range (determines gain), choose the grounding mode, assign custom scaling for the virtual channel, and give the channel a descriptive name to replace the channel number all at the same time. For example, channel 0 on the BNC-2120 is hardwired to a temperature sensor, so you could create a virtual channel for channel 0 and call it Temperature Sensor. You can create virtual channels for analog input, analog output, and digital I/O. In this case, referring to a channel by a name (Temperature Sensor) instead of a number (0) helps you remember what the channel does. Devices and Interfaces Devices and Interfaces displays the currently installed and detected National Instruments hardware. Devices and Interfaces also includes utilities for configuring and testing devices. The two utilities that are specific to DAQ devices are Properties and Test Panels. Properties Properties is a utility for configuring DAQ devices. When you launch the Properties utility, a dialog box appears with the following tabs that you can use to configure the DAQ devices. • System—The System tab allows you to change the device number, and it provides two buttons for testing the DAQ device. The first button is the Test Resources button. After you have installed the DAQ device, right-click Devices and Interfaces. Select Properties and right-click Test Resources. This button performs a basic test of the system resources assigned to the device. The system resources tested 2 are the base I/O address, the interrupt request (IRQ), and the direct memory access (DMA). – Base I/O Address—A DAQ device communicates with a computer primarily through its registers. NI-DAQ writes to configuration registers on the device to configure the device, and reads data registers on the device to obtain the device status or a signal measurement. The base I/O address setting determines where in the computer’s I/O space the device registers reside. – Interrupt Request (IRQ)—Another way the DAQ device communicates with the computer is through processor interrupts, which give the processor the ability to respond quickly to its peripherals. In the case of a DAQ device, it is not efficient for the processor to continually check if data is ready to be read from the device. A DAQ device can use an interrupt that signals the processor that it has data waiting to be read. Each interrupt request has a number assigned to it. – Direct Memory Access (DMA)—The third way the DAQ device can communicate with the computer is through direct memory access (DMA). DMA is a data transfer method in which data is transferred directly from the peripheral to computer memory, bypassing the processor. DMA is usually required to achieve maximum data transfer speed, making it useful for highspeed DAQ devices. DAQ devices that use the PCI bus have their own onboard DMA channels, and the PCI bus handles the sharing of that DMA. • AI. The AI tab allows you to configure the default Polarity/Range for the ADC and the default mode for grounding the DAQ device. The default is applied only if the settings aren’t changed in LabVIEW. • AO. The AO tab configures the default polarity of the analog output signal, and allows you to specify if you are using an external voltage reference for the DAC. • Accessory. The Accessory tab specifies any accessories you are using with the DAQ device such as the TBX-68 (terminal block with built-in cold-junction compensation). If NI-DAQ does not need to know about the accessory, it will not be on the list. In that case, choose None. • OPC. The OPC tab allows you to set the AI recalibration period if you are using the NI-DAQ OPC server. The use of the NI-DAQ OPC Server is beyond the scope of this lab. 3 Test Panels After the device passes the basic resource test and you configure the System, AI, AO, Accessory, and OPC tabs, return to the System tab and click the Test Panels button. The Test Panel is a utility for testing the analog input, analog output, digital I/O, and counter functionality of the DAQ device. The Test Panel is useful for troubleshooting because it allows you to test the functionality of the device directly from NI-DAQ. If the device does not work in the Test Panel, it will not work in LabVIEW. If you ever have unexplainable trouble with data acquisition in a LabVIEW program, use the Test Resources button and the Test Panels button to make sure the device is working properly. Scales Scales shows you all the currently configured custom scales and provides utilities for testing and reconfiguring those custom scales. Scales also provides access to the DAQ Custom Scales Wizard, which allows you to create new custom scales. DAQ Custom Scales Wizard The DAQ Custom Scales Wizard is a utility that creates custom scales you can use to determine scaling information for existing virtual channels. Each custom scale can have its own name and description to help you identify it. A custom scale can be one of three types: linear, polynomial, or table. • Linear—A scale that uses the formula y = mx + b. • Polynomial—A scale that uses the formula y = a0 + (a1 * x) + (a2 * x2) + … + (an* xn). • Table—A scale in which you enter the raw value and the corresponding scaled value in a table format. Software Software shows all the currently installed National Instruments software. The icon for each software package is also a shortcut that you can use to launch the software. The Software category also includes a Software Update Agent. The purpose of the Software Update Agent is to check if the National Instruments software is the latest version. If the software isn’t the latest version, the Software Update Agent opens the Web page on ni.com to download the latest version of the software. Software Architecture for Windows 4 The main component of NI-DAQ, the nidaq32.dll, makes function calls directly to a DAQ device. The function that the nidaq32.dll performs depends on where you access it from. Both MAX and LabVIEW can talk to NI-DAQ. MAX is used primarily for configuring and testing the DAQ device. MAX not only helps configure devices, but it also tells you what devices are present in the system. To do this, MAX must communicate with the Windows Device Manager and the Windows Registry. 5 Organization of Data Acquisition VIs Most of the Data Acquisition VIs located on the Functions»Data Acquisition palette are grouped in the following levels according to their functionality: • Easy VIs • Intermediate VIs • Utility VIs • Advanced VIs Easy VIs Easy VIs perform simple DAQ operations and typically reside in the first row of VIs in a palette. You can run these VIs from the front panel or use them as subVIs in basic applications. You need only one Easy VI to perform each basic DAQ operation. Unlike Intermediate and Advanced VIs, Easy VIs automatically alert you to errors with a dialog box that allows you to stop the execution of the VI or to ignore the error. Intermediate VIs Intermediate VIs have more hardware functionality and efficiency in developing applications than Easy VIs. Use Intermediate VIs in most applications. Intermediate VIs give you more control over error handling than Easy VIs. With each VI, you can check for errors or pass the error cluster to other VIs. 6 Utility VIs Utility VIs are also intermediate-level VIs and thus have more hardware functionality and efficiency in developing an application than Easy VIs. Utility VIs consist of convenient groupings of Intermediate VIs. They are for situations where you need more functionality control than the Easy I/O VIs provide but want to limit the number of VIs you call. Advanced VIs Advanced VIs are the lowest-level interface to the DAQ driver. Very few applications require the use of Advanced VIs. Advanced VIs return the greatest amount of status information from the DAQ driver. Use Advanced VIs when Easy or Intermediate VIs do not have the inputs necessary to control an uncommon DAQ function. 7 Homework Procedure Part 1. Measurement & Automation Explorer (MAX) In Part 1, you will become familiar with the installation and configuration of a data acquisition device. This exercise also gives a detailed tour of MAX. 1. Connect the sine wave from the function generator to analog in 1 on the BNC-2120. 2. Connect analog out 0 to analog in 2. 3. Launch MAX by double-clicking the icon on the Windows desktop. 4. Double-click the Devices and Interfaces category. MAX searches for installed hardware and lists the National Instruments devices found. A device number in parentheses is assigned to each device in the system. The LabVIEW DAQ VIs use this number to specify which device the VIs address. If the device is not listed, go to View»Refresh. 5. Right-click the DAQ device folder for the specific device and select Properties. A configuration dialog box appears. The Configuration dialog box contains several tabs. The System tab allows you to change the device number of the DAQ device. It also reports the system resources assigned to the device through the Windows Registry. The system resources shown in the Configuration dialog box include the following items: • Input/Output Range (Base I/O Address)—The DAQ device communicates with the computer primarily through its registers. The base I/O address setting determines where in the computer I/O space the device registers reside. • Interrupt Request (IRQ)—An interrupt gives the processor the ability to respond quickly to its peripherals. Think of a processor interrupt as a doorbell. If you did not have a doorbell, you would have to go to the door periodically to see if anyone were there. With a doorbell, you need to go to the door only when the doorbell rings, and you are confident that someone is there waiting. Likewise, a DAQ device uses an interrupt as a doorbell to tell the processor that it has data waiting to be read. Every device that uses processor interrupts must be assigned a different interrupt level, or the devices can conflict with each other. 8 • Direct Memory Access (DMA)—DMA is a data transfer method in which data is transferred directly from the peripheral to computer memory, bypassing the processor. DMA is usually required to achieve maximum data transfer speed, making it useful for high-speed DAQ devices. DAQ devices that use the PCI bus have their own onboard DMA channels, and the PCI bus handles the sharing of that DMA. DAQ devices that use the AT/ISA bus must assign themselves a DMA channel from the computer. 6. Select the Input/Output Range. Click View below the Resources dialog box. You can use the dialog box that appears to configure non-Plug and Play devices manually. If you have a Plug and Play device, the computer automatically configures the system resources and the Input/Output Range is dimmed. 7. Click the AI tab. This tab allows you to set the default polarity/range and grounding mode used for analog input signals. These default values are used by NI-DAQ as long as other settings do not override them. 8. Click the AO tab. This tab allows you to set the default analog output polarity. 9. Click the Accessory tab to specify any accessories that are attached to the DAQ device. Select the BNC-2120 from the list. Devices on the Accessory list usually provide some form of signal conditioning for signals, or they increase the number of channels you can measure. If an accessory does not change the way signals are measured, it does not appear on the Accessory list. 10. Click the OPC tab. The OPC tab allows you to set the recalibration period when using an OPC server. The use of an OPC server is beyond the scope of this lab. 11. Complete the following steps to verify the DAQ system is set up correctly. a. Click the System tab. b. Click Test Resources. This action tests the system resources assigned to the device. c. Click OK. 12. On the System tab, click Run Test Panels. The following front panel appears. The Analog Input tab allows you to read the analog input channels. Channel 0 can be configured as the temperature sensor on the BNC-2120. You should see a voltage between 0.2 and 0.3 V displayed on the graph. 9 13. Place your finger on the temperature sensor to increase the voltage. 14. On the Analog Input test panel, change the channel to 1. Make sure that the sine wave from the function generator is connected to analog in 1 on the BNC-2120. The sine wave probably looks distorted. In the lower left corner of the test panel, you can see the following three options for Data Mode. • Strip Chart: continuously displays data, scrolling as new data is acquired. • One Shot: displays only one screen of data. • Continuous: continuously displays a screen of data at a time One Shot and Continuous Data Modes allow you to adjust the sample rate. The higher the sample rate, the more accurately the graph displays the waveform. 15. Complete the following steps to make the graph look better. a. On the BNC-2120, set the frequency range to 100 Hz – 10 kHz and turn the Frequency Adjust to Lo. b. On the test panel, change the Data Mode to One Shot or Continuous and try different values such as 5,000, 10,000, or 15,000 for the sample rate until the graph displays a smooth sine wave. 16. Click the Analog Output tab. In this dialog box, you can set up a DC voltage or sine wave on one of the analog output channels of the DAQ device. Complete the following steps to output a DC voltage on channel 0. a. Verify that analog out 0 is connected to analog in 2 on the BNC2120. DC Voltage should already be selected for the Output Mode. b. Enter 5 V for the DC Voltage and click Update Channel. 17. Click the Analog Input tab. Change the channel to 2. You should now see 5 V displayed on the graph. You can make the signal more readable by selecting Strip Chart for the Data Mode. If you don’t see the change, click Start. 18. Click the Counter I/O tab. Complete the following steps to verify counter/timer operation, do the following: a. Change the Counter Mode to Simple Event Counting. The counter is now set up to count the pulses of a 100 kHz onboard signal. b. Click Start. The Counter Value should increment rapidly. c. Click Reset to stop the counter test. 10 19. To increase the rate of the pulses, change the Event Source to Internal 20 MHz Clock and click Start. Notice how much faster the Counter Value increases. It increments faster because the pulses being counted now occur at 20 MHz, instead of 100 kHz. Click Reset to stop the counter. 20. Click the Digital I/O tab. This tab gives you access to the eight digital lines on the device and allows you to set each line as an input or output line. 21. Close the test panel and exit MAX. 11 Part 2. Voltmeter VI Complete the following steps to build a VI that measures the voltage that the temperature sensor on the BNC-2120 returns. The temperature sensor returns a voltage proportional to the temperature. The sensor is hardwired to channel 0 of the BNC-2120. 1. Open a new VI and build the following front panel. Configure the meter scale for 0.0 to 0.4. Use the Labeling tool to doubleclick 10.0 and type 0.4. You might need to enlarge the meter to display the scale. 2. Build the following block diagram. AI Sample Channel VI (Functions»Data Acquisition»Analog Input palette)—Reads an analog input channel and returns the voltage. Wait Until Next ms Multiple function (Functions»Time & Dialog palette)—Causes the loop to execute every 100 ms. 12 3. Save the VI as Voltmeter.vi. 4. Display the front panel and run the VI. The meter displays the voltage the temperature sensor outputs. Place your finger on the temperature sensor and notice that the voltage increases. If an error occurs, the Easy I/O VIs display a dialog box showing the error code and a description of the error. 5. Close the VI. 13 Part 3. Buffered Acquisition VI With a buffered acquisition, LabVIEW tells the DAQ device how many points to acquire and at what rate to acquire them. Timing then becomes the responsibility of the DAQ device. In a buffered acquisition, the DAQ device controls all aspects of the acquisition. In contrast, with a softwaretimed acquisition, the computer is solely responsible for managing the acquisition, which can be problematic if the computer suddenly cannot give priority to the data acquisition process. 1. Open a new VI and build the following front panel. You can create most of the front panel controls shown above from the block diagram by right-clicking the appropriate terminals of the DAQ VIs and selecting Create»Control. In this exercise, you acquire data from one channel on the BNC-2120 and display the data on the graph. Set the Scan Rate to 20000 and Buffer Size to 1000. Set the DAQ Channel Name control to 1 and the Device to the proper device number for your DAQ device. 2. Build the following block diagram. 14 3. Save the VI as Buffered Acquisition.vi. 4. From the front panel, run the VI. You should see a sine wave plotted on the waveform graph. 5. Close the VI. 15 Part 4. Continuous Acquire with MIO VI Complete the following steps to build a VI that performs a continuous acquisition operation and plots the most recently acquired data on a chart. 1. Open a new VI and build the following front panel. a. You can create most of the front panel controls on the block diagram by right-clicking the appropriate terminals of the Data Acquisition VIs and selecting Create»Control from the shortcut menu. b. Acquire data from multiple channels of the BNC-2120 and display the data on the graph. Set the Scan Rate to 1000 scans/s, buffer size to 3000, and # of Scans to Read to 3000. c. Set the channel string control input to 0,1,2 or 0:2. d. Make the following connections on the BNC-2120. • Connect the sine wave output to analog input CH1. • Connect the square wave output to analog input CH2. 2. Build the following block diagram. 16 3. Save the VI as Continuous Acquire with MIO.vi. 4. Display the front panel. Run the VI and monitor the data plotted on the graph as you change the frequency knob on the BNC-2120. The numeric constant of 0 you wired to the number of scans to acquire input of AI Start enables a continuous or circular DAQ. Data fill a buffer of fixed size in memory and then, on reaching the end of the buffer, overwrite values from the beginning of the buffer. 5. Run the VI and monitor Scan Backlog as you decrease the scan rate or the number of scans to read at a time. Scan backlog is defined as the number of scans acquired into the acquisition buffer but not read. Scan backlog is a measure of how well you are keeping up with a continuous acquisition. If scan backlog steadily increases, you are not reading data fast enough from the buffer and will eventually lose data. If this happens, AI Read VI returns an error. 6. Close the VI. 17 Lab Report For your lab report, email the VIs and the answers to the questions below to the instructor no later than <date>. Data Sheet Questions 1. What are the three methods that DAQ devices can be grounded? 2. Describe three uses of Measurement & Automation Explorer. 3. What are the differences and similarities between single-point acquisition, continuous acquisition, and buffered acquisition? 18