0% found this document useful (0 votes)
32 views77 pages

Lucid LabVIEW Fundamentals I - Exercise Manual

Uploaded by

nincy84
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views77 pages

Lucid LabVIEW Fundamentals I - Exercise Manual

Uploaded by

nincy84
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 77

Lucid LabVIEW

Fundamentals I
Exercise Manual
Exercise Manual Lucid LabVIEW Fundamentals I © Sixclear, llc.

About This Manual


Overview
This manual is intended to help guide you through exercises. If you’re taking the self-paced version of
this course you will see demos of nearly everything in video form, you are encouraged to follow along in
parallel for further hands-on learning.

Our Goal
Our goal is to give you the best possible LabVIEW learning experience. We’ve put our years of
experience as engineers, computer scientists, and instructors together to build this course with that in
mind. We sincerely hope and believe you will find this manual and the other rich content provided to be
valuable resources as you learn LabVIEW in our Fundamentals series.

Our Styling Conventions


We’ve tried to use styling with some consistency to help you distinguish function names and other
references to elements of the LabVIEW language and environment from the descriptions around them.

I. File Paths and Menu Navigation


Both file paths and menu navigation will be show in italics, such as:

Replace >> Numeric >> Horizontal Pointer Slide and,


C:\Program Files\National Instruments\LabVIEW

II. Labels of Objects, names of VIs and Functions in LabVIEW


User-created labels of controls and indicators, and names of native LabVIEW functions and VIs
will be shown in bold and/or Capitalized where appropriate. For example:

“Wire the Numeric control Limit to the Multiply function’s top terminal on the Block
Diagram.”

III. User-Created VIs, Projects, and Custom Controls


User-created files in LabVIEW (non-native VIs, controls, etc) will be shown in bold with the
relevant extension (.lvproj, .vi, .ctl), such as:

Area of Right Triangle.vi

IV. Special Attention Icons

Important Technique Common Question Keep This In Mind Avoid The Following

2
Exercise Manual Lucid LabVIEW Fundamentals I © Sixclear, llc.

Our Philosophy
We’ve kept our goal of providing the best possible LabVIEW learning experience in mind at every stage,
even down to the learning process. Too much information is just that, too much.

• Early Exercises
With that in mind, the first several exercises show all block diagram code and give granular
programming instructions – this is because the early exercises are as much about learning how
to use the LabVIEW environment as they are about learning specific programming topics
involved.

• Later Exercises
Later in the course we give more general programming instructions without complete block
diagrams in some cases to promote thinking and learning. First thinking about the challenge
posed in the exercise and how to solve it in LabVIEW will significantly increase your ability to
program in LabVIEW – we know this from personal experience and have validated this principle
in instruction. We DO however include code snippets everywhere – we definitely want to use
pictures to illustrate ideas versus just plain text whenever possible – no reading for no reason!

You always have granular instructions AND block diagram code!

We always provide the full solution and a programming video capture of the solution showing every
programming step. Getting “stuck” is a natural part of the learning process and can actually help solidify
your understanding after getting “unstuck.” These resources are there specifically to help you get
“unstuck”.

We’ll say it again – the purpose of evolving to more general programming instructions and eventually
holding back block diagram code in this manual is to encourage thinking about how to program the
exercises – we feel this is an important component to really learning LabVIEW, and completing this
course ready to program like a superstar!

Manual Errata
If you find errors in this manual – we want to know! Simply login to sixclear.com as you do for this
course and tell us. We are dedicated to updating and evolving this manual and all of our products to
provide the best, most fluid learning experience possible, and we sincerely appreciate your help in that
effort.

Thank You!
Thank you for choosing Sixclear for your LabVIEW learning. We hope you’ll come back to us for future
LabVIEW learning and services – we eat, sleep, and breathe LabVIEW (not really, but we do program
quite a bit) in order to deliver the absolute best possible experience and solution for your LabVIEW
learning and service needs.

3
Exercise Manual Lucid LabVIEW Fundamentals I © Sixclear, llc.

Unit 1

Getting Dirty with LabVIEW

4
Exercise Manual Lucid LabVIEW Fundamentals I © Sixclear, llc.

Exercise - F1.1.1 - Simple Addition


Overview
The purpose of this exercise is simply to get our hands on LabVIEW – incredibly, we’ll build our very first
LabVIEW program!

User Interface
The desired front panel is shown below.

Requirements
This program should have the ability to do the following:
1. Accept two user inputs, x and y.
2. Produce the sum = x + y.

Programming Instructions
The following are high-level instructions to complete this exercise.

On the block diagram:


1. Place an Add function from the Numeric palette
a. Right-click on the Block Diagram and go to Numeric>>Add
2. Right-click on the Add function’s top input terminal choose Create >> Control
3. Right-click on the Add function’s bottom input terminal and choose Create >> Control
4. Right-click on the Add function’s output terminal and choose Create >> Indicator
5. Rename the controls if you have not already done so, to match those seen above.

On the front panel:


6. Arrange the Front Panel to match that shown in the User Interface section
7. Test the VI to ensure it meets the Requirements
8. Save the VI to the Exercises folder with name Simple Addition.vi

Observe that front panel objects are created when you create controls and indicators on the block
diagram – they are the user interface counterparts to the block diagram objects placed.
END OF EXERCISE

5
Exercise Manual Lucid LabVIEW Fundamentals I © Sixclear, llc.

Exercise - F1.1.1 - Area of Right Triangle


Overview
In this exercise we use our knowledge of front panel and block diagram concepts to build a program
which computes and displays the area of a right triangle.

User Interface
The desired front panel is shown below.

Requirements
This program should have the ability to do the following:
1. Accept two user inputs, Base and Height.
2. Produce the Area = ½*Base*Height

Programming Instructions
The following are high-level instructions to complete this exercise.

On the front panel:


1. Create the User Interface shown above with 2 Numeric Controls and a Numeric Indicator
2. Save the VI to the Exercises folder with name Area of Right Triangle.vi

On the block diagram:


3. Place a Multiply function on the Block Diagram and connect it to the appropriate terminals
4. Place a Divide function (Numeric Palette) and make the wire connections shown above from the
Multiply function’s output terminal to the Divide function’s upper terminal and from the Divide
function’s output to the Area Indicator
5. Right-click on the Divide function’s bottom input terminal, choose Create >> Constant, and give
it the value 2
6. Test the VI to ensure it meets the Requirements

END OF EXERCISE

6
Exercise Manual Lucid LabVIEW Fundamentals I © Sixclear, llc.

Exercise - F1.1.2 - Debugging the Mystery VIs


Overview
In this exercise we again use our knowledge of, and tools for, debugging in LabVIEW to determine what
functions a few mystery subVIs are performing. This task reflects precisely the steps one needs when
debugging their own code, or maintaining and updating inherited code.

User Interface
The front panel is shown below.

Requirements
The task at hand is to determine the functions of the mystery SubVIs: Mystery subVI 1.vi, Mystery subVI
2.vi, and Mystery subVI 3.vi. The Block Diagram of Mystery VI.vi is shown below.

Programming Instructions
There is no programming required in this exercise – the VI used here – Mystery VI.vi – is provided in the
exercises folder.

To ascertain what the mystery SubVIs are doing, try entering in different values to Input and observe
what each VI does to the number using the debugging tools we have discussed.

END OF EXERCISE

7
Exercise Manual Lucid LabVIEW Fundamentals I © Sixclear, llc.

Exercise - F1.1.3 - Select Shape Area


Overview
In this exercise we use our knowledge of case structures to build a program which computes either the
area of a right triangle or rectangle, depending on the value of a switch.

User Interface
The desired front panel is shown below.

Requirements
This program should have the ability to do the following:
1. To select a shape – triangle or rectangle – for which to compute the area
2. Accept two user inputs, Base and Height.
3. Produce the area of the selected shape: Atriangle = ½*Base*Height, Arectangle = Base*Height

Programming Instructions
The following are high-level instructions to complete this exercise.

1. Start by recreating the code for the Area of Right Triangle exercise
2. Obtain a case structure from the Structures palette, and click-drag-wrap it around the functions
but between the controls and indicators as shown above
3. Right-click on the case structure’s select terminal and Create>>Control to create the Select
Shape control

