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

ECE 100 Fundamentals of LabVIEW Programming

BASIC ARITHMETIC, COMPARISON AND BOOLEAN CONTROL OPERATIONS IN LABVIEW


Activity No. 2

I. INTENDED LEARNING OUTCOMES

At the end of this activity, the student shall be able to:


1. Distinguish between an Arithmetic and Comparison function.
2. Enumerate the operations under Arithmetic, Comparison and Boolean functions.
3. Create a useful VI that performs arithmetic and comparison operations in LabVIEW.

II. BACKGROUND INFORMATION

One of the fundamental LabVIEW applications is in mathematical and engineering calculations. This
platform allows the user to create a simple program using basic arithmetic functions and use the result of
these programs to evaluate a certain scenario using Boolean and comparison functions.

The basic arithmetic functions in LabVIEW include but not limited to addition, subtraction,
multiplication, division, square root, reciprocal and many more. Of course, these functions are the building
blocks of program requiring elementary and advanced calculations. Comparison operations however include,
but is not also limited to equal, less than, greater than, greater than or equal, less than or equal, equal to, not
equal to etc.

The use of arithmetic and comparison functions can be interconnected with how the results of
arithmetic functions may be evaluated. Comparison functions may be used to compare numerical values to
other numerical values such that the result of this comparison allows the program to interpret certain program
specifications. This interpretation may then be visually presented by a Boolean function such as LEDS.
Boolean LEDs may be used to visually notify the user on the numeric output and this notification interprets
something decisive or a quantity in range. However, there are Boolean functions that may be used as input.
This includes, but not limited to toggle switch, slide witch, OK, Cancel and STOP button. They may refer to
multiple states such as ON/OFF or TRUE or FALSE.
Basic Arithmetic Functions Basic Comparison Functions

III. LEARNING ACTIVITIES


Page 12
ECE 100 Fundamentals of LabVIEW Programming

ACTIVITY 2.1: BASIC ARITHMETIC OPERATIONS IN LABVIEW

1. Open LabVIEW 2012. Once the Welcome screen windows appear, click on Blank VI. The Front Panel
and Block Diagram window should appear simultaneously as shown below:

2. Create a VI on Front Panel as shown. The first three input numbers will be Numeric Controls, the next
three will be Knobs and the last four inputs will be Horizontal Pointer Slide. You can access all the controls
by Right-clicking anywhere in the Front Panel→Controls→Numeric and then select Numeric Control,
Knob and Horizontal Pointer slide. The front panel should look like as shown in the figure below:
3. Change the scale (range) of Input 4 and Input 5 Knobs. Select -100 and 100 as the minimum and maximum
range respectively. Connect the elements in the Block Diagram as shown below:

Page 13
ECE 100 Fundamentals of LabVIEW Programming

Commended on the design.

Page 14
ECE 100 Fundamentals of LabVIEW Programming

Note: To create constant on one of the inputs of the Division operation, right click on the node, choose
Create and then select Constant.

4. Click on the Run Continuously button on the Front Panel. Select desired inputs by adjusting the controls
on your desired level and confirm your calculations using manual computation. Save your VI as Act2_1_1.VI

Question: Explain how the VI works? What is the function of the given program above?

The VI adds all the values that has been entered by the user and then divides it by 10 and then displays the
sum and the average of the values. Basically, it is a calculator that computes the sum and average of the numerical
inputs.

Question: What do you notice if you use the numeric controls Inputs 1 to 3 compared with the rest of
the Input Controls?

The numerical control input 1 – 3 lets the user to input value through typing or by clicking the arrows, while
the rest of the numerical controls lets the user input value by turning or moving knobs and sliders. Numerical controls
1-3 lets the user enter value with more precision than the knobs and sliders.

Page 15
ECE 100 Fundamentals of LabVIEW Programming

5. Modify the Block Diagram of the previous VI done as shown below and click on Run Continuously button
to execute the program. Then save your VI as Act2_1_2.VI

Question: How does the modified VI work now? How do you compare the two VIs?
The modified VI now adds the values simultaneously. The modified Vi used Compound Arithmetic node
which makes compiling much faster because less process is involved while the previous VI used multiple add nodes
which involves more process and slower compilation of code.

Question: What function under Arithmetic functions has been used to get rid of multiple Add icons?
How do you find this function? (State the sequence to access this function). How does it work?
The function that was used is called the Compound Arithmetic node. You can access it by right clicking
anywhere on the block diagram and then click on numerical then select Compound Arithmetic. It works like a nested
arithmetic function which performs an operation with multiple values simultameously.

