+ All Categories
Home > Documents > 1 LabVIEW Intro PreLab 0809

1 LabVIEW Intro PreLab 0809

Date post: 17-Jul-2016
Category:
Upload: janurang
View: 26 times
Download: 3 times
Share this document with a friend
Description:
labview
31
Department of Electrical and Computer Engineering Faculty of Engineering and Architecture American University of Beirut EECE 442L – Communications Laboratory Experiment on Introduction to LabVIEW Version: August 2009
Transcript
Page 1: 1 LabVIEW Intro PreLab 0809

Department of Electrical and Computer Engineering Faculty of Engineering and Architecture

American University of Beirut  

 

 

EECE 442L – Communications Laboratory  

Experiment on Introduction to LabVIEW

Version: August 2009  

Page 2: 1 LabVIEW Intro PreLab 0809

Introduction to LabVIEW – August 2009  Page 1  

Introduction to LabVIEW OBJECTIVES

• Introduce LabVIEW basics that are relevant for developing experiments and exercises

related to communication systems.

INTRODUCTION

The purpose of this experiment is to introduce LabVIEW basics that will be used throughout

subsequent experiments. LabVIEW is a graphical programming language that uses icons

instead of lines of text to create applications. LabVIEW programs are called virtual

instruments (VIs) because their appearance and operation imitate physical instruments, such

as oscilloscopes and multimeters.

A VI contains the following three components:

Front panel: Serves as the user interface of the VI.

Block diagram: Contains the graphical source code that defines the functionality of the VI.

Icon and connector panel: Identifies the VI so that it can be used in another VI.

A VI within another VI is called a subVI. A subVI corresponds to a subroutine in text-based

programming languages. You can also use LabVIEW to communicate with hardware such as

data acquisition, vision and motion control devices, and GPIB, PXI, VXI, RS-232, and RS-

485 instruments.

A. STEPS TO CREATE A SUBVI

The creation of a subVI consists of creating the Icon, then creating the connectors which are

assigned to the Terminals, i.e., Inputs and Outputs, and finally saving the VI.

1. Build a Slope Calculator VI: Implement a simple VI that calculates the slope given two

points (X1, Y1) and (X2, Y2). You should be able to input different coordinates for the

points and the slope should be calculated and displayed. The equation of the slope is the

following:

12

12XX

YYslope −−=

After you build your slope calculator VI, choose different values for the two points and

analyze your results.

Page 3: 1 LabVIEW Intro PreLab 0809

Introduction to LabVIEW – August 2009  Page 2  

2. Create the Icon: Right-click on the icon that is placed in the upper right of the window of

the Block diagram or Front panel, then click on Edit Icon and name it as “Slope”.

Figure 1: Icon Editor.

3. Create the Connector: Again right-click on the icon pane (Front panel only), then click on

Show Connectors as shown in Figure 2.

Figure 2: Front Panel of the VI Slope Calculator.

4. Select the pattern with four inputs and one output by clicking on Patterns. The icon

shown in Figure 3 appears. Assign the terminals at left to the inputs and the one(s) at right

to the output(s).

Figure 3: Front panel of the VI Slope Calculator.

Page 4: 1 LabVIEW Intro PreLab 0809

Introduction to LabVIEW – August 2009  Page 3  

5. Save the VI and close it: Save the VI in an easy location to remember. Organize VIs by

functionality or by application by saving them in one directory or library file.

6. Use your subVI: Open a blank VI, and insert the subVI into the block diagram of the

opened VI by performing: Functions» »Select a VI or drag the saved VI icon into the

block diagram.

7. Check the Operation of your subVI: Input different values. At each input of the created

subVI, right click and select: Create» Control. As for the output, also right click and

select: Create» Indicator.

B. GRAPHS

B.1 HOW TO DRAW GRAPHS

In this section, you are going to explore the basic properties of plotting in LABVIEW.

1. Open a blank VI and place in the block diagram “Sine Waveform” located on:

Functions>> Waveform>> Analog Waveform>> Waveform Generation>> Sine

Waveform. Also you can easily search for this component by performing: Functions>>

Search and typing the name of the VI: “Sine Waveform”.

2. Create numeric controls in the front panel for the carrier frequency and amplitude. Label

each control by its appropriate name.

3. Assign for each indicator created in Part 2 the following values:

Carrier Frequency 1000Amplitude 1

4. In the block diagram, wire these indicators to the corresponding inputs of the “Sine

Waveform”.

5. Right click on the input of the “Sine Waveform” that is named “Sampling Info” and

select: Create>> Constant. Set both values to 100000.

6. In the front panel, select Controls>>Graph>>Waveform Graph.

