CSE-471 Lab 02

Download as pdf or txt
Download as pdf or txt
You are on page 1of 12

Kingdom of Saudi Arabia

‫اﻟﻤــﻤـــــــــﻠﻜــــﺔ اﻟﻌـﺮﺑﯿﺔ اﻟﺴــــــﻌﻮدﯾﺔ‬


Royal Commission at Yanbu
Colleges & Institutes Division ‫اﻟـــــــﮭـــــــــــﯿـــــﺌﺔ اﻟﻤﻠــــــﻜـــــــﯿﺔ ﺑــﯿﻨﺒﻊ‬
‫ﻗــــﻄـــﺎع اﻟـﻜــــــــــــﻠــﯿﺎت واﻟـﻤــﻌــﺎھـﺪ‬
Yanbu University College ‫ﻛـــــﻠﯿﺔ ﯾﻨﺒﻊ اﻟﺠــــــــــــــــﺎﻣـــــــــــﻌﯿﺔ‬
Computer Science & Engineering Dept. ‫ﻗﺴﻢ ﻋﻠﻮم وھﻨﺪﺳﺔ اﻟﺤﺎﺳﺐ اﻷﻟﻲ‬
Information & Computer Technology Dept. ‫ﻗﺴﻢ ﺗﻘﻨﯿﺔ اﻟﻤﻌﻠﻮﻣﺎت واﻟﺤﺎﺳﺐ اﻵﻟﻲ‬
LAB 2

ACADEMIC YEAR 1439/1440 H (2018/2019 G), SEMESTER II (182)

MICROCOMPUTER INTERFACING &


DATA ACQUISITION
CSE471
START TIME: 8:15 AM
DATE: Tuesday, 22 January, 2019
FINISH TIME: 10:05 AM

STUDENT NAME: _________________________________________________________

STUDENT ID: SECTION: 1

FOR INSTRUCTOR USE ONLY GENERAL INSTRUCTIONS

MAX MARKS
Q. No. CLOs
MARK OBTAINED

1
2
3
4
5
6
7

TOTAL MARKS

MARKED BY: Signature:

CHECKED BY: Signature:


LAB MANUAL
LAB EXPERIMENT - 02: PROGRAMMING ITERATIONS AND CONDITIONS IN LABVIEW

PROGRAMMING ITERATIONS AND CONDITIONS IN


LABVIEW

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

CSE 471 – MICROCOMPUTER INTERFACING & DATA ACQUISITION


1
LAB MANUAL
LAB EXPERIMENT - 02: PROGRAMMING ITERATIONS AND CONDITIONS IN LABVIEW

WHILE LOOP IN LABVIEW

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.

YANBU UNIVERSITY COLLEGE


2
LAB MANUAL
LAB EXPERIMENT - 02: PROGRAMMING ITERATIONS AND CONDITIONS IN LABVIEW

FOR LOOP IN LABVIEW


A for loop is a control flow statement which executes N times a block of code. Each time
before execution, comparison is performed between N and internal counter. If they both match
program exits out of for loop otherwise the code is executed and the internal counter is
incremented.

FOR LOOP IN LABVIEW

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.

CSE 471 – MICROCOMPUTER INTERFACING & DATA ACQUISITION


3
LAB MANUAL
LAB EXPERIMENT - 02: PROGRAMMING ITERATIONS AND CONDITIONS IN LABVIEW

CASE STRUCTURE IN LABVIEW


The Case Structure is a method of executing conditional statements. The case structure is
similar to if ... then ... else statements in conventional programming languages.

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.

YANBU UNIVERSITY COLLEGE


4
LAB MANUAL
LAB EXPERIMENT - 02: PROGRAMMING ITERATIONS AND CONDITIONS IN LABVIEW

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.

SELECT FUNCTION IN LABVIEW


In simple if-then-else cases, the Select function can be used. This function returns:
• The value wired to the t terminal if the value at the s terminal is TRUE.
• The value wired to the f terminal if the value at the s terminal is FALSE.

WAIT FUNCTIONS IN LABVIEW


After creating a loop, a wait function can be placed inside of the loop to control the duration it
waits before performing the next iteration. There are two basic wait functions in LABVIEW:
Wait (ms) and Wait Until Next ms Multiple.

The Wait (ms) function forces the loop to wait for a user-specified amount
of time, in milliseconds, before running the next iteration.

The Wait Until Next ms Multiple function watches the millisecond


counter and waits for it to reach a multiple of the user-specified time, in
milliseconds, before running the next iteration of the loop. In a VI this
function can be used to synchronize different activities. For example,
multiple loops can be configured to execute at each multiple of 200 ms.

CSE 471 – MICROCOMPUTER INTERFACING & DATA ACQUISITION


5
LAB MANUAL
LAB EXPERIMENT - 02: PROGRAMMING ITERATIONS AND CONDITIONS IN LABVIEW

SHIFT REGISTERS IN LABVIEW


When programming with loops, sometimes it is needed to call data from previous iterations of
the loop. In LABVIEW, this is done using shift registers, which are similar to static variables in
text-based programming languages, to pass values from one loop iteration to the next.

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.

YANBU UNIVERSITY COLLEGE


6
LAB MANUAL
LAB EXPERIMENT - 02: PROGRAMMING ITERATIONS AND CONDITIONS IN LABVIEW

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.

Q State the purpose of increment function after the iteration terminal.

CSE 471 – MICROCOMPUTER INTERFACING & DATA ACQUISITION


7
LAB MANUAL
LAB EXPERIMENT - 02: PROGRAMMING ITERATIONS AND CONDITIONS IN LABVIEW

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.

Q Explain the algorithm shown in block diagram in your own words.

YANBU UNIVERSITY COLLEGE


8
LAB MANUAL
LAB EXPERIMENT - 02: PROGRAMMING ITERATIONS AND CONDITIONS IN LABVIEW

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.

CSE 471 – MICROCOMPUTER INTERFACING & DATA ACQUISITION


9
LAB MANUAL
LAB EXPERIMENT - 02: PROGRAMMING ITERATIONS AND CONDITIONS IN LABVIEW

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.

3. State the difference between for loop and while loop?

4. How is data transferred between the iterations of the loop?

5. How does case structure works?

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.

YANBU UNIVERSITY COLLEGE


10

You might also like