8
Exercise Manual Lucid LabVIEW Fundamentals I © Sixclear, llc.

a. The Boolean control that appears on the Front Panel will not have the appearance we
want, right-click on it and replace it with a vertical toggle switch from the Boolean
palette
4. Arrange the Front Panel to match that shown in the User Interface section
5. Change the visible case of the case structure to False (shown above, on the right) and add in a
Multiply function
6. Test the VI and ensure it meets the Requirements
7. Save the VI to the Exercises folder with the name Select Shape Area.vi

Be sure to wire directly into and out of the tunnels on the case structure, or you may create
additional tunnels which will not link to the existing tunnels as desired.

END OF EXERCISE

9
Exercise Manual Lucid LabVIEW Fundamentals I © Sixclear, llc.

Exercise - F1.1.3 - Timed Odd Even Counting


Overview
In this exercise we use our knowledge of For Loops to build a program which will display the number of
odd and even numbers equal to a user-selected value.

User Interface
The desired front panel is shown below.

Requirements
This program should have the ability to do the following:
1. Allow the user to select the number of loop iterations
2. Allow the user to select the time in between loop iterations
3. Display the number of odd and even numbers equal to the selected number of loop iterations

Programming Instructions
The following are high-level instructions to complete this exercise.

On the block diagram:


1. Place a FOR loop from the Structures palette

10
Exercise Manual Lucid LabVIEW Fundamentals I © Sixclear, llc.

2. Use the Numeric and Timing palettes to place the functions seen in the diagram above (Hint: the
“+1” is the Increment function)
3. Right-click to create controls, indicators, and constants, and rename as seen above

On the front panel:


4. Right-click on the Numeric control Loop Iteration Time and choose:
Replace >> Numeric >> Horizontal Pointer Slide
5. Arrange the Front Panel to match that shown in the User Interface section
a. Add a digital display to Loop Iteration Time by right-clicking and going to Visible
Items>>Digital Display
6. Test the VI and ensure it meets the Requirements
7. Save the VI to the Exercises folder with the name Timed Odd Even Counting.vi

END OF EXERCISE

11
Exercise Manual Lucid LabVIEW Fundamentals I © Sixclear, llc.

Exercise - F1.1.3 - Random Stopping


Overview
In this exercise we use our knowledge of while loops, comparison functions, and timing functions to
build a VI which stops when a random number between 0 and 100 exceeds a user defined value.

User Interface
The desired front panel is shown below.

Requirements
This program should have the ability to do the following:
1. Generate random numbers between 0 and 100 using a While loop
2. Stops when the random number exceeds a user-defined value or the Stop button is pressed
3. Control the loop iteration time using a Horizontal Pointer Slide
4. Display the number of loop iterations it takes to stop the VI

Programming Instructions
The following are high-level instructions to complete this exercise.

12
Exercise Manual Lucid LabVIEW Fundamentals I © Sixclear, llc.

On the block diagram:


1. Place Multiply, Increment, Random Number (0,1), Greater?, Or, and Wait functions on the
block diagram from the Numeric palette and enclose them in a While Loop
2. Create controls, indicators, and constants to match the diagram shown above

On the front panel:


3. Arrange the Front Panel to match that shown in the User Interface section
4. Change the Data Entry Limits on Number to Beat so that the user must enter in a value between
0 and 100
a. Right-click on Number to Beat and go to Data Entry…
b. Uncheck Use Default Limits, enter 0 in the Minimum, 100 in the Maximum and choose
to Coerce in the Response to value outside limits selection boxes beside both Minimum
and Maximum
c. Click OK
5. Test the VI and ensure it meets the Requirements
6. Save the VI to the Exercises folder with the name Random Stopping.vi

END OF EXERCISE

13
Exercise Manual Lucid LabVIEW Fundamentals I © Sixclear, llc.

Exercise - F1.1.4 - Hotel Guests Array


Overview
In this exercise we use our knowledge of arrays to explore array functions in the context of storing hotel
guest information.

User Interface
The desired front panel is shown below.

Requirements
This program should have the ability to do the following:
1. Display a Hotel Guest Array as an Array of Numerics
2. Add a free label on the front panel to illustrate the Room # next to the array
3. Compute the total number of guests
4. Compute the number of rooms
5. Compute the number of guests in a selected room
6. Compute the room with the most people, and the number of people in the room

14
Exercise Manual Lucid LabVIEW Fundamentals I © Sixclear, llc.

7. Compute the room with the fewest people, and the number of people in the room
8. Extract a subset of rooms given a start room and # of rooms
9. Sort the rooms by number of guests

Programming Instructions
The following are high-level instructions to complete this exercise.

1. Build the Front Panel User Interface shown above with arrays of numerics, numeric controls,
and indicators
2. Place and connect the functions shown in the diagram above
a. All functions can be found in the Array and Numeric palettes
3. Test the VI and ensure it meets the Requirements
4. Save the VI to the Exercises folder with the name Hotel Guests.vi

END OF EXERCISE

15
Exercise Manual Lucid LabVIEW Fundamentals I © Sixclear, llc.

Exercise - F1.1.5 - Save the Bad Editor


Overview
In this exercise we use our knowledge of loops and arrays to explore the concept of auto-indexing.

Generally, in this program we’ll find numbers in an input string, and insert a unit (such as hours) to
produce a string which reads more sensibly. The premise here is that an editor of this excerpt has
somehow forgotten or removed the units from the text. Fortunately, there are some simple rules which
can be applied to automatically replace the units after the corresponding numbers.

User Interface
The desired front panel is shown below.

Requirements
This program should have the ability to do the following:
1. Given some input text, insert units after numbers according to the following rules:
o If a number is in the range 1-9, append the unit hours, e.g., 6 hours
o If a number is in the range 10-99, append the unit minutes, e.g. 20 minutes
o If a number is greater than or equal to 100, append the unit seconds, e.g. 200 seconds
2. Display the output string as well as an array of words and an array of words with units

Programming Instructions
The following are high-level instructions to complete this exercise.

16
Exercise Manual Lucid LabVIEW Fundamentals I © Sixclear, llc.

1. Open a new, blank VI and save to the Exercises folder with the name Save the Bad Editor.vi
2. On the Front Panel, place Input Text and Output Text
o To get the input text, simply steal from Bad Editor Text.txt in the Exercises folder of our
course Project Explorer
3. Use the spreadsheet string to array function to convert the input text to an array of words.
4. Use auto-indexing into a FOR loop to process the array word by word.
5. For each word, use the Decimal String to Number function to determine if the word represents
a number. Note: this function returns 0 for strings that do NOT represent numbers.
6. When the word DOES represent a number, append the appropriate unit based on the conditions
in the Requirements section above
o Use the Select function as a simple way to make a decision based on an input boolean
7. Use auto-indexing out of the FOR loop to build an array of words where units have been added
when appropriate – this is the array of words with units.
8. Outside the loop use the Array to Spreadsheet String function to transform your array of words
with units back into a string – this is the Output Text.
9. Arrange the Front Panel to match that shown in the User Interface section.
10. Test the VI and ensure it meets the Requirements

END OF EXERCISE

17
Exercise Manual Lucid LabVIEW Fundamentals I © Sixclear, llc.

Exercise - F1.1.5 - Random Signal Averaging


Overview
In this exercise we again use our knowledge of loops and arrays to explore a shift register use case.

There are 4 main components to this program:


• initializing a shift register which holds an array of data
• generating a random value and displaying it on the Front Panel
• updating the array of data so it has the most recent 50 data points each loop iteration
• calculating the average of those 50 data points each loop iteration and displaying the average on
the Front Panel

User Interface
The desired front panel is shown below.

Requirements
This program should have the ability to do the following:
1. Computes a random value between 9.5 and 10.5 and writes that value to a Waveform Chart in a
loop
2. Stores an array of the latest 50 random values
3. Computes the average of the latest 50 random values and writes that value to a Waveform
Chart
4. Runs until a Stop button is pressed.

Programming Instructions
The following are high-level instructions to complete this exercise.

18
Exercise Manual Lucid LabVIEW Fundamentals I © Sixclear, llc.

