[go: up one dir, main page]

0% found this document useful (0 votes)
13 views9 pages

Module 7 Addtional

Lesson 5 focuses on Case and Sequence Structures in LabVIEW, providing exercises to create various VIs such as calculating square roots, temperature control, timing random number generation, and using the Formula Node for complex calculations. Each exercise includes objectives, step-by-step instructions for building front panels and block diagrams, and guidelines for running the VIs. The exercises aim to enhance understanding of control structures and their applications in LabVIEW programming.

Uploaded by

I'm an idiot but
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)
13 views9 pages

Module 7 Addtional

Lesson 5 focuses on Case and Sequence Structures in LabVIEW, providing exercises to create various VIs such as calculating square roots, temperature control, timing random number generation, and using the Formula Node for complex calculations. Each exercise includes objectives, step-by-step instructions for building front panels and block diagrams, and guidelines for running the VIs. The exercises aim to enhance understanding of control structures and their applications in LabVIEW programming.

Uploaded by

I'm an idiot but
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/ 9

Lesson 5

Case and Sequence Structures

Exercises Page
5-1: Square Root VI ...................................................................................64

5-2: Temperature Control VI .....................................................................66

5-3: Time to Match VI ...............................................................................68

5-4: Formula Node VI................................................................................70

© National Instruments Corporation 63 LabVIEW Basics I CBT Exercises


LabVIEW Basics I CBT Exercises Lesson 5: Case and Sequence Structures

Exercise 5-1: Square Root VI


Objective: To use the Case structure in a VI.

Complete the following steps to build a VI that checks whether a number is


positive. If the number is positive, the VI calculates the square root of the
number. Otherwise, the VI returns an error message.

Front Panel
1. Open a blank VI and build the following front panel.

Block Diagram
2. Build the following block diagram.

a. Place the Case structure, located on the Functions»Execution


Control palette, on the block diagram. Click the decrement or
increment button to select the FALSE case.
b. Place the Greater or Equal to 0? function, located on the Functions»
Arithmetic & Comparison»Express Comparison palette, on the
block diagram. This function returns TRUE if Numeric is greater
than or equal to 0.
c. Right-click the numeric constant and select Properties from the
shortcut menu. Select the Format and Precision tab. Set Digits of
precision to 1, select Floating point notation, and click the OK
button to ensure there is no data conversion between the constant and
the numeric indicator outside the Case structure.
d. Place the One Button Dialog function, located on the Functions»
All Functions»Time & Dialog palette, on the block diagram.
This function displays a dialog box that contains the message
Error...Negative Number.

LabVIEW Basics I CD-Based Training 64 ni.com


Lesson 5: Case and Sequence Structures LabVIEW Basics I CBT Exercises

e. Right-click the message terminal of the One Button Dialog


function, select Create»Constant from the shortcut menu, type
Error...Negative Number in the constant and click the Enter
button on the toolbar or click outside the control. Refer to Lesson6,
Strings and File I/O for more information about strings.
f. Complete the diagram as shown in the previous figure.
3. Select the TRUE case of the Case structure.
Place the Square Root function, located on the Functions»Arithmetic
& Comparison»Express Numeric palette, on the block diagram. This
function returns the square root of Numeric. Wire the function as shown
in the following block diagram.

4. Save the VI as Square Root.vi in the C:\Exercises\LV Basics I


directory.

Run the VI
5. Display the front panel and run the VI.

Caution Do not run this VI continuously. Under certain circumstances, continuously


running this VI could result in an endless loop.

If Numeric is positive, the VI executes the TRUE case and returns


the square root of Numeric. If Numeric is negative, the VI executes
the FALSE case, returns –99999, and displays a dialog box with
the message Error...Negative Number.
6. Close the VI.

End of Exercise 5-1

© National Instruments Corporation 65 LabVIEW Basics I CD-Based Training


LabVIEW Basics I CBT Exercises Lesson 5: Case and Sequence Structures

Exercise 5-2: Temperature Control VI


Objective: To use the Case structure.

Complete the following steps to build a VI that detects when a temperature


is out of range. If the temperature exceeds the limit, an LED turns on and a
beep sounds.

Front Panel
1. Open the Temperature Running Average VI, which you built in Exercise
3-4.
2. Modify the front panel as follows.

3. Right-click the chart display and select Visible Items»Digital Display


from the shortcut menu to display the digital values.
4. Save the VI as Temperature Control.vi.

LabVIEW Basics I CD-Based Training 66 ni.com


Lesson 5: Case and Sequence Structures LabVIEW Basics I CBT Exercises