7. Wire the output of the “Sine Waveform” to the waveform graph in the block diagram.

8. Run the VI.

9. The block diagram should appear as shown in Figure 4.

Page 5: 1 LabVIEW Intro PreLab 0809

Introduction to LabVIEW – August 2009  Page 4  

Figure 4: Sine Generator.

Now, you will try to adjust the graph that is shown in the front panel.

B.1.1 ZOOMING INTO THE PLOT

1. Right-click on the waveform graph in the front panel and select: Visible Items >> Graph

Palette. The following icon should appear:

2. Click on the second box, and choose the second option in order to be able to perform

zooming.

3. Hold the mouse in the graph window and then move while holding the cursor until a clear

sine waveform appears.

4. If you want to get back the original plot, you can simply click on the lower left sided icon.

B.1.2 READING VALUES FROM THE PLOT

Now, you will try to determine the period of this waveform. In order to be able to calculate

the period, the coordinates of two points in the plot must be calculated:

1. Right-click on the waveform graph in the front panel and select: Visible Items >> Cursor

Legend. The following icon should appear:

Page 6: 1 LabVIEW Intro PreLab 0809

Introduction to LabVIEW – August 2009  Page 5  

2. Right-click on this icon and then choose: Create Cursor>>Single-Plot.

3. Repeat part 2 again in order to create another cursor.

4. In order to be able to use the cursors, you have to click on this icon:

5. On each cursor, right click and choose “Bring to Center”.

6. Now you will be able to move the cursors in the waveform graph and calculates the x-

coordinates of two points in the plot in order to know the period.

7. If you want to remove a cursor, right click on the corresponding cursor and choose “Delete

Cursor”.

B.1.3 SAVING PLOTS

In order to be able to save a plot, you have to right-click on the waveform graph in the front

panel and choose Data Operations>> Export Simplified Image, and then choose the

appropriate choice.

In all experiments, you will be asked to save plots in a word document. Therefore, you can

use the above method or you can simply do the following:

1. Right-Click on the waveform graph and choose X Scale to be sure that Auto Scale X is

unmarked.

2. Select the waveform graph and copy it using (Ctrl+C).

3. To put this plot in a word document, you have just to use (Ctrl+V).

Page 7: 1 LabVIEW Intro PreLab 0809

Introduction to LabVIEW – August 2009  Page 6  

C. COMPARING WAVEFORMS AND CLUSTERS

C.1 CLUSTERS AND ARRAYS

Arrays group data elements of the same type. An array consists of elements and dimensions.

Elements are the data that make up the array. A dimension is the length, height, or depth of

an array. An array uses an index (zero-based) so you can readily access any particular

element. Arrays can be built of numeric, Boolean, path, string, waveform, and cluster data

types. Arrays are ideal for storing data collected from waveforms or data generated in loops,

where every iteration of a loop produces one element of the array.

Clusters group data elements of mixed types, such as a bundle of wires, as in a telephone

cable, where each wire in the cable represents a different element of the cluster. A cluster is

similar to a record or a struct in text-based programming languages. Bundling several data

elements into clusters eliminates wire clutter on the block diagram and reduces the number of

connector pane terminals that subVIs need. If a front panel contains more than 28 controls

and indicators that you want to use programmatically, group some of them into a cluster and

assign the cluster to a terminal on the connector pane to eliminate clutter on the block

diagram.

D. DATA ACQUISITION

LabVIEW includes a set of VIs that let you configure, acquire data from, and send data to

DAQ devices. Often, one device can perform a variety of functions such as analog-to-digital

(A/D) conversion, digital-to-analog (D/A) conversion, digital I/O, and counter/timer

operations.

Before a computer-based measurement system can measure a physical signal, such as

temperature, a sensor or transducer must convert the physical signal into an electrical one,

such as voltage or current. You might consider the plug-in DAQ device to be the entire

measurement system, but it is actually only one system component. You cannot always

directly connect signals to a plug-in DAQ device. In these cases, you must use signal

conditioning accessories to condition the signals before the plug-in DAQ device converts

them to digital information. The software controls the DAQ system by acquiring the raw data,

analyzing, and presenting the results. Consider the following options for a DAQ system:

Page 8: 1 LabVIEW Intro PreLab 0809

Introduction to LabVIEW – August 2009  Page 7  

1. The plug-in DAQ device resides in the computer. You can plug the device into the PCI slot

of a desktop computer or the PCMCIA slot of a laptop computer for a portable DAQ

measurement system.

2. The DAQ device is external and connects to the computer through an existing port, such as

the serial port or Ethernet port, which means you can quickly and easily place

measurement nodes near sensors.

The computer receives raw data through the DAQ device. The application you write presents