Page 16
ECE 100 Fundamentals of LabVIEW Programming

ACTIVITY 2.2: BOOLEAN CONTROL AND COMPARISON OPERATIONS IN LABVIEW

1. Open the VI Act2_1_2.VI and modify it as shown in the figure below by adding two round LEDs. To add
LEDs, Right-click anywhere in the Front Panel→Controls→Boolean→Round LED. Rename the LED
as PASSED and FAILED. Change all controls to Numeric control.

**Note: The default color of the LED shown is dark green (OFF). Once the LED lit, it will turn to light green
(ON). Change the OFF color of both LEDs to Black. This can be done by Right-clicking on
LED→Properties→Colors→Off→Choose Black. Change also the ON color of the LED labelled as
FAILED to Red.

The Front Panel must resemble the figure below:

Page 17
ECE 100 Fundamentals of LabVIEW Programming

Question: How can you change Knobs and Slide Pointers to a Numeric Control without deleting the
previously used controls?

You can change objects without deleting by right clicking on the object that you want to replace then click
replace then select the on the new object that you want to replace with.

Question: How and when can we use LEDs?


We can use LEDs by connecting it to a Boolean test node. We use LEDs to indicate the decision of a
Boolean test whether it is true or false.

2. Once the Front Panel has been modified, do the same with its corresponding Block Diagram. Do the
revision of the Block Diagram as shown below:

Page 18
ECE 100 Fundamentals of LabVIEW Programming

Page 19
ECE 100 Fundamentals of LabVIEW Programming

3. Save the VI as Act2_2_1.VI. Before running, manipulate the controls and input the following values to
Numeric control respectively:
Input 1 = 74 Input 4 = 45 Input 7 = 67 Input 10 = 71
Input 2 = 77 Input 5 = 69 Input 8 = 77
Input 3 = 68 Input 6 = 70 Input 9 = 70

Next, Run the VI by clicking on the Run Continuously button.

Question: What happened after you run the VI with the input values indicated above were set?

The VI displayed the sum and the average and the LEDs light up according to the average that was
computed. The Passed LED lit up when the average is above 75 and Failed LED lit up when the average is less than
75.

4. Change the values of input controls as shown below: Observe the LEDs.
Input 1 = 783 Input 4 = 100 Input 7 = 83 Input 10 = 92
Input 2 = 77 Input 5 = 69 Input 8 = 77
Input 3 = 95 Input 6 = 95 Input 9 = 100

Page 20
ECE 100 Fundamentals of LabVIEW Programming

Question: How does the entire VI work?

First, the user enters 10 values and then the Compound Arithmetic node adds them together, after the sum
was computed, the indicator displays the computed sum. The sum also is divided by 10 to get the average and is
displayed by the indicator. The computed average is now tested if it is greater than or less than 75, if the average is
greater than 75, the “Passed” labeled LED lights up, otherwise, the “Failed” labeled LED lights up.

Page 21
ECE 100 Fundamentals of LabVIEW Programming

V. ASSESSMENT TASKS

1. When you right-click on an empty space in a block diagram window, and choose
Programming→Numeric, what are the objects do you see as you browse on the given sequence? State
the functions of the objects you see.
Why did you use different font style?

Absolute Returns the absolute value of the input.


Value

Add Computes the sum of the inputs.

Add Array Returns the sum of all the elements in numeric array.
Elements

Compound Performs arithmetic on one or more numeric, array, cluster, or Boolean inputs.
Arithmetic To select the operation (Add, Multiply, AND, OR, or XOR), right-click the function and
select Change Mode from the shortcut menu. When you select this function from the
Numeric palette, the default mode is Add. When you select this function from
the Boolean
palette, the default mode is OR.
DBL Use the DBL numeric constant to pass a double-precision, floating-point numeric value
Numeric to the block diagram. Set this value by clicking inside the constant with the Operating tool
Constant and typing a value.

Decrement Subtracts 1 from the input value.

Divide Computes the quotient of the inputs.

Enum Use the enumerated constant to create a list of string labels with corresponding integer
Constant values you can select on the block diagram.
Expression Use the Expression Node to calculate expressions that contain a single variable. The
Node following built-in functions are allowed in
formulas: abs, acos, acosh, asin, asinh, atan, atanh, ceil, cos, cosh, cot, csc,
exp, expm1, floor, getexp, getman, int, intrz, ln, lnp1, log, log2, max, min,
mod, rand, rem, sec, sign, sin, sinc, sinh, sizeOfDim, sqrt, tan, tanh.
Increment Adds 1 to the input value.