1. Open a blank VI and save to the Exercises folder with the name Random Signal Averaging.vi
2. Create a VI which generates a random value between 9.5 and 10.5 in a while loop – this will
represent the Random Signal value - wire that random value to a Waveform Chart which you’ll
find in the Graph palette on the Front Panel
3. Create a shift register and initialize it with a DBL array using the Initialize Array function – initial
values should be 10 and the size (dimension size) should be input from a control labeled
#elements to average containing an initial value of 50
4. Inside the loop, use the Replace Array Subset function to replace the oldest value of the shift
register array with the current Random Signal value – the resulting array should be fed to the
right shift register which now contains the latest 50 points of random signal data
5. Branch from the array coming from the left shift register and compute the average of the latest
50 points of random signal data - wire that average value to a Waveform Chart
6. Arrange the Front Panel to match that shown in the User Interface section.
7. Test the VI and ensure it meets the Requirements

END OF EXERCISE

19
Exercise Manual Lucid LabVIEW Fundamentals I © Sixclear, llc.

Unit 2

Proficient Programming in
LabVIEW

20
Exercise Manual Lucid LabVIEW Fundamentals I © Sixclear, llc.

Exercise - F1.2.1 - Create SubVI


Overview
In this exercise we again create a subVI – a modular, reusable function in LabVIEW.

Here we’ll use the Area of a Triangle VI we built, and create a subVI. We’ll see how we can create a
subVI in two different ways from any piece of code – first by creating terminals and making the working
VI itself available as a subVI, and second highlighting a section of code within a working VI, and
transforming that into a subVI.

User Interface & Block Diagram

Instructions
The following are high-level instructions to complete this exercise.

Method 1: Making an existing VI available as a subVI.

The goal here is to assign input and output terminals (controls and indicators respectively) so that the
code can be used as a subVI in other VIs.

1. Make a copy of Area of a Right Triangle.vi in your exercises folder that you built in a previous
exercise
o Rename the VI: Area of a Triangle subVI 1.vi
2. Give the VI a meaningful icon by EITHER method:
o Open the VI and double click on the icon in the upper right corner of the front panel to
open the icon editor and create an icon
o Using Windows Explorer, browse to the Create SubVI icon in the …\Exercises\icons
folder, click – drag – and drop it on to the icon in the upper right corner of the front
panel
3. Right-click on the icon in the upper right corner of the front panel and select Show Connector as
shown below:

21
Exercise Manual Lucid LabVIEW Fundamentals I © Sixclear, llc.

o Click on a Connector Pane terminal and then a front panel terminal to assign – repeat
for other terminals.

o After assigning terminals, you may right-click on the Connector Pane and choose Show
Icon.
4. The VI can now be used as a subVI – open a blank VI try the following methods for placing it as a
subVI on the block diagram:
o Click-drag-and-drop the icon of Area of a Triangle subVI 1.vi onto the new block
diagram (yes, from one VI’s front panel, to another VI’s block diagram)

22
Exercise Manual Lucid LabVIEW Fundamentals I © Sixclear, llc.

o Using Windows Explorer, browse to the location where Area of a Triangle subVI 1.vi is
stored on your computer, click-drag-and-drop the icon onto the new block diagram
o Right-click on the new block diagram, choose Select a VI…, and find + select the Area of
a Triangle subVI on your computer

Method 2: Transforming a code portion, within a VI, into a subVI.

The goal here is to transform a piece of code within a VI into a subVI.

1. Make a copy of the Area of a Triangle VI named “Area of a Triangle Container.vi”


2. Click-drag-release to highlight and select the function as shown below:

3. Now click Edit >> Create SubVI from the main menu

23
Exercise Manual Lucid LabVIEW Fundamentals I © Sixclear, llc.

o Observe the code snippet has turned into a subVI with terminal connections already
made!

4. Double-click to open the newly created subVI, and save it as “Area of a Triangle subVI 2.vi”

You can now use this subVI as any other function or subVI, placing it on any block diagram as we
did in Method 1 above
END OF EXERCISE

24
Exercise Manual Lucid LabVIEW Fundamentals I © Sixclear, llc.

Exercise - F1.2.1 - The Project Explorer


Overview
In this exercise we’ll get our hands on the basics of the Project Explorer in LabVIEW, a convenient tool
for housing and organizing VIs for a project, as well as performing common operations on those VIs.
We’ve already been using a Project Explorer to house and access VIs for this course

Goals
We will not focus on VI front panels in this exercise – rather we’ll spend most of our time in the Project
Explorer we’ll create, with the following items to address:
• Creating a Project Explorer
• Creating a new VI
• Renaming a VI
• Adding an existing VI
• Creating a Virtual Folder
• Creating and moving VIs in Virtual Folders

Instructions
The following instructions will guide you through the Project Explorer basics.

1. Create a new Project Explorer clicking File>>New Project in any open LabVIEW window and save
the Project Explorer instance as My Favorite Project Explorer.lvproj

25
Exercise Manual Lucid LabVIEW Fundamentals I © Sixclear, llc.

2. Add a new VI by right-clicking on My Computer and selecting New >> VI

a. Save the VI as My Favorite VI.vi to your Exercises folder


3. Rename the VI to My Very Favorite VI.vi by right-clicking on it and selecting Rename…

Notice you can click to select the VI, and type the F2 key as shortcut to rename a VI.

26
Exercise Manual Lucid LabVIEW Fundamentals I © Sixclear, llc.

4. Add an existing VI by right-clicking on My Computer and selecting Add >> File… and choosing
the Area of Right Triangle VI we completed in a previous exercise.

5. Create a Virtual Folder by right-clicking on My Computer and selecting New>>Virtual Folder and
name it My Favorite Virtual Folder

6. Finally, let’s move My Very Favorite VI.vi to our newly created Virtual Folder by clicking and
dragging it to My Favorite Virtual Folder right in the Project Explorer.

You can also create/add VIs and child folders directly in the Virtual Folder via its right-click menu.

END OF EXERCISE
27
Exercise Manual Lucid LabVIEW Fundamentals I © Sixclear, llc.

Exercise - F1.2.2 - 2D Array Hotel Data


Overview
In this exercise we expand on our knowledge of arrays to build a 2D array of hotel data where each
element holds the number of guests per room. Using this array and our array functions, we’ll make
some relevant computations.

User Interface
The desired front panel is shown below:

Requirements
This program should have the ability to do the following:
1. Display a 2D array of Numerics (2 by 3)
o Rows represent floors (there will be 3 floors in our hotel)
o Each floor has two rooms – room 1 and room 2
o The elements of the array represent the number of people staying in that room
2. Compute the number of guests on a selected floor
3. Compute the number of guests in a selected room (on the selected floor)
4. Compute the total number of guests
o We compute it two ways in the solution, and as implied in the user interface above,
using auto-indexing and an array sum function

Programming Instructions
The following are high-level instructions to complete this exercise.

Notice that we will now very seldom show the entire Block Diagram of what you are building.
Rather, we encourage you to follow instructions and apply the principles we’ve been discussing.
Take a look at the solution VIs (and/or the solution video if you are self-pacing) for guidance if you
become stuck.

1. Open a new VI and save the VI to the Exercises folder with the name 2D Array Hotel Data.vi

On the front panel:

28
Exercise Manual Lucid LabVIEW Fundamentals I © Sixclear, llc.

2. Create the front panel as shown above


a. Controls:
i. A Number of Guests 2D array of Integer Numerics
ii. A Select Floor Integer Numeric
iii. A Select Room Integer Numeric
b. Indicators
i. Number of Guests on Floor Integer Numeric
ii. Number of Guests in Room Integer Numeric
iii. Total Guests Integer Numeric
iv. Total Guests by Auto Indexing Integer Numeric

On the block diagram:


With controls and indicators now available, you can:

3. Use an Index Array function to select a floor (row), along with an Add Array

Elements function to compute the Number of Guests on Floor


4. Use an Index Array function to pick off the Number of Guests in Room for the selected floor
and room.
5. Use an Add Array Elements function to compute the Total Guests in the hotel

Notice you can wire a 2D array into the Add Array Elements function

6. Use For Loops and auto-indexing on the 2D array to compute the Total Guests by Auto-
Indexing. Use shift registers on the For Loops to hold data as you cycle through the array
elements and sum the values.

