LOGICAL FUNCTIONS

14.2.1 Comparison of Values

[an error occurred while processing this directive]

Comparison functions are shown in Figure 14.15 Comparison Functions. Previous function blocks were outputs, these replace input contacts. The example shows an EQU (equal) function that compares two floating point numbers. If the numbers are equal, the output bit light is true, otherwise it is false. Other types of equality functions are also listed.

 

Figure 14.15 Comparison Functions

The example in Figure 14.16 Comparison Function Examples shows the six basic comparison functions. To the right of the figure are examples of the comparison operations.

 

Figure 14.16 Comparison Function Examples

The ladder logic in Figure 14.16 Comparison Function Examples is recreated in Figure 14.17 Equivalent Statements Using CMP Statements with the CMP function that allows text expressions.

 

Figure 14.17 Equivalent Statements Using CMP Statements

Expressions can also be used to do more complex comparisons, as shown in Figure 14.18 A More Complex Comparison Expression. The expression will determine if B is between A and C.

 

Figure 14.18 A More Complex Comparison Expression

The LIM and MEQ functions are shown in Figure 14.19 Complex Comparison Functions. The first three functions will compare a test value to high and low limits. If the high limit is above the low limit and the test value is between or equal to one limit, then it will be true. If the low limit is above the high limit then the function is only true for test values outside the range. The masked equal will compare the bits of two numbers, but only those bits that are true in the mask.

 

Figure 14.19 Complex Comparison Functions

Figure 14.20 A Number Line for the LIM Function shows a numberline that helps determine when the LIM function will be true.

 

Figure 14.20 A Number Line for the LIM Function

File to file comparisons are also permitted using the FSC instruction shown in Figure 14.21 File Comparison Using Expressions. The instruction uses the control word c_0. It will interpret the expression 10 times, doing two comparisons per logic scan (the Mode is 2). The comparisons will be f[10]<f[0], f[11]<f[0] then f[12]<f[0], f[13]<f[0] then f[14]<f[0], f[15]<f[0] then f[16]<f[0], f[17]<f[0] then f[18]<f[0], f[19]<f[0]. The function will continue until a false statement is found, or the comparison completes. If the comparison completes with no false statements the output A will then be true. The mode could have also been All to execute all the comparisons in one scan, or Increment to update when the input to the function is true - in this case the input is a plain wire, so it will always be true.

 

Figure 14.21 File Comparison Using Expressions

14.2.2 Boolean Functions

[an error occurred while processing this directive]

Figure 14.22 Boolean Functions shows Boolean algebra functions. The function shown will obtain data words from bit memory, perform an and operation, and store the results in a new location in bit memory. These functions are all oriented to word level operations. The ability to perform Boolean operations allows logical operations on more than a single bit.

 

Figure 14.22 Boolean Functions

The use of the Boolean functions is shown in Figure 14.23 Boolean Function Example. The first three functions require two arguments, while the last function only requires one. The AND function will only turn on bits in the result that are true in both of the source words. The OR function will turn on a bit in the result word if either of the source word bits is on. The XOR function will only turn on a bit in the result word if the bit is on in only one of the source words. The NOT function reverses all of the bits in the source word.

 

Figure 14.23 Boolean Function Example

[an error occurred while processing this directive]