Page 22
ECE 100 Fundamentals of LabVIEW Programming

Machine Represents the round-off error for a floating-point number with a


Epsilon given precision. Use the machine epsilon constant to compare
whether two floating-point numbers are equivalent.

Multiply Returns the product of the inputs.

Multiply Array Returns the product of all the elements in numeric array.
Elements If numeric array is an empty array, the function returns a value
of 1. If numeric array contains only one element, the function
returns that element.

Negate Negates the input value.

Numeric Use the numeric constant to pass a numeric value to the block
Constant diagram. Set this value by clicking inside the constant with
the Operating tool and typing a value.

Quotient & Computes the integer quotient and the remainder of the inputs. This
Remainder function rounds floor(x/y) to the nearest integer towards -inf.

Random Produces a double-precision, floating-point number between 0 and


Number (0-1) 1. The number generated is greater than or equal to 0, but less than
1. The distribution is uniform.

Reciprocal Divides 1 by the input value.

Ring Use the ring constant to create a list of value pairs you can select
Constant on the block diagram. Each value pair consists of a numeric value
and corresponding string label.

Round to Rounds the input to the nearest integer. If the value of the input is
Nearest midway between two integers, the function returns the nearest even
integer.

Round Truncates the input to the next lowest integer.


Toward -
Infinity

Round Rounds the input to the next highest integer.


Toward
+Infinity
Page 23
ECE 100 Fundamentals of LabVIEW Programming

Scale by Power Of Multiplies x by 2 raised to the power of n.


2

Sign Returns the sign of number.

Square Computes the square of the input value.

Square Root Computes the square root of the input value.

Subtract Computes the difference of the inputs.

2. When you right-click on an empty space in a block diagram window, and choose
Programming→Comparison, what are the objects do you see as you browse on the given sequence? State
the functions of the objects you see.

Comparison Compares input items you specify to determine whether values are equal,
greater than, less than, and so on.

Decimal Digit? Returns TRUE if char represents a decimal digit ranging from 0 through 9.
If char is a string, this function uses the first character in the string. If char is
a number, this function interprets it as the ASCII value of a character.
If char is a floating-point number, this function rounds to the nearest
integer. Otherwise, this function returns FALSE.

Empty Array? Returns TRUE if the input array is empty. Otherwise, this function returns
FALSE.

Empty Returns TRUE if string/path is an empty string or an empty path. Otherwise,


String/Path? this function returns FALSE. This function is also designed to work with
variants, pictures, and DSC tags.

Equal To 0? Returns TRUE if x is equal to 0. Otherwise, this function returns FALSE.

Equal? Returns TRUE if x is equal to y. Otherwise, this function returns FALSE. You
can change the comparison mode of this function.

Fixed-Point Returns TRUE if FXP includes an overflow status and FXP is the result of an
Overflow? operation that overflowed. Otherwise, this function returns FALSE.

Page 24
ECE 100 Fundamentals of LabVIEW Programming

Greater or Returns TRUE if x is greater than or equal to 0. Otherwise, this function returns
Equal To 0? FALSE.

Greater or Returns TRUE if x is greater than or equal to y. Otherwise, this function returns
Equal? FALSE. You can change the comparison mode of this function.

Greater Returns TRUE if x is greater than 0. Otherwise, this function returns FALSE.
Than 0?

Greater? Returns TRUE if x is greater than y. Otherwise, this function returns FALSE. You
can change the comparison mode of this function.

Hex Digit? Returns TRUE if char represents a hex digit ranging from 0 through 9, A through F,
or a through f. If char is a string, this function uses the first character in the string.
If char is a number, this function interprets it as the ASCII value of a character.
If char is a floating-point number, this function rounds to the nearest integer.
Otherwise, this function returns FALSE.

In Range Determines whether x falls within a range specified by the upper limit and lower
and Coerce limit inputs and optionally coerces the value to fall within the range. The function
performs the coercion only in Compare Elements mode. This function accepts
time stamp values if all inputs are time stamp values. You can change the
comparison mode of this function.

Is Path and Returns TRUE if path is any value other than <Not A Path> or an empty path.
Not Empty? Otherwise, this VI returns FALSE.

Is Value Returns TRUE if this is the first call of this VI or if the input value is different from
Changed the value when this VI was last called.

Less or Returns TRUE if x is less than or equal to 0. Otherwise, this function returns
Equal To 0? FALSE.

Less or Returns TRUE if x is less than or equal to y. Otherwise, this function returns
Equal? FALSE. You can change the comparison mode of this function.