Code Snippet:

7. Test the VI and ensure it meets the Requirements

END OF EXERCISE

29
Exercise Manual Lucid LabVIEW Fundamentals I © Sixclear, llc.

Exercise - F1.2.2 - Hotel Room Data


Overview
In this exercise we work with clusters – collections of primitive data types in LabVIEW which allow us to
build up “custom” data types. We’ll continue our hotel theme and build a cluster which houses Hotel
Room data: a card holder’s name, the number of guests in the room, and whether the guests is a
rewards club member.

User Interface
The desired front panel is shown below.

Requirements
This program should start with a front panel cluster named Hotel Room Cluster and do the following
1. Extract the Card Holder Name and Number of Guests with the Unbundle By Name function
2. Extract the Number of Guests and Rewards Club? Indicators with the Unbundle function
3. Modify Hotel Room Cluster with a Bundle by Name function
4. Create a cluster from String and Numeric constants (for Card Holder Name and Number of
Guests) with the Bundle function

Programming Instructions
The following are high-level instructions to complete this exercise
1. Open a new VI and save the VI to the Exercises folder with the name Hotel Room Data.vi

On the front panel:


2. Create only the Hotel Room Cluster show on the front panel. Everything else can be created
while working on the block diagram

30
Exercise Manual Lucid LabVIEW Fundamentals I © Sixclear, llc.

a. Right-click on the cluster’s border and select Reorder Clusters in Control… to verify and
make sure (set if necessary) that the Card Holder Name is item 0, Number of Guests is
item 1, and Rewards Member? Is item 2
On the block diagram:
We now have a Hotel Room Cluster available. Use the names shown on the front panel screenshot
above to create relevant indicators as you complete the following.

3. Use the Unbundle By Name function to strip out Card Holder Name and Number of Guests and
display them as indicators

4. Also use the Unbundle function to pull out Number of Guests and Rewards Club? and display
them as indicators

5. Use the Bundle By Name function to modify values in the existing Hotel Room Cluster and
create the new cluster: Modified Hotel Room Cluster with the values changed as follows:
o Change the value of Card Holder Name to Willie Nelson and Number of Guests to 30

6. Also use the Bundle function to produce another cluster named Different Cluster with a String
and Numeric, having respective values Willie Nelson and 30

7. Test the VI and ensure it meets the requirements

There are a couple important distinctions to draw about these cluster functions:

I. The Unbundle By Name and Bundle By Name functions REQUIRE an existing cluster for
input; that’s how they know which cluster element names to expose
• Unbundle By Name is really a “read” operation, reading values from the cluster while
keeping the names of the elements being read in view.
• Bundle By Name is like a “write” operation, or more specifically a “copy” operation
because it produces a new cluster with equivalent data types, but new data values.
II. The Bundle function does NOT require an input cluster

END OF EXERCISE

31
Exercise Manual Lucid LabVIEW Fundamentals I © Sixclear, llc.

Exercise - F1.2.2 - 2D Cluster Array Hotel Data


Overview
In this exercise we put our understanding of 2D arrays and clusters together to conveniently capture
Card Holder Name and Number of Guests data for rooms a hotel.

User Interface
The desired front panel is shown below.

Requirements
This program should start with a front panel 2D array of clusters named Hotel Room Information and
compute:
• # Guest per Floor – an Array where values are the number of guests on that floor.
• # Guests in Hotel – a Numeric representing the total number of guests in the hotel.

Programming Instructions
The following are high-level instructions to complete this exercise

1. Open a new VI and save it to the Exercises folder with the name 2D Cluster Array Hotel Data.vi

On the front panel:


2. Create the Hotel Room Information 2D array of clusters show on the front
a. Create the cluster, or copy from the previous exercise to this front panel
b. Drag the cluster into an array shell on the front panel
c. Resize the array indexing control to have two dimensions
d. Resize the array itself to expose 6 elements as shown above.

32
Exercise Manual Lucid LabVIEW Fundamentals I © Sixclear, llc.

On the block diagram:


We now have a Hotel Room Information cluster available.

3. Use nested For Loops to calculate the number of guests in each floor and the total number of
guests in the hotel
a. Auto-index our 2D array of clusters (Hotel Room Information) using a For Loop to
expose the rows (floors) on each iteration.

b. Create an inner For Loop to access the individual clusters in each row (floor of the hotel)
through auto-indexing
c. Use an Unbundle By Name function to access the Number of Guests
d. Use a Shift Register to keep a running sum of the number of guests

e. Output an array of the number of guests per floor and total number of guests in the
hotel
f. Use indexing OUT OF the outer loop to produce our # Guests per Floor array
g. Outside both the loops, use the Add Array Elements function to sum the # Guests per
Floor array to produce our desired # Guests in Hotel

33
Exercise Manual Lucid LabVIEW Fundamentals I © Sixclear, llc.

4. Test the VI and ensure it meets the requirements

END OF EXERCISE

34
Exercise Manual Lucid LabVIEW Fundamentals I © Sixclear, llc.

Exercise - F1.2.3 - Noisy Signals Chart


Overview
Our primary purpose in this exercise is to get our hands on charts in LabVIEW. We’ll take this
opportunity to use some additional functions such as sine/cosine and noise generation in LabVIEW.

User Interface
The desired front panel is shown below.

Requirements
This program should:
1. Accept 3 numeric inputs
o signal amplitude
o noise amplitude
o samples per period
2. Produce a sine and cosine function one point at a time in a loop (10ms loop timing)
3. The sine and cosine function should have the signal amplitude and samples per period specified
4. Gaussian White noise at the specified noise amplitude should be added to both the sine and
cosine signals to produce the noisy signals
5. Both noisy signals should be plotted to a Waveform Chart
6. A Stop button should stop the loop and the VI

Implementation Strategy

35
Exercise Manual Lucid LabVIEW Fundamentals I © Sixclear, llc.

How might we solve this problem? At first it may seem difficult, but as we’ll see there are only a few
pieces to the puzzle.

We want to produce signals one point at a time so it makes sense for us to use a Waveform Chart. To
build up a signal one point at a time, we can use a loop as suggested in the requirements. The question
now boils down to:

How do I produce the desired noisy sine and cosine signals, and allow for the signal amplitude, noise
amplitude, and samples per second to be specified?

The answer is fairly straightforward: we’ll build a noise signal as well as sine and cosine signals
independently, add them to produce a noisy signal, and plot the results to a Waveform Chart.

Programming Instructions
The following are high-level instructions to complete this exercise

1. Open a new VI and save it to the Exercises folder with the name Noisy Signals Chart.vi

On the front panel:


2. Build the front panel as seen above:
a. Raw Signal – Waveform Chart (Graph palette)
b. Signal amplitude – a Vertical Pointer Slide (Numeric palette)
c. Noise amplitude – a Vertical Pointer Slide (Numeric palette)
d. Samples per period – a Horizontal Pointer Slide (Numeric palette)
e. Stop button – a Stop Button (Boolean palette)

On the block diagram:


3. Place a While Loop on the block diagram and use the Stop button to control it

4. Add a Wait (ms) function to delay the loop timing by 10ms

We can attack building the code within our While Loop in distinct parts:
A. Generate the noise signal
B. Generate the sine/cosine signals
C. Add the noise to the sine/cosine signals
D. Plot the signal data to the graph

5. Generate the noise signal


a. Place the VI: Gaussian White Noise PtbyPt.vi on the block diagram
b. Multiply that noise value by the noise amplitude control value, the resulting product
will be added to the sine/cosine signal values that we’ll create in the next step

36
Exercise Manual Lucid LabVIEW Fundamentals I © Sixclear, llc.

6. Generate the sine/cosine signals


• Use the Sine & Cosine function from the Mathematics >> Elementary & Special Functions >>
Trigonometric Functions palette which produces scalar sine and cosine values from the input
values

To produce a sine or cosine wave from the scalars, we simply need to produce the following
sequence of numbers (as the loop iterates) for input into our Sine & Cosine function: (we show
how to do this in 2 steps)
i. 0*2π/n = 0
ii. 1*2π/n
iii. 2*2π/n
iv. …
v. (n-1)*2π/n = 2π
vi. repeat the sequence…
The value n then will be our number of samples per period control because the period of a pure
sine or cosine wave is 2π

