CSE-471 Lab 02
CSE-471 Lab 02
CSE-471 Lab 02
MAX MARKS
Q. No. CLOs
MARK OBTAINED
1
2
3
4
5
6
7
TOTAL MARKS
PERFORMANCE OBJECTIVES:
Upon completion of this laboratory exercise, the student technicians/engineers will be able to:
1. Perform iterations in LABVIEW program using while and for programming structures.
2. Perform decision making in LABVIEW program using select function and case
structure.
3. Program time delays in LABVIEW program using various types of wait function.
4. Program shift registers for iterative calculations in LABVIEW program.
EQUIPMENT:
1 LABVIEW equipped PC
DISCUSSION:
WHILE LOOP IN LABVIEW
A while loop is a control flow statement that is used to execute a block of the sub-diagram code
repeatedly until a given Boolean condition is met. First the code within the sub-diagram, and
then the conditional terminal is evaluated. A while loop does not have a set iteration count;
thus, a while loop executes indefinitely if the condition never occurs.
START
CODE
NO
CONDITION?
YES
END
The iteration terminal is an output terminal that contains the number of completed iterations.
The iteration count always starts at zero. During the first iteration, the iteration terminal returns
0. The conditional terminal has two possible states:
Stop if True: The while loop will continue to repeat the code until a Boolean value of TRUE
is passed to the conditional terminal.
Continue if True: The while loop will continue to repeat the code until a Boolean value of
FALSE is passed to the conditional terminal.
The conditional terminal can be changed back and forth by popping-up on the terminal and selecting Stop If True
or Continue If True from the pop-up menu.
The iteration terminal in for loop is a terminal that outputs the number of times the loop has
been executed. The count starts at zero (the first iteration of the loop is Iteration Zero). This
terminal is often wired to an indicator terminal to keep track of the number of iterations. It can
also be utilized to increment data in the loop. The count terminal is where the predetermined
count is placed. Often, a control terminal or a numeric constant is wired to the count terminal to
control the number of iterations.
Based on the input it receives on the case selector terminal, the case structure chooses which
“case,” or section of code, to execute. The case selector terminal appears as a small question
mark (?) on the left side of the case structure. If the input to the case selector terminal is
changed, the section of code that is executed changes.
The case selector terminal can receive multiple data types. You can use the following data types
as inputs to the case selector terminal:
• Integers
• Boolean values
• Strings
• Enumerated type values (Enums)
A case structure with a Boolean wired to its selector terminal has a maximum of two cases; all
other data types allow two or more cases.
The Wait (ms) function forces the loop to wait for a user-specified amount
of time, in milliseconds, before running the next iteration.
It can be seen from the illustration that data enters the right shift register and is passed to the left
shift register on the next iteration of the loop.
TASK-1
NUMBER MATCHING
Write a VI that shows the number of iterations done to match a randomly generated number with
a given number. The design must observe the followings:
• The user interface should have field to take the input from 0 to 10.
• The user interface should display loop counter and generated random number.
• The loop must run till two numbers match and the counter is displayed.
• There must be a time delay of 500 ms.
PROCEDURE:
1. On the front panel place one numeric control and two numeric indicators.
2. On the block diagram insert a while loop and connect the required components as shown in
the following.
TASK-2
MAXIMUM AND MINIMUM NUMBER SEARCH
Write a VI that shows the minimum and maximum occurrences of a randomly generated number.
The design must observe the followings:
• The user interface should have field to take the input.
• The user interface should display random number, minimum and maximum values.
Make sure that display format is set to 4 digits only.
• There must be a time delay of 500 ms.
PROCEDURE:
1. On the front panel place one numeric control and three numeric indicators. The labels of
which are shown in the front panel.
2. On the block diagram insert for loop and connect the required components as shown in the
following.
TASK-3
SQUARE ROOT OF POSITIVE NUMBER
Design a VI that displays the square root of a positive number whereas for negative number it
generates a message “Enter Positive Value”. The design must observe following:
• The front panel should have one numeric control and one numeric indicator.
• Case structure must be used to handle positive and negative values.
PROCEDURE:
1. On the front panel place one numeric control and one numeric indicator. The labels of which
are shown in the front panel.
2. On the block diagram insert case structure and connect the required components as shown in
the following for both true and false cases.
REVIEW QUESTIONS
1. Using case structure design to solve quadratic equation 𝒂𝒙𝟐 + 𝒃 + 𝒄 = 𝟎
2. Design a VI that shows the occurrences of even and odd numbers by LED indicators.
FINAL CHECKLIST
All the students must make sure, before they leave the Lab:
1. Clean your equipment, materials, and work benches before you leave.
2. Return all equipment and materials to their proper storage area.
3. Submit your lab report and answers to the questions, together with your data, calculations (if any) and
results before the next laboratory sessions.