Page 25
ECE 100 Fundamentals of LabVIEW Programming

Less Than 0? Returns TRUE if x is less than 0. Otherwise, this function returns
FALSE.

Less? Returns TRUE if x is less than y. Otherwise, this function returns


FALSE. You can change the comparison mode of this function.

Lexical Class Returns the class number for char. If char is a string, this function
uses the first character in the string. If char is a number, this
function interprets it as the ASCII value of a character.

Max & Min Compares x and y and returns the larger value at the top output
terminal and the smaller value at the bottom output terminal. This
function accepts time stamp values if all inputs are time stamp
values. If the inputs are time stamp values, the function returns the
later time at the top and the earlier time at the bottom. You
can change the comparison mode of this function.

Not A Returns TRUE if number/path/refnum is not a number (NaN), <Not


Number/Path/Refnum? a Path>, or not a refnum. Otherwise, this function returns FALSE.

Not Equal To 0? Returns TRUE if x is not equal to 0. Otherwise, this function returns
FALSE.

Not Equal? Returns TRUE if x is not equal to y. Otherwise, this function returns
FALSE. You can change the comparison mode of this function.

Octal Digit? Returns TRUE if char represents an octal digit ranging from 0
through 7. If char is a string, this function uses the first character in
the string. If char is a number, this function interprets it as the ASCII
value of a character. If char is a floating-point number, this function
rounds to the nearest integer. Otherwise, this function returns
FALSE.

Page 26
ECE 100 Fundamentals of LabVIEW Programming

Printable? Returns TRUE if char represents a printable ASCII character. If char is a string, this
function uses the first character in the string. If char is a number, this function
interprets it as the ASCII value of a character. If char is a floating-point number,
this function rounds to the nearest integer. Otherwise, this function returns
FALSE.

Select Returns the value wired to the t input or f input, depending on the value of s. If s is
TRUE, this function returns the value wired to t. If s is FALSE, this function returns
the value wired to f.

White Returns TRUE if char represents a white space character, such as Space, Tab,
Space? Newline, Carriage Return, Form Feed, or Vertical Tab. If char is a string, this
function uses the first character in the string. If char is a number, this function
interprets it as the ASCII value of a character. If char is a floating-point number,
this function rounds to the nearest integer. Otherwise, the function returns FALSE.

3. What is the function of a Boolean operator? Why do we consider LEDs as Boolean components?

Boolean operators test a statement whether it is true or false. We consider LEDs as Boolean components
because they serve as an indicator of what the Boolean operators decide. True or False statements reflect on the
LED because it only accepts 2 data: ‘true or false’ or ‘1 or 0’. They interpret True or 1 as ‘ON’ and False or 0 as
‘OFF’.

4. What are the other Boolean objects? State their functions.


Buttons Use as a control to select a command by depressing the button.

Rockers, Use as a control to select a command by rocking, toggling, or switching


Toggles, and the object from one position to the other.
Switches
LEDs Use as an indicator to display that a condition is met. LabVIEW turns
the light ON or OFF depending on whether the condition is met.
Radio Buttons Use as a control to select a command from a list of choices.

Checkboxes (System palette only) Use as a control to select a TRUE or FALSE state,
such as when only one option is possible.

Mixed (System palette only) Use as a control to select a TRUE, FALSE, or


Checkboxes MIXED state, such as when simultaneously setting a property of
multiple objects where some are TRUE and FALSE.

Page 27
ECE 100 Fundamentals of LabVIEW Programming

5. How does arithmetic, comparison and Boolean objects may be interconnected with each other? Give some
example of programs (not those which are in this activity) that best exemplify the use of the said three
functions?

An example of a scenario where Arithmetic, Comparison, and Boolean objects can be interconnected is in a
scanner that detect sick people or a thermal scanner. The thermometer scans a person to get his/her temperature.
The scanned temperature is in a numerical data which is then tested by a greater than or equal node, if the
temperature exceeds 37◦C, the LED lights turn red to inform the personnel that the scanned person is sick.

VI. CONCLUSION

In conclusion, I conclude that Arithmetic, Comparison, and Boolean objects are essentials in creating
systems in LabVIEW. It enables major parts of a system to function properly or to give accurate data. There
function makes programming in LabVIEW fun for me because it makes me think about the logic or how will I
make the system work. Understanding the uses and functions of these objects makes programming in
LabVIEW a lot easier because it helps me understand how a system works.

VII. RUBRICS FOR LABORATORY PERFORMANCE

Page 28

You might also like