• Multiply our sine and cosine signals by the signal amplitude control value – the result is our
sine and cosine signals, ready for us to add noise

Notice the above is the While Loop’s iteration count variable. Also notice the coercion dots we
discussed – the integer data types are being converted to floating point values in this case. The
constant can be found in our Numeric >> Math Constants palette.

7. Add the noise signal to the sine and cosine signals separately

8. Plot the signal data to the graph


a. Bundle the noisy sine and cosine using a Bundle function, and wire the result to our Raw
Signal Chart

37
Exercise Manual Lucid LabVIEW Fundamentals I © Sixclear, llc.

9. Test the VI and ensure it meets the requirements

END OF EXERCISE

38
Exercise Manual Lucid LabVIEW Fundamentals I © Sixclear, llc.

Exercise - F1.2.3 - Dynamic Signals


Overview
The primary purpose of this exercise is to show the utility of Waveform Graphs. However, it is also a
great opportunity for us to apply our knowledge of clusters, arrays, and other structures to grow our
programming ability, and get a glimpse into some increasingly powerful functionality and programming
techniques.

User Interface
The desired front panel is shown below

Requirements
This program should have the ability to do the following:
1. Allow a user to specify any number of signals to plot
2. Signals should be defined with the following properties:
o Enable/disable
o Type (sine, square, triangle, sawtooth)
o Amplitude
o Frequency
3. Allow the user to set the number of samples per signal (applies to all signals)
4. Plot the enabled signals in a Graph
o As Amplitude and Frequency are changed for enabled signals, the Graph should update
in real-time to reflect those changes
5. Changes in the signal configurations should update the graph immediately
6. A stop button should stop the program

Implementation Strategy
39
Exercise Manual Lucid LabVIEW Fundamentals I © Sixclear, llc.

At this stage, the requirements may seem a little scary, and even the user interface might seem a bit
complex. We need to let a user specify arbitrarily many signals, each of which can be enabled/disabled,
and can have different types, amplitudes, and frequencies.

However, we can build this program in a very elegant way using just the constructs we understand
already.

This is also our first real opportunity to “architect” a nice solution to a seemingly complex problem.

Here’s our attack:


A. Build a VI which generates signals specified in a signals array
• Use a cluster to wrap the signal configuration information (enable Boolean, signal type
Enum, amplitude Numeric, frequency Numeric)
• Create an array of those clusters to define/hold configuration for multiple signals
• Use For Loop to auto-index that array to pick off the current signal configuration
(cluster)
• Unbundling the cluster’s Type element tells us what kind of signal to build – we’ll use a
case structure with the Type as the selector input to determine which signal to build
• With a case for each signal, we can now unbundle the cluster’s amplitude and
frequency, and use a LabVIEW-provided function to construct the signal array with
those properties
Note: we will also unbundle the enable/disable boolean here, if it’s disabled we’ll simply
output an array of zeros instead of the signal data – that will suffice for turning off the
signal (just plots a flat line at 0)
• Finally, we can auto-index OUT OF the For Loop to build the array of signals (a 2D array)
which can be accepted by our Graph
• Here’s how our architecture will look inside the While Loop:

B. Make that VI into a subVI


• Define the connector pane and VI icon to all this to be used as a subVI
C. Build a wrapper VI which uses that subVI to continuously generate + update the signals when we
make changes
• Simply wrap everything in a While Loop with a Stop button and some loop timing
• We will be adding more functionality to this wrapper VI in a future exercise

40
Exercise Manual Lucid LabVIEW Fundamentals I © Sixclear, llc.

Programming Instructions
The following are high-level instructions to complete this exercise

We will expose a few very important and efficient techniques here. In particular, we’ll show how
to duplicate case structures and replace functions with similar functions to very rapidly implement
our desired functionality within our architecture.

A. Build a VI which generates signals specified in a signals array

1. Open a new VI and save it to the Exercises folder with the name Generate Signals.vi

On the front panel:


2. Build a cluster named Signal Config
a. It will have the following elements:
i. Enable (Boolean Round LED changed to a control)
ii. Type (Enum with elements: Sine, Square, Triangle, Sawtooth)
iii. Amplitude Horizontal Pointer Slide
iv. Frequency Horizontal Pointer Slide
b. Drag that cluster into an array shell to create an array of signal clusters named
Signals Array
c. Add a Numeric control named Samples per Signal
d. Add a Waveform Graph named Signals Graph

The Front Panel of our calling VI: Dynamic Signals.vi will look exactly the same but will have an
additional Stop button. We will see this later.

On the block diagram:


3. Using a For Loop and Case Structure, build out the architecture framework as shown below
a. Auto-index the For Loop by wiring the Signals Array through it
b. Unbundle the resulting cluster inside to expose the Type element
c. Use that Type element as the Case Structure’s selector input
d. Do not worry about feeding the Signals Graph yet – next we’ll construct our signals

41
Exercise Manual Lucid LabVIEW Fundamentals I © Sixclear, llc.

4. We’ll now produce our signals in our Case Structure, note that the yellow labels in the
figure are just free labels

a. Place the Sine Wave.vi from the Signal Processing >> Signal Generation
palette and wire the Samples per Signal wire to it

b. Find the Unbundle by Name in the Cluster, Class, & Variant palette and
wire the Signal Config cluster to it

c. Find the Select function in the Comparison palette


d. Create the array of zeros outside the For Loop and wire it in using the Initialize Array

function

5. Now we need to create cases for our other signal types.

Question: Our other cases will be very similar, do we need to code the other cases from scratch?
Answer: NO! We can actually Duplicate this case three times so we don’t have to recode

Here’s how to duplicate cases:


a. Right-click on our Case Structure and choose Duplicate Case:

42
Exercise Manual Lucid LabVIEW Fundamentals I © Sixclear, llc.

b. Repeat to create 4 total cases (including the sine case we already made)

IMPORTANT TECHNIQUE – duplicating code allows us to very rapidly build similar cases – this is a
very powerful strategy which we’ll see again and make quite valuable use of

IMPORTANT OBSERVATION – notice that our duplicated cases automatically take up the next
items we specified in our Type Enum – this is the LabVIEW development environment being smart
– thanks LabVIEW! This is special functionality for Enums because the values it contains become
part of the underlying data type

6. Now we need to replace the Sine Wave.vi with our other signal types in our new cases.

Question: Do I need to delete the Sine Wave.vi and rewire a new VI in its place?
Answer: NO! We can actually replace Sine Wave.vi in-place without having to re-wire

Here’s how to do this in-place replacement operation:


a. First, show the Square case in our Case Structure.
b. Right-click on the Sine Wave.vi and select Replace >> All Palettes >> Signal Processing >>
Signal Generation >> Square Wave.vi

43
Exercise Manual Lucid LabVIEW Fundamentals I © Sixclear, llc.

a. Repeat for the Triangle and Sawtooth cases – there are corresponding VIs in the
same Signal Generation palette.

IMPORTANT TECHNIQUE – replacing existing code with new functions or VIs is a powerful
technique. It saves you from having to re-wire.

b. You should now have something that looks like the following: g

7. Run Generate Signals.vi and ensure it meets the requirements

44
Exercise Manual Lucid LabVIEW Fundamentals I © Sixclear, llc.

B. Make Generate Signals.vi into a subVI

8. Make this a subVI with Samples per Signal, Signals Array, and Signals Graph as inputs and
outputs

a. Create a connector pane similar to


b. Give the VI a meaningful icon

i. Using Windows Explorer, browse to the Generate Signals icon in the


…\Exercises\icons folder, click – drag – and drop it on to the icon in the
upper right corner of the front panel
C. Make a Wrapper VI

9. Create a new VI and save it as Dynamic Signals.vi


10. To complete the programming for this exercise, put an instance of our new Generate
Signals.vi into the block diagram, create the controls and indicators from it, and wrap a
While Loop around it with a Stop button and some loop timing

11. Test the VI and ensure it meets the requirements


a. Dynamically change the signal configurations in the array and notice the signals
update accordingly

END OF EXERCISE

