Learn Labview 2013-4 Fast
Learn Labview 2013-4 Fast
2013/2014 Fast
A Primer for
Automatic Data
Acquisition
SDC
P U B L I C AT I O N S
Chapter 1
Figure 1.1.1
A data acquisition system is composed of several components as shown in Figure 1.1.1, which
may take on different configurations depending on the type of system used, but perform similar
functions regardless of the system. A typical data acquisition system would have an input or
output device; a signal conditioner, which, for the purposes of this introduction, will be broadly
interpreted as a device that alters, modifies, or manipulates a signal; a data acquisition (DAQ)
board that can convert analog to digital signals or vice versa; a computer; and software to allow
the computer to communicate with the DAQ board. The specific components used depend on the
type of data and the flow of data, that is, if data is measured or generated.
2
Figure 1.1.2
Figure 1.1.3
Starting LabVIEW
If your version of LabVIEW was installed using the default installation procedure, launch
LabVIEW by selecting All Programs>>National Instruments>>LabVIEW 2013 (or
LabVIEW 2014)>>LabVIEW 2013 (or LabVIEW 2014) from the Start menu. Or, if
available, double click on the LabVIEW shortcut icon on the desktop. A LabVIEW
window will appear as shown in Figure 1.3.1. Click on Create Project and select
Blank VI to open a new file for this exercise. Later, you may select a previously used
file in the panel located under Open Existing or click on Open Existing to browse for
an existing file not shown.
Figure 1.3.1
1.3.2
The front panel window displays controls (user input) and indicators (data output). It can
be configured to appear like the instrument panel on measurement equipment. For
example, you can place virtual knobs and switches (controls) and display charts, graphs,
or virtual LEDs (indicators) in this panel. It is the graphical user interface. This panel
provides input to the block diagram through the controls and displays the output of the
block diagram through the indicators. The controls and indicators also appear as
terminals in the block diagram. Terminals pass data between the front panel and the block
diagram, either from the controls or to the indicators. This is the only panel you need to
see when your VI is running.
The block diagram window contains the source code of the program and displays the
interconnected objects of the graphical programming language. This is the panel where
the program is developed and debugged. The block diagram consists of nodes, which are
objects that have inputs and outputs and perform some type of operation when the VI
executes. Nodes comprise functions, subVIs, Express VIs, and structures. Functions are
built-in elements that perform specific operations, subVIs are self-contained sections of
code like subroutines in text-based programming languages, Express VIs are configurable
VIs, and structures control VI execution. Wires transfer data between the nodes in the
block diagram. Wires take on different color, thickness, and texture depending on the
type of data they carry.
1.3.3
Figure 1.3.2
1.3.4
Toolbars
The front panel and the block diagram have toolbars that contain commands, some of
which are in the pull-down menus, that manipulate the objects to provide good
housekeeping, provide means to debug the VI, get information on VI objects, and run the
VI.
Figure 1.3.3
The front panel toolbar is shown in Fig. 1.3.3. The four buttons on the left of the toolbar
control program execution. The Run button takes on different appearances depending
on the status of the VI, as shown by the top four buttons in Fig. 1.3.4. The other buttons
control the execution of the program. When selected, the Run Continuously button runs
the VI over and over again until you abort or pause the execution. For example, one could
write a program to take one data measurement and then select the Run Continuously
button to take multiple measurements. However, there are LabVIEW structures, such as
the While Loop, that perform this type of task more efficiently. The Run Continuously
button should not be a substitute for this type of programming. Likewise, the Abort
Figure 1.3.4 Buttons that control the execution of the VI or show its status
Many of the buttons in the block diagram toolbar, shown in Fig. 1.3.5, perform the same
functions as described for the front panel toolbar. However, the block diagram toolbar
also contains buttons to help debug the VI. The Highlight Execution button and the
Step buttons animate the data flow, provide step-by-step control over program
execution, and provide the means to see data values at each node. The middle set of
buttons on the toolbar provides options for general housekeeping. A neat and organized
set of objects in the block diagram, especially when it pertains to new LabVIEW users,
reduces the chances for wiring errors and makes debugging easier.
Figure 1.3.5
1.3.5
Palettes
There are three important palettes: Tools, Controls, and Functions. The Controls
palette is available only in the front panel, the Functions palette is available only in the
block diagram, and the Tools palette is available in both.
The Tools palette, as shown in Fig. 1.3.6, contains special cursors that enable you to
perform different functions, like typing alphanumeric characters, entering values, and
wiring, selecting, resizing, and positioning objects. A functional name for each tool is
given in Fig. 1.3.6 along with the name assigned in the Tools palette in parentheses.
This palette may already be displayed in the front panel. If not, click on Tools Palette
from the View pulldown menu. At the top of the Tools palette, there is an automatic
tool selection button. When this button is highlighted green, LabVIEW tries to anticipate
what cursor you will need. You may find that this feature improves your programming
efficiency although use of the automatic tool selection is a personal preference. If you
find that you dont like it, you can disable the feature by clicking on any of the buttons in
the Tools palette and the automatic feature will be disabled. You will then need to
manually select the tool needed until you click on the Automatic Tool Selection button
at a later time.
Figure 1.3.6
Four of the tools that you will frequently use in this primer include:
Operating
Positioning
Labeling
Wiring
10
The Operating tool allows you to enter data or change the value of a control. The
Positioning tool allows you to select, move, or resize an object. The Labeling tool
allows you to create a free label or edit an existing one. The Wiring tool allows you to
establish data flow between nodes in the block diagram by wiring them together.
Figure 1.3.7
The Controls palette contains different controls and indicators for the front panel
(virtual instrument panel). If the Controls palette is not visible in the front panel, there
are two options to retrieve the palette. One option is to select Controls Palette from the
Views menu and the Controls palette will remain with the front panel as you use the
selected icons. You may have to expand the palette by clicking on the button with the
right facing arrow if a view similar to the one in Fig. 1.3.7 does not appear. The other
option is to place the mouse over an open area in the front panel and right click. Using
this approach, a view similar to the first image in Fig. 1.3.7 should appear. The
Controls palette disappears after the icon is selected, which frees up space on the front
panel. If you retrieve the palette by right-clicking on the front panel and want the palette
to remain, you may also tack down the palette by clicking on the thumbtack in the upper
11
12
Figure 1.3.8
13
The material discussed in this section assumes that LabVIEW Professional Version or Student
Version software, NI-DAQ software, and a data acquisition board have been installed on your
computer.
14
Figure 1.4.1
The general analog input VI showing the option to measure data continuously
Figure 1.4.2
The general analog input VI showing the option to measure a finite set of data
15
Case Structures
Figure 1.4.3
Two cases of a Case Structure are shown in Figure 1.4.3. The subdiagram, or code, that is
to be conditionally executed is contained within the border of each case of the Case
Structure. Each case will have a different subdiagram. Cases are stacked and show only
one subdiagram at a time, unlike Fig. 1.4.3, which includes an offset second case for
illustration purposes.
16
The case is determined by the data type wired to the selector terminal. A numeric control
is wired to the example shown in Fig. 1.4.3, which shows two number cases, 0 and 1. The
number case 0 has been selected as the default case. The default case will be executed
if a wired value does not match any of the other cases. The default case might include an
error message, for example. The example in Fig. 1.4.3 shows that a control is wired to the
selector terminal, which would allow the user to directly select the case.
Input and output data may pass through tunnels in the border of the Case Structure. The
tunnels are depicted by squares on the border. Input data that passes through tunnels is
available to all cases. If output data is wired to the border of one case of the Case
Structure, all cases must output a value or else the Run arrow on the toolbar will
remain broken. An output tunnel appears as a hollow square until data is provided from
all cases, at which point the tunnel appears as a solid square.
Steps 1-5: Creating a Case Structure
The general analog input VI that is to be developed in this problem is designed to allow
the user to select finite or continuous measurement of data. For this VI, the user will
provide input through the front panel to select a measurement case for data acquisition:
either continuous or finite. A Case Structure (represented by the outermost border in Figs.
1.4.1 and 1.4.2) will be used to determine what case will be executed. When the data
acquisition mode is set to True, data is taken continuously. Likewise, when the data
acquisition mode is set to False, a finite set of data is taken. Two cases (True and False)
of the same Case Structure are shown in Figs. 1.4.1 and 1.4.2.
1. If you havent already done so, launch LabVIEW by selecting All
Programs>>National Instruments>>LabVIEW 2013 (or LabVIEW 2014)
>>LabVIEW 2013 (or LabVIEW 2014) from the Start menu.
Note: Read Section 1.3 to get the necessary background on the LabVIEW environment, if you
havent already done so.
2. Select Blank VI to open a new file for this exercise.
Tip:
Use the keyboard shortcut <Ctrl T> to tile the windows with the front panel above and
the block diagram below.
3. In the Functions palette, place the cursor over the Express palette and then over the
Execution Control subpalette. Depress the left mouse key on the Case Structure icon
in the Execution Control subpalette and drag the structure to the block diagram. This
17
The initial size is not critical since the Case Structure can be resized at any time by
clicking on the border and dragging the border with the mouse on one of the blue
handles.
5. Place the cursor over the selector terminal (box containing the question mark on the
left border), right click, and select Create Control.
Note: A Boolean push button control appears simultaneously in the front panel and a terminal
appears in the block diagram. This control will allow a user to determine if a finite set of
data will be measured or if the data will be measured continuously.
Additional Information about Case Structures
Different data types, such as Boolean (True or False) and string (text), can be wired to the
selector terminal and case values will be shown at the top of the border in the Selector
label area. You can select a case by cycling through the available cases using the
increment and decrement arrows or by using the pull-down menu by selecting the down
arrow in the Selector label.
A number of options for the Case Structure are available if you right-click on the
structure border, as shown in Fig. 1.4.3. For example, you can add or delete a case. If you
add a case, you can change the value in the selector label using the Edit Text (letter A)
cursor.
Case Structures are part of a larger class of structures that control the execution of data
flow in a VI. Some of the other structures used in this primer are listed below.
18
The While Loop continuously executes a portion of code within its borders, called
a subdiagram, until a condition is met;
the For Loop executes a subdiagram a finite number of times;
1.4.2
Figure 1.4.4
The DAQ Assistant guides the user through a series of windows to configure the data
acquisition task as shown for an analog input measurement task in Fig. 1.4.4. The DAQ
19
20
You can double-click on the DAQ Assistant icon to edit the configurations at a later time,
if needed.
Note: The DAQ Assistant can be displayed as an icon or an expanded node by dragging the
icon by the handle at the bottom of the icon.
Additional Information about the DAQ Assistant
The DAQ Assistant can, among other things:
Specifications in the data measurement or generation task include the acquisition mode
and timing. As seen at the bottom of the window in Fig. 1.4.5, there are four acquisition
modes: two of which take single samples, a finite set of N samples, and continuous
acquisition by repetitively taking blocks of a finite set of N samples. The timing can be
either software timing controlled by the computers CPU clock, which occurs when the
LabVIEW software calls a subVI to acquire data, or by hardware timing, which occurs
when a clock on the DAQ board or an external hardware device controls the data
acquisition.
The first acquisition mode, 1 Sample (On Demand), employs software timing since the
sample is not acquired until a LabVIEW subVI demands the sample. It is referred to as
software timing since the execution of the LabVIEW software is controlled by the CPU
clock. This sample mode can also permit continuous data acquisition if the calling subVI
is placed in a loop. However, the time spacing between VI calls depends on the execution
time of the program and the CPU clock, which has other priorities as well as LabVIEW.
This can result in uneven time spacing, especially for fast sampling rates, and ultimately
limits how fast data can be acquired.
21
22
23
24
25
26
You can double-click on the Write to Measurement File icon to edit the configurations
at a later time, if needed.
18. Place the cursor over the filename input terminal (its the bottom terminal on the
left side of the unexpanded node-see view number 1 of Fig. 1.4.6), right-click the
mouse, and create a control. The control will appear in the front panel and the
corresponding terminal will appear on the block diagram.
Tip:
If you are having difficulty locating the filename input terminal, there are two ways to
easily find it if the node is not expanded. The first way is to place the Connect Wire
(solder spool) cursor over the terminals to locate the filename input terminal. As the
Connect Wire cursor passes over a terminal, the terminal name pops up. The second
way is to use the Context Help window. Select Show Context Help from the Help
pull-down menu to show labeled terminals. If you are using the Connect Wire cursor,
the terminal will blink in the Context Help window and light up on the icon with the
terminal name displayed in the block diagram.
Note: The filename control will allow a user to enter a filename without having to open the
Write to Measurement File configuration window every time a different filename is
desired.
19. Click on the filename input terminal with the Position (arrow) cursor and drag the
terminal near the left border of the Case Structure, as shown in Fig. 1.4.1, so that it
will be outside of the inner loop.
27
Figure 1.4.7
28
While Loop
29
Figure 1.4.8
30
Tip:
If you make a mistake dragging the While Loop, you can undo the creation of the While
Loop using the Undo command from the Edit pulldown menu and start over.
Tip:
You may also resize the Case Structure or While Loop using the blue handles if you need
more room.
Figure 1.4.9
Intermediate view of the block diagram after the While Loop is created
Note: Two tunnels should appear on the left border of the While Loop showing that the
Filename and Time Delay terminals become inputs. The conditional terminal is
connected with a Boolean control and an iteration terminal also appears. You may also
need to left-click the mouse on the Boolean control using the Position (arrow) cursor to
drag it to expose the wire that connects to the conditional terminal.
Additional Information about While Loops
The input to the Conditional terminal must be placed inside the While Loop to prevent
the possibility of an infinite loop, a condition that occurs when there is no way to stop
execution of a repeated section of code. Values of variables that pass through the
boundary of the While Loop remain constant during the execution of the While Loop
until the loop stops. For example, consider that the value of a Boolean control in the front
panel is set to false. If the corresponding Boolean terminal wired to the Conditional
terminal in the block diagram is outside of the While Loop, then an infinite loop will be
established. In this example, the false value is read once when the loop first executes and
will not change, even if the user changes the value outside the loop at a later time as the
31
Figure 1.4.10 The While Loop with a simple example to show components
Shift registers pass variable values from previous iterations to the next iteration. A pair of
terminals appears when a shift register is added. A shift register may be added by right
clicking the mouse on the border and selecting Add Shift Register. The terminal on the
right border marked by the upward arrow stores a value at the end of the most recent
iteration. This value then becomes available at the beginning of the next iteration from
the corresponding shift register on the left border with a downward arrow. On the first
iteration of the While Loop, the initial value may be specified by using a constant or
32
Waveform Chart
33
Locate the chart terminal in the block diagram by double-clicking on the chart in the front
panel. A black border will temporarily appear around the chart terminal. The method of
double-clicking on any of the controls and indicators in the front panel may be used to
locate the corresponding terminals in the block diagram. Likewise, double-clicking on
terminals in the block diagram may be used to locate corresponding controls and
indicators in the front panel.
26. Using the Position (arrow) cursor, drag the chart terminal in the block diagram
within the While Loop border and above the Write to Measurement File subVI, as
shown in Fig. 1.4.1.
34
35
Waveform Graph
The graph may be resized by selecting one of the blue handles using the Position
(arrow) cursor and dragging the graph to the desired size.
28. Place the graph terminal in the block diagram to the right of the While Loop border
but within the Case Structure as shown in Fig. 1.4.1.
36
Figure 1.4.12
37
The subpalette at the bottom of Fig. 1.4.12 is displayed when the Zoom button is
selected using the Operate Value (pointing hand) cursor. The top three options on the
subpalette show that portions of the data can be enlarged by selecting one of the zoom
buttons to expand the data and then dragging the cursor over the data of interest in your
graph. You may also zoom in or out about a point with the lower right buttons. Finally,
the lower left button auto-scales the x- and y-axes, which restores the plot to the original
size.
The X Scrollbar is a convenient feature when you zoom in on the plot data. The X
Scrollbar allows you to scroll through detailed (zoomed in) portions of data that are too
magnified to fit on a single graph panel. Add the X Scrollbar by selecting Visible
Items>>X Scrollbar from the shortcut menu.
1.4.8
Data Types
Figure 1.4.13 Wire styles and colors for different LabVIEW data types
Dataflow is accomplished by LabVIEW via data paths, called wires, which connect nodes
and terminals in the block diagram. A wire can emanate from one source terminal to one
or more sink terminals. The wires style, thickness, and color indicate the data type it
carries. Examples of common wire types are shown in Fig. 1.4.13. A thin wire is
displayed if the wire carries a single element, or scalar. A thicker wire will be displayed if
the wire carries a 1-D array, for example, a row of data elements. This is typical of a
number of data points taken over time on a single measurement channel. Depending on
the data type, either an even thicker line or pair of lines will be displayed if the wire
carries a 2-D array. An example of a 2-D array would be a number of data points taken
38
Figure 1.4.14 Intermediate stage of the example VI to continuously measure analog input data
based on steps 1-28
Tip:
An important aspect of wiring is to connect the correct terminals, and there are a number
of aids to help. Wiring is performed using the Connect Wire (solder spool) cursor. If
this cursor is placed over a terminal, the terminal will highlight the data type color. A tip
strip, which is the terminal identifier, also appears. You may also show the objects
terminals by opening the Context Help window. If you havent already done so, open
this window using the Help pull-down menu and selecting Help>>Show Context Help
or pressing <Ctrl H> on the keyboard. The Control Help window shows all of the
objects terminals and, when the Connect Wire (solder spool) cursor is placed over a
39
There are a number of tips to wiring two terminals together. Wiring may begin from the
source terminal to the sink terminal or vice versa. Place the Connect Wire cursor over
the desired terminal, left click the mouse to tack the wire to the terminal, move the mouse
to the second terminal, and left click once again on the blinking receiving terminal. You
do not need to hold down the left mouse button as you wire although you can tack down
the wire at any point by left clicking on the mouse. As you proceed through this example,
you may also notice that LabVIEW will automatically wire objects that have just been
placed in the block diagram if the terminal of a close object has a similar name and data
type as the one placed next to it. The automatic wiring feature may be disabled by
pressing the space bar.
29. Wire terminals together as shown in Fig. 1.4.15. Wire the data output terminal from
the DAQ Assistant to the waveform chart and the signals input terminal of the Write
to Measurement File Express VI. Notice that the waveform chart changes to the
dynamic data type when the wire is connected. You can start wiring from a wire that
already connects two terminals.
Figure 1.4.15 Example VI to continuously measure analog input data showing wiring
Note: The Express VIs also contain terminals that pass along information about errors that may
have occurred before or during the execution of the VI. If an error occurs during the
execution of the Express VI, an error message will be generated and pass through the
error out terminal. Any error that occurs before the execution of the Express VI is
40
A floating point numeric contains a decimal point and may be a real or complex,
positive or negative value. It may have a single precision (32 bit), double
precision (default precision, 64 bit), or extended precision (128 bit)
representation.
Integers are whole numbers and may be positive only (unsigned) or both positive
and negative (signed). Integers may be represented as a byte (8 bit), word (16 bit),
long (32 bit), or quad (64 bit) integer.
The Boolean data type contains two values: logical TRUE and FALSE.
A string is a sequence of ASCII characters, most commonly alphanumeric
characters. For example, a data measurement stored in binary format must be
converted to a string of human-recognizable numbers to store in a text or
spreadsheet file.
A cluster is a group of data elements of mixed type. An important cluster is the
error cluster, which groups the error status (Boolean, that is, there is an errorTRUE or no error-FALSE), the error code (integer), and the source of the error
(string).
The path data type contains the location of a file or directory.
Most Express VIs use the dynamic data type, which includes the data and its
attributes, such as the signal name or time the data was taken. Other functions and
subVIs do not accept this data type.
The waveform data type contains not only data but the start time and uniform time
spacing of the data. A common example of the waveform data type is when you
use it as an input to a graph.
41
Color
Representation
Floating
Point
Numeric
Orange
Integer
Blue
Boolean
String
Green
Pink
SGL-Single Precision
DBL-Double Precision
EXT-Extended Precision
CSG-Complex Single
CDB-Complex Double
CXT-Complex Extended
8-bit, 16-bit, 32-bit, or 64-bit
Signed or Unsigned
Cluster
Path
Brown-Numeric
Pink-Non-numeric
Yellow-Error code
Teal Green
Dynamic
Waveform
Dark Blue
Brown
Table 1.4.1
Default
Value
0.0
0.0+0.0i
0
False
Empty
String
Empty
Path
LabVIEW allows different data types to be used in many functions by coercing one of the
data types. For example, it can add an integer to a floating point numeric. Data that is
coerced will have a small coercion dot placed at the functions input terminal.
If an attempt is made to wire a source and sink terminal that are not compatible, a dashed
line will appear with an X, which is called a broken wire. Examples include attempting to
wire two controls or indicators together, wiring a terminal of one data type to a terminal
of a different data type, or wiring a scalar to an array. The Run button on the block
diagram toolbar will appear as a broken arrow (see Fig. 1.3.4) if there are any broken
wires. The error associated with the broken wire can be displayed by left clicking on the
Run button. You may also use the keyboard shortcut <Ctrl B> to remove broken wires.
1.4.9