• No results found

BOOLEAN AND COMPARISON FUNCTIONS

In document Labview Engineers (Page 95-102)

LabVIEW Math Functions

1. Show context help with block diagram menu options: Help / Show ContextHelp

3.5 BOOLEAN AND COMPARISON FUNCTIONS

Some fields within engineering rarely use the Boolean functions and comparison functions, but others use them frequently. Boolean and comparison functions are both used for making decisions, but there is a difference in the expected data type of the inputs to each type of function:

• Boolean functions take Boolean values (TRUE, FALSE) as inputs and return Boolean outputs.

• Comparison functions take numeric values as inputs and return Boolean outputs.

LabVIEW provides access to the following Boolean and comparison functions in two locations: in both the Programming and Express groups:

• Functions Palette/Programming Group/Boolean Group

• Functions Palette/Programming Group/Comparison Group

• Functions Palette/Express Group/Arithmetic & Comparison Group/Express Boolean Group

• Functions Palette/Express Group/Arithmetic & Comparison Group/Express Comparison Group

LabVIEW’s Boolean functions are listed in Table 3.4, and the comparison functions are listed in Table 3.5.

E X A M P L E 3 . 7

Section 3.5 Boolean and Comparison Functions 81

Table 3.4 Boolean functions

Function Comment

And AND

Boolean To (0,1) Converts FALSE, TRUE to 0, 1 and TF data type to 116 Compound Arithmetic Performs certain math operations (Add, Multiply, AND, OR,

or XOR) on more than two values

Exclusive Or XOR

False Constant Returns FALSE

Not And NAND

Not Exclusive Or NOT XOR

Not Or NOR

Not NOT

Or OR

True Constant Returns TRUE

Table 3.5 Comparison functions

Function Comment (from LabVIEW help system)

Equal To 0? 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.

Greater Or Equal To 0?

» 0 Returns TRUE if x is greater than or equal to 0. Otherwise, this function returns FALSE.

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

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

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

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

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

Less Than 0? <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.

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. The wire is broken if the inputs are not the same data type.

Not Equal To 0? 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.

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.

C h e c k S t a t u s o f S a f e t y I n t e r l o c k S w i t c h e s b e f o r e A c t i v a t i n g M a c h i n e r y

One example of the use of Boolean functions is checking the status of two safety switches that both must be in the ON position before a piece of machinery can be started. In this example, if either switch A or switch B is in the OFF position

Figure 3.34

Safety Interlock: Equipment will not start unless both switches are ON.

Figure 3.35

When both switches are ON, it is OK to start equipment.

The block diagram for this VI is shown in Figure 3.36.

Figure 3.36

Block diagram for the safety interlock (uses an AND function).

(as in Figure 3.34), then the equipment cannot be started. But, if switch A and switch B are both ON (as in Figure 3.35), an LED indicator will be illuminated indicating that it is OK to start the equipment.

Section 3.5 Boolean and Comparison Functions 83

PRACTICE

Using Boolean values

LabVIEW provides a Select function that will perform one of two actions depending on Boolean value. The function is available in either of two groups on the Functions Palette:

Functions Palette / Express Group / Arithmetic & Comparison Group / Express Comparison Group / Select

Functions Palette / Programming Group / Comparison Group / Select

For practice using the Select function, create a VI that will display either the natural logarithm of a value, or the base 10 logarithm depending on the position of a toggle switch. The front panel is shown in Figure 3.37.

Solution

The block diagram for this problem is shown in Figure 3.38. Notice that both log-arithms are calculated, the Select function is used to determine which value is displayed. The toggle switch sends a Boolean value into the Select function.

Figure 3.37 Front panel of a VI that allows the user to select type of logarithm.

Figure 3.38

Block diagram of a VI that allows the user to select type of logarithm.

• When the switch sends a True, the upper path of the Select function is used and the natural logarithm is passed to the Result indicator.

• When the switch sends a False, the lower path of the Select function is used and the base 10 logarithm is passed to the Result indicator.

A P P L I C A T I O N

The block diagram is shown without annotations in Figure 3.42 for those who like to figure things out on their own, and with annotations in Figure 3.43.

To determine how much gasoline is left in the tank, someone will lower a measuring rod into the tank and see how much of the rod comes out wet; this is the liquid level, LL. Measuring the liquid level is easy, but determining the liquid volume is not quite so simple. If this is a task that needs to be done routinely, you can write a LabVIEW VI to easily compute liquid volume from liquid level. The front panel is shown in Figure 3.40.

R=2.5m

L=15m Figure 3.39

Underground storage tank.

Vo l u m e i n a c y l i n d r i c a l t a n k

Gasoline is often stored in underground cylindrical tanks (see Figure 3.39).

The math involved is reasonably straightforward. With variables defined as shown in Figure 3.41, the equation for liquid volume is

where

u = 2 Acos¢R - LL

R ≤

V = 1

2LR2[u - sin(u)]

Figure 3.40 Front panel of a VI to compute liquid volume in a cylindrical tank.

LL

R q

Figure 3.41

Variables used to determine liquid volume.

A P P L I C A T I O N

Section 3.5 Boolean and Comparison Functions 85

Figure 3.43

Cylindrical tank volume block diagram, annotated.

Figure 3.44

When level is below 80%

the pump stays on.

Figure 3.42

Cylindrical tank volume block diagram, without annotations.

U s i n g c o m p a r i s o n f u n c t i o n s t o c h e c k t a n k s t a t u s

An overflowing tank can be an environmental disaster. In this example comparison functions and Boolean functions are used to deactivate a tank fill pump when the liquid level in a tank exceeds a specified Alarm Level. Figures 3.44 and 3.45 illustrate how the front panel looks before and after the High Level Warning.

Figure 3.46

The block diagram for the high level warning system.

Figure 3.45

When level rises above 80%

the high level warning shuts down the pump.

The block diagram for this VI is shown in Figure 3.46.

In Figure 3.46 the Greater Than comparison function tests to see if the actual tank level is greater than the alarm level. If it is, a TRUE is sent to the High Level Warning LED, illuminating that LED.

The NOT in the Boolean wire downstream of the Greater Than turns any TRUE generated by the Greater Than into a FALSE. The AND will send a TRUE to the Pump On When Lit LED (and, presumably, power to the pump) only when the pump power switch is on AND the actual tank level is NOT greater than the alarm level.

The goal of this chapter was to introduce some of the commonly used Lab-VIEW functions and show how they can be combined into VIs. There are many, many more functions available than have been covered here. LabVIEW’s help system can assist you in becoming familiar with the functions that you might need in the future.

Section 3.6 Programming Preview: Debugging 87

In document Labview Engineers (Page 95-102)