Lucid LabVIEW Fundamentals I - Exercise Manual
Lucid LabVIEW Fundamentals I - Exercise Manual
Fundamentals I
Exercise Manual
Exercise Manual Lucid LabVIEW Fundamentals I © Sixclear, llc.
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.
“Wire the Numeric control Limit to the Multiply function’s top terminal on the Block
Diagram.”
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!
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
4
Exercise Manual Lucid LabVIEW Fundamentals I © Sixclear, llc.
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.
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.
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.
END OF EXERCISE
6
Exercise Manual Lucid LabVIEW Fundamentals I © Sixclear, llc.
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.
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.
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.
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
END OF EXERCISE
11
Exercise Manual Lucid LabVIEW Fundamentals I © Sixclear, llc.
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.
END OF EXERCISE
13
Exercise Manual Lucid LabVIEW Fundamentals I © Sixclear, llc.
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.
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.
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.
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.
Instructions
The following are high-level instructions to complete this exercise.
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
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.
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.
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.
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
28
Exercise Manual Lucid LabVIEW Fundamentals I © Sixclear, llc.
3. Use an Index Array function to select a floor (row), along with an Add Array
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:
END OF EXERCISE
29
Exercise Manual Lucid LabVIEW Fundamentals I © Sixclear, llc.
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
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
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.
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
32
Exercise Manual Lucid LabVIEW Fundamentals I © Sixclear, llc.
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.
END OF EXERCISE
34
Exercise Manual Lucid LabVIEW Fundamentals I © Sixclear, llc.
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
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
36
Exercise Manual Lucid LabVIEW Fundamentals I © Sixclear, llc.
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
37
Exercise Manual Lucid LabVIEW Fundamentals I © Sixclear, llc.
END OF EXERCISE
38
Exercise Manual Lucid LabVIEW Fundamentals I © Sixclear, llc.
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.
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.
1. Open a new VI and save it to the Exercises folder with the name Generate Signals.vi
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.
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
function
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
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
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
44
Exercise Manual Lucid LabVIEW Fundamentals I © Sixclear, llc.
8. Make this a subVI with Samples per Signal, Signals Array, and Signals Graph as inputs and
outputs
END OF EXERCISE
45
Exercise Manual Lucid LabVIEW Fundamentals I © Sixclear, llc.
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.
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 Generate Circles.vi
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
Build a Wrapper VI
48
Exercise Manual Lucid LabVIEW Fundamentals I © Sixclear, llc.
END OF EXERCISE
49
Exercise Manual Lucid LabVIEW Fundamentals I © Sixclear, llc.
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
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.
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
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
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.
User Interface
The desired front panel is shown below displaying two tabs in a single tab control
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
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
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
57
Exercise Manual Lucid LabVIEW Fundamentals I © Sixclear, llc.
END OF EXERCISE
58
Exercise Manual Lucid LabVIEW Fundamentals I © Sixclear, llc.
User Interface
The desired front panels are shown below
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.
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
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.
User Interface
The desired front panel is shown below.
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
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.
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:
66
Exercise Manual Lucid LabVIEW Fundamentals I © Sixclear, llc.
User Interface
The desired front panels are shown below
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
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
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
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
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
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.
73
Exercise Manual Lucid LabVIEW Fundamentals I © Sixclear, llc.
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
74
Exercise Manual Lucid LabVIEW Fundamentals I © Sixclear, llc.
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
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