LabView is a software suite for data acquisition, processing and visualization.  It  uses a graphical programming interface that is meant to look like drawing a circuit  Lab supplement Introduction to LabView  

advertisement
BIOEN 327 Solids and Fluids Lab
Lab supplement Introduction to LabView LabView is a software suite for data acquisition, processing and visualization. It uses a graphical programming interface that is meant to look like drawing a circuit schematic. A LabView program is called a Virtual Instrument (VI) because it, with associated hardware, can take the place of an electronic instrument such as . Each VI is programmed in two windows: a front panel and a block diagram. The first part of this exercise is meant to get you familiar with the LabView interface. The second part starts a VI that you will use to run your photometer. Part 1: Familiarization 1. Open LabView, then click Find Examples in the lower right corner of the start window. Search for “running” then open Calculate Running Average VI. The first window you see is the Front Panel, which contains one Control (the stop button) and one Indicator (the plot window). 2. By default, LabView automatically changes the pointer to match each object (e.g. cross, arrow, text cursor, hand/finger). If you would rather select the pointer yourself, select View >> Tools Palette, then click off the green bar. You can then choose any of the tools shown in the palette. Either way, try moving or resizing the displays using the arrow. 3. Select Help>>Show Context Help. Note that the Context Help window displays details about whichever component is under the mouse pointer. 4. If your VI is ready to run, there will be a white arrow in the upper left corner of the window. If not, there will be a broken gray arrow. Clicking on a broken gray arrow will bring up a list of errors so you can address them. 5. Run the VI using clicking the white arrow, or Operate >> Run, or ctrl‐R. The plot shows some random numbers (white diamonds) and a running average (green line). Press the STOP button to stop the VI. 6. Select Window>>Show Block Diagram. The large gray rectangle represents a while loop. The green T/F box and tiny stop sign determine when the loop stops, and the watch in the yellow box controls how fast it runs. The red triangles on the left and right borders are Shift Registers, which store a number from one iteration of the loop to the next. There are three arrows on the left border because the previous three numbers are being stored for averaging. Small rectangles (and sometimes squares like this ) represent constants, inputs, or outputs. Rectangles with bold outlines are typically Controls (inputs from the front panel), while rectangles with narrow outlines are Indicators (outputs to the front panel). Print date: 10/31/2011 1 BIOEN 327 Solids and Fluids Lab
The icons are connected by wires, as if the program were implemented in hardware. The wires’ color and pattern indicate the data type that they carry. Some examples: blue for integer, red for floating point, green for logical (true/false); narrow line for scalar, thick line for 1‐D array, double line for 2‐D array. 7. Right‐click the block diagram to bring up the Functions palette, pin it to the desktop, then expand it with the arrows at the bottom of the window. Select Programming >> Structures, and note the variety of structures that can be used as containers for programming elements. For example, to put functions in a for‐
next loop, you actually place icons and wires into the For Loop structure, or draw the loop around existing icons. Information enters on the left, is processed within, and exits on the right through tunnels. The structures of most importance to us are the While Loop, For Loop, Case Structure (equivalent to if‐
then‐else code), and MathScript node. The MathScript node allows us to include MATLAB code in the LabView VI so that we do not need to program complicated mathematical formulas icon by icon. 8. While viewing the block diagram, run the VI. While it is running, click the light bulb (Highlight Execution) and observe the flow of data through the diagram. Note that highlighting execution slows down the VI. 9. If time permits, ask an instructor how to control and display the loop rate. ☽
☼
10. Close the running average VI and open the Moonlanding VI. 11. Play for a while, but not too long. 12. Switch to the block diagram, and note the collection of large blue icons. Each of these is an interactive function box, called an Express VI. They perform signal input & output, mathematics, file input and output, signal processing, and timing. 13. Double click on one of the formula icons, and note that it is a programming calculator. Close it. The Trigger and Gate VI does some functions similar to an oscilloscope, and the In Range VI does a comparison operation. These operations could just as easily have been carried out by simpler functions – for example, the Time Delay is equivalent to the millisecond constant and the watch icon that we saw in the Calculate Running Average VI earlier. In some cases, however, the Express VI’s make our lives easier, especially when dealing with data acquisition and output. 14. Before moving to a data I/O example, note the blue dashed lines running around the Moonlanding block diagram. This is LabView’s “Dynamic Data Type” which means that it can represent any of a variety of signal types. It is flexible, but it can obscure the underlying data structure. 15. Note also the black arrows contained in the black rectangles. These are feedback icons, which we use when we want to store a value from one iteration of the loop and use it in the next iteration. See the Notes on page 4 for some additional hints and practice. Print date: 10/31/2011 2 BIOEN 327 Solids and Fluids Lab
Part 2: Your data acquisition VI for today 1. Before starting, plug in a USB‐6009 data acquisition module and complete any necessary installation procedures. 2. Start a new, blank VI, and switch to the block diagram. 3. In the Functions palette, select Measurement I/O >> NI-DAQmx >> DAQ Assistant. Place the assistant on the block diagram. It will open a window in which you can set up data acquisition. Select Analog input >> Voltage, click OK. Select channels 0 and 1, and change Samples to Read to 1 Sample (on demand) Click OK and let the assistant complete its setup. 4. Right‐click on the dataf output from the DAQ assistant and select Create > Graph Indicator. Place the graph icon to the right of the DAQ icon. Go to the front panel, right click on the new graph, select Replace > Graph Indicators > Chart. 5. Create a While loop that encompasses the DAQ and graph icons. 6. Select Timing>>Wait next ms multiple (the metronome) from the function palette and place it in the loop. Right click on its input, and select Create>>Numeric constant. Enter 100 as the text; this means 100 milliseconds. 7. Right click on the stop sign in the lower right corner of the loop, and select Create > control. Double‐click the new control icon and it will be highlighted on the front panel. 8. Run the VI. Good so far? Now things get tricky. 9. Stop and return to the block diagram. 10. Select a file‐save icon via Programming>>File I/O >> Write Meas File (or Express>>Output>>Write Meas File) and place it to the right of the loop. In the dialog box, browse to the folder where you would like to store the data. Suggestions: check Ask user to choose file, and One column only in the X Value Columns choices. After you have clicked OK, expand the blue box downward to see all of the possible inputs and outputs. 11. Select Express >> Signal manipulation >> From DDT. This will give you an interactive icon in which you should select 1D array (Auto). Click OK, then connect the data output from the DAQ icon to the input side of the From DDT icon. 12. Right click the right border of the While loop, and select Add shift register. Note that triangles appear on both the left and right borders. 13. Select Programming>>Array>>Initialize Array and place the icon to the left of the loop. Expand the icon to make it taller, thereby adding one dimension (it is also possible to right click on a dimension input and select Add dimension). Wire [0] to all three inputs. This creates a 2‐D array of size 0×0 (weird, but effective). 14. Place an Array>>Build Array icon inside the loop. 15. Wire the initialized array into the left‐hand shift register icon, then continue to the top input of the Build Array icon. Connect the output of the From DDT icon to the lower array input; this appends new data to the existing array. Print date: 10/31/2011 3 BIOEN 327 Solids and Fluids Lab
16. Wire Build Array output to the right‐hand shift register, and then into the Signals input of the Write To Measurement File. You should be able to run the VI now. Notes: a) Your DAQ module can collect voltages either in differential mode or single‐
ended (RSE) mode. You can choose which in the setup dialog in the DAQ assistant. In RSE mode, each input voltage (AI0, AI1, AI2… AI7) is measured with respect to ground. In differential mode, they are subtracted: Ch0 = AI0–AI4, Ch1 = AI1–AI5, etc. Make sure your wire connections match the mode selection! b) Charts collect incoming data in a buffer, so one datum per loop is sufficient. Graphs discard all previously received data, so one point per loop is not enough. c) Controls and indicators may be interchanged by selecting “Change to” on the right‐click menu. Note that the appearance usually changes on both the diagram and the front panel. d) On the front panel, pressing the space bar toggles the mouse pointer between the finger (change input) and arrow (move/size display). On the diagram, the space bar cycles the pointer through the wire, arrow and finger. e) By default, new controls and indicators show up on the block diagram as squares like this . You can make them smaller by right clicking and unchecking “show as icon.” Control/indicator icons with bold outlines on the block diagram are typically controls, while rectangles with narrow outlines are indicators. f) Any VI can be used as a subroutine within a larger VI. Typically these sub‐VIs appear as white squares, which can be opened and edited (right click > Open front panel). They perform a variety of procedures and complicated mathematical functions. g) When complicated instrument drivers are involved, the fastest way to get the program you need is often to modify one of the example VI’s. Open Help>>Examples>>I/O Interfaces>>DAQ Examples; the Analog Input and Analog Output lists contain the most useful starting points for our data acquisition cards. Extra exercises 1. Inside the While loop, create a case structure and place a different string constant in each case window. Right click the green [?] box and Create control. Right click one string constant, Create indicator; move the indicator outside the case box; wire the string constant to the indicator, switch to the other case, and wire that string to the indicator. Return to the front panel and run. 2. Use what you learned from the previous exercise to put the Write Measurement
File icon inside a case structure. Create a Boolean control inside the while loop, and wire it to the conditional [?] terminal of the case structure. This way, you should be able to control from the front panel whether your VI attempts to save your data. Print date: 10/31/2011 4 
Download