Block Diagram
5. Modify the block diagram as follows. The FALSE case of the Case
structure is empty.

a. Place the Greater? function located on the Functions»Arithmetic &


Comparison»Express Comparison palette. This function returns
TRUE if the temperature exceeds High Limit. Otherwise, the
function returns FALSE.
b. Place the Beep VI located on the Functions»All Functions»
Graphics & Sound»Sound palette. This VI sounds a beep if the
selector terminal of the Case structure receives TRUE.
c. (MacOS) Provide values for the Beep VI input terminals.
6. Save the VI because you will use this VI later in the course.
7. Display the front panel, enter 80 in High Limit, and run the VI.
If the VI returns a temperature greater than High Limit, Warning
turns on, the VI executes the TRUE case, and a beep sounds. If the
temperature is less than High Limit, Warning turns off, the VI executes
the FALSE case, and no beep sounds.
8. Close the VI.

End of Exercise 5-2

© National Instruments Corporation 67 LabVIEW Basics I CD-Based Training


LabVIEW Basics I CBT Exercises Lesson 5: Case and Sequence Structures

Exercise 5-3: Time to Match VI


Objective: To use the Sequence structure.

Complete the following steps to build a VI that computes the time it takes
to generate a random number that matches a number you specify.

Front Panel
1. Open the Auto Match VI, which you built in Exercise 3-1.
2. Modify the front panel as follows.

a. Change Number to Match, Current Number, and # of iterations


to I32 representation.
b. Change Time to Match to DBL representation and 3 digits
of precision.
3. Save the VI as Time to Match.vi.

LabVIEW Basics I CD-Based Training 68 ni.com


Lesson 5: Case and Sequence Structures LabVIEW Basics I CBT Exercises

Block Diagram
4. Modify the block diagram as follows.

a. Place a Stacked Sequence structure located on the Functions»All


Functions»Structures palette.
b. Right-click the structure border and select Add Frame After from
the shortcut menu to add a frame.
c. Place the Tick Count (ms) function located on the Functions»All
Functions»Time & Dialog palette. This function reads the current
value of the operating system clock and returns the value in
milliseconds.
5. Save the VI.
6. Display the front panel, enter a number in Number to Match, and run
the VI.
In frame 0, the VI executes the While Loop while Current Number
does not match Number to Match. In frame 1, the Tick Count (ms)
function reads the operating system clock. The VI subtracts the new
value from the initial time read and returns the elapsed time in seconds.

Note If Time to Match is always 0.000, the VI might be running too quickly. Either
run the VI with execution highlighting enabled or increase the numeric constant wired
to the Multiply function in frame 0 to a large value, such as 1000000.

7. Close the VI.

End of Exercise 5-3

© National Instruments Corporation 69 LabVIEW Basics I CD-Based Training


LabVIEW Basics I CBT Exercises Lesson 5: Case and Sequence Structures

Exercise 5-4: Formula Node VI


Objective: To use the Formula Node in a VI.

Complete the following steps to build a VI that uses the Formula Node
to perform a complex mathematical operation and graphs the results.

Front Panel
1. Open a blank VI and build the following front panel.

Block Diagram
1. Build the following block diagram.

a. Place the Formula Node, located on the Functions»All Functions»


Structures palette, on the block diagram.
b. Create the x input terminal by right-clicking the left border and
selecting Add Input from the shortcut menu. Type x into the box
that appears.
c. Create the y and a output terminals by right-clicking the right border
and selecting Add Output from the shortcut menu. Enter y and a,
respectively, in the boxes that appear. You must create output
terminals for temporary variables like a.

LabVIEW Basics I CD-Based Training 70 ni.com


Lesson 5: Case and Sequence Structures LabVIEW Basics I CBT Exercises

Note When you create an input or output terminal, you must use a variable name
that exactly matches the one in the equation. Variable names are case sensitive.

d. Type the following equations in the Formula Node, where ** is


the exponentiation operator. Refer to the LabVIEW Help for more
information about syntax for the Formula Node.
a = tanh(x) + cos(x);
y = a**3 + a;
e. Complete the block diagram as shown.
2. Save the VI as Formula Node Exercise.vi in the C:\Exercises\
LV Basics I directory.

Run the VI
3. Display the front panel and run the VI. The graph displays the plot
of the equation y = f(x)3 + f(x), where f(x) = tanh(x) + cos(x).
During each iteration, the VI divides the iteration terminal value
by 15.0. The quotient is wired to the Formula Node, which calculates
the function value. The VI plots the array as a graph.
4. Close the VI.

End of Exercise 5-4

© National Instruments Corporation 71 LabVIEW Basics I CD-Based Training

You might also like