and manipulates the raw data in a form you can understand. The software also controls the

DAQ system by commanding the DAQ device when and from which channels to acquire

data. Typically, DAQ software includes drivers and application software. Drivers are unique

to the device or type of device and include the set of commands the device accepts.

Application software, such as LabVIEW, sends the drivers commands, such as acquire and

return a thermocouple reading. The application software also displays and analyzes the

acquired data. NI measurement devices include NI-DAQ driver software, a collection of VIs

you use to configure, acquire data from, and send data to the measurement devices.

D.1 DAQ VIS

The LabVIEW Data Acquisition VIs are located on the Data Acquisition palette and the

DAQmx - Data Acqusition palette. The Data Acquisition palette contains the traditional

NI-DAQ VIs. The DAQmx – Data Acquisition palette contains the VIs for NI-DAQmx. The

DAQmx - Data Acquisition palette contains all the VIs necessary to perform analog I/O,

digital I/O, and counter/timer operations.

You can configure a task to perform a very specific function by using the Property Nodes in

the palette. Many applications that do not require advanced timing and synchronization can

be performed by using the DAQ Assistant Express VI. This section describes the use of the

DAQ Assistant Express VI to perform data acquisition.

The DAQ Assistant Express VI allows you to easily configure the data acquisition device.

When you place the DAQ Assistant Express VI on the block diagram, a dialog box appears

where you configure a local task to perform a specific measurement function. Creating a local

task allows you to specify the exact type of measurement to take. Figure 5 presents the DAQ

Assistant.

Page 9: 1 LabVIEW Intro PreLab 0809

Introduction to LabVIEW – August 2009  Page 8  

Figure 5: DAQ Assistant.

After you create a task, the information for the local task is stored in the DAQ Assistant

Express VI. You can reconfigure the DAQ Assistant Express VI by double clicking the VI

and creating a new task.

NI PXI-5421 Arbitrary Waveform Generator: The National Instruments PXI- 5421 is a

100 MS/s arbitrary waveform generator featuring 16-bit resolution and up to 512 MB of

onboard memory in a compact, 1 slot 3U PXI module (see Figure 6). With this combination

of high-resolution and deep memory, you can generate long, precise, aperiodic waveforms.

The NI PXI-5421 is ideal for a range of applications in communications, consumer

electronics, scientific research, automotive, and military/aerospace. Because the PXI-5421

uses the PCI-based PXI platform, waveforms can be downloaded up to 280 times faster than

with GPIB-based generators. Using PXI timing and synchronization and the Synchronization

and Memory Core (SMC), you can create stimulus/response systems with digitizers and high-

speed digital I/O or synchronize multiple arbitrary waveform generators to form a phase-

coherent multichannel generation system.

Page 10: 1 LabVIEW Intro PreLab 0809

Introduction to LabVIEW – August 2009  Page 9  

Figure 6: NI PXI-5421.

PXI 5620 Digitizer: NI PXI-5620 is a single-channel digitizer module for a broad range of

applications in research, product design and validation, and manufacturing test (see Figure 7).

Its dynamic range and resolution make it ideal for all types of frequency domain analysis. It

is well suited for applications ranging from ultrasound and high-resolution ATE to digital

communications analysis such as cable, DSL, and wireless. The NI PXI-5620 has the

following specifications:

- 1 KS/s to 64 MS/s sampling rate

- 10 kHz to 36 MHz bandwidth (-3 dB)

- Deep segmented memory

- 14-bit resolution

- 80 dB spurious -free dynamic range

- Outstanding distortion-free performance

Figure 7: NI PXI-5620.

Page 11: 1 LabVIEW Intro PreLab 0809

Introduction to LabVIEW – August 2009  Page 10  

EXERCISE I: WAVEFORM GENERATOR

To access the AWG, go to Programs >> National Instruments >> NI-FGEN >> FGEN

Soft Front Panel.

Figure 8: AWG.

Perform the following set of steps:

1. Generate a sine input signal from the AWG. Set the frequency to 1 KHz, amplitude to 2 V,

and offset to 0.

2. Use a coaxial cable to connect CH 0 of the function generator to CH 0 of the digitizer.

3. In LabVIEW, download “ni-Scope.vi”. This subVI is able to read data that is fed into the

digitizer. Then build the VI shown in Figure 9.

Figure 9: Block diagram.

The input parameters for the “ni-scope.vi” are the following:

Channel 0 MinRecordLength 1000MinSamplingRate 20k

VerticalRange 2V

Page 12: 1 LabVIEW Intro PreLab 0809

Introduction to LabVIEW – August 2009  Page 11  

4. Double click on “NI SCOPE” and set the input resource name of “NI SCOPE INIT” to

