File Arithmetic and Logic (FAL)

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
Ladder_FAL_v1
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
Format
Description
Control
CONTROL
Tag
Control structure for the operation
Length
DINT
Immediate
This represents the CONTROL structure .LEN
Position
DINT
Immediate
This represents the CONTROL structure .POS
Mode
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
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
LINT
USINT
UINT
UDINT
ULINT
REAL
LREAL
Tag
The value of the Expression will be stored in destination.
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.
.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.
L5K_FAL_All Mode_v31
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.
FAL_All Mode 2
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.
L5K_FAL_numerical mode_v31
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.
FAL numerical mode 2
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.
L5K_FAL_Incremental Mode_v31
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.
L5K_FAL_Incremental Mode 2_v31
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, ACS, ASN, ATN, COS, DEG, FRD, LN, LOG, RAD, SIN, SQR, TAN, TOD, TRN
3
**
4
- (negate), NOT
5
*, /, MOD
6
- (subtract), +
7
AND
8
XOR
9
OR
Affects Math Status Flags
No
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)
RSL5K_FAL Flow Chart_EnableIn is False
FAL Flow Chart (Rung-condition-out is True)
RSL5K_FAL Flow Chart EnableIn is True
FAL Flow Chart (All Mode)
AllModeFlowChart
FAL Flow Chart (Numerical Mode)
NumModeFlowChart
FAL Flow Chart (Incremental Mode)
IncModeFlowChart
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.
L5K_FAL_example 1_array_v31
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.
L5K_FAL_example 2_array_v31
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.
L5K_FAL_example 3_array_v31
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.
L5K_FAL_example 4_v31
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.
L5K_FAL_Example 5
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.
L5K_FAL_example 6_v31
Example 7:
Arithmetic operation: (element + array) to element
FTStudio-FAL-LD-EX7-V1
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.
L5K_FAL_example 7_v31
Example 8:
Arithmetic operation: (array * array) to element
FTStudio-FAL-LD-EX8-V1
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.
FAL_example 8
Provide Feedback
Have questions or feedback about this documentation? Please submit your feedback here.