45
Exercise Manual Lucid LabVIEW Fundamentals I © Sixclear, llc.

OPTIONAL Exercise - F1.2.3 - Dynamic Circles


Overview
The primary purpose of this exercise is to see a working use case for XY Graphs. We’ll make a VI that is
able to create circles with dynamically changing parameters for use in future exercises.

User Interface
The desired front panel is shown below.

Requirements
This program should have the ability to do the following:
1. Allow a user to specify any number of circles to plot
2. Circles should be defined with the following properties:
o X offset
o Y offset
o radius
3. Allow the user to set the number of samples per circle (applies to all signals)
4. Plot all defined circles in an XY Graph
5. The circles should dynamically respect any changes in their configuration (x offset, y offset, and
radius)

Implementation Strategy
Here we have a situation very similar to our last exercise:

46
Exercise Manual Lucid LabVIEW Fundamentals I © Sixclear, llc.

A. Build a VI which generates circles specified in a circles array


• Define an array of clusters, where each cluster holds a circle definition and configuration
• We can cycle through the array by auto-indexing a For Loop
• Generate the circle data for each circle defined
• Plot it all to an XY Graph
B. Make a subVI
• Define the connector pane and VI icon to all this to be used as a subVI
C. Build a wrapper VI
• This will call the subVI to continuously generate + update the circles when we make
changes
• Wrap everything in a While Loop with a Stop button and some loop timing
• We will be adding more functionality to this wrapper VI in a future exercise

Programming Instructions
The following are high-level instructions to complete this exercise

Build a VI which generates circles specified in a circles array

1. Open a new VI and save it to the Exercises folder with the name Generate Circles.vi

On the front panel:


2. Build a cluster named Circle Data
a. It will have the following elements:
i. X offset (Horizontal Pointer Slide)
ii. Y offset (Horizontal Pointer Slide)
iii. Radius (Horizontal Pointer Slide)
b. Drag that cluster into an array shell to create an array of signal clusters named
Circles Array
c. Add a Numeric control named Samples per Circle
d. Add an XY Graph named XY Graph

On the block diagram:


3. Auto-index the Circles Array into a For Loop and use an Unbundle By Name on the incoming

cluster to expose the radius, x offset, and y offset elements

4. Use the Generate Circle Data.vi provided in the Exercises folder to create X and Y circle
data for the incoming cluster – wire in the inputs:
a. Samples per Circle
b. Radius
c. X offset
d. Y offset
5. Pass data out of the For Loop to be displayed on the XY Graph
a. Use a Bundle function to bundle the X and Y data into a cluster – this is a circle
plot

47
Exercise Manual Lucid LabVIEW Fundamentals I © Sixclear, llc.

b. Auto-index OUT OF the For Loop to build the array of circle plots – this is the data
structure which our XY Graph accepts to plot our circles
c. We now have something like:

Make a subVI

6. Run the newly created to see it working


7. This is a nice piece of code which generates circles – let’s wrap it into a subVI so we can use it
later
a. Make this a subVI with Samples per Circle, Circles Array, and XY Graph as inputs and
outputs accordingly, named Generate Circles.vi

b. Use a connector pane similar to


c. Give the VI a meaningful icon

i. Using Windows Explorer, browse to the Generate Circles icon in the


…\Exercises\icons folder, click – drag – and drop it on to the icon in the upper
right corner of the front panel

Build a Wrapper VI

8. Now create a new VI named Dynamic Circles.vi


9. To complete the programming for this exercise, put an instance of our new Generate Circles.vi
into the block diagram, create the controls and indicators from it, and wrap a While Loop
around it with a Stop button and some loop timing

48
Exercise Manual Lucid LabVIEW Fundamentals I © Sixclear, llc.

10. Test the VI and ensure it meets the requirements


e. Dynamically change the signal configurations in the array and notice the signals update
accordingly

END OF EXERCISE

49
Exercise Manual Lucid LabVIEW Fundamentals I © Sixclear, llc.

Exercise - F1.2.4 - Processing Spreadsheet Data


Overview
The purpose of this exercise is get our hands on some practical spreadsheet file handing and processing

User Interface
The desired front panel is shown below

Requirements
This program should have the ability to do the following:
1. Read in a specified spreadsheet file and the specified number of bytes to read
2. Show the raw spreadsheet data
3. Process and show a 2D array of strings of the spreadsheet data
4. Process and plot that data to an XY Graph

Implementation Strategy
This program can be broken down into simple pieces given what we’ve learned about File I/O and
processing strings and arrays
• Read in data from a spreadsheet file
• Parse the spreadsheet string data into an array
• Remove the column headers since they are not part of the actual data to plot
• Process the data and plot it to an XY Graph

Each of those steps feeds into the next, passing on further processed data until the data is plotted

50
Exercise Manual Lucid LabVIEW Fundamentals I © Sixclear, llc.

Programming Instructions
The following are high-level instructions to complete this exercise

1. Open a new VI and save it to the Exercises folder with the name Processing Spreadsheet Data.vi

On the front panel:


2. Build the front panel as shown which includes
a. File path File Path control
b. Bytes to Read Numeric Control
c. Inventory 2D array of String Indicators
d. Spreadsheet Signals XY Graph
e. Raw Spreadsheet Data String Indicator

On the block diagram:


3. Read in data from a spreadsheet file
a. Use a File Open, Read, and Close functions to read the provided Signal Data.csv (see the
Exercises folder in our course Project Explorer)
b. Use a Simple Error Handler to check for potential errors

Note – A csv file is a comma-delimited spreadsheet file, meaning there are commas in between
each element of the spreadsheet. This is an alternative to the tab-delimited file.

4. Parse the spreadsheet string data into an array


a. Use the Spreadsheet String to Array function from the String palette, with comma
delimiter and string format specifier (%s) to convert the spreadsheet string to an array
of strings

5. Remove the column headers since they are not part of the actual data to plot

51
Exercise Manual Lucid LabVIEW Fundamentals I © Sixclear, llc.

a. Use the Delete From Array function to remove the header row

6. Process the data and plot it to an XY Graph


a. Use the Fract/Exp String To Number function to convert the string array to a
corresponding array of double precision floats

b. The first column of the spreadsheet is the time and the next three columns are the
signals. Use an Index Array function to separate the X (time) data array, and each of the
3 signals arrays. Use Bundle functions to build an XY plot for each signal, and the Build
Array function to build the multi-plot data type for the Spreadsheet signals XY Graph

7. Test the VI and ensure it meets the requirements

END OF EXERCISE

52
Exercise Manual Lucid LabVIEW Fundamentals I © Sixclear, llc.

Unit 3

Application Programming in
LabVIEW

53
Exercise Manual Lucid LabVIEW Fundamentals I © Sixclear, llc.

OPTIONAL Exercise - F1.3.1 - Managing Parallel Loops


Overview
The purpose of this exercise is to see how a multiple loop structure can drive two independent pieces of
functionality “simultaneously”. We’ll see how we can easily use a parallel loop architecture to drive both
our Signal Generation code as well as our Dynamic Circles code.

Execution is not actually simultaneous on a single-processor machine, but LabVIEW automatically


abstracts away operating system threading to split time between parallel running loops to
effectively create an simultaneous operations.

User Interface
The desired front panel is shown below displaying two tabs in a single tab control

Dynamic Signals Tab Dynamic Circles Tab

Requirements
This program should have the ability to do the following:
1. Provide the Dynamic Signals functionality AND Dynamic Circles functionality in a single VI
2. Allow the user to view either operation using a Tab Control
3. Provide a single stop button to stop the entire VI

Implementation Strategy
Our goal is to use parallel loops to drive our Signal Generation and Dynamic Circles functionality
• To start, we’ll copy and paste the original code from each into a single block diagram
• We’ll then reduce the stop functionality to use just one stop button

Programming Instructions
The following are high-level instructions to complete this exercise

1. Open a new VI and save it to the Exercises folder with the name Managing Parallel Loops.vi

On the block diagram:


2. Copy the entire contents (including the While Loop) of the Dynamic Signals.vi we built in a
previous exercise onto the block diagram

54
Exercise Manual Lucid LabVIEW Fundamentals I © Sixclear, llc.