“DAQ::1” or “DAQ::2” according to what is specified on the PXI. Refer to Figure 10.

Figure 10: Block diagram.

5. Save the final VI as “GroupID_Wave generator.vi”.

Page 13: 1 LabVIEW Intro PreLab 0809

Introduction to LabVIEW – August 2009  Page 12  

EXERCISE II: CARRIER FREQUENCY MODULATION

Open a new VI. Use the “SineWaveform” VI to generate a carrier waveform. Create user

control knobs in the front panel for the carrier frequency and amplitude. Refer to Figure 11.

Figure 11: Carrier wave.

The input parameters of the waveform are the following:

Carrier Frequency 200 KHz Carrier Amplitude 1V

Save the final VI as “GroupID_CarrierWave.vi”.

Unbundle vs. Get Waveform Components: Open “GroupID_Wave generator.vi”. Click

on the pink wire at the ni-Scope output, then click on on the upper –right of the block

diagram, you will see the following:

Figure 12: Context Help.

Notice that the Signal waveform is a “cluster” of 3 elements. Therefore, we use the function

“Unbundle” to get the components of this cluster.

Page 14: 1 LabVIEW Intro PreLab 0809

Introduction to LabVIEW – August 2009  Page 13  

Now, open “GroupID_CarrierWave.vi”. Click on the red wire at the Sine-Waveform

output, then click on on the upper –right of the block diagram, you will see the following.

Figure 13: Context Help.

Notice that the Signal out is a “Waveform”. Therefore, we use the function “Get Waveform

Components” to get the components of this cluster.

Page 15: 1 LabVIEW Intro PreLab 0809

Introduction to LabVIEW – August 2009  Page 14  

EXERCISE III: INTRODUCTION TO DSB-SC AM MODULATION

A. DSB-SC AMPLITUDE MODULATION

Develop a new VI, using the VIs of the previous exercises, by drawing the following block

diagram.

Figure 14: DSB-SC Amplitude Modulation VI Block Diagram.

The input parameters for the “ni-scope.vi” are the following:

Channel 0 MinRecordLength 10000MinSamplingRate 2M

VerticalRange 2V

The input parameters of the waveform are the following:

Carrier Frequency 200 KHz Carrier Amplitude 1V

Run your VI and check the different waveforms on the front panel.

Save the final VI as “GroupID_ DSB-SC_AM_Mod.vi”.

Page 16: 1 LabVIEW Intro PreLab 0809

Introduction to LabVIEW – August 2009  Page 15  

B. TWO-SIDED SPECTRA

Download “testCFFSpectrum.vi” along with “Complex FFT double sided.vi”.

Open “testCFFSpectrum.vi” and on the block diagram make sure that “MT modulate

AM.vi” is set to “AM-DSB”.

On the front panel, choose the sampling frequency to be fs = 1KHz, and the number of

samples 1000.

Check and analyze the results for the following cases:

1. Frequency = 100Hz

2. Frequency = 500Hz

3. Frequency = 1KHz

Page 17: 1 LabVIEW Intro PreLab 0809

Department of Electrical and Computer Engineering Faculty of Engineering and Architecture

American University of Beirut  

 

 

EECE 442L – Communications Laboratory  

Experiment on Introduction to LabVIEW: Pre-Lab

Version: August 2009  

Page 18: 1 LabVIEW Intro PreLab 0809

Introduction to LabVIEW: Pre‐Lab – August 2009  Page 1 

 

Introduction to LabVIEW: Pre-Lab

OBJECTIVES

• Introduce LabVIEW basic functionalities.

INTRODUCTION

The purpose of this experiment is to introduce LabVIEW basics that you will be using

throughout subsequent experiments. LabVIEW is a graphical programming language that

uses icons instead of lines of text to create applications. LabVIEW programs are called

virtual instruments, or VIs, because their appearance and operation imitate physical

instruments, such as oscilloscopes and multimeters.

A. REPETITION AND LOOPS

The aim of this part is to introduce the WHILE Loop and FOR Loop structures, along with

functions commonly used with these structures.

A.1 WHILE LOOP

Figure 1 shows a WHILE Loop in LabVIEW, a flow chart equivalent to the WHILE Loop

functionality, and a pseudo code example of the functionality of the WHILE Loop.

Figure 1: WHILE Loop in LabVIEW.

The WHILE Loop is located on the Functions»Programming»Structures palette. Select the

WHILE Loop from the palette then use the cursor to drag a selection rectangle around the

section of the block diagram you want to repeat. When you release the mouse button, a

Page 19: 1 LabVIEW Intro PreLab 0809

Introduction to LabVIEW: Pre‐Lab – August 2009  Page 2 

 

