Math Status Flags

Follow the guidelines in this topic for Math Status Flags.
Description
Controllers
Description
CompactLogix
5380,
CompactLogix
5480,
ControlLogix
5580,
Compact GuardLogix
5380, and
GuardLogix
5580 controllers
A set of Math Status Flags for accessing directly with instructions. These flags are only updated in ladder diagram routines, and are not tags, and flag aliases are not applicable.
CompactLogix 5370, ControlLogix 5570, Compact GuardLogix 5370, and GuardLogix 5570 controllers
A set of Math Status Flags for accessing directly with instructions. These flags are updated in all routine types, but are not tags, and flag aliases are not applicable.
Status Flags
Status Flag
Description
(For CompactLogix 5380, CompactLogix 5480, ControlLogix 5580, Compact GuardLogix 5380, and GuardLogix 5580 controllers)
Description
(For CompactLogix 5370, ControlLogix 5570, Compact GuardLogix 5370, and GuardLogix 5570 controllers)
S:FS
First scan flag
The first scan flag is set by the controller:
  • The first time a program is scanned after the controller goes to Run mode
  • The first time a program is scanned after the program is uninhibited
  • When a routine is called from an SFC Action and the step that owns that Action is first scanned.
Use the first scan flag to initialize data for use in later scans. It is also referred to as the first pass bit.
The first scan flag is set by the controller:
  • The first time a program is scanned after the controller goes to Run mode
  • The first time a program is scanned after the program is uninhibited
  • When a routine is called from an SFC Action and the Step that owns that Action is first scanned.
Use this flag to initialize data for use in later scans. It is also referred to as the first pass bit.
S:N
Negative flag
The controller sets the negative flag when the result of a math or logical operation is a negative value. Use this flag as a quick test for a negative value.
The controller sets the negative flag when the result of a math or logical operation is a negative value. Use this flag as a quick test for a negative value.
Using S:N is more efficient than using the CMP instruction.
S:Z
Zero flag
The zero flag is set by the controller when the result of a math or logical operation is zero. Use this flag as a quick test for a zero value.
The zero flag clears at the start of executing an instruction capable of setting this flag.
The controller sets the zero flag when the result of a math or logical operation is zero. Use this flag as a quick test for a zero value.
S:V
Overflow flag
The controller sets the overflow flag when:
  • The result of a math operation results in an overflow.
    For example, adding 1 to a SINT generates an overflow when the value goes from 127 through -128.
  • The destination tag is too small to hold the value.
    For example, if you try to store the value 123456 to a SINT or INT tag.
Use the overflow flag to verify the result of an operation is still in range.
If the data being stored is a string type, S:V is set if the string is too large to fit into the destination tag.
Tip:
If applicable, set S:V with an OTE or OTL instruction.
Click
Controller Properties > Advanced tab > Report Overflow Faults
to enable or disable reporting overflow faults.
If an overflow occurs while evaluating an array subscript, a minor fault is generated and a major fault is generated to indicate the index is out of range.
The controller sets the overflow flag when:
  • The result of a math operation results in an overflow.
    For example, adding 1 to a SINT generates an overflow when the value goes from 127…-128.
  • The destination tag is too small to hold the value.
    For example, if you try to store the value 123456 to a SINT or INT tag.
Use the overflow flag to check that the result of an operation is still in range.
A minor fault is generated anytime an overflow flag is set.
Tip:
If applicable,set S:V with an OTE or OTL instruction.
S:C
Carry flag
The controller sets the carry flag when the result of a math operation resulted in the generation of a carry out of the most significant bit.
Only the ADD and SUB instructions, and not the + and – operators, with integer values affect this flag.
The controller sets the carry flag when the result of a math operation resulted in the generation of a carry out of the most significant bit.
S:MINOR
Minor fault flag
The controller sets the minor fault flag when there is at least one minor program fault.
Use the minor fault tag to test if a minor fault occurred. This bit only triggers by programming faults, such as overflow. It is not triggered by a battery fault. The bit clears at the beginning of every scan.
Tip:
If applicable, explicitly set S:MINOR with an OTE or OTL instruction.
The controller sets the minor fault flag when there is at least one minor program fault.
Use the minor fault flag to test if a minor fault occurred and take appropriate action. This bit is triggered only by programming faults, such as overflow. It is not triggered by a battery fault. The bit clears at the beginning of every scan.
Tip:
If applicable, explicitly set S:MINOR with an OTE or OTL instruction.
IMPORTANT
The math status flags are set based on the stored value. Instructions that normally do not affect math status flags might appear to affect math status flags if type conversion occurs from mixed data types for the instruction parameters. The type conversion process sets the math status flags.
Expressions in Array Subscripts
Controllers
Description
CompactLogix
5380,
CompactLogix
5480,
ControlLogix
5580,
Compact GuardLogix
5380, and
GuardLogix
5580 controllers
Expressions do not set status flags based on the results of math operations. If expressions overflow:
  • A minor fault generates if the controller is configured to generate minor faults.
  • A major fault (type 4, code 20) generates because the resulting value is out of range.
CompactLogix 5370, ControlLogix 5570, Compact GuardLogix 5370, and GuardLogix 5570 controllers
Expressions set status flags based on the results of math operations. If an array subscript is an expression, the expression and the instruction could generate minor faults.
TIP:
If an array subscript is too large (out of range), a major fault (type 4, code 20) generates.
Provide Feedback
Have questions or feedback about this documentation? Please submit your feedback here.