3. Copy the entire contents (including the While Loop) of the Dynamic Circles.vi we built in a
previous exercise onto the block diagram

4. Delete the Stop button from the Dynamic Circles loop – instead use a Local Variable created
from the Dynamic Signals loop’s Stop button
a. Click the broken Run arrow and notice you now have at least one error, telling us the
Local Variables are not compatible with the Latch Mechanical Action

55
Exercise Manual Lucid LabVIEW Fundamentals I © Sixclear, llc.

Recall the Latch Mechanical Action causes a control to return to its default state after being read
on the block diagram. If LabVIEW allowed Local Variables on controls with this Mechanical Action,
it would cause an instance of a “race condition” – code which has an unknown order of events,
such as:
I. Suppose a Stop button is clicked so that the Stop button control value is now True
II. Either of the following two events could occur, but the order cannot be determined:
a) The Stop button value could be read by the Stop terminal on the block diagram,
and the value immediately returned to False due to Latch Mechanical Action
b) The Stop button Local Variable instance could read the value

The problem here is that:


• If a) occurs before before b) then the Local Variable will read False
• If b) occurs before before a) then the Local Variable will read True

Thus, LabVIEW does NOT allow Local Variables on Latch Mechanical Action booleans.

b. Since we need the Local Variable to stop both loops with one Stop button, change the
Mechanical Action of the Stop button to a Switch Mechanical Action type

56
Exercise Manual Lucid LabVIEW Fundamentals I © Sixclear, llc.

Question: How do I make my Stop button return to the un-pressed (false) state with a Switch
Mechanical Action? (I’m used to the Latch Mechanical Action doing it for me!)

Answer: Use a Local Variable at the end of the program to return it back to the un-pressed (False)
state after the rest of the code has completed.

5. Use the technique we learned to stop parallel loops – a single frame Sequence Structure,
dataflow control, and a Stop button Local Variable to return the Stop button to False

On the front panel:


6. Place a Tab control and arrange the Front Panel to match that shown in the User Interface
section

57
Exercise Manual Lucid LabVIEW Fundamentals I © Sixclear, llc.

7. Test the VI and ensure it meets the requirements

END OF EXERCISE

58
Exercise Manual Lucid LabVIEW Fundamentals I © Sixclear, llc.

OPTIONAL Exercise - F1.3.1 - Global Stop


Overview
The purpose of this exercise is to apply our knowledge of Global Variables to implement global stop
functionality for two VIs – if either is stopped, they both stop.

User Interface
The desired front panels are shown below

Dynamic Signals GLOBAL STOP.vi Dynamic Circles GLOBAL STOP.vi

Requirements
This program should implement global stop functionality for our signal generation and dynamic circles
VIs using a global variable.

Implementation Strategy
The following is the approach we’ll take for implementing this functionality.

A. Create a Stop button Global Variable


• This global stop will be set whenever either of our VIs in this exercise stop
B. Update Dynamic Signals GLOBAL STOP.vi and Dynamic Circles GLOBAL STOP.vi
We want to stop when:
• The global stop Global Variable becomes True.
• When the VI’s own stop button is clicked (becomes True)

Programming Instructions
The following are high-level instructions to complete this exercise

1. Save a copy of the Dynamic Signals and Dynamic Circles VIs as:
a. Dynamic Signals GLOBAL STOP.vi
b. Dynamic Circles GLOBAL STOP.vi
2. Create the global variable
a. On the block diagram of Dynamic Signals GLOBAL STOP.vi, place a Global Variable from
the Structures palette
b. Double-click the Global Variable to open it

59
Exercise Manual Lucid LabVIEW Fundamentals I © Sixclear, llc.

c. Add a Stop button to the Front Panel, and change the Mechanical Action to Switch type
d. Save it as Global Stop.vi

e. It should look something like on your Dynamic Signals GLOBAL STOP.vi Block
Diagram (you may have to click on the Global Variable with the operate tool to select
the Stop value)
3. We want to stop when either the Global Stop is set OR when we click our local Stop button. We
can use a simple OR condition in our While Loop:

4. We’re not quite finished yet though. We need to make sure when we click stop in one of the
VIs, that we SET the global stop to true so that it stops the other VI. We can SET it easily just
outside the loop:

5. Add the global variable to the Block Diagram of Dynamic Circles GLOBAL STOP.vi and implement
the same algorithm as shown above

We’re still not quite done.

What happens if we stop the VIs, and then try to start one (or both) again?

Well, the global stop is STILL SET to True! This would cause our While Loop to stop on the first
iteration. We can solve this by making sure to RESET the global stop back to False at the
beginning of our VIs, before we enter the While Loop:

60
Exercise Manual Lucid LabVIEW Fundamentals I © Sixclear, llc.

6. Adding this code to both our VIs will properly reset the Global Stop when we run either of our
VIs the second time (or anytime thereafter)

7. Run both Dynamic Signals GLOBAL STOP.vi and Dynamic Circles GLOBAL STOP.vi
a. Press the stop button on each VI between consecutive runs to ensure that the global
stop mechanism works

END OF EXERCISE

61
Exercise Manual Lucid LabVIEW Fundamentals I © Sixclear, llc.

Exercise - F1.3.1 - Functions Functional Global


Overview
The purpose of this exercise is to implement a simple yet practical example of a functional global
variable. We’ll create a functional global that performs a selected arithmetic operation, and we’ll build
another VI which uses it to perform a simple computation.

User Interface
The desired front panel is shown below.

Functions Functional Global.vi Test Functions Functional Global.vi

Requirements
This program computes the function -1/[(A-B)*C/D] using a functional global variable that implements
each of the necessary operations:
• Initialize
• Add
• Subtract
• Multiply
• Divide
• Negate
• Reciprocal
• Read

Implementation Strategy
We have two basic parts here:
A. Build the functional global
1. It should provide the operations above
B. Build the wrapper VI
1. It simply uses our functional global to compute the desired function -1/[(A-B)*C/D]

62
Exercise Manual Lucid LabVIEW Fundamentals I © Sixclear, llc.

Programming Instructions
The following are high-level instructions to complete this exercise

Build the functional global


1. Open and new VI and save it as Functions Functional Global.vi

On the front panel:


2. Create the front panel as shown in the User Interface section
a. Value Numeric control
b. Result Numeric indicator
c. Function Enum with items:
i. Initialize
ii. Add
iii. Subtract
iv. Multiply
v. Divide
vi. Negate
vii. Reciprocal
viii. Read

3. Create the connector pane similar to

4. Create an icon (or use ours in your …Exercises\icons directory):

On the block diagram:


5. Start with a While Loop and Case Structure, with the While Loop terminated by a constant
True, and the Functions Enum wired to the Case Structure (the Functions Enum can be
inside or outside the While Loop, it doesn’t matter since the loop will only execute once
each time the VI runs)

63
Exercise Manual Lucid LabVIEW Fundamentals I © Sixclear, llc.

Notice our first case already has the Add value in it – that’s LabVIEW automatically populating the
first case since we’re using an Enum Question: Can LabVIEW automatically create the additional
cases for us?
Answer: Yes, we could right-click and select Add Case for Every Value as shown here
(DON’T DO THIS HOWEVER… WE’LL EXPLAIN BELOW)

We actually want to build our first case, then start using the Duplicate Case feature, followed by
the Replace feature for functions, just like we did in a previous exercise. This will save us more
programming than having LabVIEW add all of our cases here.

BUT KEEP THIS IN YOUR BAG OF TRICKS – YOU’LL FIND IT USEFUL DOWN THE ROAD!

6. Build the Add case as shown, including creating the Shift Register as needed

7. Build the other cases – use the cases shown below if you’re unsure how to build a function.

64
Exercise Manual Lucid LabVIEW Fundamentals I © Sixclear, llc.

PROGRAMMING HINTS
• Use the Duplicate Case functionality to save on programming
• Use the Replace functionality on functions to build out similar cases

65
Exercise Manual Lucid LabVIEW Fundamentals I © Sixclear, llc.

8. Test the VI and make sure it operates correctly

Build the wrapper VI


9. Open a new VI and save it as Test Functions Functional Global.vi