WHILE Loop boundary encloses the section you selected. The WHILE Loop executes the

sub-diagram until the conditional terminal, an input terminal, receives a specific Boolean

value. The default behavior and appearance of the conditional terminal is Stop If True,

shown to the left. When a conditional terminal is Stop If True, the WHILE Loop executes its

sub-diagram until the conditional terminal receives a True value.

The iteration terminal, an output terminal, shown to the left, contains the number of

completed iterations. The iteration count always starts at zero. During the first iteration, the

iteration terminal returns zero.

EXERCISE: WHILE LOOP

Perform the following set of steps to build a VI that generates random numbers until the

number generated matches a number you specify. The iteration terminal records the count of

random numbers generated until a match occurs.

1. Open a blank VI.

2. Place a numeric control, located on the Controls»Programming»Numeric palette, on the

front panel. Label it Number to Match.

3. Place a numeric indicator, located on the Controls»Programming»Numeric palette, on

the front panel. Label the indicator Current Number. This indicator displays the current

random number.

4. Place another numeric indicator on the front panel. Label the indicator # of iterations. This

indicator displays the number of iterations before a match.

5. Build the block diagram shown in Figure 2.

Figure 2: Block diagram of the WHILE Loop exercise.

Page 20: 1 LabVIEW Intro PreLab 0809

Introduction to LabVIEW: Pre‐Lab – August 2009  Page 3 

 

a. Place the Random Number (0-1) function, located on the Functions»

Programming»Numeric palette, on the block diagram. This function produces a

random number between 0 and 1.

b. Place the Multiply function, located on the Functions» Programming»Numeric

palette, on the block diagram. This function multiplies the random number by 10000

to produce a random number between 0 and 10000.

c. Right-click the y terminal of the Multiply function, select Create»Constant from the

shortcut menu, type 10000, and press the <Enter> key to create a numeric constant.

d. Place the Round To Nearest function, located on the Functions»

Programming»Numeric palette, on the block diagram. This function rounds the

random number to the nearest integer.

e. Place the Not Equal? function, located on the Functions»

Programming»Comparison palette, on the block diagram. This function compares

the random number with Number to Match and returns True if the numbers are not

equal; otherwise, it returns False.

f. Place the WHILE Loop, located on the Functions» Programming»Structures

palette, on the block diagram. Right-click the conditional terminal and select

Continue if True from the shortcut menu.

g. Wire the iteration terminal to the border of the WHILE Loop. A blue tunnel appears

on the WHILE Loop border. You will wire the tunnel to the Increment function. Each

time the loop executes, the iteration terminal increments by one. The iteration count

passes out of the loop upon completion. Increment this value by one outside the loop

because the count starts at 0.

h. Place the Increment function, located on the Functions» Programming»Numeric

palette, on the block diagram. This function adds 1 to the WHILE Loop count. A

coercion dot appears on the # of iterations output to indicate that LabVIEW coerced

the numeric representation of the iteration terminal to match the numeric

representation of the # of iterations output. Refer to the For Loop section for more

information about numeric conversion.

6. Save the VI as “GroupID_While.vi”.

7. Run the VI and make sure that it is running correctly.

8. Upload your VI

Page 21: 1 LabVIEW Intro PreLab 0809

Introduction to LabVIEW: Pre‐Lab – August 2009  Page 4 

 

A.2 FOR LOOP

A FOR Loop executes a sub-diagram a set number of times. Figure 3 shows a FOR Loop in

LabVIEW, a flow chart equivalent to the FOR Loop functionality, and a pseudo code

example of the functionality of the FOR Loop.

Figure 3: FOR Loop in LabVIEW.

The FOR Loop is located on the Functions»Programming»Structures palette. You can also

place a WHILE Loop on the block diagram, right-click the border of the WHILE Loop, and

select Replace with FOR Loop from the shortcut menu to change a WHILE Loop to a FOR

Loop. The value in the count terminal (an input terminal), shown to the left, indicates how

many times to repeat the sub-diagram.

EXERCISE: FOR LOOP

Perform the following set of steps to build a VI that uses a simple FOR Loop to generate a

random number every second for 100 seconds and displays the random numbers in a numeric

indicator. Figure 4 shows the block diagram to be built.

1. Place a FOR Loop, located on the Functions»Programming»Structures palette, on the

block diagram. Right-click the Loop Count terminal in the upper left corner of the FOR

Loop and select Create Constant from the shortcut menu. Type 100 in the constant to set

the FOR Loop to repeat 100 times.

Page 22: 1 LabVIEW Intro PreLab 0809

Introduction to LabVIEW: Pre‐Lab – August 2009  Page 5 

 

