File Arithmetic and Logic (FAL)
This instruction applies to the
Compact GuardLogix
5370 and Compact GuardLogix
5380, CompactLogix
5370, CompactLogix
5380, and CompactLogix
5480, ControlLogix
5570 and ControlLogix
5580, and GuardLogix
5570 and GuardLogix
5580 controllers.The FAL instruction performs copy, arithmetic, logic, and function operations on data stored in an array. When the rung-condition-in of the FAL instruction transitions from false to true, the expression given will be executed over the specified mode of iteration.
There are rules for allowable operators in safety applications. See Valid Operators.
Available Languages
Ladder Diagram
Function Block
This instruction is not available in function block.
Structured Text
This instruction is not available in structured text.
Operands
IMPORTANT:
Unexpected operation may occur if:
- Output tag operands are overwritten.
- Members of a structure operand are overwritten.
- Except when specified, structure operands are shared by multiple instructions.
There are data conversion rules for mixing numeric data types within an instruction. See Data Conversions.
Ladder Diagram
Operand | Data Type CompactLogix 5370, ControlLogix 5570, Compact GuardLogix 5370, and GuardLogix 5570 controllers | Data Type CompactLogix 5380, CompactLogix 5480, ControlLogix 5580, Compact GuardLogix 5380, and GuardLogix 5580 controllers | Format | Description |
---|---|---|---|---|
Control | CONTROL | CONTROL | Tag | Control structure for the operation |
Length | DINT | DINT | Immediate | This represents the CONTROL structure .LEN |
Position | DINT | DINT | Immediate | This represents the CONTROL structure .POS |
Mode | DINT | DINT | Immediate | Shows how to distribute the operation. Select INC, ALL, or enter number in the range of 1 to 2147483647 |
Expression | SINT INT DINT REAL | SINT INT DINT LINT USINT UINT UDINT ULINT REAL LREAL | Immediate Tag | An expression consisting of tags and/or immediate values separated by operators. |
Destination | SINT INT DINT REAL | SINT INT DINT LINT USINT UINT UDINT ULINT REAL LREAL | Tag | The value of the Expression will be stored in destination. |
Length and Position (corresponding to .LEN and .POS in the control tag) are pseudo-operands. For details, see Pseudo-operand initialization.
CONTROL Structure
Mnemonic | Data Type | Description |
---|---|---|
.EN | BOOL | The enable bit indicates the FAL instruction is enabled. |
.DN | BOOL | The done bit is set when the instruction has operated on the last element (.POS = .LEN). |
.ER | BOOL | When an overflow occurs, both platforms will set .ER and sop executing the instruction. The following controllers will generate an overflow:
|
.LEN | DINT | The length specifies the number of elements in the array on which the FAL instruction operates. |
.POS | DINT | The position is initialized to 0 when the instruction starts and is incremented each time the loop operates. |
The value of the expression is stored in the specified destination tag. When an overflow occurs, it will set the ER bit and stop the execution. Once FAL completes all of the configured iterations, the .DN bit will be set.
Select Mode of Operation
For FAL instructions, the mode tells the controller how to distribute the array operation.
If: | Select this mode: |
---|---|
Operating on all of the specified elements in an array before continuing to the next instruction. | All |
Distributing array operation over a number of scans. Enter the number of elements to operate on per scan (1-2147483647). | Numerical |
Manipulating one element of the array each time the EnableIn goes from false to true. | Incremental |
All Mode
In All Mode, the instruction operates on all the specified elements of the array before continuing to the next instruction. The operation begins when the instruction’s EnableIn goes from false to true. The position (.POS) value in the control structure points to the element in the array that the instruction is currently using. Operation stops when the .POS value equals or exceeds the .LEN value, and when overflow occurs in the expression and the .ER bit is set to true.
The following timing diagram shows the relationship between status bits and instruction operation. When the instruction execution is complete, the .DN bit is true. The .DN bit, the .EN bit, and the .POS value are cleared when the EnableIn is false. Only then can another execution of the instruction be triggered by a false-to-true transition of EnableIn.
Numerical Mode
Numerical mode distributes the array operation over a number of scans. Use this mode when working with non-time-critical data or large amounts of data. Enter the number of elements to operate on for each scan, which keeps scan time shorter.
Execution is triggered when the EnableIn goes from false to true. Once triggered, the instruction is executed each time it is scanned for the number of scans necessary to complete operating on the entire array. Once triggered, EnableIn can change repeatedly without interrupting execution of the instruction.
Avoid using the results of a file instruction operating in numerical mode until the .DN bit is set.
The following timing diagram shows the relationship between status bits and instruction operation. When the instruction execution is complete, the .DN bit is set.
If the EnableIn is true at completion, the .EN and .DN bit are true until the EnableIn goes false. When the EnableIn goes false, these bits are cleared and the .POS value is cleared.
If the EnableIn is false at completion, the .EN bit is cleared immediately. One scan after the .EN bit is cleared, the .DN bit and the .POS value are cleared.
Incremental Mode
Incremental mode manipulates one element of the array each time the instruction’s EnableIn goes from false to true.
The following timing diagram shows the relationship between status bits and instruction operation. Execution occurs only in a scan in which the EnableIn goes from false to true. Each time this occurs, only one element of the array is manipulated. If the EnableIn remains true for more than one scan, the instruction only executes during the first scan.
The .EN bit is set when EnableIn is true. The .DN bit is set when the last element in the array has been manipulated. When the last element has been manipulated and the EnableIn goes false, the .EN bit, the .DN bit, and the .POS value are cleared.
The difference between incremental mode and numerical mode at a rate of one element per scan is:
Numerical mode with any number of elements per scan requires only one false-to-true transition of the EnableIn to start execution. The instruction continues to execute the specified number of elements each scan until completion regardless of the state of the EnableIn.
Incremental mode requires the EnableIn to change from false to true to manipulate one element in the array.
Format expressions
For each operator that you use in an expression, you must provide one or two operands (tags or immediate values). Use the following table to format operators and operands within an expression.
For operators that operate on: | Use this format: | Example |
---|---|---|
One operand | operator(operand) | ABS(tag) |
Two operands | operand_a operator operand_b | tag_b + 5 tag_c AND tag_d (tag_e**2) MOD (tag_f / tag_g) |
Determine the order of operation
The operations in the expression are performed by the instruction in a prescribed order, not necessarily the order they appear. The order of operation can be specified by grouping terms within parentheses, forcing the instruction to perform an operation within the parentheses ahead of other operations.
Operations of equal order are performed from left to right.
Order | Operation |
---|---|
1 | ( ) |
2 | ABS, ACOS, ASIN, ATAN, COS, DEG, BCD_TO, LN, LOG, RAD, SIN, SQRT, TAN, TO_BCD, TRUNC |
3 | ** |
4 | - (negate), NOT |
*, /, MOD | |
6 | - (subtract), + |
7 | AND |
8 | XOR |
9 | OR |
Affects Math Status Flags
Controllers | Affects Math Status Flags |
---|---|
CompactLogix 5380, CompactLogix 5480, ControlLogix 5580, Compact GuardLogix 5380, and GuardLogix 5580 controllers | No |
CompactLogix 5370, ControlLogix 5570, Compact GuardLogix 5370, and GuardLogix 5570 controllers | Yes |
Major/Minor Faults
A major fault will occur if: | Fault type | Fault code |
---|---|---|
.POS < 0 or .LEN < 0 | 4 | 21 |
See Index Through Arrays for array-indexing faults.
Execution
Ladder Diagram
Condition / State | Action Taken |
---|---|
Prescan | N/A |
Rung-condition-in is false | Set Rung-condition-out to Rung-condition-in. See FAL Flow Chart (Rung-condition-out is False) |
Rung-condition-in is true | Set Rung-condition-out to Rung-condition-in. See FAL Flow Chart (Rung-condition-out is True) |
Postscan | N/A |
FAL Flow Chart (Rung-condition-out is False)
FAL Flow Chart (Rung-condition-out is True)
FAL Flow Chart (All Mode)
FAL Flow Chart (Numerical Mode)
FAL Flow Chart (Incremental Mode)
Examples
Example 1
Array-to-array.
Ladder Diagram
When enabled, the FAL instruction copies each element of array_2 into the same position within array_1.
Example 2
Element-to-array copy.
Ladder Diagram
When enabled, the FAL instruction copies value_1 into the first 10 positions of the second dimension of array_2.
Example 3:
Array-to-element copy.
Each time the FAL instruction is enabled, it copies the current value of array_1 to value_1. The FAL instruction uses incremental mode, so only one array value is copied each time the instruction is enabled. The next time the instruction is enabled, the instruction overwrites value_1 with the next value in array_1.
Example 4:
Arithmetic operation: array / array to array
When enabled, the FAL instruction divides the value in the current position of array_2 with the value in the current position of array_3 and stores the result in the current position of array_1.
Example 5:
Arithmetic operation: array / array to array
When enabled, the FAL instruction adds value_1 and value_2 and stores the result in the current position of array_1.
Example 6:
Arithmetic operation: array + element to array
When enabled, the FAL instruction adds the value at the current position in array_1 to value_1 and stores the result in the current position in array_3. The instruction must execute 10 times for the entire array_1 and array_3 to be manipulated.
Example 7:
Arithmetic operation: (element + array) to element
Each time the FAL instruction is enabled, it adds value_1 to the current value of array_1 and stores the result in value_2. The FAL instruction uses incremental mode, so only one array value is added to value_1 each time the instruction is enabled. The next time the instruction is enabled, the instruction overwrites value_2.
Example 8:
Arithmetic operation: (array * array) to element
When enabled, the FAL instruction multiplies the current value of array_1 by the current value of array_3 and stores the result in value_1. The FAL instruction uses incremental mode, so only one pair of array values is multiplied each time the instruction is enabled. The next time the instruction is enabled, the instruction overwrites value_1.
Provide Feedback