From the course: Data Acquisition with LabVIEW

Analog input with DAQ Assistant - LabVIEW Tutorial

From the course: Data Acquisition with LabVIEW

Analog input with DAQ Assistant

- [Instructor] I've spent a lot of time talking so far, about the DAQ hardware and related concepts. Now it's time to finally start writing LabVIEW Code beginning here with a blank VI. The quickest way to get up and running to take a measurement is using the DAQ Assistant express VI. Which is included on the DAQmx menu of the Functions palette under Measurement IO, DAQmx, DAQ Assistant. When I place the express VI it brings up a configuration based Wizard to configure tasks for a DAQ device, this first menu let's me select the measurement type for this task. To create analog input tasks I'll select acquire signal, analog input and then that gives me a list of common measurements and types of sensors. There's voltage, several types of temperature sensors, strain gauges, current, resistance, frequency and so on. Different types of measurement tasks have different configuration options, use different devices and it affects how data is interpreted. For this demonstration I'll be using a function generator to produce the input signal to my DAQ device, so I'll select voltage which is the most common type of measurement. The next menu lets me select which device to use, I only have one my USB 6,001 and then I can choose among its eight analog input channels. I'll select AI zero and then click Finish. This next menu lets me configure the settings for this measurement device. The terminal configuration drop down menu lets me select among the different input modes that are supported by this device. I'll choose differential. The acquisition mode drop down menu let's me choose whether do I acquire a single sample, a preset finite number of samples or continuously sample until told to stop, for now I'll choose N Samples. I'll set the sample rate to be 20 kilo samples per second which is the highest my device supports and I'll increase the samples to read to 10,000. These other tabs like triggering, and advanced timing allow you to configure other options which I'll cover later in this course. If I go to the connection diagram, the DAQ Assistant shows me how to connect my signal source to the physical pins on the DAQ device for the measurement that I configured. I'll be using this bench top function generator as my signal source which is set to produce a 50 Hertz five volt peak to peak sign wave. It's a grounded signal source which is why I need to configure and connect my DAQ device for differential input. I'll connect a BNC cable to the function generator's output terminal and on the other end of that cable, are two clips. I'll connect the positive lead to this little red wire I've screwed into the AI zero plus terminal on my USB 6,001 and then connect the other negative lead to this little black wire tied into the AI zero minus terminal. Back in the DAQ Assistant I'll return to the Express tab and now that I have my signal connected I can preview the measurement by clicking the Run button. That looks like a sign wave which is what I expect. The time scale along the bottom indicates that it's showing half a second worth of data and that makes sense because I'm sampling at a rate of 20 kilo samples per second and reading 10,000 samples which corresponds to half a second. I now know that my signal's connected correctly. So I'll click OK to close the configuration wizard. The DAQ Assistant takes a moment to generate the underlying code to interface with the DAQ device and when it finishes I get this big blue express VI with an output terminal labeled Data. I'll right click on that output terminal, go down to Create and select Graph Indicator. And I'll stretch that out to make it a little larger on my front panel. Now I can click the Run button and after about half a second it displays my sign wave. If I hit Run again I get a new set of 10,000 samples. Every time I click Run it acquires a new set of samples. Now rather than acquiring a preset finite number of samples let's say I want this task to continuously acquire data until I tell it to stop? To do that I'll double click on the DAQ Assistant to re-open the configuration window for the acquisition mode I'll change it from N Samples to Continuous Samples and I'll also change the number of samples to read from 10,000 down to 2,000. So it will be reading 2,000 samples at a time. But I'll leave the sample rate at 20 kilo samples per second. That means I'll get a new set of 2,000 samples 10 times per second to update the display. I'll click okay to accept those changes. And after rebuilding the underlying code the DAQ Assistant recognizes that I've selected a continuous acquisition mode and prompts me to add a while loop. We need a while loop around the DAQ Assistant to repeatedly read data from it. So I'll click Yes it automatically creates a stop button control and wires it to the stop input terminal on the DAQ Assistant and it also connects the output terminal indicating when the DAQ assistant has stopped to the while loop's conditional terminal. When I run this program now, it continuously acquires and displays the signal. If I adjust the frequency of the sign wave on my function generator I can see it change in real time on the graph, when I'm done I'll click the Stop button to end the acquisition.

Contents