Figure 4: Block diagram of the FOR Loop exercise.

2. Place the Wait Until Next ms Multiple function, located on the Functions»

Programming»Timing palette, on the block diagram. Right-click the input and select

Create»Constant from the shortcut menu. Enter a value of 1000 to set the wait to every

second. The Wait Until Next ms Multiple function monitors a millisecond counter and

waits until the millisecond counter reaches a multiple of the amount you specify. Use this

function to synchronize activities. Placing this function within a loop controls the loop

execution rate.

3. Place the random number generator.

4. Place a numeric indicator, located on the Controls»Numeric palette, on the front panel.

Label the indicator Random Number Indicator. This indicator displays the generated

random number.

5. Save the VI as “GroupID_For.vi”.

6. Run the VI and make sure that it is running correctly.

7. Upload your VI.

A.3 SHIFT REGISTERS FOR LOOP STRUCTURES

The Shift Registers are available at left or right border of loop structures. To add them to the

loop, right-click the border and select Add Shift Register. The right terminal stores data on

completion of iteration while the left terminal provides stored data at beginning of next

iteration i.e. it Stores data when the loop completes iteration, then sends that value to the next

iteration of the loop. The example shown in Figure 5 clears the operation.

Page 23: 1 LabVIEW Intro PreLab 0809

Introduction to LabVIEW: Pre‐Lab – August 2009  Page 6 

 

Figure 5: Example on Shift Registers of a FOR Loop.

The FOR Loop must complete 2 iterations:

1. In the first iteration the left shift register is initialized with 1. The content of the left shift

register is always added to 2, so in the first iteration the loop performs 1+ 2 = 3, then 3 is

stored in the right shift register.

2. In the second iteration the content of the right shift register is moved to the left shift

register so it contains the value 3 which is added again to 2 to give 5. When the FOR Loop

executes all the iterations the right shift register displays its final value so the output is 5.

B. LABVIEW’S COMPOSITE DATA: ARRAYS AND CLUSTERS

The aim of this part is to describe how to use arrays to group elements of the same type and

clusters to group elements of mixed types.

B.1 ARRAYS

Arrays group data elements of the same type. An array consists of elements and dimensions.

Elements are the data that make up the array. A dimension is the length, height, or depth of

an array. An array uses an index (zero-based) so you can readily access any particular

element. Arrays can be built of numeric, Boolean, path, string, waveform, and cluster data

types. Arrays are ideal for storing data collected from waveforms or data generated in loops,

where each iteration of a loop produces one element of the array.

Page 24: 1 LabVIEW Intro PreLab 0809

Introduction to LabVIEW: Pre‐Lab – August 2009  Page 7 

 

1. Creating array controls and indicators: To create an array control or indicator, as shown

in Figure 6, select an array on the Controls»All Controls»Array & Cluster palette, place it

on the front panel, and drag a control or indicator into the array shell.

Figure 6: Array Control or Indicator

To add dimensions to an array one at a time, right-click the index display and select Add

Dimension from the shortcut menu. You also can use the positioning tool to resize the index

display until you have as many dimensions as you want. Figure 7 is an example of a 2D array

control.

Figure 7: 2D array control.

2. Auto-indexing: If you wire an array to a For Loop or While Loop input tunnel, you can

read and process every element in that array by enabling auto-indexing. When you auto-index

an array output tunnel, the output array receives a new element from every iteration of the

loop. Figure 8 shows an example of loop array wiring.

Figure 8: Auto-indexing.

Disable auto-indexing by right-clicking the tunnel and selecting Disable Indexing from the

shortcut menu. Disable auto-indexing if you need only the last value passed to the tunnel in

the previous example.

Page 25: 1 LabVIEW Intro PreLab 0809

Introduction to LabVIEW: Pre‐Lab – August 2009  Page 8 

 

3. Creating 2D arrays: You can use two For Loops, one inside the other, to create a 2D

array. The outer For Loop creates the row elements, and the inner For Loop creates the

column elements, as shown in Figure 9.

Figure 9: Creating 2D array.

4. Array functions: Use the array functions located on the Functions»All Functions»Array

palette to create and manipulate arrays. The more commonly used array functions are: Array

Size, Initialize Array, Array Subset, Build Array, and Index Array. Refer to Context Help

(or Ctrl H) to view the functionality of each array function.

5. Polymorphism: Numeric functions that are located on the Functions»All

Functions»Numeric palette are polymorphic. This means that the inputs to these functions

can be different data structures, such as scalar values and arrays. For example, you can use

the Add function to add a scalar value to an array or to add two arrays together. For example,

if you wire to the Add function a scalar value equal to two and an array containing (1, 3, 2),