10. Build the Front Panel as shown in the User Interface section above with 4 Numeric Controls
and a Numeric Indicator
i. Use a free label to identify A, B, C & D and document the formula

11. Since our Functions Functional Global.vi will store current computations within (that’s what
functional globals do with their uninitialized shift registers) we simply need to cycle through
the operations in the right order to compute: -1/[(A-B)*C/D].

Let’s take this opportunity to use a compact little structure for cycling through operations.
Consider the following structure:

It runs through the case cases one by one.


With that in mind, consider that we can implement -1/[(A-B)*C/D] using the following
sequence of operations and our functional global variable

i. Initialize to 0, our functional global value is now 0


ii. Add the value A, our functional global value is now A
iii. Subtract the value B, our functional global value is now A-B
iv. Multiply the value by C, our functional global value is now (A-B)*C
v. Divide the value by D, our functional global value is now (A-B)*C/D
vi. Take the Reciprocal, our functional global value is now 1/[(A-B)*C/D]
vii. Negate, our functional global value is now -1/[(A-B)*C/D]
viii. Read, this does not change the value, just returns the value
(we don’t actually need this case since the current value is always returned, but
we’ll add it just to test our functional global variable here)

12. Test the VI and ensure it meets the requirements

PROGRAMMING HINT – Use the Duplicate Case functionality to save on programming!


END OF EXERCISE

66
Exercise Manual Lucid LabVIEW Fundamentals I © Sixclear, llc.

Exercise - F1.3.2 - LabVIEW Toaster


Overview
The primary purpose of this exercise is to implement a state machine for a practical purpose – a toaster.
However, since functional global variables are so useful, we’ll also build a timer functional global
variable here, which will allow us to add some interesting functionality and user interface updates to our
toaster application.

User Interface
The desired front panels are shown below

LabVIEW Toaster.vi Timer Functional Global.vi

Requirements
This program should have the ability to do the following:
1. Start in an Idle state
2. When the Toast button is clicked, walk through the following sequence of states
o Start Toasting
o Toasting
o Popup Toast
o Start Cooling
o Cooling

67
Exercise Manual Lucid LabVIEW Fundamentals I © Sixclear, llc.

o Idle
3. Monitor the temperature of the toaster in the Toasting state, if the temperature goes above the
overheat temperature of 104.9° C, then stop the Toasting state, move immediately to the Start
Cooling state, and turn on the Overheat boolean
o When the idle state is again reached after cooling, turn off the Overheat Boolean
4. Stop when the Stop button is clicked from any state

Implementation Strategy
The application can be represented as a state diagram:

We have two VIs to build here – a timer VI and our top level state machine VI

A. Timer Functional Global.vi


a. Provide the following functions
1. Set
2. Start
3. Read
b. Provide the following outputs each time the VI is called
1. Done – boolean indicating if the wait time has elapsed

68
Exercise Manual Lucid LabVIEW Fundamentals I © Sixclear, llc.

2. Time Left String – a string representing the remaining wait time in seconds

B. LabVIEW Toaster.vi
a. State machine with states
1. Idle
2. Start Toasting
3. Toasting
4. Popup Toast
5. Start Cooling
6. Cooling
b. The Toast button will drive the Idle to Start Toasting state transition
c. The Start Toasting state will Set the timer, then Start the timer, and transition immediately
to the Toasting state
d. The Toasting state will read the timer and check the temperature of the toaster. The next
state will be the Toasting state while the timer has not yet elapsed and the toaster has not
overheated. When the timer is Done, the Popup Toast state will execute. If the toaster
overheats, the Start Cooling state will execute.
e. The Popup Toast state will popup an alert box indicating “The toast is ready!” and then
immediately transition to the Start Cooling state.
f. The Start Cooling state (much like the Start Toasting state) will Set the timer, then Start the
timer, and transition immediately to the Cooling state
g. The Cooling state will first read the timer. The next state will be the Cooling state until the
timer is Done. When the timer is Done, it will transition to the Idle state.

Programming Instructions
The following are high-level instructions to complete this exercise

Timer Functional Global.vi


1. Open a new VI and save it as Timer Functional Global.vi

On the front panel:


2. Let’s start our timer functional global by building the front panel as shown in the User
Interface section
a. Wait time is a double numeric
b. The Operation Enum should have the items
1. Set
2. Start
3. Read
c. Put down an error in and error out cluster

On the block diagram:

3. This functional global will hold TWO uninitialized shift registers for
a. Start time
b. Wait time
1. Our basic structure looks like:

69
Exercise Manual Lucid LabVIEW Fundamentals I © Sixclear, llc.

b. Use the Add Case for Every Value technique we discussed (but did not actually use)
in the previous exercise to populate our Case Structure with cases
4. Program the Start case
a. Initialize our start time shift register with a Get Date/Time in Seconds function
(Timing palette)
b. Convert the timestamp output to a double numeric

5. Program the Set case


a. We use the Wait Time control to set the wait time shift register
b. We pass through our Start Time; we don’t need to set or change it here

6. Program the Read case by creating code for the following indicators
a. Done – True if Elapsed Time is greater than or equal to Wait Time

70
Exercise Manual Lucid LabVIEW Fundamentals I © Sixclear, llc.

b. Time Left String –the time left is the Wait Time minus the time that has elapsed
rounded to the nearest integer, and then converted to a string
c. Use the Round Toward + Infinity and Number to Decimal String functions

7. The error in and error out clusters are just to control dataflow on the calling VI, so leave
them unwired

8. Go to the Front Panel and test the timer VI

71
Exercise Manual Lucid LabVIEW Fundamentals I © Sixclear, llc.

9. To complete our Timer Functional Global.vi we just create the connector page and icon

LabVIEW Toaster.vi
10. Open a new VI and save it as LabVIEW Toaster.vi

On the front panel:


11. Create the front panel as shown in the User Interface section.
a. You can steal the image from the solution if you like
b. Status is a string indicator
c. Right-click on the Square LED Overheated Boolean and change the ON and OFF
color of the Boolean to bright red when on and dim red when off

On the block diagram:


12. Create an Enum constant with our desired states
a. Idle
b. Start Toasting
c. Toasting
d. Popup Toast
e. Start Cooling
f. Cooling

72
Exercise Manual Lucid LabVIEW Fundamentals I © Sixclear, llc.

13. Create a state machine using a While Loop, Enum, Shift Register, and a Case Structure.
Notice we also add some loop timing and wire our Stop button.

14. Program the Idle state


a. The Toast button will drive the Idle to Start Toasting state transition

73
Exercise Manual Lucid LabVIEW Fundamentals I © Sixclear, llc.

15. Program the Start Toasting state


a. This will Set the timer, then Start the timer, and transition immediately to the
Toasting state

16. The Toasting state will read the timer and check the temperature. The next state will
remain the Toasting state while the timer has not yet elapsed and the toaster has not
overheated. When the timer is Done, it will transition to the Popup Toast state. If the
toaster overheats it will go to the Start Cooling state and turn on the Overheated Boolean.
a. Create another shift register to hold the state of the Overheated Boolean, go back
and wire the value from the left to the right shift register in the Start Toasting state,
but wire a value of False to the right shift register in the Idle state to turn off the
Boolean when the toaster has finished cooling

b. The Temperature Simulator VI can be found in your Exercises directory and


simulates a varying temperature

74
Exercise Manual Lucid LabVIEW Fundamentals I © Sixclear, llc.

Notice the user of the Concatenate String function here

17. Program the Popup Toast state


a. This will popup an alert box indicating “The toast is ready!” and then immediately
transition to the Start Cooling state.

18. Program the Start Cooling state

75
Exercise Manual Lucid LabVIEW Fundamentals I © Sixclear, llc.

a. This state (much like the Start Toasting state) will Set the timer, then Start the
timer, and transition immediately to the Cooling state

19. Program the Cooling state


a. This will first read the timer. The next state will be the Cooling state until the timer
is Done. When the timer is Done, it will transition to the Idle state.

20. Run LabVIEW Toaster.vi and ensure it meets the requirements

76
Exercise Manual Lucid LabVIEW Fundamentals I © Sixclear, llc.

a. Run it a few times to ensure that the toaster occasionally overheats and responds
appropriately

END OF EXERCISE

77

You might also like