the function will add the scalar to each element of the array and return (3, 5, 4).

EXERCISE: ARRAYS

The aim of this exercise is to create arrays and become familiar with the array functions.

Perform the following set of steps to build a VI that creates an array of random numbers,

scales the resulting array by an input scaling factor, and takes a subset of the final array based

on two input parameters.

1. Open a blank VI and build the front panel shown in Figure 10.

2. Place an array, located on the Controls»Array, Matrix & Cluster palette, on the Front

panel.

3. Label the array Random Array.

Page 26: 1 LabVIEW Intro PreLab 0809

Introduction to LabVIEW: Pre‐Lab – August 2009  Page 9 

 

4. Place a numeric indicator, located on the Controls»Numeric palette, in the array shell.

5. Use the Positioning tool to resize the array control to contain ten numeric indicators.

6. Press the <Ctrl> key while you click and drag the Random Array control to create two

copies of the control.

Figure 10: Front panel diagram.

7. Label the copies “Final Array” and “Subset Array”.

8. Place three numeric controls, located on the Controls»Numeric Controls palette, and

label them Scaling Factor, Start Subset, and # of Elements.

9. Right-click the Start Subset and # of Elements controls and select Representation»I32

from the shortcut menu.

10. Do not change the values of the front panel controls.

11. The next step is to build the block diagram shown in Figure 11.

Figure 11: Block diagram.

Page 27: 1 LabVIEW Intro PreLab 0809

Introduction to LabVIEW: Pre‐Lab – August 2009  Page 10 

 

a. Place the Random Number (0-1) function, located on the Functions»

Programming»Numeric palette, on the block diagram. This function generates a

random number between 0 and 1.

b. Place the For Loop, located on the Functions»Programming»Structures palette, on

the block diagram. The loop accumulates an array of 10 random numbers at the output

tunnel. Create a constant of 10 for the count terminal.

c. Place the Multiply function, located on the Functions» Programming»Numeric

palette, on the block diagram. In this exercise this function multiplies Random Array

by Scaling Factor and returns Final Array.

d. Place the Array Subset function, located on the Functions» Programming»Array

palette, on the block diagram (you may also use the search function located on the

Functions to find the Array Subset). This function returns a portion of an array

starting at Start Subset and containing # of Elements elements.

12. Save the VI as “GroupID_Array.vi”.

13. Display the front panel, change the values of the controls, and run the VI a few times to

make sure it is working correctly. The For Loop runs for 10 iterations. Each iteration

generates a random number and stores it at the output tunnel. Random Array displays an

array of 10 random numbers. The VI multiplies each value in Random Array by Scaling

Factor to create Final Array. The VI takes a subset of Final Array starting at Start Subset

for # of Elements and displays the subset in Subset Array.

14. Upload your VI.

B.2 CLUSTERS

Clusters group data elements of mixed types, such as a bundle of wires, as in a telephone

cable, where each wire in the cable represents a different element of the cluster. A cluster is

similar to a record or a struct in text-based programming languages. Bundling several data

elements into clusters eliminates wire clutter on the block diagram and reduces the number of

connector pane terminals that subVIs need. If a front panel contains more than 28 controls

and indicators that you want to use programmatically, group some of them into a cluster and

assign the cluster to a terminal on the connector pane to eliminate clutter on the block

diagram.

Page 28: 1 LabVIEW Intro PreLab 0809

Introduction to LabVIEW: Pre‐Lab – August 2009  Page 11 

 

1. Creating cluster controls and indicators: To create a cluster control or indicator, select a

cluster on the Controls»Array, Matrix & Cluster palette, place it on the front panel, and

drag controls or indicators into the cluster shell. Resize the cluster shell by dragging the

cursor while you place the cluster shell. Figure 12 shows an example of a cluster with three

controls.

Figure 12: Creating cluster controls and indicators.

2. Cluster order: Cluster elements have a logical order unrelated to their position in the

shell. The first object you place in the cluster is element 0, the second is element 1, and so on.

You can view and modify the cluster order by right-clicking the cluster border and selecting

Reorder Controls In Cluster from the shortcut menu.

3. Cluster functions: Use the Cluster functions located on the Functions»All

Functions»Cluster palette to create and manipulate clusters. Use the Bundle and Bundle by

Name functions to assemble and manipulate clusters and use the Unbundle and Unbundle by

Name functions to disassemble clusters. Refer to Context Help (or Ctrl+H) to view the

functionality of each cluster function.

EXERCISE: CLUSTERS

The aim of this exercise is to create clusters and use the Cluster functions to assemble and

disassemble clusters. Perform the following set of steps:

1. Open a blank VI.

2. Place a while loop in the block diagram located on: Functions>>Programming>>

Structures palette. Right-click the Loop Condition terminal and select “create control”,

a stop button should appear inside the while loop.

3. In the front panel, place a cluster, located on the Controls»Array, Matrix & Cluster

palette.

4. Inside the cluster frame, place a numeric control, located on the Controls»Numeric

palette, a vertical toggle switches, located on the Controls»Boolean palette.

Page 29: 1 LabVIEW Intro PreLab 0809

Introduction to LabVIEW: Pre‐Lab – August 2009  Page 12 

 

5. Build the block diagram shown in Figure 13.

Figure 13: Block diagram.

a. Place the Unbundle By Name function, located on the Functions»

Programming»Cluster & Variant palette, on the block diagram. This function

disassembles Cluster.

b. Place the Bundle By Name function, located on the Functions»

Programming»Cluster &Variant palette, on the block diagram. This function

assembles Small Cluster. At its output, right-click and select create indicator.

c. Place the Increment function, located on the Functions» Programming»Numeric

palette, on the block diagram. This function adds one to the value of Numeric. At

its output, right-click and select create indicator.

d. Place the Not function, located on the Functions»Programming»Boolean

palette, on the block diagram. This function returns the logical opposite of the

value of the Boolean terminal of the Unbundle by Name function. At its output,

right-click and select create indicator.

e. Complete the block diagram and wire the objects as shown in the figure.

6. Save the VI as Cluster “GroupID_Cluster.vi”.

7. Display the front panel and run the VI. Enter different values in Cluster and run the VI

again.

8. Upload your VI.

Page 30: 1 LabVIEW Intro PreLab 0809

Introduction to LabVIEW: Pre‐Lab – August 2009  Page 13 

 

C. MAKING DECISIONS IN A VI

This part introduces methods for making decisions in a VI. These methods include the select

function, the case structure, and the formula node.

The main objective of this exercise is to allow you to:

• Make decisions with the Select function.

• Use the Case structure.

• Use the Formula Node.

C.1 SELECT FUNCTION

The Select function selects between two values depending on a Boolean input. If the Boolean

input is true, this function returns the value wired to the T input and if the Boolean input is

false, this function returns the value wired to the F input. See the symbol below.

The Select function is located on the Functions»Programming»Structures Palette.

C.2 CASE STRUCTURES

A Case structure has two or more sub-diagrams, or cases. Only one sub-diagram is visible at

a time and the structure executes only one case at a time. An input value determines which

sub-diagram executes. The Case structure is similar to case statements or if...then...else

statements in text-based programming languages. The symbol below shows a Case structure.

The case selector identifier at the top of the Case structure contains the case selector identifier

in the center and decrement and increment buttons on each side. Use the decrement and

increment buttons to scroll through the available cases. Wire an input value, or selector, to the

selector terminal to determine which case executes. You must wire an integer, Boolean value,

string, or enumerated type value to the selector terminal. You can position the selector

terminal anywhere on the left border of the Case structure.

Page 31: 1 LabVIEW Intro PreLab 0809

Introduction to LabVIEW: Pre‐Lab – August 2009  Page 14 

 

If you wire a Boolean to the selector terminal, the structure has a True case and a False case.

If you wire an integer, string, or enumerated type value to the selector terminal the structure

can have up to 231– 1 cases.

You can specify a default case for the Case structure. You must specify a default case to

handle out-of-range values or explicitly list every possible input value. For example, if you

specified cases for 1, 2, and 3 but you get an input of 4, the Case structure executes the

default case. Right-click the case-structure border to add, duplicate, remove, or rearrange

cases and select a default case. The Case structure could be Boolean, integer, string,

enumerated, or error.

C.3 FORMULA NODE

The Formula Node is a convenient text-based node you can use to perform mathematical

operations on the block diagram. Formula Nodes are useful for equations that have many

variables or are otherwise complicated and for using existing text-based code. You can copy

and paste the existing text-based code into a Formula Node rather than recreating it

graphically on the block diagram. Create the input and output terminals of the Formula Node

by right-clicking the border of the node and selecting Add Input or Add Output from the

shortcut menu, then enter the variable for the input or output. Type the equation in the

structure. Each equation statement must terminate with a semicolon (;).

Formula Nodes also can be used for decision making. It is located on the Functions»

Arithmetic & Comparison palette. An example is shown below.

EXERCISE: FORMULAS

1. Open a blank VI.

2. Use a “FOR Loop” in order to create an array of 15 elements. This array must hold only

values above 0.5. (Hint: you need to use a case structure, random number and greater

function located in Functions>>Programming>>Comparison).

3. Save your VI and Upload it.


Recommended