Allen-Bradley ControlLogix, CompactLogix, SoftLogix, FlexLogix Logix5000 Controller, PowerFlex 700S Reference Manual
Logix5000 Controllers ControlLogix, CompactLogix, SoftLogix, FlexLogix, PowerFlex 700S are industrial controllers designed for a range of automation applications. They offer flexibility and scalability with various programming languages and communication protocols. These controllers can be used to control and monitor processes, machines, and systems in a variety of industries.
Advertisement
Advertisement
Reference Manual
Logix5000 Controllers General Instructions Reference Manual
Catalog Numbers 1756 ControlLogix, 1768 CompactLogix, 1769 CompactLogix, 1789 SoftLogix, 1794 FlexLogix, PowerFlex 700S with DriveLogix
Important User Information
Solid-state equipment has operational characteristics differing from those of electromechanical equipment. Safety
Guidelines for the Application, Installation and Maintenance of Solid State Controls (publication SGI-1.1
available from your local Rockwell Automation® sales office or online at http://www.rockwellautomation.com/literature/ ) describes some important differences between solid-state equipment and hard-wired electromechanical devices. Because of this difference, and also because of the wide variety of uses for solid-state equipment, all persons responsible for applying this equipment must satisfy themselves that each intended application of this equipment is acceptable.
In no event will Rockwell Automation, Inc. be responsible or liable for indirect or consequential damages resulting from the use or application of this equipment.
The examples and diagrams in this manual are included solely for illustrative purposes. Because of the many variables and requirements associated with any particular installation, Rockwell Automation, Inc. cannot assume responsibility or liability for actual use based on the examples and diagrams.
No patent liability is assumed by Rockwell Automation, Inc. with respect to use of information, circuits, equipment, or software described in this manual.
Reproduction of the contents of this manual, in whole or in part, without written permission of Rockwell Automation,
Inc., is prohibited.
Throughout this manual, when necessary, we use notes to make you aware of safety considerations.
WARNING: Identifies information about practices or circumstances that can cause an explosion in a hazardous environment, which may lead to personal injury or death, property damage, or economic loss.
ATTENTION: Identifies information about practices or circumstances that can lead to personal injury or death, property damage, or economic loss. Attentions help you identify a hazard, avoid a hazard, and recognize the consequence.
SHOCK HAZARD: Labels may be on or inside the equipment, for example, a drive or motor, to alert people that dangerous voltage may be present.
BURN HAZARD: Labels may be on or inside the equipment, for example, a drive or motor, to alert people that surfaces may reach dangerous temperatures.
IMPORTANT
Identifies information that is critical for successful application and understanding of the product.
Allen-Bradley, Rockwell Software, Rockwell Automation, RSLogix, ControlLogix, CompactLogix, SoftLogix, FlexLogix, DriveLogix, PowerFlex, Logix5000, SLC, MicroLogix, PLC-2, PLC-3, PLC-5, PhaseManager,
RSLinx, RSView, and TechConnect are trademarks of Rockwell Automation, Inc.
Trademarks not belonging to Rockwell Automation are property of their respective companies.
Summary of Changes
This manual contains new and updated information. Changes throughout this revision are marked by change bars, as shown to the right of this paragraph.
Topic
ALMD instruction operand descriptions and graphics for Relay Ladder Logic and Function Block Diagram languages
ALARM_DIGITAL structure input parameter descriptions
Shelve operands added to ALARM_DIGITAL structure output parameter descriptions
RSLinx software and alarm log data access. Replaced RSView software with FactoryTalkView software.
Relay Ladder action for Prescan condition
Structured Text and Function Block action for Prescan condition, EnableIn and Postscan condition
Corrected Relay Ladder Logix graphic with Shelved parameter
Corrected Function Block Diagram ALMD tag graphic
Analog alarm operand descriptions
ALARM_ANALOG structure input parameter descriptions
Shelve operands added to ALARM_ANALOG input parameter descriptions
Shelve operands added to ALARM_ANALOG output parameter descriptions
Relay Ladder action descriptions changed
Structured Text and Function Block action includes xShelved parameters and various other changes
Corrected RLL and FBD ALMA tag graphics
Corrected ALMD and ALMA tag graphic and Configuration tab graphics
Corrected ALMD and ALMA Messages tab graphics
Corrected ALMD and ALMA Status tab graphics
Added updated buffer alarm information
Added ProgUnshelve, OperShelve and OperSuppress elements to the Alarm Structure Elements in the Programmatically Access Alarm Information section
Corrected ALMA tag graphic
Corrected text for when an alarm is Disabled per version 21.00.00 changes, added Shelve, Suppress and Disable alarms information with state model for alarms
Updated State Alarms graphics
Controller memory use: added digital alarm memory consumption
Controller memory use: added analog alarm memory consumption
Scan execution times for analog and digital alarm instructions
CIP Generic messages
Watchdog and battery bit descriptions corrected for MajorFaultBits and MinorFaultBits
Important table added for ** operand and REALs for the CPT instruction.
Information added for ** operand for the CPT instruction.
Removed code 51 from DTOS Structured Text Fault Condition table
Removed code 51 from RTOS Structured Text Fault Condition table
Page
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
3
Summary of Changes
Notes:
4
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Table of Contents
Common Information for All Instructions . . . . . . . . . . . . . . . . . . . . . . . . . 38
Conventions and Related Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
Relay Ladder Rung Condition. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
ALARM_DIGITAL Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
State Diagrams When Acknowledgement Required . . . . . . . . . . . . . 49
State Diagrams When Acknowledgment Not Required. . . . . . . . . . 49
ALMD Alarm Acknowledge Required and Latched . . . . . . . . . . . . . 51
ALMD Alarm Acknowledge Required and Not Latched. . . . . . . . . 52
ALMD Alarm Acknowledge Not Required and Latched. . . . . . . . . 52
ALMD Alarm Acknowledge Not Required and Not Latched . . . . 53
ALARM_ANALOG Structure. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
State Diagrams When Acknowledgement Required . . . . . . . . . . . . . 64
State Diagrams When Acknowledgement Not Required. . . . . . . . . 65
ALMA Level Condition Acknowledge Required . . . . . . . . . . . . . . . . 67
ALMA Level Condition Acknowledge Not Required. . . . . . . . . . . . 68
ALMA Rate of Change Acknowledge Required . . . . . . . . . . . . . . . . 69
ALMA Rate of Change Acknowledge Not Required . . . . . . . . . . . . 70
Multiple Language Versions of Alarm Messages . . . . . . . . . . . . . . . . . 76
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
5
Table of Contents
6
(XIC, XIO, OTE, OTL, OTU, ONS, OSR,
Programmatically Access Alarm Information . . . . . . . . . . . . . . . . . . . . . . . 78
Controller-based Alarm Execution. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Table of Contents
Timer and Counter Instructions
(TON, TOF, RTO, TONR, TOFR, RTOR,
One Shot Rising with Input (OSRI) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
FBD_ONESHOT Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
One Shot Falling with Input (OSFI). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112
FBD_ONESHOT Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112
Timer On Delay with Reset (TONR). . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128
FBD_TIMER Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128
Function Block Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131
Timer Off Delay with Reset (TOFR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132
Function Block Operands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132
FBD_TIMER Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132
Retentive Timer On with Reset (RTOR) . . . . . . . . . . . . . . . . . . . . . . . . . 136
Function Block Operands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136
FBD_TIMER Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136
COUNTER Structure. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
7
Table of Contents
8
COUNTER Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144
Count Up/Down (CTUD) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148
FBD_COUNTER Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148
PLC and SLC Error Codes (.ERR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164
Block-transfer Error Codes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166
Specify This Data for a Logix5000 Controller as a Target Device 168
Specify CIP Data Table Read and Write Messages . . . . . . . . . . . . . . 168
Reconfigure an I/O Module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169
Specify CIP Generic Messages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171
Specify Block-transfer Messages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176
Specify the Communication Details. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179
System Protocol Tab Configuration. . . . . . . . . . . . . . . . . . . . . . . . . . . 183
Specify a Communication Method or Module Address . . . . . . . . . 185
Get System Value (GSV) and Set System Value (SSV) . . . . . . . . . . . . . . 188
AddOnInstructionDefinition Attributes . . . . . . . . . . . . . . . . . . . . . . 192
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Table of Contents
(CMP, EQU, GEQ, GRT, LEQ, LES, LIM,
ControllerDevice Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 194
WallClockTime Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205
GSV/SSV Programming Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 206
Set Enable And Disable Flags . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207
Determine the Order of Operation . . . . . . . . . . . . . . . . . . . . . . . . . . . 218
Use Strings in an Expression. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 219
FBD_COMPARE Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
9
Table of Contents
10
Greater Than or Equal To (GEQ) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 224
FBD_COMPARE Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 225
FBD_COMPARE Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 229
FBD_COMPARE Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233
FBD_COMPARE Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 237
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Table of Contents
FBD_LIMIT Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 241
FBD_MASK_EQUAL Structure. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 247
Entering an Immediate Mask Value . . . . . . . . . . . . . . . . . . . . . . . . . . . 247
FBD_COMPARE Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 252
(CPT, ADD, SUB, MUL, DIV, MOD, SQR,
Determine the Order of Operation . . . . . . . . . . . . . . . . . . . . . . . . . . . 260
FBD_MATH Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 262
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
11
Table of Contents
12
FBD_MATH Structure. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 266
FBD_MATH Structure. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 269
FBD_MATH Structure. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 272
FBD_MATH Structure. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 277
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Table of Contents
(MOV, MVM, BTD, MVMT, BTDT, CLR,
SWPB, AND, OR, XOR, NOT, BAND,
FBD_MATH_ADVANCED Structure . . . . . . . . . . . . . . . . . . . . . . 280
FBD_MATH Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 283
FBD_MATH_ADVANCED Structure . . . . . . . . . . . . . . . . . . . . . . 286
Enter an Immediate Mask Value . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 294
Masked Move with Target (MVMT) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 296
FBD_MASKED_MOVE Structure. . . . . . . . . . . . . . . . . . . . . . . . . . . 296
Enter an Immediate Mask Value by Using an Input Reference. . . 297
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
13
Table of Contents
14
Bit Field Distribute with Target (BTDT) . . . . . . . . . . . . . . . . . . . . . . . . . 302
FBD_BIT_FIELD_DISTRIBUTE Structure. . . . . . . . . . . . . . . . . . 303
FBD_LOGICAL Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 313
FBD_LOGICAL Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 317
FBD_LOGICAL Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 321
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Table of Contents
Array (file)/Misc. Instructions
(FAL, FSC, COP, CPS, FLL, AVE, SRT,
FBD_LOGICAL Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 325
FBD_BOOLEAN_AND Structure. . . . . . . . . . . . . . . . . . . . . . . . . . . 327
FBD_BOOLEAN_OR Structure. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 330
Boolean Exclusive OR (BXOR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 333
FBD_BOOLEAN_XOR Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . 333
FBD_BOOLEAN_NOT Structure. . . . . . . . . . . . . . . . . . . . . . . . . . . 336
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
15
Table of Contents
16
CONTROL Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 346
Determine the Order of Operation. . . . . . . . . . . . . . . . . . . . . . . . . . . . 356
CONTROL Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 357
Determine the Order of Operation. . . . . . . . . . . . . . . . . . . . . . . . . . . . 363
Use Strings in an Expression . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 364
Copy File (COP) Synchronous Copy File (CPS) . . . . . . . . . . . . . . . . . . . 365
CONTROL Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 376
CONTROL Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 380
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Array (file)/Shift Instructions
(BSL, BSR, FFL, FFU, LFL, LFU)
Table of Contents
CONTROL Structure. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 385
CONTROL Structure. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 398
CONTROL Structure. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 402
CONTROL Structure. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 407
CONTROL Structure. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 413
CONTROL Structure. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 419
CONTROL Structure. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 425
CONTROL Structure. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 432
Enter an Immediate Mask Value . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 433
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
17
Table of Contents
(JMP, LBL, JSR, RET, SBR, JXR, TND,
MCR, UID, UIE, AFI, NOP, EOT, SFP,
18
Enter an Immediate Mask Value . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 437
Resetting the Position of SQO . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 439
CONTROL Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 440
Subroutine (SBR) Return (RET) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 449
Relay Ladder and Structured Text. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 454
EXT_ROUTINE_CONTROL Structure. . . . . . . . . . . . . . . . . . . . . 460
User Interrupt Disable (UID) User Interrupt Enable (UIE). . . . . . . . . 466
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
(FOR, FOR...DO, BRK, EXIT, RET)
Table of Contents
COMPARE Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 490
COMPARE Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 497
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
19
Table of Contents
Enter an Immediate Mask Value . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 504
Proportional Integral Derivative (PID). . . . . . . . . . . . . . . . . . . . . . . . . . . . 507
Anti-reset Windup and Bumpless Transfer from Manual to Auto 516
Feedforward or Output Biasing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 523
PID Process with Master/Slave Loops . . . . . . . . . . . . . . . . . . . . . . . . . 526
(SIN, COS, TAN, ASN, ASIN, ACS, ACOS,
FBD_MATH_ADVANCED Structure. . . . . . . . . . . . . . . . . . . . . . . 528
20
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Table of Contents
FBD_MATH_ADVANCED Structure . . . . . . . . . . . . . . . . . . . . . . 531
FBD_MATH_ADVANCED Structure . . . . . . . . . . . . . . . . . . . . . . 534
FBD_MATH_ADVANCED Structure . . . . . . . . . . . . . . . . . . . . . . 537
FBD_MATH_ADVANCED Structure . . . . . . . . . . . . . . . . . . . . . . 540
FBD_MATH_ADVANCED Structure . . . . . . . . . . . . . . . . . . . . . . 544
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
21
Table of Contents
(DEG, RAD, TOD, FRD, TRN, TRUNC)
FBD_MATH_ADVANCED Structure. . . . . . . . . . . . . . . . . . . . . . . 548
FBD_MATH_ADVANCED Structure. . . . . . . . . . . . . . . . . . . . . . . 551
FBD_MATH Structure. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 555
FBD_MATH_ADVANCED Structure. . . . . . . . . . . . . . . . . . . . . . . 561
22
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Table of Contents
FBD_MATH_ADVANCED Structure . . . . . . . . . . . . . . . . . . . . . . 564
FBD_CONVERT Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 566
FBD_CONVERT Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 569
FBD_TRUNCATE Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 571
ASCII Serial Port Instructions
(ABL, ACB, ACL, AHL, ARD, ARL, AWA,
ASCII Test For Buffer Line (ABL) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 579
SERIAL_PORT_CONTROL Structure. . . . . . . . . . . . . . . . . . . . . . 579
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
23
Table of Contents
24
SERIAL_PORT_CONTROL Structure . . . . . . . . . . . . . . . . . . . . . . 582
ASCII Handshake Lines (AHL) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 586
SERIAL_PORT_CONTROL Structure . . . . . . . . . . . . . . . . . . . . . . 587
SERIAL_PORT_CONTROL Structure . . . . . . . . . . . . . . . . . . . . . . 591
SERIAL_PORT_CONTROL Structure . . . . . . . . . . . . . . . . . . . . . . 595
ASCII Write Append (AWA). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 598
SERIAL_PORT_CONTROL Structure . . . . . . . . . . . . . . . . . . . . . . 599
SERIAL_PORT_CONTROL Structure . . . . . . . . . . . . . . . . . . . . . . 603
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Table of Contents
(CONCAT, DELETE, FIND, INSERT, MID)
String Concatenate (CONCAT). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 610
(STOD, STOR, DTOS, RTOS, UPPER,
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
25
Table of Contents
26
Expressions in Array Subscripts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 645
Guidelines for Floating-point Math Operations . . . . . . . . . . . . . . . . 646
LINT Data Type Considerations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 649
SINT or INT to DINT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 649
DINT to SINT or INT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 651
Resolve Data Flow between Two Blocks . . . . . . . . . . . . . . . . . . . . . . . 658
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Table of Contents
Function Block Responses to Overflow Conditions . . . . . . . . . . . . . . . . 659
Common Instruction Parameters for Timing Modes . . . . . . . . . . . 660
Overview of Timing Modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 663
Specify a Non-retentive Assignment . . . . . . . . . . . . . . . . . . . . . . . . . . 671
Assign an ASCII Character to a String . . . . . . . . . . . . . . . . . . . . . . . . 672
Use Arithmetic Operators and Functions. . . . . . . . . . . . . . . . . . . . . . 674
Use Relational Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 675
Determine the Order of Execution. . . . . . . . . . . . . . . . . . . . . . . . . . . . 678
Some Key Words are Reserved. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 680
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
27
Table of Contents
Notes:
28
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Instruction Locator
Where to Find an Instruction
Use this locator to find the reference details about Logix instructions (the grayed-out instructions are available in other manuals). This locator also lists which programming languages are available for the instructions.
If the locator lists
A page number
Coordinate
Motion
PhaseManager™
Process control
The instruction is documented in
This manual
Motion Coordinate System User Manual, publication MOTION-UM002
Logix5000 Controllers Motion Instructions Reference Manual, publication MOTION-RM002
PhaseManager User Manual, publication LOGIX-UM001
Logix5000 Controllers Process Control and Drives Instructions Reference Manual, publication 1756-RM006
Instruction
ABL
ASCII Test For Buffer Line
ABS
Absolute Value
Location
ACB
ASCII Chars in Buffer
ACL
ASCII Clear Buffer
ACS
Arc Cosine
ADD
Add
Languages
Relay ladder
Structured text
Relay ladder
Structured text
Function block
Relay ladder
Structured text
Relay ladder
Structured text
Relay ladder
Structured text
Function block
Relay ladder
Structured text
Function block
Relay ladder AFI
Always False Instruction
AHL
ASCII Handshake Lines
ALM
Alarm
ALMA
Analog Alarm
ALMD
Digital Alarm
AND
Bitwise AND
Process control
Relay ladder
Structured text
Structured text
Function block
Relay ladder
Structured text
Function block
Relay ladder
Structured text
Function block
Relay ladder
Structured text
Function block
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
29
Instruction Locator
Instruction
ARD
ASCII Read
ARL
ASCII Read Line
ASN
Arc Sine
Location
ATN
Arc Tangent
AVE
File Average
AWA
ASCII Write Append
AWT
ASCII Write
BAND
Boolean AND
BNOT
Boolean NOT
BOR
Boolean OR
BPT
Breakpoints
BRK
Break
BSL
Bit Shift Left
BSR
Bit Shift Right
BTD
Bit Field Distribute
BTDT
Bit Field Distribute with Target
BTR
Message
BTW
Message
BXOR
Boolean Exclusive OR
CC
Coordinated Control
CLR
Clear
Process control
30
DELETE
String Delete
DERV
Derivative
DFF
D Flip-Flop
DIV
Divide
DTOS
DINT to String
DTR
Data Transitional
EOT
End of Transition
Instruction
CMP
Compare
CONCAT
String Concatenate
COP
Copy File
COS
Cosine
CPS
Synchronous Copy File
CPT
Compute
CTD
Count Down
CTU
Count Up
CTUD
Count Up/Down
D2SD
Discrete 2-State Device
D3SD
Discrete 3-State Device
DDT
Diagnostic Detect
DEDT
Deadtime
DEG
Degrees
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Relay ladder
Relay ladder
Relay ladder
Relay ladder
Structured text
Function block
Relay ladder
Structured text
Relay ladder
Structured text
Structured text
Function block
Structured text
Function block
Relay ladder
Structured text
Languages
Relay ladder
Structured text
Relay ladder
Structured text
Relay ladder
Structured text
Function block
Relay ladder
Structured text
Function block
Relay ladder
Relay ladder
Structured text
Relay ladder
Structured text
Structured text
Function block
Structured text
Function block
Structured text
Function block
Relay ladder
Location
Process control
Process control
Process control
Process control
Process control
Languages
Relay ladder
Relay ladder
Structured text
Relay ladder
Structured text
Relay ladder
Structured text
Function block
Relay Ladder
Structured text
Relay ladder
Relay ladder
Relay ladder
Structured text
Function block
Structured text
Function block
Structured text
Function block
Relay ladder
Structured text
Function block
Relay ladder
Structured text
Function block
Relay ladder
Structured text
Structured text
Function block
Structured text
Function block
Relay ladder
Structured text
Function block
Relay ladder
Structured text
Relay ladder
Relay ladder
Structured text
Instruction Locator
Instruction
EQU
Equal to
ESEL
Enhanced Select
EVENT
Trigger Event Task
FAL
File Arithmetic and Logic
FBC
File Bit Comparison
FFL
FIFO Load
FFU
FIFO Unload
FGEN
Function Generator
FIND
Find String
FLL
File Fill
FOR
For
FRD
Convert to Integer
FSC
File Search and Compare
GEQ
Greater than or Equal to
GRT
Greater Than
GSV
Get System Value
HLL
High/Low Limit
HPF
High Pass Filter
ICON
Input Wire Connector
IMC
Internal Model Control
INSERT
Insert String
Location
Process control
Process control
Process control
Process control
Process control
Relay ladder
Structured text
Function block
Relay ladder
Structured text
Relay ladder
Relay ladder
Relay ladder
Function block
Relay ladder
Relay ladder
Structured text
Function block
Relay ladder
Structured text
Function block
Relay ladder
Structured text
Structured text
Function block
Structured text
Function block
Function block
Structured text
Function block
Relay ladder
Structured text
Languages
Relay ladder
Structured text
Function block
Structured text
Function block
Relay ladder
Structured text
Relay ladder
Relay ladder
Relay ladder
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Process control
Motion
Process control
Process control
Location
Process control
Process control
LFL
LIFO Load
LFU
LIFO Unload
LIM
Limit
LN
Natural Log
LOG
Log Base 10
Instruction
INTG
Integrator
IOT
Immediate Output
IREF
Input Reference
JKFF
JK Flip-Flop
JMP
Jump to Label
JSR
Jump to Subroutine
JXR
Jump to External Routine
LBL
Label
LDL2
Second-Order Lead Lag
LDLG
Lead-Lag
LEQ
Less Than or Equal to
LES
Less Than
LOWER
Lower Case
LPF
Low Pass Filter
MAAT
Motion Apply Axis Tuning
Structured text
Function block
Structured text
Function block
Relay ladder
Structured text
Function block
Relay ladder
Structured text
Function block
Relay ladder
Relay ladder
Relay ladder
Function block
Relay ladder
Structured text
Function block
Relay ladder
Structured text
Function block
Relay ladder
Structured text
Structured text
Function block
Relay ladder
Structured text
Languages
Structured text
Function block
Relay ladder
Structured text
Function block
Structured text
Function block
Relay ladder
Relay ladder
Structured text
Function block
Relay ladder
Relay ladder
31
Instruction Locator
Instruction
MAFR
Motion Axis Fault Reset
MAG
Motion Axis Gear
MAHD
Motion Apply Hookup Diagnostics
MAH
Motion Axis Home
MAJ
Motion Axis Jog
MAM
Motion Axis Move
MAOC
Motion Arm Output Cam
MAPC
Motion Axis Position Cam
MAR
Motion Arm Registration
MASD
Motion Axis Shutdown
MAS
Motion Axis Stop
MASR
Motion Axis Shutdown Reset
MATC
Motion Axis Time Cam
MAVE
Moving Average
MAW
Motion Arm Watch
MAXC
Maximum Capture
MCCD
Motion Coordinated Change
Dynamics
MCCM
Motion Coordinated Circular Move
MCCP
Motion Calculate Cam Profile
MCD
Motion Change Dynamics
MCLM
Motion Coordinated Linear Move
MCR
Master Control Reset
Location
Motion
Motion
Motion
Motion
Motion
Motion
Motion
Motion
Motion
Motion
Motion
Motion
Motion
Process control
Motion
Process control
Coordinate
Coordinate
Motion
Motion
Coordinate
32
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Languages
Relay ladder
Structured text
Relay ladder
Structured text
Relay ladder
Structured text
Relay ladder
Structured text
Relay ladder
Structured text
Structured text
Function block
Relay ladder
Structured text
Structured text
Function Block
Relay ladder
Structured text
Relay ladder
Structured text
Relay ladder
Structured text
Relay ladder
Structured text
Relay ladder
Structured text
Relay ladder
Structured text
Relay ladder
Structured text
Relay ladder
Structured text
Relay ladder
Structured text
Relay ladder
Structured text
Relay ladder
Structured text
Relay ladder
Structured text
Relay ladder
Structured text
Relay ladder
Instruction
MCSD
Motion Coordinated Shutdown
MCS
Motion Coordinated Stop
MCSR
Motion Coordinated Shutdown
Reset
MCT
Motion Coordinated Transform
Location
Coordinate
Coordinate
Coordinate
Coordinate
MCTP
Motion Calculate Transform
Position
MDAC
Motion Master Driven Axis Control
Coordinate
Motion
MDCC
Motion Master Driven Coordinated
Control
Motion
Motion MDF
Motion Direct Drive Off
MDOC
Motion Disarm Output Cam
Motion
Motion MDO
Motion Direct Drive On
MDR
Motion Disarm Registration
MDW
Motion Disarm Watch
MEQ
Mask Equal to
Motion
Motion
MGSD
Motion Group Shutdown
MGS
Motion Group Stop
MGSP
Motion Group Strobe Position
MGSR
Motion Group Shutdown Reset
MID
Middle String
MINC
Minimum Capture
MMC
Modular Multivariable Control
Motion
Motion
Motion
Motion
Process control
Process control
Languages
Relay ladder
Structured text
Relay ladder
Structured Text
Relay ladder
Structured text
Relay ladder
Structured text
Relay ladder
Structured text
Relay ladder
Structured text
Relay ladder
Structured text
Relay ladder
Structured text
Relay ladder
Structured text
Relay ladder
Structured text
Relay ladder
Structured text
Relay ladder
Structured text
Relay ladder
Structured text
Function Block
Relay ladder
Structured text
Relay ladder
Structured text
Relay ladder
Structured text
Relay ladder
Structured text
Relay ladder
Structured text
Structured text
Function block
Structured text
Function block
Instruction Locator
Instruction
MOD
Modulo
MOV
Move
MRAT
Motion Run Axis Tuning
MRHD
Motion Run Hookup Diagnostics
MRP
Motion Redefine Position
MSF
Motion Servo Off
MSG
Message
MSO
Motion Servo On
MSTD
Moving Standard Deviation
MUL
Multiply
Motion
Motion
Motion
Motion
Motion
Process control
MUX
Multiplexer
MVM
Masked Move
MVMT
Masked Move with Target
NEG
Negate
Location
Process control
NEQ
Not Equal to
NOP
No Operation
NOT
Bitwise NOT
NTCH
Notch Filter
OCON
Output Wire Connector
ONS
One Shot
Process control
Relay ladder
Structured text
Function block
Relay ladder
Structured text
Function block
Relay ladder
Structured text
Function block
Relay ladder
Relay ladder
Structured text
Function block
Structured text
Function block
Function block
Relay ladder
Languages
Relay ladder
Structured text
Function block
Relay ladder
Relay ladder
Structured text
Relay ladder
Structured text
Relay ladder
Structured text
Relay ladder
Structured text
Relay ladder
Structured text
Relay ladder
Structured text
Structured text
Function block
Relay ladder
Structured text
Function block
Function block
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Instruction
OR
Bitwise OR
Location
OREF
Output Reference
OSFI
One Shot Falling with Input
OSF
One Shot Falling
OSRI
One Shot Rising with Input
OSR
One Shot Rising
OTE
Output Energize
OTL
Output Latch
OTU
Output Unlatch
PATT
Attach to Equipment Phase
PCLF
Equipment Phase Clear Failure
PCMD
Equipment Phase Command
PDET
Detach from Equipment Phase
PFL
Equipment Phase Failure
PIDE
Enhanced PID
PID
Proportional Integral Derivative
PI
Proportional + Integral
PMUL
Pulse Multiplier
POSP
Position Proportional
POVR
Equipment Phase Override
Command
PPD
Equipment Phase Paused
PhaseManager
PhaseManager
PhaseManager
PhaseManager
PhaseManager
Process control
Process control
Process control
Process control
PhaseManager
PhaseManager
Languages
Relay ladder
Structured text
Function block
Function block
Structured text
Function block
Relay ladder
Structured text
Function block
Relay ladder
Relay ladder
Relay ladder
Relay ladder
Relay ladder
Structured text
Relay ladder
Structured text
Relay ladder
Structured text
Relay ladder
Structured text
Relay ladder
Structured text
Structured text
Function block
Relay ladder
Structured text
Structured text
Function block
Structured text
Function block
Structured text
Function block
Relay ladder
Structured text
Relay ladder
Structured text
33
Instruction Locator
SCL
Scale
SCRV
S-Curve
SEL
Select
SETD
Set Dominant
SFP
SFC Pause
SFR
SFC Reset
SIN
Sine
Instruction Location
PRNP
Equipment Phase New Parameters
PhaseManager
PSC
Phase State Complete
PhaseManager
PXRQ
Equipment Phase External Request
PhaseManager
RAD
Radians
RESD
Reset Dominant
RES
Reset
RET
Return
RLIM
Rate Limiter
RMPS
Ramp/Soak
RTO
Retentive Timer On
RTOR
Retentive Timer On with Reset
RTOS
REAL to String
SBR
Subroutine
Process control
Process control
Process control
Process control
Process control
Process control
Process control
Relay ladder
Structured text
Function block
Structured text
Function block
Structured text
Function block
Relay ladder
Structured text
Function block
Relay ladder
Structured text
Relay ladder
Structured text
Function block
Structured text
Function block
Structured text
Function block
Function block
Languages
Relay ladder
Structured text
Relay ladder
Structured text
Relay ladder
Structured text
Relay ladder
Structured text
Function block
Structured text
Function block
Relay ladder
Structured text
Function block
Relay ladder
Structured text
Relay ladder
Structured text
Relay ladder
Structured text
Function block
34
Instruction
SIZE
Size In Elements
SNEG
Selected Negate
SOC
Second-Order Controller
SQI
Sequencer Input
SQL
Sequencer Load
SQO
Sequencer Output
SQR
Square Root
SQRT
Square Root
SRT
File Sort
SRTP
Split Range Time Proportional
SSUM
Selected Summer
SSV
Set System Value
STD
File Standard Deviation
STOD
String To DINT
STOR
String To REAL
SUB
Subtract
Location
Process control
Process control
Process control
Process control
SWPB
Swap Byte
TAN
Tangent
TND
Temporary End
TOD
Convert to BCD
TOFR
Timer Off Delay with Reset
Relay ladder
Structured text
Relay ladder
Structured text
Relay ladder
Structured text
Function block
Relay ladder
Structured text
Relay ladder
Structured text
Function block
Relay ladder
Relay ladder
Function block
Structured text
Function block
Relay ladder
Function block
Structured text
Relay ladder
Structured text
Structured text
Function block
Structured text
Function block
Relay ladder
Structured text
Relay ladder
Languages
Relay ladder
Structured text
Structured text
Function block
Structured text
Function block
Relay ladder
Relay ladder
Relay ladder
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Instruction Locator
Instruction
TOF
Timer Off Delay
TONR
Timer On Delay with Reset
TON
Timer On Delay
TOT
Totalizer
TPT
Tracepoints
TRN
Truncate
TRUNC
Truncate
UID
User Interrupt Disable
UIE
User Interrupt Enable
UPDN
Up/Down Accumulator
UPPER
Upper Case
XIC
Examine If Closed
XIO
Examine If Open
XOR
Bitwise Exclusive OR
XPY
X to the Power of Y
Process control
Location
Process control
Relay ladder
Function block
Structured text
Relay ladder
Structured text
Relay ladder
Structured text
Structured text
Function block
Relay ladder
Structured text
Relay ladder
Relay ladder
Relay ladder
Structured text
Function block
Relay ladder
Structured text
Function block
Languages
Relay ladder
Structured text
Function block
Relay ladder
Structured text
Function block
Relay ladder
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
35
Instruction Locator
Notes:
36
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Preface
Introduction
This manual provides a programmer with details about each available instruction for a Logix-based controller.
Who Should Use This Manual
You should be familiar with how the Logix-based controller stores and processes data.
Novice programmers should read all of the details about an instruction before using the instruction. Experienced programmers can refer to the instruction information to verify details.
Purpose of This Manual
This manual is one of a set of related manuals that shows common procedures for programming and operating Logix5000™ controllers. For a complete list of common procedures manuals, see the Logix5000 Controllers Common
Procedures Programming Manual, publication 1756-PM001 .
The term Logix5000 controller refers to any controller that is based on the
Logix5000 operating system, such as:
• CompactLogix™ controllers
• ControlLogix® controllers
• DriveLogix™ controllers
• FlexLogix™ controllers
• SoftLogix™5800 controllers
Table 1 - Description of Instruction Format
Section
Instruction name
Operands
Information
Identifies the instruction.
Defines whether the instruction is an input or an output instruction.
Lists all the operands of the instruction.
If available in relay ladder, describes the operands.
If available in structured text, describes the operands.
If available in function block, describes the operands.
The pins shown on a default function block are only the default pins. The operands table lists all the possible pins for a function block.
Instruction structure
Description
Arithmetic status flags
Lists control status bits and values, if any, of the instruction,
Describes the instruction’s use.
Defines any differences when the instruction is enabled and disabled, if appropriate.
Defines whether or not the instruction affects arithmetic status flags.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
37
Preface
Table 1 - Description of Instruction Format
Section
Fault conditions
Execution
Example
Information
Defines whether or not the instruction generates minor or major faults. If so, defines the fault type and code.
Defines the specifics of how the instruction operates.
Provides at least one programming example in each available programming language.
Includes a description explaining each example.
The following icons help identify language-specific information.
Icon Programming Language
Relay ladder
Structured text
Function block
Common Information for
All Instructions
The Logix5000 instruction set has some common attributes.
Information
Common attributes
Function block attributes
Appendix
defines:
• Arithmetic status flags
• Data types
• Keywords
defines:
• Program and operator control
• Timing modes
Conventions and
Related Terms
This manual uses set and clear to define the status of bits (Boolean) and values (non-Boolean).
Term
Set
Clear
Means
The bit is set to 1 (ON).
A value is set to any non-zero number.
The bit is cleared to 0 (OFF).
All the bits in a value are cleared to 0.
38
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Preface
If an operand or parameter supports more than one data type, the bold data types indicate optimal data types. An instruction executes faster and requires less memory if all the operands of the instruction use the same optimal data type, typically DINT or REAL.
Relay Ladder Rung Condition
The controller evaluates ladder instructions based on the rung condition preceding the instruction (rung-condition-in). Based on the rung-condition-in and the instruction, the controller sets the rung condition following the instruction (rung-condition-out), which in turn, affects any subsequent instruction.
Input Instruction
Output Instruction
Rungcondition-in
Rungcondition-out
If the rung-condition-in to an input instruction is true, the controller evaluates the instruction and sets the rung-condition-out based on the results of the instruction. If the instruction evaluates to true, the rung-condition-out is true; if the instruction evaluates to false, the rung-condition-out is false.
The controller also prescans instructions. Prescan is a special scan of all routines in the controller. The controller scans all main routines and subroutines during prescan, but ignores jumps that could skip the execution of instructions. The controller executes all FOR loops and subroutine calls. If a subroutine is called more than once, it is executed each time it is called. The controller uses prescan of relay ladder instructions to reset non-retentive I/O and internal values.
During prescan, input values are not current and outputs are not written. The following conditions generate prescan:
• Toggle from Program to Run mode.
• Automatically enter Run mode from a power-up condition.
Prescan does not occur for a program when the following occurs:
• The program becomes scheduled while the controller is running.
• The program is unscheduled when the controller enters Run mode.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
39
Preface
Possible Condition
Prescan
Instruction first scan
Instruction first run
Function Block States
IMPORTANT
When programming in function block, restrict the range of engineering units to +/-10
+/-15
because internal floating point calculations are done by using single precision floating point.
Engineering units outside of this range may result in a loss of accuracy if results approach the limitations of single precision floating point
(+/-10
+/-38
).
The controller evaluates function block instructions based on the state of different conditions.
Description
Prescan for function block routines is the same as for relay ladder routines. The only difference is that the Enablein parameter for each function block instruction is cleared during prescan.
Instruction first scan refers to the first time an instruction is executed after prescan. The controller uses instruction first scan to read current inputs and determine the appropriate state to be in.
Instruction first run refers to the first time the instruction executes with a new instance of a data structure. The controller uses instruction first run to generate coefficients and other data stores that do not change for a function block after initial download.
Every function block instruction also includes EnableIn and EnableOut parameters:
• Function block instructions execute normally when EnableIn is set.
• When EnableIn is cleared, the function block instruction either executes prescan logic, postscan logic, or just skips normal algorithm execution.
• EnableOut mirrors EnableIn, however, if function block execution detects an overflow condition EnableOut is also cleared.
• Function block execution resumes where it left off when EnableIn toggles from cleared to set. However, there are some function block instructions that specify special functionality, such as re-initialization, when EnableIn toggles from cleared to set. For function block instructions with time base parameters, whenever the timing mode is Oversample, the instruction always resumes were it left off when EnableIn toggles from cleared to set.
If the EnableIn parameter is not wired, the instruction always executes as normal and EnableIn remains set. If you clear EnableIn, it changes to set the next time the instruction executes.
40
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Preface
Studio 5000 Environment
The Studio 5000™ Engineering and Design Environment combines engineering and design elements into a common environment. The first element in the
Studio 5000 environment is the Logix Designer application. The Logix Designer application is the rebranding of RSLogix™ 5000 software and will continue to be the product to program Logix5000™ controllers for discrete, process, batch, motion, safety, and drive-based solutions.
Additional Resources
See these manuals and documents for more information about using motionmodules in a Logix5000 control system.
Resource
Logix5000 Controllers Common Procedures Programming Manual, publication 1756-
PM001
Motion Coordinate System User Manual, publication MOTION-UM002
Description
Provides links to a collection of programming manuals that describe how you can use procedures that are common to all Logix5000 controller projects.
Provides information to create a coordinate system by using Logix5000 motion modules.
Logix5000 Controllers Motion Instructions Reference Manual, publication MOTION-RM002 Provides a programmer with details about the motion instructions that are available for a Logix5000 controller.
PhaseManager User Manual, publication LOGIX-UM001
Logix5000 Controllers Process Control and Drives Instructions Reference Manual, publication 1756-RM006
PlantPAx Automation System Reference Manual, publication PROCES-RM001
Shows you how to set up and program a Logix5000 controller to use equipment phases.
Provides a programmer with details about each available instruction for a Logix-based controller with regard to process control and drives.
Provides information about how to set up a PlantPAx system.
You can view or download Rockwell Automation publications at http:/www.rockwellautomation.com/literature/ . To order paper copies of technical documentation, contact your local Allen-Bradley distributor or
Rockwell Automation sales representative.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
41
Preface
Notes:
42
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Chapter
1
FactoryTalk Alarms and Events
Logix-based Instructions
(ALMD, ALMA)
Topic
Configure an Alarm Instruction
Programmatically Access Alarm Information
Shelve, Suppress, or Disable Alarms
Controller-based Alarm Execution
Page
These Logix-based alarm instructions are available in relay ladder, structured text, and function block diagram. These instructions detect alarm conditions and publish alarm events that can be displayed and logged through FactoryTalkView
Alarms and Events servers.
If you want to
Detect alarms based on Boolean (true/false) conditions
Detect alarms based on the level or rate of change of a value
Use this instruction
ALMD
ALMA
Available in
Relay ladder
Structured text
Function block
Relay ladder
Structured text
Function block
Page
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
43
Chapter 1
FactoryTalk Alarms and Events Logix-based Instructions (ALMD, ALMA)
Digital Alarm (ALMD)
Operands:
The ALMD instruction detects alarms based on Boolean (true/false) conditions.
Program (Prog) and operator (Oper) control parameters provide an interface for alarm commands.
Relay Ladder
In relay ladder, the alarm condition input (In) is obtained from the rung condition.
Operand
ALMD tag
Type
ALARM_DIGITAL
Format
Structure
Description
Tag using ALMD structure.
Structured Text
ALMD(ALMD, In, ProgAck,
ProgReset, ProgDisable, ProgEnable);
The operands are the same as those for the relay ladder ALMD instruction, with one exception as indicated above.
Function Block
Operand
ALMD tag
Type
ALARM_DIGITAL
Format
Structure
Description
Tag using ALMD structure.
44
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Input Parameter
EnableIn
Data Type
BOOL
In
InFault
Condition
AckRequired
Latched
ProgAck
OperAck
ProgReset
OperReset
ProgSuppress
OperSuppress
BOOL
BOOL
BOOL
BOOL
BOOL
BOOL
BOOL
BOOL
BOOL
BOOL
BOOL
FactoryTalk Alarms and Events Logix-based Instructions (ALMD, ALMA)
Chapter 1
ALARM_DIGITAL Structure
Description
Relay Ladder
Corresponds to the rung state. Does not affect processing.
Function Block
If cleared, the instruction does not execute and outputs are not updated.
If set, the instruction executes.
Default is set.
Structured Text
No effect. The instruction always executes.
The digital signal input to the instruction.
Default is cleared.
Relay Ladder
Function Block
Follows the rung condition. Set if the rung condition is true. Cleared if the rung condition is false.
Structured Text
Copied from instruction operand.
Bad health indicator for the input. The user application may set InFault to indicate the input signal has an error. When set, the instruction sets InFaulted (Status.1). When cleared, the instruction clears InFaulted (Status .1). In either case, the instruction continues to evaluate In for alarm conditions.
Default is cleared (good health).
Specifies how alarm is activated. When Condition is set, the alarm condition is activated when In is set. When Condition is cleared, the alarm condition is activated when In is cleared.
Default is set.
Specifies whether alarm acknowledgement is required. When set, acknowledgement is required. When cleared, acknowledgement is not required and Acked is always set.
Default is set.
Specifies whether the alarm is latched. Latched alarms remain InAlarm when the alarm condition becomes false, until a
Reset command is received. When set, the alarm is latched. When cleared, the alarm is unlatched.
A latched alarm can be reset only when the alarm condition is false.
Default is cleared.
For Relay Ladder Logic, on transition from cleared to set, acknowledges alarm (if acknowledgement is required).
Default is cleared.
Relay Ladder
Copies value from the instruction operand.
Structured Text
Copies value from the instruction operand.
Set by the operator interface to acknowledge the alarm. Takes effect only if the alarm is unacknowledged. The instruction clears this parameter.
Default is cleared.
For Relay Ladder Logic, on transition from cleared to set, acknowledges alarm (if acknowledgement is required).
Default is cleared.
Relay Ladder
Copied from the instruction operand.
Structured Text
Copied from the instruction operand.
Set by the operator interface to reset the latched alarm. Takes effect only if the latched alarm is InAlarm and the alarm condition is false. The alarm instruction clears this parameter.
Default is cleared.
Set by the user program to suppress the alarm.
Default is cleared.
Set by the operator interface to suppress the alarm. The alarm instruction clears this parameter.
Default is cleared.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
45
Chapter 1
FactoryTalk Alarms and Events Logix-based Instructions (ALMD, ALMA)
Input Parameter
ProgUnsuppress
OperUnsuppress
OperShelve
ProgUnshelve
OperUnshelve
ProgDisable
OperDisable
ProgEnable
OperEnable
AlarmCountReset
UseProgTime
ProgTime
Severity
Data Type
BOOL
BOOL
BOOL
BOOL
BOOL
BOOL
BOOL
BOOL
BOOL
BOOL
BOOL
LINT
DINT
Description
Set by the user program to unsuppress the alarm. Takes precedence over Suppress commands.
Default is cleared.
Set by the operator interface to unsuppress the alarm. Takes precedence over Suppress commands. The alarm instruction clears this parameter.
Default is cleared.
Set by the operator interface to shelve or reshelve the alarm. Takes action on transition from cleared to set. The instruction clears this parameter.
Unshelve commands take precedence over Shelve commands.
Connecting a push button to the OperShelve tag:
The alarm instruction only processes the OperShelve tag on transition from cleared to set to prevent unwanted reshelving of the alarm. For example, if an operator presses a push button to shelve the alarm while the ProgUnshelve tag is set, the alarm is not shelved because the ProgUnshelve tag takes precedence. To shelve the alarm, the operator can release and press the push button again once ProgUnshelve is cleared.
Set by the user program to unshelve the alarm. Takes precedence over Shelve commands. Default is cleared.
For more information on shelving an alarm, see the description for the OperShelve
parameter.
Set by the operator interface to unshelve the alarm. The alarm instruction clears this parameter. Takes precedence over
Shelve commands. Default is cleared.
For more information on shelving an alarm, see the description for the OperShelve
parameter.
Set by the user program to disable the alarm. Takes action on transition from cleared to set.
Default is cleared.
Relay Ladder
Copied from the instruction operand.
Structured Text
Copied from the instruction operand.
Set by the operator interface to disable the alarm. The alarm instruction clears this parameter.
Default is cleared.
Set by the user program to enable the alarm. Takes precedence over a Disable command. Takes action on transition from cleared to set.
Default is cleared.
Relay Ladder
Copied from the instruction operand.
Structured Text
Copied from the instruction operand.
Set by the operator interface to enable the alarm. Takes precedence over Disable command. The alarm instruction clears this parameter.
Default is cleared.
Set by the operator interface to reset the alarm count to zero. The alarm instruction clears this parameter.
Default is cleared.
Specifies whether to use the controller’s clock or the ProgTime value to timestamp alarm state change events. When set, the ProgTime value provides timestamp. When cleared, the controller’s clock provides timestamp.
Default is cleared.
If UseProgTime is set, this value is used to provide the timestamp value for all events. This lets the application apply timestamps obtained from the alarm source, such as a sequence-of-events input module.
Severity of the alarm. This does not affect processing of alarms by the controller, but can be used for sorting and filtering functions at the alarm subscriber.
Valid = 1...1000 (1000 = most severe; 1 = least severe).
Default = 500.
46
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Input Parameter
MinDurationPRE
Data Type
DINT
ShelveDuration
MaxShelveDuration
DINT
DINT
Output Parameter
EnableOut
InAlarm
Acked
InAlarmUnack
Suppressed
Shelved
Disabled
Commissioned
MinDurationACC
AlarmCount
InAlarmTime
AckTime
RetToNormalTime
AlarmCountResetTime
ShelveTime
UnshelveTime
BOOL
BOOL
BOOL
BOOL
DINT
DINT
LINT
LINT
LINT
LINT
LINT
LINT
Data Type
BOOL
BOOL
BOOL
BOOL
Status DINT
FactoryTalk Alarms and Events Logix-based Instructions (ALMD, ALMA)
Chapter 1
Description
Minimum duration preset (milliseconds) for the alarm condition to remain true before the alarm is marked as InAlarm and alarm notification is sent to clients. The controller collects alarm data as soon as the alarm condition is detected, so no data is lost while waiting to meet the minimum duration.
Valid = 0...2,147,483,647.
Default = 0.
You do not want to use some other tag on the MinDurationPRE faceplate to control the state, then enter the ALMD tag
.MinDurationPRE on the instruction faceplate, for example, myalmd.MinDurationPRE.
Length of time in minutes to shelve an alarm. Set by the operator interface to unshelve the alarm. The alarm instruction clears this parameter. Takes precedence over Shelve commands. Default is cleared.
Minimum time is one minute. Maximum time is defined by MaxShelveDuration.
Maximum time duration in minutes for which an alarm can be shelved. For more information on shelving an alarm, see the description for
parameter.
Description
Enable output.
Alarm active status. Set when the alarm is active. Cleared when the alarm is not active (normal status).
Alarm acknowledged status. Set when the alarm is acknowledged. Cleared when the alarm is not acknowledged.
Acked is always set when AckRequired is cleared.
Combined alarm active and acknowledged status. Set when the alarm is active (InAlarm is set) and unacknowledged
(Acked is cleared). Cleared when the alarm is normal (inactive), acknowledged, or both.
Suppressed status of the alarm. Set when the alarm is suppressed. Cleared when the alarm is not suppressed.
Set by the operator to shelve the alarm. Takes action on transition from cleared to set.
Cleared when alarm is unshelved.
Disabled status of the alarm. Set when the alarm is disabled. Cleared when the alarm is enabled.
Reserved for future use.
Elapsed time since the alarm was detected. When this value reaches MinDurationPRE, the alarm becomes active (InAlarm is set), and a notification is sent to clients.
Number of times the alarm has been activated (InAlarm is set). If the maximum value is reached, the counter leaves the value at the maximum count value.
Timestamp of alarm detection.
Timestamp of alarm acknowledgement. If the alarm does not require acknowledgement, this timestamp is equal to alarm time.
Timestamp of alarm returning to a normal state.
Timestamp indicating when the alarm count was reset.
Timestamp indicating when the alarm was shelved the last time. Each time the alarm is shelved, the timestamp is set to the current time.
For more information on shelving an alarm, see the description for the Shelved
parameter.
Timestamp indicating when the alarm is going to be unshelved. This value is set every time the alarm is shelved (even if the alarm has already been shelved). The timestamp is determined by adding the ShelveDuration to the current time. If the alarm is unshelved programmatically or by an operator, then the value is set to the current time.
For more information on shelving an alarm, see the description for the Shelved
parameter.
Combined status indicators:
Status.0 = InstructFault.
Status.1= InFaulted.
Status.2 = SeverityInv.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
47
Chapter 1
FactoryTalk Alarms and Events Logix-based Instructions (ALMD, ALMA)
Output Parameter
InstructFault (Status.0)
InFaulted (Status.1)
SeverityInv (Status.2)
Data Type
BOOL
BOOL
BOOL
Description
Instruction error conditions exist. This is not a minor or major controller error. Check the remaining status bits to determine what occurred.
User program has set InFault to indicate bad quality input data. Alarm continues to evaluate In for alarm condition.
Alarm severity configuration is invalid.
If severity <1, the instruction uses Severity = 1.
If severity >1000, the instruction uses Severity = 1000.
Description:
The ALMD instruction detects alarms based on Boolean (true/false) conditions.
The ALMD instruction provides additional functionality when used with
RSLinx® Enterprise and FactoryTalk View SE software. You can display alarms in the Alarm Summary, Alarm Banner, Alarm Status Explorer, and Alarm Log
Viewer displays in FactoryTalk View SE software.
RSLinx Enterprise software subscribes to Alarm Log in the controller. If a connection to RSLinx Enterprise software is lost, the controller continues to store alarm data into the log and data can be accessed when the communication is restored.
48
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
FactoryTalk Alarms and Events Logix-based Instructions (ALMD, ALMA)
Chapter 1
State Diagrams When Acknowledgement Required
Latched = False
InAlarm = False
Acked = True
Ack
1
InAlarm = False
Acked = False
In = Condition, MinDurationACC >= MinDurationPRE
In
In !
= C ond itio n
Min
Du rat ion
PR
E
= C on diti on
, M inD ura tion
AC
C >=
In !=
Con ditio n
InAlarm = True
Acked = False
Ack
1
InAlarm = True
Acked = True
Latched = True
InAlarm = False
Acked = True
In = Condition, MinDurationACC >= MinDurationPRE
In != Condition, Reset
2
In !=
Co nditio n, Re set
2
InAlarm = True
Acked = False
Ack
1
InAlarm = True
Acked = True
1. Alarm can be acked several different ways: ProgAck, OperAck, clients (Studio 5000 software, FactoryTalkView software.
2. Alarm can be reset several different ways: ProgReset, OperReset, clients (Studio 5000 software, FactoryTalkView software.
State Diagrams When Acknowledgment Not Required
Latched = False
In = Condition, MinDurationACC >= MinDurationPRE
InAlarm = False InAlarm = True
In != Condition
Acked = True
Latched = True
InAlarm = False
In = Condition, MinDurationACC >= MinDurationPRE
In != Condition, Reset
1
InAlarm = True Acked = True
1. Alarm can be acked several different ways: ProgReset, OperReset, clients (Studio 5000 software, FactoryTalk View software.
Arithmetic Status Flags:
None
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
49
Chapter 1
FactoryTalk Alarms and Events Logix-based Instructions (ALMD, ALMA)
Fault Conditions:
None
Execution:
Condition
Prescan
Condition
Prescan
Instruction first scan
Instruction first run
EnableIn is cleared
EnableIn is set
Postscan
Rung-condition-in is false
Rung-condition-in is true
Postscan
Relay Ladder Action
The rung-condition-out is set to false.
InAlarm and Shelved are cleared and Acked is set.
All operator requests and timestamps are cleared.
The rung-condition-out is set to false.
EnableIn and EnableOut are cleared.
The In parameter is cleared, and the instruction evaluates to determine the alarm state.
The rung-condition-out is set to true.
EnableIn and EnableOut are set.
The In parameter is set, and the instruction evaluates to determine the alarm state.
The rung-condition-out is set to false.
Function Block Action
All operator requests and timestamps are cleared.
InAlarm, Shelved, and EnableOut are cleared and Acked is set.
No action taken.
No action taken.
The instruction does not execute. All operator requests are cleared.
EnableOut is cleared.
The instruction executes.
EnableOut is set.
EnableOut is cleared.
Structured Text Action
All operator requests and timestamps are cleared.
InAlarm, Shelved and EnableOut are cleared and Acked is set.
No action taken.
No action taken.
The instruction executes.
EnableOut is cleared.
The instruction executes.
EnableOut is always set.
EnableOut is cleared.
50
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
FactoryTalk Alarms and Events Logix-based Instructions (ALMD, ALMA)
Chapter 1
ALMD Alarm Acknowledge Required and Latched
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
51
Chapter 1
FactoryTalk Alarms and Events Logix-based Instructions (ALMD, ALMA)
ALMD Alarm Acknowledge Required and Not Latched
ALMD Alarm Acknowledge Not Required and Latched
52
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
FactoryTalk Alarms and Events Logix-based Instructions (ALMD, ALMA)
Chapter 1
ALMD Alarm Acknowledge Not Required and Not Latched
Example:
Two motor failure signals are combined such that if either one occurs, a motor fault alarm is activated. Programmatically acknowledge the alarm with a clearedto-set transition of the AckThisAlarm tag value. The application logic must clear
AckThisAlarm.
Relay Ladder
AckThisAlarm
0
500
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
53
Chapter 1
FactoryTalk Alarms and Events Logix-based Instructions (ALMD, ALMA)
Structured Text
Motor101FaultConditions := Motor101Overtemp OR
Motor101FailToStart;
ALMD(Motor101Fault,Motor101FaultConditions,
Motor101Ack,0,0,0 );
Function Block
54
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
FactoryTalk Alarms and Events Logix-based Instructions (ALMD, ALMA)
Chapter 1
Analog Alarm (ALMA)
Operands:
The ALMA instruction detects alarms based on the level or rate of change of an analog value. Program (Prog) and operator (Oper) control parameters provide an interface for alarm commands.
Relay Ladder
Operand
ALMA tag
Type
ALARM_ANALOG
Format
Structure
Description
ALMA structure.
ALMA(ALMA, In, ProgAckAll,
ProgDisable, ProgEnable);
Structured Text
The operands are the same as those for the relay ladder ALMD instruction, with a few exceptions as indicated above.
Function Block
Operand
ALMA tag
Type
ALARM_ANALOG
Format
Structure
Description
ALMA structure.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
55
Chapter 1
FactoryTalk Alarms and Events Logix-based Instructions (ALMD, ALMA)
Input Parameter
EnableIn
In
InFault
HHEnabled
HEnabled
LEnabled
LLEnabled
AckRequired
ProgAckAll
OperAckAll
HHProgAck
HHOperAck
HProgAck
Data Type
BOOL
REAL
BOOL
BOOL
BOOL
BOOL
BOOL
BOOL
BOOL
BOOL
BOOL
BOOL
BOOL
ALARM_ANALOG Structure
Description
Relay Ladder
Corresponds to the rung state. If cleared, the instruction does not execute and outputs are not updated.
Structured Text
If cleared, the instruction does not execute and outputs are not updated.
Default is set.
Function Block
If cleared, the instruction does not execute and outputs are not updated.
Default is set.
The alarm input value, which is compared with alarm limits to detect alarm conditions.
Default = 0.0.
Relay Ladder
Copied from the instruction operand.
Structured Text
Copied from instruction operand.
Bad health indicator for the input. The user application may set InFault to indicate the input signal has an error. When set, the instruction sets InFaulted (Status.1). When cleared, the instruction clears InFaulted (Status.1). In either case, the instruction continues to evaluate In for alarm conditions.
Default is cleared (good health).
High High alarm condition detection. Set to enable detection of the High High alarm condition. Clear to disable detection of the High High alarm condition.
Default is set.
High alarm condition detection. Set to enable detection of the High alarm condition. Clear to disable detection of the High alarm condition.
Default is set.
Low alarm condition detection. Set to enable detection of the Low alarm condition. Clear to disable detection of the Low alarm condition.
Default is set.
Low Low alarm condition detection. Set to enable detection of the Low Low alarm condition. Clear to disable detection of the
Low Low alarm condition.
Default is set.
Specifies whether alarm acknowledgement is required. When set, acknowledgement is required. When cleared, acknowledgement is not required and HHAcked, HAcked, LAcked, LLAcked, ROCPosAcked, and ROCNegAcked are always set.
Default is set.
For Relay Ladder Logic, on transition from cleared to set, acknowledges alarm (if acknowledgement allowed).
Default is cleared.
Relay Ladder
Copies value from the instruction operand.
Structured Text
Copies value from the instruction operand.
Set by the operator interface to acknowledge all conditions of this alarm. Takes effect only if an alarm condition is unacknowledged. The alarm instruction clears this parameter.
Default is cleared.
High High program acknowledge. Set by the user program to acknowledge a High High condition. Requires a cleared-to-set transition while the alarm condition is unacknowledged.
Default is cleared.
High High operator acknowledge. Set by the operator interface to acknowledge a High High condition. Requires a cleared-toset transition while the alarm condition is unacknowledged. The alarm instruction clears this parameter.
Default is cleared.
High program acknowledge. Set by the user program to acknowledge a High condition. Requires a cleared-to-set transition while the alarm condition is unacknowledged.
Default is cleared.
56
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
ROCNegProgAck
ROCNegOperAck
ProgSuppress
OperSuppress
ProgUnsuppress
OperUnsuppress
HHOperShelve
Input Parameter
HOperAck
LProgAck
LOperAck
LLProgAck
LLOperAck
ROCPosProgAck
ROCPosOperAck
HOperShelve
BOOL
BOOL
BOOL
BOOL
BOOL
BOOL
BOOL
BOOL
BOOL
Data Type
BOOL
BOOL
BOOL
BOOL
BOOL
BOOL
FactoryTalk Alarms and Events Logix-based Instructions (ALMD, ALMA)
Chapter 1
Description
High operator acknowledge. Set by the operator interface to acknowledge a High condition. Requires a cleared-to-set transition while the alarm condition is Unacknowledged. The alarm instruction clears this parameter.
Default is cleared.
Low program acknowledge. Set by the user program to acknowledge a Low condition. Requires a cleared-to-set transition while the alarm condition is unacknowledged.
Default is cleared.
Low operator acknowledge. Set by the operator interface to acknowledge a Low condition. Requires a cleared-to-set transition while the alarm condition is unacknowledged. The alarm instruction clears this parameter.
Default is cleared.
Low Low program acknowledge. Set by the user program to acknowledge a Low Low condition. Requires a cleared-to-set transition while the alarm condition is unacknowledged.
Default is cleared.
Low Low operator acknowledge. Set by the operator interface to acknowledge a Low Low condition. Requires a cleared-to-set transition while the alarm condition is unacknowledged. The alarm instruction clears this parameter.
Default is cleared.
Positive rate of change program acknowledge. Set by the user program to acknowledge a positive rate-of-change condition.
Requires a cleared-to-set transition while the alarm condition is unacknowledged.
Default is cleared.
Positive rate of change operator acknowledge. Set by the operator interface to acknowledge a positive rate-of-change condition. Requires a cleared-to-set transition while the alarm condition is unacknowledged. The alarm instruction clears this parameter.
Default is cleared.
Negative rate of change program acknowledge. Set by the user program to acknowledge a negative rate-of-change condition.
Requires a cleared-to-set transition while the alarm condition is unacknowledged.
Default is cleared.
Negative rate of change operator acknowledge. Set by the operator interface to acknowledge a negative rate-of-change condition. Requires a cleared-to-set transition while the alarm condition is unacknowledged. The alarm instruction clears this parameter.
Default is cleared.
Set by the user program to suppress the alarm.
Default is cleared.
Set by the operator interface to suppress the alarm. The alarm instruction clears this parameter.
Default is cleared.
Set by the user program to unsuppress the alarm. Takes precedence over Suppress commands.
Default is cleared.
Set by the operator interface to unsuppress the alarm. Takes precedence over Suppress commands. The alarm instruction clears this parameter.
Default is cleared.
High-high operator shelve. Set by the operator to shelve or reshelve a high-high condition. Takes action on transition from cleared to set. The alarm instruction clears this parameter.
Default is cleared.
Connecting a push button to the OperShelve tag:
The alarm instruction only processes the OperShelve tag on transition from cleared to set to prevent unwanted reshelving of the alarm. For example, if an operator presses a push button to shelve the alarm while the ProgUnshelve tag is set, the alarm is not shelved because the ProgUnshelve tag takes precedence. To shelve the alarm, the operator can release and press the push button again once ProgUnshelve is cleared.
High operator shelve. Set by the operator interface to shelve or reshelve a high condition. Takes action on transition from cleared to set. The alarm instruction clears this parameter.
Default is cleared.
Unshelve commands take precedence over Shelve commands.
Connecting a push button to the OperShelve tag:
The alarm instruction only processes the OperShelve tag on transition from cleared to set to prevent unwanted reshelving of the alarm. For example, if an operator presses a push button to shelve the alarm while the ProgUnshelve tag is set, the alarm is not shelved because the ProgUnshelve tag takes precedence. To shelve the alarm, the operator can release and press the push button again once ProgUnshelve is cleared.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
57
Chapter 1
FactoryTalk Alarms and Events Logix-based Instructions (ALMD, ALMA)
Input Parameter
LOperShelve
LLOperShelve
ROCPosOperShelve
ROCNegOperShelve
ProgUnshelveAll
HHOperUnshelve
HOperUnshelve
LOperUnshelve
LLOperUnshelve
ROCPosOperUnshelve
ROCNegOperUnshelve
ProgDisable
OperDisable
ProgEnable
OperEnable
58
Data Type
BOOL
BOOL
BOOL
BOOL
BOOL
BOOL
BOOL
BOOL
BOOL
BOOL
BOOL
BOOL
BOOL
BOOL
BOOL
Description
Low operator shelve. Set by the operator interface to shelve or reshelve a low condition. Requires a change from a cleared state in one program scan to a set state in the next program scan. The alarm instruction clears this parameter. Default is cleared.
Unshelve commands take precedence over Shelve commands.
Connecting a push button to the OperShelve tag.
Low-low operator shelve. Set by the operator interface to shelve or reshelve a low-low condition. Requires a change from a cleared state in one program scan to a set state in the next program scan. The alarm instruction clears this parameter. Default is cleared.
Unshelve commands take precedence over Shelve commands.
Connecting a push button to the OperShelve tag.
Positive rate-of-change operator shelve. Set by the operator interface to shelve or reshelve a positive rate-of-change condition. Requires a change from a cleared state in one program scan to a set state in the next program scan. The alarm instruction clears this parameter. Default is cleared.
Unshelve commands take precedence over Shelve commands.
Connecting a push button to the OperShelve tag.
Negative rate-of-change operator shelve. Set by the operator interface to shelve or reshelve a negative rate-of-change condition. Requires a change from a cleared state in one program scan to a set state in the next program scan. The alarm instruction clears this parameter. Default is cleared.
Unshelve commands take precedence over Shelve commands.
Connecting a push button to the OperShelve tag.
Set by the user program to unshelve all conditions on this alarm. If both shelve and unshelve are set, unshelve commands take precedence over shelve commands. Default is cleared.
High-high operator unshelve. Set by the operator interface to unshelve a high-high condition. The alarm instruction clears this parameter. If both shelve and unshelve are set, unshelve commands take precedence over shelve commands. Default is cleared.
High operator unshelve. Set by the operator interface to unshelve a high condition. The alarm instruction clears this parameter. If both shelve and unshelve are set, unshelve commands take precedence over shelve commands. Default is cleared.
Low operator unshelve. Set by the operator interface to unshelve a low condition. The alarm instruction clears this parameter.
If both shelve and unshelve are set, unshelve commands take precedence over shelve commands. Default is cleared.
Low-low operator unshelve. Set by the operator interface to unshelve a low-low condition. The alarm instruction clears this parameter. If both shelve and unshelve are set, unshelve commands take precedence over shelve commands. Default is cleared.
Positive rate-of-change operator unshelve. Set by the operator interface to unshelve a positive rate-of-change condition. The alarm instruction clears this parameter. If both shelve and unshelve are set, unshelve commands take precedence over shelve commands. Default is cleared.
Negative rate-of-change operator unshelve. Set by the operator interface to unshelve a negative rate-of-change condition.
The alarm instruction clears this parameter. If both shelve and unshelve are set, unshelve commands take precedence over shelve commands. Default is cleared.
Set by the user program to disable the alarm. On transition from cleared to set, disables the alarm.
Default is cleared.
Relay Ladder
Copied from the instruction operand.
Structured Text
Copied from the instruction operand.
Set by the operator interface to disable the alarm. The alarm instruction clears this parameter.
Default is cleared.
Set by the user program to enable the alarm. Takes precedence over a Disable command. Takes action on transition from cleared to set.
Default is cleared.
Relay Ladder
Copied from the instruction operand.
Structured Text
Copied from the instruction operand.
Set by the operator interface to enable the alarm. Takes precedence over Disable command. The alarm instruction clears this parameter.
Default is cleared.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Input Parameter
AlarmCountReset
HHMinDurationEnable
HMinDurationEnable
LMinDurationEnable
LLMinDurationEnable
HHLimit
Data Type
BOOL
BOOL
BOOL
BOOL
BOOL
REAL
HHSeverity DINT
HLimit
HSeverity
LLimit
LSeverity
LLLimit
LLSeverity
MinDurationPRE
ShelveDuration
MaxShelveDuration
REAL
DINT
REAL
DINT
REAL
DINT
DINT
DINT
DINT
FactoryTalk Alarms and Events Logix-based Instructions (ALMD, ALMA)
Chapter 1
Description
Set by the user program to reset the alarm counts for all conditions.
Default is cleared.
High-high minimum duration enable. Set to enable minimum duration timer when detecting the high-high condition.
Default is enabled.
High minimum duration enable. Set to enable minimum duration timer when detecting the high condition. Default is enabled.
Low minimum duration enable. Set to enable minimum duration timer when detecting the low condition. Default is enabled.
Low-low minimum duration enable. Set to enable minimum duration timer when detecting the low-low condition. Default is enabled.
High High alarm limit.
Valid = HLimit < HHLimit < maximum positive float.
Default = 0.0.
Severity of the High High alarm condition. This does not affect processing of alarms by the controller, but can be used for sorting and filtering functions at the alarm subscriber.
Valid = 1...1000 (1000 = most severe; 1 = least severe).
Default = 500.
High alarm limit.
Valid = LLimit < HLimit < HHLimit.
Default = 0.0.
Severity of the High alarm condition. This does not affect processing of alarms by the controller, but can be used for sorting and filtering functions at the alarm subscriber.
Valid = 1...1000 (1000 = most severe; 1 = least severe).
Default = 500.
Low alarm limit.
Valid = LLLimit < LLimit < HLimit.
Default = 0.0.
Severity of the Low alarm condition. This does not affect processing of alarms by the controller, but can be used for sorting and filtering functions at the alarm subscriber.
Valid = 1...1000 (1000 = most severe; 1 = least severe).
Default = 500.
Low Low alarm limit.
Valid = maximum negative float < LLLimit < LLimit.
Default = 0.0
Severity of the Low Low alarm condition. This does not affect processing of alarms by the controller, but can be used for sorting and filtering functions at the alarm subscriber.
Valid = 1...1000 (1000 = most severe; 1 = least severe).
Default = 500.
Minimum duration preset (milliseconds) for an alarm level condition to remain true before the condition is marked as InAlarm and alarm notification is sent to clients. The controller collects alarm data as soon as the alarm condition is detected, so no data is lost while waiting to meet the minimum duration. Does not apply to rate-of-change conditions.
MinDurationPRE applies only to the first excursion from normal in either direction. For example, once the High condition times out, the High High condition will become active immediately, while a low condition will wait for the time-out period.
Valid = 0...2,147,483,647.
Default = 0.
Time duration (in minutes) for which a shelved alarm will be shelved. Minimum time is one minute. Maximum time is defined by MaxShelveDuration.
Maximum time duration (in minutes) for which an alarm can be shelved.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
59
Output Parameter
EnableOut
InAlarm
AnyInAlarmUnack
HHInAlarm
HInAlarm
LInAlarm
LLInAlarm
ROCPosInAlarm
ROCNegInAlarm
ROC
HHAcked
HAcked
Chapter 1
FactoryTalk Alarms and Events Logix-based Instructions (ALMD, ALMA)
Input Parameter
Deadband
ROCPosLimit
ROCPosSeverity
ROCNegLimit
ROCNegSeverity
ROCPeriod
60
Data Type
REAL
REAL
DINT
REAL
DINT
REAL
Data Type
BOOL
BOOL
BOOL
BOOL
BOOL
BOOL
BOOL
BOOL
BOOL
REAL
BOOL
BOOL
Description
Deadband for detecting that High High, High, Low, and Low Low alarm levels have returned to normal.
A non-zero Deadband can reduce alarm condition chattering if the In value is continually changing but remaining near the level condition threshold. The Deadband value does not affect the transition to the InAlarm (active) state. Once a level condition is active, but before the condition will return to the inactive (normal) state, the In value must either:
• drop below the threshold minus the deadband (for High and High High conditions).
OR
• rise above the threshold plus the deadband (for Low and Low Low conditions).
The Deadband is not used to condition the Minimum Duration time measurement.
Valid = 0 Deadband < Span from first enabled low alarm to the first enabled high alarm.
Default = 0.0.
Limit for an increasing rate-of-change in units per second. Detection is enabled for any value > 0.0 if ROCPeriod is also > 0.0.
Valid = 0.0...maximum possible float.
Default = 0.0.
Severity of the increasing rate-of-change condition. This does not affect processing of alarms by the controller, but can be used for sorting and filtering functions at the alarm subscriber.
Valid = 1...1000 (1000 = most severe; 1 = least severe).
Default = 500.
Limit for a decreasing rate-of-change in units per second. Detection is enabled for any value > 0.0 if ROCPeriod is also > 0.0.
Valid = 0.0...maximum possible float.
Default = 0.0.
Severity of the decreasing rate-of-change condition. This does not affect processing of alarms by the controller, but can be used for sorting and filtering functions at the alarm subscriber.
Valid = 1...1000 (1000 = most severe; 1 = least severe).
Default = 500.
Time period in seconds for calculation (sampling interval) of the rate of change value. Each time the sampling interval expires, a new sample of In is stored, and ROC is recalculated.
Rate-of-change detection is enabled for any value > 0.0.
Valid = 0.0...maximum possible float.
Default = 0.0.
Description
Enable output.
Alarm active status. Set when any alarm condition is active. Cleared when all alarm conditions are not active (normal status).
Combined alarm active and acknowledged status. Set when any alarm condition is detected and unacknowledged.
Cleared when all alarm conditions are normal (inactive), acknowledged, or both.
High High alarm condition status. Set when a High High condition exists. Cleared when no High High condition exists.
High alarm condition status. Set when a High condition exists. Cleared when no High condition exists.
Low alarm condition status. Set when a Low condition exists. Cleared when no Low condition exists.
Low Low alarm condition status. Set when a Low Low condition exists. Cleared when no Low Low condition exists.
Positive rate-of-change alarm condition status. Set when a positive rate-of-change condition exists. Cleared when no positive rate-of-change condition exists.
Negative rate-of-change alarm condition status. Set when a negative rate-of-change condition exists. Cleared when no negative rate-of-change condition exists.
Calculated rate-of-change of the In value. This value is updated when the instruction is scanned following each elapsed
ROCPeriod. The ROC value is used to evaluate the ROCPosInAlarm and ROCNegInAlarm conditions.
ROC = (current sample of In – previous sample of In) / ROCPeriod.
High High condition acknowledged status. Set when a High High condition is acknowledged. Always set when
AckRequired is cleared. Cleared when a High High condition is not acknowledged.
High condition acknowledged status. Set when a High condition is acknowledged. Always set when AckRequired is cleared. Cleared when a High condition is not acknowledged.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
BOOL
BOOL
BOOL
BOOL
BOOL
BOOL
BOOL
BOOL
Data Type
BOOL
BOOL
BOOL
BOOL
BOOL
BOOL
BOOL
BOOL
BOOL
BOOL
BOOL
HHShelved
HShelved
LShelved
LLShelved
Output Parameter
LAcked
LLAcked
ROCPosAcked
ROCNegAcked
HHInAlarmUnack
HInAlarmUnack
LInAlarmUnack
LLInAlarmUnack
ROCPosInAlarmUnack
ROCNegInAlarmUnack
Suppressed
ROCPosShelved
ROCNegShelved
Commissioned
Disabled
FactoryTalk Alarms and Events Logix-based Instructions (ALMD, ALMA)
Chapter 1
Description
Low condition acknowledged status. Set when a Low condition is acknowledged. Always set when AckRequired is cleared. Cleared when a Low condition is not acknowledged.
Low Low condition acknowledged status. Set when a Low Low condition is acknowledged. Always set when AckRequired is cleared. Cleared when a Low Low condition is not acknowledged.
Positive rate-of-change condition acknowledged status. Set when a positive rate-of-change condition is acknowledged.
Always set when AckRequired is cleared. Cleared when a positive rate-of-change condition is not acknowledged.
Negative rate-of-change condition acknowledged status. Set when a negative rate-of-change condition is acknowledged. Always set when AckRequired is cleared. Cleared when a negative rate-of-change condition is not acknowledged.
Combined High High condition active and unacknowledged status. Set when the High High condition is active
(HHInAlarm is set) and unacknowledged. Cleared when the High High condition is normal (inactive), acknowledged, or both.
Combined High condition active and unacknowledged status. Set when the High condition is active (HInAlarm is set) and unacknowledged. Cleared when the High condition is normal (inactive), acknowledged, or both.
Combined Low condition active and unacknowledged status. Set when the Low condition is active (LInAlarm is set) and unacknowledged. Cleared when the Low condition is normal (inactive), acknowledged, or both.
Combined Low Low condition active and unacknowledged status. Set when the Low Low condition is active (LLInAlarm is set) and unacknowledged. Cleared when the Low Low condition is normal (inactive), acknowledged, or both.
Combined positive rate-of-change condition active and unacknowledged status. Set when the positive rate-of-change condition is active (ROCPosInAlarm is set) and unacknowledged. Cleared when the positive rate-of-change condition is normal (inactive), acknowledged, or both.
Combined negative rate-of-change condition active and unacknowledged status. Set when the negative rate-of-change condition is active (ROCNegInAlarm is set) and unacknowledged. Cleared when the negative rate-of-change condition is normal (inactive), acknowledged, or both.
Suppressed status of the alarm. Set when the alarm is suppressed. Cleared when the alarm is not suppressed.
High-high condition shelved status. Set when a high-high condition is shelved. Cleared when high-high condition is unshelved.
High condition shelved status. Set when a high condition is shelved. Cleared when high condition is unshelved.
Low condition shelved status. Set when a low condition is shelved. Cleared when low condition is unshelved.
Low-low condition shelved status. Set when a low-low condition is shelved. Cleared when low-low condition is unshelved.
Positive rate-of-change condition shelved status. Set when a positive rate-of-change condition is shelved. Cleared when positive rate-of-change condition is unshelved.
Negative rate-of-change condition shelved status. Set when a negative rate-of-change condition is shelved. Cleared when negative rate-of-change condition is unshelved.
Reserved for future use.
Disabled status of the alarm. Set when the alarm is disabled. Cleared when the alarm is enabled.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
61
HHInAlarmTime
HHAlarmCount
HInAlarmTime
HAlarmCount
LInAlarmTime
LAlarmCount
LLInAlarmTime
LLAlarmCount
ROCPosInAlarmTime
ROCPosInAlarmCount
ROCNegInAlarmTime
ROCNegAlarmCount
AckTime
RetToNormalTime
AlarmCountResetTime
ShelveTime
UnshelveTime
LINT
LINT
LINT
LINT
LINT
LINT
DINT
LINT
DINT
LINT
DINT
LINT
DINT
LINT
DINT
LINT
DINT
Chapter 1
FactoryTalk Alarms and Events Logix-based Instructions (ALMD, ALMA)
Output Parameter
MinDurationACC
Status
InstructFault (Status.0)
Data Type
DINT
DINT
BOOL
Description
Elapsed time since an alarm condition was detected. When this value reaches MinDurationPRE, the alarm becomes active (InAlarm is set), and alarm notification is sent to clients. Does not apply to rate of change conditions or to conditions for which the minimum duration detection is disabled.
If the alarm condition becomes inactive before MinDurationACC reaches MinDurationPRE, then the MinDuration timer is stopped. MinDurationACC is not reset so it keeps its last value. MinDurationACC is reset when an alarm level condition is newly detected and thus the MinDuration timer is started again.
The MinDuration timer can be stopped before expiration if EnableIn is cleared or the alarm is disabled. In all of these cases, MinDurationACC keeps its last value and is not reset until the MinDuration timer is started again.
Timestamp when the ALMA instruction detected that the In value exceeded the High High condition limit for the most recent transition to the active state.
The number of times the High High condition has been activated. If the maximum value is reached, the counter leaves the value at the maximum count value.
Timestamp when the ALMA instruction detected that the In value exceeded the High condition limit for the most recent transition to the active state.
The number of times the High condition has been activated. If the maximum value is reached, the counter leaves the value at the maximum count value.
Timestamp when the ALMA instruction detected that the In value exceeded the Low condition limit for the most recent transition to the active state.
The number of times the Low condition has been activated. If the maximum value is reached, the counter leaves the value at the maximum count value.
Timestamp when the ALMA instruction detected that the In value exceeded the Low Low condition limit for the most recent transition to the active state.
The number of times the Low Low condition has been activated. If the maximum value is reached, the counter leaves the value at the maximum count value.
Timestamp when the ALMA instruction detected that the In value exceeded the positive rate-of-change condition limit for the most recent transition to the active state.
The number of times the positive rate-of-change condition has been activated. If the maximum value is reached, the counter leaves the value at the maximum count value.
Timestamp when the ALMA instruction detected that the In value exceeded the negative rate-of-change condition limit for the most recent transition to the active state.
The number of times the negative rate-of-change condition has been activated. If the maximum value is reached, the counter leaves the value at the maximum count value.
Timestamp of most recent condition acknowledgement. If the alarm does not require acknowledgement, this timestamp is equal to most recent condition alarm time.
Timestamp of alarm returning to a normal state.
Timestamp indicating when the alarm count was reset.
Timestamp indicates when an alarm condition was shelved the last time. Each time alarm condition is shelved the timestamp is set to current time.
Timestamp indicating when all alarm conditions are going to be unshelved. Value is set only when no alarm condition is shelved yet or when an alarm condition is reshelved. The timestamp is determined as sum of the ShelveDuration time period and current time. If an alarm condition is unshelved programmatically or by an operator and no other alarm condition is shelved, then value is set to the current time.
Combined status indicators:
Status.0 = InstructFault.
Status.1 = InFaulted.
Status.2 = SeverityInv.
Status.3 = AlarmLimitsInv.
Status.4 = DeadbandInv.
Status.5 = ROCPosLimitInv.
Status.6 = ROCNegLimitInv.
Status.7 = ROCPeriodInv.
Instruction error conditions exist. This is not a minor or major controller error. Check the remaining status bits to determine what occurred.
62
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Output Parameter
InFaulted (Status.1)
SeverityInv (Status.2)
Data Type
BOOL
BOOL
AlarmLimitsInv (Status.3)
DeadbandInv (Status.4)
ROCPosLimitInv (Status.5)
ROCNegLimitInv (Status.6)
ROCPeriodInv (Status.7)
BOOL
BOOL
BOOL
BOOL
BOOL
FactoryTalk Alarms and Events Logix-based Instructions (ALMD, ALMA)
Chapter 1
Description
User program has set InFault to indicate bad quality input data. Alarm continues to evaluate In for alarm conditions.
Alarm severity configuration is invalid.
If severity <1, the instruction uses Severity = 1.
If severity >1000, the instruction uses Severity = 1000.
Alarm Limit configuration is invalid (for example, LLimit < LLLimit). If invalid, the instruction clears all level conditions active bits. Until the fault is cleared, no new level conditions can be detected.
Deadband configuration is invalid. If invalid, the instruction uses Deadband = 0.0.
Valid = 0 Deadband < Span from first enabled low alarm to the first enabled high alarm.
Positive rate-of-change limit invalid. If invalid, the instruction uses ROCPosLimit = 0.0, which disables positive rate-ofchange detection.
Negative rate-of-change limit invalid. If invalid, the instruction uses ROCNegLimit = 0.0, which disables negative rateof-change detection.
Rate-of-change period invalid. If invalid, the instruction uses ROCPeriod = 0.0, which disables rate-of-change detection.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
63
Chapter 1
FactoryTalk Alarms and Events Logix-based Instructions (ALMD, ALMA)
Description
The ALMA instruction detects alarms based on the level or rate of change of a value.
The ALMA instruction provides additional functionality when used with
FactoryTalk View SE software. You can display alarms in the Alarm Summary,
Alarm Banner, Alarm Status Explorer, and Alarm Log Viewer displays in
FactoryTalk View SE software.
FactoryTalk Alarms and Events server subscribes to alarms in the controller. Use the output parameters to monitor the instruction to see the alarm subscription status and to display alarm status changes. If a connection to the FactoryTalk
Alarms and Events server is lost, the controller can briefly buffer alarm data until the connection is restored.
State Diagrams When Acknowledgement Required
In >= HLimit, MinDurationACC >= MinDurationPRE
HInAlarm = False
HAcked = True
Ack
1
HInAlarm = False
HAcked = False
In <
(HL imit
In
>=
- De adb and
)
In
HL imi t, M inD ura tion
AC
< (
Hli mit
- D ea db an d)
C >
= M inD ura tion
PR
E
HInAlarm = True
HAcked = False
Ack
1
HInAlarm = True
HAcked = True
1
H alarm condition can be acked by several different ways: HProgAck, HOperAck, ProgAckAll, OperAckAll, clients (Studio 5000 software, FactoryTalk View software).
In >= HHLimit, MinDurationACC >= MinDurationPRE
HHInAlarm = False
HHAcked = True
Ack
1
HHInAlarm = False
HHAcked = False
In <
(HH
Lim
In
>= it - D ead ban d)
In ura tion
AC
C >
= M
HH
Lim it, M inD
De ad ba nd
)
< (
HH
Lim it inD ura tion
PR
E
HHInAlarm = True
HHAcked = False
Ack
1
HHInAlarm = True
HHAcked = True
1
HH alarm condition can be acked by several different ways: HHProgAck, HHOperAck, ProgAckAll, OperAckAll, clients (Studio 5000 software, FactoryTalk View software).
In <= LLimit, MinDurationACC >= MinDurationPRE
LInAlarm = False
LAcked = True
Ack
1
LInAlarm = False
LAcked = False
In >
(LLim
In it +
Dea dban d)
De ad ba nd
)
In
> (
Llim it + ura tion
AC
C >
= M inD ura tion
PR
E
LL imi t, M inD
<=
LInAlarm = True
LAcked = False
Ack
1
LInAlarm = True
LAcked = True
1
L alarm condition can be acked by several different ways: LProgAck, LOperAck, ProgAckAll, OperAckAll, clients (Studio 5000 software, FactoryTalk View software).
In <= LLLimit, MinDurationACC >= MinDurationPRE
LLInAlarm = False
LLAcked = True
Ack
1
LLInAlarm = False
LLAcked = False
In >
(LLL imit
In
<=
+ D ead band
)
In
> ( ura tion
AC
De ad ba nd
)
LL
Lim it +
C >
= M inD ura tion
PR
E
LL
Lim it, M inD
LLInAlarm = True
LLAcked = False
Ack
1
LLInAlarm = True
LLAcked = True
1
LL alarm condition can be acked by several different ways: LLProgAck, LLOperAck, ProgAckAll, OperAckAll, clients (Studio 5000 software, FactoryTalk View software).
ROC
=
In(Current Sample) In(Previou sSample)
ROCPeriod
Where a new sample is collected on the next scan after the ROCPeriod has elapsed.
ROC >= RocPosLimit
RocPosInAlarm = False
RocPosAcked = True
Ack
1
RocPosInAlarm = False
RocPosAcked = False
RO
C <
Roc
Pos
Lim it
RO
C >
= R ocP osL imi t
RO
C <
Ro cP osL imi t
RocPosInAlarm = True
RocPosAcked = False
Ack
1
RocPosInAlarm = True
RocPosAcked = True
1
ROCPos alarm condition can be acked by several different ways: RocPosProgAck, RocPosOperAck, ProgAckAll,
OperAckAll, clients (Studio 5000 software, FactoryTalk View software).
l,
ROC <= -RocNegLimit
RocNegInAlarm = False
RocNegAcked = True
Ack
1
RocNegInAlarm = False
RocNegAcked = False
RO
C >
-Ro cNe gLim it
RO
C <
= -
Ro cN eg
Lim it
RO
C >
-Ro cN eg
Lim it
RocNegInAlarm = True
RocNegAcked = False
Ack
1
RocNegInAlarm = True
RocNegAcked = True
1
ROCNeg alarm condition can be acked by several different ways: RocNegProgAck, RocNegOperAck, ProgAckAll,
OperAckAll, clients (Studio 5000 software, FactoryTalk View software).
,
64
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
FactoryTalk Alarms and Events Logix-based Instructions (ALMD, ALMA)
Chapter 1
State Diagrams When Acknowledgement Not Required
In >= HLimit, MinDurationACC >= MinDurationPRE
HInAlarm = False HInAlarm = True
In < (HLimit - Deadband)
HAcked = True
In <= LLimit, MinDurationACC >= MinDurationPRE
LInAlarm = False LInAlarm = True LAcked = True
In > (LLimit + Deadband)
HHInAlarm = False
In >= HHLimit, MinDurationACC >= MinDurationPRE
In < (HHLimit - Deadband)
HHInAlarm = True
LLInAlarm = False
In <= LLLimit, MinDurationACC >= MinDurationPRE
In > (LLLimit + Deadband)
LLInAlarm = True
HHAcked = True
LLAcked = True
ROC
=
In(Current Sample) In(Previou sSample)
ROCPeriod
ROC >= ROCPosLimit
RocPosInAlarm = False
ROC < ROCPosLimit
ROC <= -ROCNegLimit
RocNegInAlarm = False
ROC > -ROCNegLimit
Where a new sample is collected on the next scan after the ROCPeriod has elapsed.
RocPosInAlarm = True
RocNegInAlarm = True
RocPosAcked = True
RocNegAcked = True
Arithmetic Status Flags:
Arithmetic status flags are set for the ROC output.
Fault Conditions:
Minor Fault
ROC overflow
Fault Type
4
Execution:
Condition
Prescan
Rung-condition-in is false
Rung-condition-in is true
Postscan
Fault Code
4
Relay Ladder Action
The rung-condition-out is set to false.
All of the xInAlarm parameters and xShelved are cleared and all alarm conditions are acknowledged.
All operator requests and timestamps are cleared.
The instruction does not execute.
EnableOut is cleared.
The rung-condition-out is set to false.
The instruction executes.
EnableOut is set.
The rung-condition-out is set to true.
The rung-condition-out is set to false.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
65
Chapter 1
FactoryTalk Alarms and Events Logix-based Instructions (ALMD, ALMA)
Condition
Prescan
Instruction first scan
Instruction first run
EnableIn is false
EnableIn is true
Postscan
Function Block Action
All operator requests and timestamps are cleared.
All of the xInAlarm and xShelved parameters are cleared. EnableOut is cleared. All alarm conditions are acknowledged.
No action taken.
No action taken.
The instruction does not execute. All operator requests are cleared.
EnableOut is cleared.
The instruction executes.
EnableOut is set.
EnableOut is cleared.
Structured Text Action
All operator requests and timestamps are cleared.
All of the xInAlarm and xShelved parameters are cleared. EnableOut is cleared. All alarm conditions are acknowledged.
No action taken.
No action taken.
The instruction does not execute.
EnableOut is cleared.
The instruction executes.
EnableOut is always set to true.
EnableOut is cleared to false.
66
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
FactoryTalk Alarms and Events Logix-based Instructions (ALMD, ALMA)
Chapter 1
ALMA Level Condition Acknowledge Required
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
67
Chapter 1
FactoryTalk Alarms and Events Logix-based Instructions (ALMD, ALMA)
ALMA Level Condition Acknowledge Not Required
68
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
FactoryTalk Alarms and Events Logix-based Instructions (ALMD, ALMA)
Chapter 1
ALMA Rate of Change Acknowledge Required
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
69
Chapter 1
FactoryTalk Alarms and Events Logix-based Instructions (ALMD, ALMA)
ALMA Rate of Change Acknowledge Not Required
70
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
FactoryTalk Alarms and Events Logix-based Instructions (ALMD, ALMA)
Chapter 1
Example:
A tank alarm is activated if the tank level surpasses a High or High limit.
Programmatically acknowledge all the alarm conditions with a cleared-to-set transition of the Tank32LevelAck tag value. The application logic must clear
Tank32LevelAck.
Relay Ladder
Structured Text
ALMA(Tank32Level,Tank32LT,Tank32LevelAck,0, 0);
Function Block
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
71
Chapter 1
FactoryTalk Alarms and Events Logix-based Instructions (ALMD, ALMA)
Configure an Alarm
Instruction
After you enter an ALMD or ALMA instruction and specify the alarm tag name, use the Alarm Configuration dialog box to specify the details of the message.
The Properties dialog box for the alarm instruction includes a Configuration tab.
Option
Condition - ALMD instruction
Input Level - ALMA instruction
Input Rate of Change - ALMA instruction
For each alarm instruction, configure this information.
Description
Condition to trigger the alarm.
Select Input=1 for an active alarm when In=1. Select Input=0 for an active alarm when In=0.
Input Level (High High, High, Low, or Low Low) or Input Rate of Change (Positive or Negative) to trigger an alarm.
Select the alarm conditions and enter the limits for those conditions. Disable rate-of-change conditions by entering a 0 for the period or limit.
72
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Option
Severity
Minimum Duration
Latched - ALMD instruction
Deadband - ALMA instruction
Acknowledgement Required
Alarm class
View command
Shelve Duration
Maximum Shelve Duration
FactoryTalk Alarms and Events Logix-based Instructions (ALMD, ALMA)
Chapter 1
Description
Select a severity range from 1…1000 to rank the importance of an alarm condition. A severity of 1 is for low priority alarms; a severity of 1000 is for an emergency condition.
By default, in the FactoryTalk Alarms and Events system, severity ranges are mapped to priorities as follows:
• 1…250 are low priority.
• 251…500 are medium priority.
• 501…750 are high priority.
• 751…1000 are urgent priority.
You can configure the severity-to-priority mapping in the FactoryTalk Alarms and Events system. See the FactoryTalk help for details.
Enter the amount of time in ms an alarm condition must be active before reporting the alarm.
Select Latched if you want the alarm to stay active (InAlarm) after the alarm condition returns to inactive (normal).
Latched alarms require a reset command to transition to normal. The reset command must be received after the condition returns to normal.
Acknowledge commands will not reset a latched alarm.
Specify a Deadband value to reduce alarm condition chattering caused by small fluctuations in the In value.
The deadband value does not affect the alarm limit for the transition into the active state, and is also not used during the
Minimum Duration interval.
Once a level condition becomes active (InAlarm), it will remain active until the In value crosses back over the limit by the specified deadband. For example, if the High limit is 80, the Low limit is 20, and the Deadband is 5, the High condition will be active at 80 and return to normal at 75; the Low condition will be active at 20 and return to normal at 25.
The Deadband has no effect on Rate of Change alarm conditions.
Alarms are configured to require acknowledgement by default. Acknowledgement indicates that an operator is aware of the alarm condition, whether or not conditions have returned to normal.
Clear the Acknowledgement Required setting when you want the alarm to appear and disappear from the Alarm
Summary on the HMI with no operator interaction.
Alarms that do not require acknowledgement always have the Acked status set.
If a digital alarm is configured as latched, the reset command also acknowledges the alarm.
Use the alarm class to group related alarms. Specify the alarm class exactly the same for each alarm you want in the same class. The alarm class is case sensitive.
For example, specify class Tank Farm A to group all the tank alarms for a specific area. Or specify class Control Loop to group all alarms for PID loops.
You can then display and filter alarms at the HMI based on the class. For example, an operator can display all tank alarms or all PID loop alarms.
The alarm class does not limit the alarms that an Alarm Summary object subscribes to. Use the alarm class to filter the alarms that display to an operator once they have been received by the Alarm Summary object. FactoryTalk View software can filter the alarm class substituting wild cards for characters.
Execute a command on the operator station when requested by an operator for a specific alarm. This lets an operator execute any standard FactoryTalk View command, such as call specific faceplates and displays, execute macros, access help files, and launch external applications. When the alarm condition occurs and is displayed to the operator, a button on the summary and banner displays lets the operator run an associated view command.
Be careful to enter the correct command syntax and test the command at runtime as there is no error checking performed when the command is entered.
Enter the amount of time in minutes to shelve an alarm condition.
Enter the maximum time duration in minutes for which an alarm condition can be shelved.
You can edit all aspects of the alarm configuration offline and online. Online edits of the configuration impacting run-time behavior on new and existing alarms are immediately sent to FactoryTalk subscribers (legacy HMI terminals that are just polling the tags do not automatically update). FactoryTalk subscribers do not have to re-subscribe to receive updated information. Online changes automatically propagate from the controller alarm structure to the rest of the architecture.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
73
Chapter 1
FactoryTalk Alarms and Events Logix-based Instructions (ALMD, ALMA)
Enter Alarm Message Text
Enter appropriate message text to display when an alarm condition is active
(InAlarm). For an ALMD instruction, you enter the message information on the
Configuration tab. For an ALMA instruction, you enter the message information on the Message tab.
Option
Message string
Associated tags
74
To define an alarm message, specify this information.
Description
The message string contains the information to display to the operator regarding the alarm. In addition to entering text, you can also embed variable information. In the alarm message editor, select the variable you want and add it anywhere in the message string.
The message string can have a maximum of 255 characters, including the characters that specify any embedded variables
(not the number of characters in the actual values of the embedded variables). For example, /*S:0 %Tag1*/ specifies a string tag and adds 13 characters towards the total string length, but the actual value of the string tag could contain 82 characters.
You cannot programmatically access the alarm message string from the alarm tag. To change the alarm message based on specific events, configure one of the associated tags as a string data type and embed that associated tag in the message.
You can have multiple language versions of messages. You enter the different language via the import/export utility. For
.
You can select as many as four additional tags from the controller project to associate with the alarm. The values of these tags are sent with an alarm message to the alarm server. For example, a digital alarm for a pressure relief valve might also include information such as pump speed and tank temperature.
Associated tags may be any atomic data type (BOOL, DINT, INT, SINT, or REAL) or a STRING. They may be elements in a UDT or an Array. Variable array references are not allowed. If the alarm is controller-scoped, the associated tags must also be controller-scoped.
Optionally, embed the associated tags into the message text string.
Associated tag values are always sent with the alarm, viewable by the operator, and entered in the history log, regardless of whether you embed them in the message string.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
FactoryTalk Alarms and Events Logix-based Instructions (ALMD, ALMA)
Chapter 1
Variable
Alarm name
Condition name
Input value
Limit value
Severity
Values of associated tags
Message String Variables
Embeds in the message string
The name of the alarm, which consists of the controller name, program name, and tag name. For example,
[Zone1Controller]Program:Main.MyAlarmTagName.
The condition that triggers the alarm:
• Digital alarm displays the trip.
• Analog alarm displays HiHi, Hi, Lo, LoLo, ROC_POS, or ROC_NEG.
The input value to the alarm:
• Digital alarm displays 0 or 1.
• Analog alarm displays the value of the input variable being monitored by the alarm.
The threshold of the alarm:
• Digital alarm displays 0 or 1.
• Analog alarm displays the actual configured range check for the analog alarm condition.
The configured severity of the alarm condition.
The value of a tag configured to be included with the alarm event.
Default code added to message string
/*S:0 %AlarmName*/
/*S:0 %ConditionName*/
/*N:5 %InputValue NOFILL DP:0*/
/*N:5 %LimitValue NOFILL DP:0*/
/*N:5 %Severity NOFILL DP:0*/
/*N:5 %Tag1 NOFILL DP:0*/
The code varies depending on the type of tag you select, how many digits or characters are in a tag value, and whether you want to left fill the empty bits with spaces or zeroes. See the following example.
Tag
BOOL value
DINT value, 9 digits, space left fill
REAL input value, 9 digits (includes decimal), 3 digits after decimal, zero left fill
Code
/*N:1 %Tag1 NOFILL DP:0*/
/*N:9 %Tag2 SPACEFILL DP:0*/
/*N:9 %InputValue NOFILL DP:3*/
REAL value, 8 digits (includes decimal), 4 digits after decimal, zero left fill /*N:8 %Tag3 ZEROFILL DP:4*/
String value, no fixed width /*S:0 %Tag4*/
String value, 26 characters, fixed width /*S:26 %Tag4*/
All of this variable information is included with the alarm data, viewable by the operator, and entered in the history log, regardless of whether you embed the information in the message text.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
75
Chapter 1
FactoryTalk Alarms and Events Logix-based Instructions (ALMD, ALMA)
Multiple Language Versions of Alarm Messages
You can maintain alarm messages in multiple languages. Either enter the different languages in the associated language versions of Logix Designer application or in an import/export (.CSV or .TXT) file.
You can access alarm message text from an import/export (.CSV or .TXT) file and add additional lines for translated versions of the original message string.
Messages in different languages use ISO language codes in the TYPE column.
Alarm message text, including embedded variable codes, for the operator is in the
DESCRIPTION column. The SPECIFIER identifies the alarm condition.
Use the import/export utility to create and translate message strings into multiple languages. The .TXT import/export format supports double-byte characters, so you can use this format for all languages, including Chinese, Japanese, and
Korean. The .CSV import/export format does not support double-byte characters.
Importing and exporting messages always performs a merge. Deleting a message in a .CSV or .TXT file does not delete the message from the .ACD file. To delete a message, import the .CSV or .TXT file with the type, name, and specifier fields filled in but the description blank.
76
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Monitor Alarm Status
FactoryTalk Alarms and Events Logix-based Instructions (ALMD, ALMA)
Chapter 1
On the Status tab of the alarm dialog box, monitor the alarm condition, acknowledge an alarm, disable an alarm, suppress an alarm, shelve an alarm or reset an alarm. Use the dialog box selections to see how an alarm behaves, without needing an operational HMI.
Alarms Log
In order to receive controller-based alarm messages, the alarm client (Factory
Talk Alarms and Events server) must establish a subscription to the Alarm Log object in the Logix controller.
As alarm state changes occur, the alarm instructions in the controller store the necessary information (such as timestamps and associated tag values) to the
Alarm Log. The publisher mechanism delivers the alarm messages to each subscriber as quickly as possible.
When the Alarm Log is full, the oldest alarm messages are rewritten. The size of the Alarm Log is controller-family dependent.
When the subscriber re-establishes a connection, it begins to receive current alarm messages. The historic data is available and the subscriber can obtain the sequence number of the first (and last message) to see what data is missed during the disconnect period.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
77
Chapter 1
FactoryTalk Alarms and Events Logix-based Instructions (ALMD, ALMA)
Programmatically Access
Alarm Information
Access
User program
Custom HMI
Standard HMI object
Not accessible
Each alarm instruction has an alarm structure that stores alarm configuration and execution information. The alarm structure includes both Program and Operator control elements and operator elements. The alarm instructions do not use mode settings to determine whether program access or operator access is active, so these elements are always active.
There are three ways to perform actions on an alarm instruction.
Alarm Structure Elements
• ProgAck
• ProgReset
• ProgUnshelve
• ProgSuppress
• ProgDisable
• ProgEnable
• OperAck
• OperReset
• OperShelve
• OperUnshelve
• OperSuppress
• OperDisable
• OperEnable
Considerations
Use controller logic to programmatically access elements of the alarming system. For example, the control program can determine whether to disable a series of alarms that are related to a single root cause. For example, the control program could disable an alarm instruction, MyDigitalAlarm of data type ALARM_DIGITAL, by accessing the tag member MyDigitalAlarm.ProgDisable.
Create a custom HMI faceplate to access elements of the alarming system. For example, if the operator needs to remove a tool, rather than manually disable or suppress alarms individually from the alarming screens, the operator can press a disable key that accesses a tag MyDigitalAlarm.OperDisable.
Operator parameters work with any Rockwell Automation or third-party operator interface to allow control of alarm states.
When an operator parameter is set, the instruction evaluates whether it can respond to the request, then always resets the parameter.
Normal operator interaction is through the alarm summary, alarm banner, and alarm status explorer objects in the FactoryTalk View application. This interaction is similar to the custom HMI option described above, but there is no programmatic visibility or interaction.
When you create an alarm instruction, you must create and assign a tag of the correct alarm data type for that alarm. For example, create MyDigitalAlarm of data type ALARM_DIGITAL. In relay ladder, these instruction parameters must be entered on the instruction:
• ProgAck
• ProgReset
• ProgDisable
• ProgEnable
In relay ladder and structured text, the value or tag you assign to an instruction parameter (such as ProgAck) is automatically written to the alarm tag member
(such as MyAnalogAlarm.ProgAck) each time the instruction is scanned.
78
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
FactoryTalk Alarms and Events Logix-based Instructions (ALMD, ALMA)
Chapter 1
In relay ladder and structured text, if you want to programmatically access the alarm structure, assign the structure tag to the parameter on the instruction. For example, to use MyAnalogAlarm.ProgAck in logic, assign the tag
MyAnalogAlarm.ProgAck to the ProgAck parameter.
Shelve, Suppress, or Disable
Alarms
FactoryTalk Alarms and Events system provides three mechanisms to prevent indication of the alarm in the alarm summary: suppress, shelve, and disable.
Shelve and Suppress allow you to clear the alarm from the alarm summary or banner while you are resolving a known alarm, without continuing to view alarm information once the alarm is acknowledged. Shelve has an automatic timeout, after which the alarm is automatically Unshelved and returned to the operator view. Suppress does not have an automatic timeout. If the alarm is unacknowledged at the time it is Shelved or Suppressed, it will continue to appear on the alarm summary and banner until it has been acknowledged, at which point, it will be removed from view. A Shelved or Suppressed alarm is still able to transition alarm status (except becoming unacknowledged), send alarm state changes to subscribers, log state changes in the historical database, and is responsive to other programmatic or operator interactions:
• When an alarm is Suppressed or Shelved, it continues to function normally, monitor the In parameter for alarm conditions, and respond to
Acknowledge requests. All subscribers are notified of this event, and any alarm messages generated while the alarm is in the Suppressed or Shelved state include the Suppressed or Shelved status. An alarm is not allowed to become unacknowledged while Shelved or Suppressed.
• When an alarm is Unsuppressed or Unshelved, all subscribers are notified and alarm messages to subscribers no longer include the Suppressed or
Shelved status. If the alarm is active when Unsuppressed or Unshelved and acknowledge is required, the alarm becomes unacknowledged (Acked is cleared).
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
79
Chapter 1
FactoryTalk Alarms and Events Logix-based Instructions (ALMD, ALMA)
Disable an alarm to take the alarm out-of-service in the control program. A disabled alarm does not transition alarm status or get logged in the historical database. If the alarm is Unacknowledged at the time it is Disabled, it will continue to appear on the alarm summary and banner until it has been
Acknowledged, at which point it will be removed from view. A disabled alarm can be re-enabled in the Alarm Status Explorer in FactoryTalk View SE software:
• When an alarm is Disabled, all of its conditions are inactivated (InAlarm is cleared) except the Acknowledged status if Unacknowledged. The In parameter is not monitored for alarm conditions, but will respond to an
Acknowledged event. All subscribers are notified of this event.
• When an alarm is Enabled, it begins to monitor the In parameter for alarm conditions. All subscribers are notified of this event. If the alarm is active when Enabled and Acknowledge is required, the alarm becomes
Unacknowledged (Acked is cleared).
Shelve, Suppress, and Disable are all methods to suppress indication of alarms, following ANSI/ISA-18.2-2009, Management of Alarm Systems for the Process
Industries. You can use Shelve, Suppress, and Disable functionality to track operator-initiated actions from design-initiated actions and maintenance actions.
Following this method, use Shelve to initiate this action by the operator
(equivalent to the Shelve state in ISA 18.2). The controller must use Suppress to programmatically inhibit operator notification (equivalent to the Suppress-by-
Design state in ISA 18.2). Use Disable to inhibit the alarm for maintenance purposes (equivalent to Out-of-Service state in ISA 18.2).
80
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
FactoryTalk Alarms and Events Logix-based Instructions (ALMD, ALMA)
Chapter 1
Figure 1 - State Model for Alarms
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
81
Chapter 1
FactoryTalk Alarms and Events Logix-based Instructions (ALMD, ALMA)
4
5
Table 2 - State Model for Alarms
Note
1
2
3
6
Description
The Program Unshelve command is provided so that the user has a means, using a small amount of programming, to unshelve alarms based on an event, for example End of Shift.
Following ANSI/ISA-18.2-2009, Suppress could be used to provide Suppress-by-Design functionality. Suppress could also be used to provide Outof-Service if logging while Out-of-Service is desired and logging while Suppressed-by-Design is not desired. Operator commands for Suppress/
Unsuppress are provided, but would not be used if using Suppress to implement Suppress-by-Design as outlined in ISA 18.2.
Following ANSI/ISA-18.2-2009, Disable could be used to provide Out-of-Service state described by the standard. Disable could also be used to provide Suppress-by-Design if logging while Suppressed-by-Design is not desired and logging while Out-of-Service is desired. Operator commands for Enable/Disable are provided, but would not be used if using Suppress to implement Suppress-by-Design as outlined in ISA 18.2.
While Disabled, Suppressed, or Shelved, an acknowledged alarm will not become unacknowledged.
While Disabled, Suppressed, or Shelved, if acknowledge is required, an unacknowledged alarm will remain unacknowledged until it is acknowledged.
An alarm will become unacknowledged if the alarm is InAlarm when an alarm changes state to Enabled, Unsuppressed, and Unshelved.
82
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Controller-based Alarm
Execution
Source
Alarm tag members
Client messages
FactoryTalk Alarms and Events Logix-based Instructions (ALMD, ALMA)
Chapter 1
Controller-based alarms process inputs from two sources.
Description
Alarm tag members are, for the most part, processed when the user application scans the alarm instruction. This includes:
• processing changes to configuration parameters.
• evaluating the alarm condition.
• measuring elapsed time for MinDuration.
• capturing InAlarmTime and RetToNormalTime timestamps.
• capturing associated tag values.
• processing Prog and Oper commands.
Client messages are processed as they are received, asynchronously to the program scan:
• Reset, Acknowledge, Disable/Enable, Shelve/Unshelve and Suppress/Unsuppress commands from a Studio 5000
Environment terminal
• Reset, Acknowledge, Disable/Enable, Shelve/Unshelve and Suppress/Unsuppress commands from a FactoryTalk View
SE alarm subscriber
Use care when determining where to place alarm instructions in the application.
The accuracy of the timestamps are affected by how quickly the instruction is scanned after the alarm condition changes state. MinDuration time accumulation and Rate of Change calculations require repeated scanning, within time intervals determined by the user application. Alarm instructions must continue to be scanned after the alarm condition becomes false, so that the ReturnToNormal transition may be detected. For example, if you desire 10 ms accuracy on timestamps, you could place the alarm instructions that need that resolution in a
10 ms periodic task.
Controller Memory Use
As a guideline, use the following alarm sizes for a rough calculation of controller memory usage:
• Typically 1 KB per digital alarm with no associated tags
Digital Alarm Example
Digital alarm with no associated tags
Digital alarm with no associated tags and this configuration:
• Alarm message: Contactor Fault
• Alarm Class: Tank Farm A
Digital alarm with two associated tags and this configuration:
• Alarm message: Contactor Fault
• Alarm Class: Tank Farm A
• Associated Tag 1 = DINT data type
• Associated Tag 2 = DINT data type
Digital alarm with two associated tags and this configuration:
• Alarm message: Contactor Fault
• Alarm Class: Tank Farm A
• Associated Tag 1 = DINT data type
• Associated Tag 2 = STRING data type
Approximate Size
1056 bytes
1144 bytes
1216 bytes
1560 bytes
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
83
Chapter 1
FactoryTalk Alarms and Events Logix-based Instructions (ALMD, ALMA)
• Typically 2.2 KB per analog alarm with no associated tags
Analog Alarm Example
Analog alarm with no associated tags
Analog alarm with no associated tags and this configuration:
• HH Alarm message: Level Alarm
• H Alarm Message: Level Alarm
• L Alarm Message: Level Alarm
• LL Alarm Message: Level Alarm
• Rate of Change Positive Message: Fill Too Fast
• Rate of Change Negative Message: Empty Too Fast
• Alarm Class: Tank Farm A
Analog alarm with two associated tags and this configuration:
• HH Alarm message: Level Alarm
• H Alarm Message: Level Alarm
• L Alarm Message: Level Alarm
• LL Alarm Message: Level Alarm
• Rate of Change Positive Message: Fill Too Fast
• Rate of Change Negative Message: Empty Too Fast
• Alarm Class: Tank Farm A
• Associated Tag 1 = DINT data type
• Associated Tag 2 = DINT data type
Analog alarm with two associated tags and this configuration:
• HH Alarm message: Level Alarm
• H Alarm Message: Level Alarm
• L Alarm Message: Level Alarm
• LL Alarm Message: Level Alarm
• Rate of Change Positive Message: Fill Too Fast
• Rate of Change Negative Message: Empty Too Fast
• Alarm Class: Tank Farm A
• Associated Tag 1 = DINT data type
• Associated Tag 2 = STRING data type
Approximate Size
2496 bytes
2624 bytes
2952 bytes
4632 bytes
Longer message strings, as well as message strings for multiple languages, consume additional memory from your controller.
Actual memory usage will depend on how the alarm is configured, message length, and any associated tags passed with the alarm.
84
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
FactoryTalk Alarms and Events Logix-based Instructions (ALMD, ALMA)
Chapter 1
Scan Time
These execution times show how ALMD instructions and ALMA instructions affect total scan time in a 1756-L7 x nonredundant controller.
Rung State Execution Times
No Input/State change
Activation
EnableIn true (rung value for RLL) No Input/State change
HAlarm Condition/
Activation
HHAlarm Condition/
Activation
EnableIn/False
Digital Alarm (ALMD)
6.6 µs
15.7 µs
—
—
—
—
Analog Alarm (ALMA)
—
—
15 µs
21.1 µs
25 µs
4.7 µs
An alarm state change is any event that changes the condition of the alarm, such as acknowledging or suppressing the alarm. Minimize the potential for a large number of alarms changing state simultaneously (alarm bursts) by creating dependencies on related alarms. Large alarm bursts can have a significant impact on application code scan time.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
85
Chapter 1
FactoryTalk Alarms and Events Logix-based Instructions (ALMD, ALMA)
Notes:
86
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Chapter
2
Bit Instructions
(XIC, XIO, OTE, OTL, OTU, ONS, OSR, OSF, OSRI, OSFI)
Topic
One Shot Rising with Input (OSRI)
One Shot Falling with Input (OSFI)
Page
Use the bit (relay-type) instructions to monitor and control the status of bits.
If you want to
Enable outputs when a bit is set
Enable outputs when a bit is cleared
Set a bit
Set a bit (retentive)
Clear bit (retentive)
Enable outputs for one scan each time a rung goes true
Set a bit for one scan each time a rung goes true
Set a bit for one scan each time the rung goes false
Set a bit for one scan each time the input bit is set in function block
Set a bit for one scan each time the input bit is cleared in function block
Use this instruction
XIC
XIO
OTE
OTL
OTU
ONS
OSR
OSF
OSRI
OSFI
Available in
Relay ladder
Structured text
(1)
Relay ladder
Structured text
(1)
Relay ladder
Structured text
(1)
Relay ladder
Structured text
(1)
Relay ladder
Structured text
(1)
Relay ladder
Structured text
(1)
Relay ladder
Relay ladder
Structured text
Function block
Structured text
Function block
(1) There is no equivalent structured text instruction. Use other structured text programming to achieve the same result. See the description for the instruction.
Page
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
87
Chapter 2
Bit Instructions (XIC, XIO, OTE, OTL, OTU, ONS, OSR, OSF, OSRI, OSFI)
Bit Addressing
Bits in a Logix controller exist in one of several forms:
• BOOL tag
• BOOL array
• Bits within an integer (SINT, INT, or DINT) tag
• Bits within an integer array
Any of the above constructs may also exist as members of a structure, whether it’s a system defined data type (SDT) or user-defined data type (UDT).
Bits defined as BOOLs are referenced simply by name. For example, XIC myBool.
Bits within BOOL arrays are referenced by a subscript appended to the array name. Subscripts can be a literal value (for example, XIC boolArray[31]), a tag
(for example, XIC boolArray[index]), or an expression (for example, XIC boolArray[index+1]).
Bits within an integer tag or integer array may be addressed similarly. This is what
Logix often refers to as bit addressing mode for integers. IEC 61131-3 might refer to it as ‘partial access of ANY_BIT variables’. Bit addressing for integers is programmed by adding a dot (or period) to the integer indicating subelement processing followed by a subscript (for example, myInteger[3].11 addresses bit
11, subelement [3]of the myInteger array). There is a shorthand form for literal subscripts in this case, which is simply a dot followed by the literal value (for example, myInteger.3, meaning bit 3 of myInteger). Similar to subscripts for
BOOL arrays above, one can specify a tag or expression for the subscript.
Integer arrays are dealt with similarly except that you must specify a member of the array from which indexing begins. For example, XIC myIntArray[4].[index+1] says to start at the 5th element of myIntArray and access bit ‘index+1.’ Bounds checking is performed on all subscripts to make sure the reference does not go beyond the boundary of the data object specified.
Literals are checked for conformance during verification.
88
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Bit Instructions (XIC, XIO, OTE, OTL, OTU, ONS, OSR, OSF, OSRI, OSFI)
Chapter 2
Example:
Indirect Serial Bit Reference in a DINT array
Tag
MyBits : DINT[10]
BitRef : DINT
EndTag
MOV(34,BitRef )
XIC(MyBits[(BitRef AND NOT 31)/32].[BitRef AND 31])
Explanation
(BitRef AND NOT 31)/32=Calculates the element in the DINT
.[BitRef AND 31]=Calculates the bit within the element
If the tag MyBits is defined as an INT or SINT, the mask value would be 15 or 7, respectively. Both the Diagnostic Detect (DDT) and File Bit Compare (FBC) instructions provide a bit number as a result of their operation. These instructions are limited to DINT arrays, and so the indirect addressing example can be used to programmatically locate the bit number returned from these instructions.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
89
Chapter 2
Bit Instructions (XIC, XIO, OTE, OTL, OTU, ONS, OSR, OSF, OSRI, OSFI)
Examine If Closed (XIC)
Operands:
The XIC instruction examines the data bit to see if it is set.
Relay Ladder
Operand
Data bit
Type
BOOL
Format
Tag
Description
Bit to be tested
Structured Text
Structured text does not have an XIC instruction, but you can achieve the same results by using an IF…THEN construct.
IF data_bit THEN
<
statement>;
END_IF;
See Function Block Attributes for information on the syntax of constructs within
structured text.
Description:
The XIC instruction examines the data bit to see if it is set.
Arithmetic Status Flags:
Not affected
Fault Conditions:
None
90
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Execution:
Condition
Prescan
Rung-condition-in is false
Rung-condition-in is true
Examine data bit.
Data Bit = 1
Rung-condition-out is set to true.
Data Bit = 0
Bit Instructions (XIC, XIO, OTE, OTL, OTU, ONS, OSR, OSF, OSRI, OSFI)
Chapter 2
Relay Ladder Action
The rung-condition-out is set to false.
The rung-condition-out is set to false.
Rung-condition-out is set to false.
End
Postscan The rung-condition-out is set to false.
Example 1:
If limit_switch_1 is set, this enables the next instruction (the rung-condition-out is true).
Relay Ladder
Structured Text
IF limit_switch THEN
< statement>;
END_IF;
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
91
Chapter 2
Bit Instructions (XIC, XIO, OTE, OTL, OTU, ONS, OSR, OSF, OSRI, OSFI)
Example 2:
If S:V is set (indicates that an overflow has occurred), this enables the next instruction (the rung-condition-out is true).
Relay Ladder
Structured Text
IF S:V THEN
<
statement>;
END_IF;
92
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Bit Instructions (XIC, XIO, OTE, OTL, OTU, ONS, OSR, OSF, OSRI, OSFI)
Chapter 2
Examine If Open (XIO)
Operands:
The XIO instruction examines the data bit to see if it is cleared.
Relay Ladder
Operand
Data bit
Type
BOOL
Format
Tag
Description
Bit to be tested
Structured Text
Structured text does not have an XIO instruction, but you can achieve the same results by using an IF...THEN construct.
IF NOT data_bit THEN
<
statement>;
END_IF;
See Function Block Attributes for information on the syntax of constructs within
structured text.
Description:
The XIO instruction examines the data bit to see if it is cleared.
Arithmetic Status Flags:
Not affected
Fault Conditions:
None
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
93
Chapter 2
Bit Instructions (XIC, XIO, OTE, OTL, OTU, ONS, OSR, OSF, OSRI, OSFI)
Execution:
Condition
Prescan
Rung-condition-in is false
Relay Ladder Action
The rung-condition-out is set to false.
The rung-condition-out is set to false.
Rung-condition-in is true
Examine data bit.
Data Bit = 1
Rung-condition-out is set to false.
Data Bit = 0
Rung-condition-out is set to true.
End
Postscan The rung-condition-out is set to false.
94
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Bit Instructions (XIC, XIO, OTE, OTL, OTU, ONS, OSR, OSF, OSRI, OSFI)
Chapter 2
Example 1:
If
limit_switch_2 is cleared, this enables the next instruction (the rung-conditionout is true).
Relay Ladder
Structured Text
IF NOT limit_switch_2 THEN
<
statement>;
END_IF;
Example 2:
If S:V is cleared (indicates that no overflow has occurred), this enables the next instruction (the rung-condition-out is true).
Relay Ladder
Structured Text
IF NOT S:V THEN
<
statement>;
END_IF;
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
95
Chapter 2
Bit Instructions (XIC, XIO, OTE, OTL, OTU, ONS, OSR, OSF, OSRI, OSFI)
Output Energize (OTE)
Operands:
The OTE instruction sets or clears the data bit.
Relay Ladder
Operand
Data bit
Type
BOOL
Format
Tag
Description
Bit to be set or cleared
Condition
Prescan
Postscan
Structured Text
Structured text does not have an OTE instruction, but you can achieve the same results by using a non-retentive assignment. data_bit [:=] BOOL_expression;
See
Function Block Attributes for information on the syntax of assignments and
expressions within structured text.
Description:
When the OTE instruction is enabled, the controller sets the data bit. When the
OTE instruction is disabled, the controller clears the data bit.
Arithmetic Status Flags:
Not affected
Fault Conditions:
None
Execution:
Rung-condition-in is false
Rung-condition-in is true
Relay Ladder Action
The data bit is cleared.
The rung-condition-out is set to false.
The data bit is cleared.
The rung-condition-out is set to false.
The data bit is set.
The rung-condition-out is set to true.
The data bit is cleared.
The rung-condition-out is set to false.
96
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Bit Instructions (XIC, XIO, OTE, OTL, OTU, ONS, OSR, OSF, OSRI, OSFI)
Chapter 2
Example:
When switch is set, the OTE instruction sets (turns on) light_1. When
switch is cleared, the OTE instruction clears (turns off ) light_1.
Relay Ladder
Structured Text
light_1 [:=] switch;
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
97
Chapter 2
Bit Instructions (XIC, XIO, OTE, OTL, OTU, ONS, OSR, OSF, OSRI, OSFI)
Output Latch (OTL)
The OTL instruction sets (latches) the data bit.
Operands:
Relay Ladder
Operand
Data bit
Type
BOOL
Format
Tag
Description
Bit to be set
Condition
Prescan
Postscan
Structured Text
Structured text does not have an OTL instruction, but you can achieve the same results by using an IF...THEN construct and an assignment.
IF BOOL_expression THEN data_bit := 1;
END_IF;
See
Function Block Attributes for information on the syntax of constructs,
expressions, and assignments within structured text.
Description:
When enabled, the OTL instruction sets the data bit. The data bit remains set until it is cleared, typically by an OTU instruction. When disabled, the OTL instruction does not change the status of the data bit.
Arithmetic Status Flags:
Not affected
Fault Conditions:
None
Execution:
Rung-condition-in is false
Rung-condition-in is true
Relay Ladder Action
The data bit is not modified.
The rung-condition-out is set to false.
The data bit is not modified.
The rung-condition-out is set to false.
The data bit is set.
The rung-condition-out is set to true.
The data bit is not modified.
The rung-condition-out is set to false.
98
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Bit Instructions (XIC, XIO, OTE, OTL, OTU, ONS, OSR, OSF, OSRI, OSFI)
Chapter 2
Example:
When enabled, the OTL instruction sets
light_2. This bit remains set until it is cleared, typically by an OTU instruction.
Relay Ladder
Structured Text
IF BOOL_expression THEN light_2 := 1;
END_IF;
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
99
Chapter 2
Bit Instructions (XIC, XIO, OTE, OTL, OTU, ONS, OSR, OSF, OSRI, OSFI)
Output Unlatch (OTU)
Operands:
The OTU instruction clears (unlatches) the data bit.
Relay Ladder
Operand
Data bit
Type
BOOL
Format
Tag
Description
Bit to be cleared
Condition
Prescan
Postscan
Structured Text
Structured text does not have an OTU instruction, but you can achieve the same results by using an IF...THEN construct and an assignment.
IF BOOL_expression THEN data_bit := 0;
END_IF;
See
Function Block Attributes for information on the syntax of constructs,
expressions, and assignments within structured text.
Description:
When enabled, the OTU instruction clears the data bit. When disabled, the
OTU instruction does not change the status of the data bit.
Arithmetic Status Flags:
Not affected
Fault Conditions:
None
Execution:
Rung-condition-in is false
Rung-condition-in is true
Relay Ladder Action
The data bit is not modified.
The rung-condition-out is set to false.
The data bit is not modified.
The rung-condition-out is set to false.
The data bit is cleared.
The rung-condition-out is set to true.
The data bit is not modified.
The rung-condition-out is set to false.
100
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Bit Instructions (XIC, XIO, OTE, OTL, OTU, ONS, OSR, OSF, OSRI, OSFI)
Chapter 2
Example:
When enabled, the OTU instruction clears
light_2.
Relay Ladder
Structured Text
IF BOOL_expression THEN light_2 := 0;
END_IF;
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
101
Chapter 2
Bit Instructions (XIC, XIO, OTE, OTL, OTU, ONS, OSR, OSF, OSRI, OSFI)
One Shot (ONS)
Operands:
The ONS instruction enables or disables the remainder of the rung, depending on the status of the storage bit.
Relay Ladder
Operand
Storage bit
Type
BOOL
Format
Tag
Description
Internal storage bit.
Stores the rung-condition-in from the last time the instruction was executed
Structured Text
Structured text does not have an ONS instruction, but you can achieve the same results by using an IF...THEN construct.
IF BOOL_expression AND NOT storage_bit THEN
<
statement>;
END_IF; storage_bit :=
BOOL_expression;
See
Function Block Attributes for information on the syntax of constructs,
expressions, and expressions within structured text.
Description:
When enabled and the storage bit is cleared, the ONS instruction enables the remainder of the rung. When disabled or when the storage bit is set, the ONS instruction disables the remainder of the rung.
Arithmetic Status Flags:
Not affected
Fault Conditions:
None
102
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Condition
Prescan
Rung-condition-in is false
Bit Instructions (XIC, XIO, OTE, OTL, OTU, ONS, OSR, OSF, OSRI, OSFI)
Chapter 2
Execution:
Relay Ladder Action
The storage bit is set to prevent an invalid trigger during the first scan.
The rung-condition-out is set to false.
The storage bit is cleared.
The rung-condition-out is set to false.
Rung-condition-in is true
Postscan
Examine storage bit.
storage bit = 1
Storage Bit = 0
Storage bit remains set.
Rung-condition-out is set to
false.
Storage bit is set.
End
The storage bit is cleared.
The rung-condition-out is set to false.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
103
Chapter 2
Bit Instructions (XIC, XIO, OTE, OTL, OTU, ONS, OSR, OSF, OSRI, OSFI)
Example:
You typically precede the ONS instruction with an input instruction because you scan the ONS instruction when it is enabled and when it is disabled for it to operate correctly. Once the ONS instruction is enabled, the rung-condition-in must go clear or the storage bit must be cleared for the ONS instruction to be enabled again.
On any scan for which
limit_switch_1 is cleared or storage_1 is set, this rung has no affect. On any scan for which limit_switch_1 is set and storage_1 is cleared, the
ONS instruction sets storage_1 and the ADD instruction increments sum by 1.
As long as limit_switch_1 stays set, sum stays the same value. The limit_switch_1 must go from cleared to set again for sum to be incremented again.
Relay Ladder
Structured Text
IF limit_switch_1 AND NOT storage_1 THEN sum := sum + 1;
END_IF; storage_1 := limit_switch_1;
104
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Bit Instructions (XIC, XIO, OTE, OTL, OTU, ONS, OSR, OSF, OSRI, OSFI)
Chapter 2
One Shot Rising (OSR)
Operands:
The OSR instruction sets or clears the output bit, depending on the status of the storage bit.
This instruction is available in structured text and function block as OSRI,
.
Relay Ladder
Operand
Storage bit
Type
BOOL
Format
Tag
Description
Internal storage bit
Stores the rung-condition-in from the last time the instruction was executed
Bit to be set Output bit BOOL Tag
Description:
When enabled and the storage bit is cleared, the OSR instruction sets the output bit. When enabled and the storage bit is set or when disabled, the OSR instruction clears the output bit .
Rung-condition-in
Storage Bit
Output Bit
Arithmetic Status Flags:
Not affected
Fault Conditions:
None
Instruction is executed
Instruction resets during next scan execution
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
105
Chapter 2
Bit Instructions (XIC, XIO, OTE, OTL, OTU, ONS, OSR, OSF, OSRI, OSFI)
Execution:
Condition
Prescan.
Rung-condition-in is false.
Relay Ladder Action
The storage bit is set to prevent an invalid trigger during the first scan.
The output bit is cleared.
The rung-condition-out is set to false.
The storage bit is cleared.
The output bit is not modified.
The rung-condition-out is set to false.
Rung-condition-in is true.
Examine storage bit.
Storage Bit = 0
Storage Bit = 1
Postscan
End
The storage bit is cleared.
The output bit is not modified.
The rung-condition-out is set to false.
Example:
Each time
limit_switch_1 goes from cleared to set, the OSR instruction sets
output_bit_1 and the ADD instruction increments sum by five. As long as
limit_switch_1 stays set, sum stays the same value. The limit_switch_1 must go from cleared to set again for sum to be incremented again. You can use
output_bit_1 on multiple rungs to trigger other operations
106
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Bit Instructions (XIC, XIO, OTE, OTL, OTU, ONS, OSR, OSF, OSRI, OSFI)
Chapter 2
One Shot Falling (OSF)
Operands:
The OSF instruction sets or clears the output bit depending on the status of the storage bit.
This instruction is available in structured text and function block as OSFI, see
Relay Ladder Operands
Operand
Storage bit
Type
BOOL
Format
Tag
Description
Internal storage bit
Stores the rung-condition-in from the last time the instruction was executed
Bit to be set Output bit BOOL Tag
Description:
When disabled and the storage bit is set, the OSF instruction sets the output bit.
When disabled and the storage bit is cleared, or when enabled, the OSF instruction clears the output bit.
Rung-condition-in
Storage Bit
Output Bit
Instruction is executed
Instruction resets during next scan execution
Arithmetic Status Flags:
Not affected
Fault Conditions:
None
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
107
Chapter 2
Bit Instructions (XIC, XIO, OTE, OTL, OTU, ONS, OSR, OSF, OSRI, OSFI)
Execution:
Condition
Prescan.
Relay Ladder Action
The storage bit is cleared to prevent an invalid trigger during the first scan.
The output bit is cleared.
The rung-condition-out is set to false.
Rung-condition-in is false.
Examine storage bit.
Storage Bit = 0
Storage Bit = 1
Rung-condition-in is true.
Postscan.
End
The storage bit is set.
The output bit is cleared.
The rung-condition-out is set to true.
See rung-condition-in is false above.
Example:
Each time limit_switch_1 goes from set to cleared, the OSF instruction sets
output_bit_2 and the ADD instruction increments sum by 5. As long as
limit_switch_1 stays cleared, sum stays the same value. The limit_switch_1 must go from set to cleared again for sum to be incremented again. You can use
output_bit_2 on multiple rungs to trigger other operations.
108
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Bit Instructions (XIC, XIO, OTE, OTL, OTU, ONS, OSR, OSF, OSRI, OSFI)
Chapter 2
One Shot Rising with Input
(OSRI)
The OSRI instruction sets the output bit for one execution cycle when the input bit toggles from cleared to set.
This instruction is available in relay ladder as OSR, see page 105
.
Operands:
OSRI(OSRI_tag);
Structured Text
Operand
OSRI tag
Type
FBD_ONESHOT
Format
Structure
Description
OSRI structure
Input Parameter
EnableIn
Data Type
BOOL
InputBit
Output Parameter
EnableOut
OutputBit
BOOL
Data Type
BOOL
BOOL
Function Block
Operand
OSRI tag
Type
FBD_ONESHOT
Format
Structure
Description
OSRI structure
FBD_ONESHOT Structure
Description
Function Block
If cleared, the instruction does not execute and outputs are not updated.
If set, the instruction executes.
Default is set.
Structured Text
No effect. The instruction executes.
Input bit. This is equivalent to rung condition for the relay ladder OSR instruction.
Default is cleared.
Description
The instruction produced a valid result.
Output bit.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
109
Chapter 2
Bit Instructions (XIC, XIO, OTE, OTL, OTU, ONS, OSR, OSF, OSRI, OSFI)
Description:
When InputBit is set and InputBit
OutputBit. When InputBit n-1
is set or when InputBit is cleared, the OSRI instruction clears OutputBit.
n-1
is cleared, the OSRI instruction sets
InputBit
InputBit n-1
OutputBit
Instruction is executed
Instruction resets during next scan execution
40048
Condition
Prescan
Instruction first scan
Instruction first run
EnableIn is cleared
EnableIn is set
Postscan
Arithmetic Status Flags:
Not affected
Fault Conditions:
None
Execution:
Function Block Action
No action taken.
InputBit
n-1
is set.
InputBit
n-1
is set.
EnableOut is cleared, the instruction does nothing, and the outputs are not updated.
On a cleared to set transition of InputBit, the instruction sets InputBit n-1
.
The instruction executes.
EnableOut is set.
No action taken.
Structured Text Action
No action taken.
InputBit
n-1
is set.
InputBit
n-1
is set.
N/A
On a cleared to set transition of InputBit, the instruction sets InputBit n-1
.
EnableIn is always set.
The instruction executes.
No action taken.
110
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Bit Instructions (XIC, XIO, OTE, OTL, OTU, ONS, OSR, OSF, OSRI, OSFI)
Chapter 2
Example:
When
limit_switch1 goes from cleared to set, the OSRI instruction sets
OutputBit for one scan.
Structured Text
OSRI_01.InputBit := limit_switch1;
OSRI(OSRI_01);
State := OSRI_01.OutputBit;
Function Block
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
111
Chapter 2
Bit Instructions (XIC, XIO, OTE, OTL, OTU, ONS, OSR, OSF, OSRI, OSFI)
One Shot Falling with Input
(OSFI)
The OSFI instruction sets the OutputBit for one execution cycle when the
InputBit toggles from set to cleared.
This instruction is available in relay ladder as OSF, see page 107
.
Operands:
OSFI(OSFI_tag);
Structured Text
Operand
OSFI tag
Type
FBD_ONESHOT
Format
Structure
Description
OSFI structure
Input Parameter
EnableIn
Data Type
BOOL
InputBit
Output Parameter
EnableOut
OutputBit
BOOL
Data Type
BOOL
BOOL
Function Block
Operand
OSFI tag
Type
FBD_ONESHOT
Format
Structure
Description
OSFI structure
FBD_ONESHOT Structure
Description
Function Block
If cleared, the instruction does not execute and outputs are not updated.
If set, the instruction executes.
Default is set.
Structured Text
No effect. The instruction executes.
Input bit. This is equivalent to rung condition for the relay ladder OSF instruction
Default is cleared.
Description
The instruction produced a valid result.
Output bit.
112
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Bit Instructions (XIC, XIO, OTE, OTL, OTU, ONS, OSR, OSF, OSRI, OSFI)
Chapter 2
Description:
When the InputBit is cleared and the InputBit the OutputBit. When InputBit
n-1 instruction clears the OutputBit.
n-1
is set, the OSFI instruction sets
is cleared or when InputBit is set, the OSFI
InputBit
InputBit n-1
OutputBit
Instruction is executed
Instruction resets during next scan execution
Condition
Prescan
Instruction first scan
Instruction first run
EnableIn is cleared
EnableIn is set
Postscan
Arithmetic Status Flags:
Not affected
Fault Conditions:
None
Execution:
Function Block Action
No action taken.
InputBit
n-1
is cleared.
InputBit
n-1
is cleared.
EnableOut is cleared, the instruction does nothing, and the outputs are not updated.
On a cleared to set transition of InputBit, the instruction clears
InputBit n-1
.
The instruction executes.
EnableOut is set.
No action taken.
Structured Text Action
No action taken.
InputBit
n-1
is cleared.
InputBit
n-1
is cleared.
N/A
On a cleared to set transition of InputBit, the instruction clears
InputBit n-1
.
EnableIn is always set.
The instruction executes.
No action taken.
40047
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
113
Chapter 2
Bit Instructions (XIC, XIO, OTE, OTL, OTU, ONS, OSR, OSF, OSRI, OSFI)
Example:
When
limit_switch1 goes from set to cleared, the OSFI instruction sets
OutputBit for one scan.
Structured Text
OSFI_01.InputBit := limit_switch1;
OSFI(OSFI_01);
Output_state := OSFI_01.OutputBit;
Function Block
114
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Chapter
3
Timer and Counter Instructions
(TON, TOF, RTO, TONR, TOFR, RTOR, CTU, CTD, CTUD, RES)
If you want to
Time how long a timer is enabled
Time how long a timer is disabled
Accumulate time
Time how long a timer is enabled with built-in reset in function block
Time how long a timer is disabled with built-in reset in function block
Accumulate time with built-in reset in function block
Count up
Count down
Count up and count down in function block
Reset a timer or counter
Topic
Timer On Delay with Reset (TONR)
Timer Off Delay with Reset (TOFR)
Retentive Timer On with Reset (RTOR)
Timers and counters control operations based on time or the number of events.
Use this instruction
TON
TOF
RTO
TONR
TOFR
RTOR
CTU
CTD
CTUD
RES
Available in these languages
Relay ladder
Relay ladder
Relay ladder
Structured text
Function block
Structure text
Function block
Structured text
Function block
Relay ladder
Relay ladder
Structured text
Function block
Relay ladder
Page
The time base for all timers is 1 ms.
Page
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
115
Chapter 3
Timer and Counter Instructions (TON, TOF, RTO, TONR, TOFR, RTOR, CTU, CTD, CTUD, RES)
Timer On Delay (TON)
The TON instruction is a non-retentive timer that accumulates time when the instruction is enabled (rung-condition-in is true).
Mnemonic
.EN
.TT
.DN
.PRE
.ACC
Operands:
This instruction is available in structured text and function block as TONR.
Relay Ladder
Operand
Timer
Preset
Accum
Type
TIMER
DINT
DINT
Format
Tag
Immediate Tag
Immediate Tag
Description
Timer structure
How long to delay (accumulate time)
Total milliseconds the timer has counted
Initial value is typically 0
Data Type
BOOL
BOOL
BOOL
DINT
DINT
TIMER Structure
Description
The enable bit indicates that the TON instruction is enabled.
The timing bit indicates that a timing operation is in process.
The done bit is set when .ACC .PRE.
The preset value specifies the value (1 ms units) that the accumulated value must reach before the instruction sets the .DN bit.
The accumulated value specifies the number of milliseconds that have elapsed since the TON instruction was enabled.
Description:
The TON instruction accumulates time until the following occurs:
• The TON instruction is disabled
• The .ACC .PRE
The time base is always 1 ms. For example, for a two-second timer, enter 2000 for the .PRE value.
116
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Timer and Counter Instructions (TON, TOF, RTO, TONR, TOFR, RTOR, CTU, CTD, CTUD, RES)
Chapter 3
When the TON instruction is disabled, the .ACC value is cleared.
Rung-condition-in
Timer Enable Bit (.EN)
IMPORTANT
Timer Timing Bit (.TT)
Timer Done Bit (.DN)
Preset
ON
Delay
Timer Accumulated Value (.ACC)
0
Timer did not reach
.PRE value
16649
A timer runs by subtracting the time of its last scan from the time now:
ACC = ACC + (
current_time - last_time_scanned)
After it updates the ACC, the timer sets last_time_scanned = current_time. This gets the timer ready for the next scan.
Make sure to scan the timer at least every 69 minutes while it runs. Otherwise, the ACC value won’t be correct.
The last_time_scanned value has a range of up to 69 minutes. The timer’s calculation rolls over if you don’t scan the timer within 69 minutes. The ACC value won’t be correct if this happens.
While a timer runs, scan it within 69 minutes if you put it in the following:
• A subroutine
• A section of code that is between JMP and LBL instructions
• A sequential function chart (SFC)
• An event or periodic task
• A state routine of a phase
Arithmetic Status Flags:
Not affected
Fault Conditions:
A major fault will occur if
.PRE < 0
.ACC < 0
4
4
Fault type Fault code
34
34
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
117
Chapter 3
Timer and Counter Instructions (TON, TOF, RTO, TONR, TOFR, RTOR, CTU, CTD, CTUD, RES)
Execution:
Condition
Prescan
Rung-condition-in is false
Relay Ladder Action
The .EN, .TT, and .DN bits are cleared.
The .ACC value is cleared.
The rung-condition-out is set to false.
The .EN, .TT, and .DN bits are cleared.
The .ACC value is cleared.
The rung-condition-out is set to false.
Rung-condition-in is true.
Examine .DN Bit
.DN Bit = 1
.DN Bit = 0
Postscan
.TT bit is set.
Examine .EN Bit
.EN Bit = 1
.EN Bit = 0 last_time = current_time
.EN bit is set.
TT bit is set last_time = current_time
.ACC .PRE
Examine .ACC
.ACC < .PRE
.DN is set
.TT bit is cleared
.ACC Value Rolls Over
No
Yes
.ACC = 2,147,483,647
The rung-condition-out is set to false.
Rung-condition-out is set to
true.
End
118
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Timer and Counter Instructions (TON, TOF, RTO, TONR, TOFR, RTOR, CTU, CTD, CTUD, RES)
Chapter 3
Example:
When
limit_switch_1 is set, light_2 is on for 180 ms (timer_1 is timing). When
timer_1.acc reaches 180, light_2 goes off and light_3 goes on. Light_3 remains on until the TOF instruction is disabled. If
limit_switch_1 is cleared while timer_1 is timing, light_2 goes off.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
119
Chapter 3
Timer and Counter Instructions (TON, TOF, RTO, TONR, TOFR, RTOR, CTU, CTD, CTUD, RES)
Timer Off Delay (TOF)
Operands:
The TOF instruction is a non-retentive timer that accumulates time when the instruction is enabled (rung-condition-in is false). This instruction is available in structured text and function block as TOFR.
Relay Ladder
Operand
Timer
Preset
Accum
Type
TIMER
DINT
DINT
Format
Tag
Immediate
Immediate
Description
Timer structure
How long to delay (accumulate time)
Total milliseconds the timer has counted
Initial value is typically 0
Mnemonic
.EN
.TT
.DN
.PRE
.ACC
TIMER Structure
Data Type
BOOL
BOOL
BOOL
DINT
DINT
Description
The enable bit indicates that the TOF instruction is enabled.
The timing bit indicates that a timing operation is in process
The done bit is cleared when .ACC .PRE.
The preset value specifies the value (1 ms units) that the accumulated value must reach before the instruction clears the
.DN bit.
The accumulated value specifies the number of milliseconds that have elapsed since the TOF instruction was enabled.
Description:
The TOF instruction accumulates time until the following occurs:
• The TOF instruction is disabled
• The .ACC .PRE
The time base is always 1 ms. For example, for a two-second timer, enter 2000 for the .PRE value.
120
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Timer and Counter Instructions (TON, TOF, RTO, TONR, TOFR, RTOR, CTU, CTD, CTUD, RES)
Chapter 3
When the TOF instruction is disabled, the .ACC value is cleared.
Rung-condition-in
Timer Enable Bit (.EN)
Timer Timing Bit (.TT)
Timer Done Bit (.DN)
OFF Delay
Preset
Timer Accumulated Value (.ACC)
0
16650
Timer did not reach .PRE value
IMPORTANT
A timer runs by subtracting the time of its last scan from the time now:
ACC = ACC + ( current_time - last_time_scanned)
After it updates the ACC, the timer sets last_time_scanned = current_time. This gets the timer ready for the next scan.
Make sure to scan the timer at least every 69 minutes while it runs. Otherwise, the ACC value won’t be correct.
The last_time_scanned value has a range of up to 69 minutes. The timer’s calculation rolls over if you don’t scan the timer within 69 minutes. The ACC value won’t be correct if this happens.
While a timer runs, scan it within 69 minutes if you put it in the following:
• A subroutine
• A section of code that is between JMP and LBL instructions
• A sequential function chart (SFC)
• An event or periodic task
• A state routine of a phase
Arithmetic Status Flags:
Not affected
Fault Conditions:
A major fault will occur if
.PRE < 0
.ACC < 0
Fault type
4
4
Fault code
34
34
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
121
Chapter 3
Timer and Counter Instructions (TON, TOF, RTO, TONR, TOFR, RTOR, CTU, CTD, CTUD, RES)
Execution:
Condition
Prescan
Relay Ladder Action
The .EN, .TT, and .DN bits are cleared.
The .ACC value is set to equal the .PRE value.
The rung-condition-out is set to false.
Rung-condition-in is false
.TT bit is set.
Examine .DN bit.
.DN Bit = 0
.DN Bit = 1
Examine .EN Bit.
.EN bit = 1
.EN bit = 0
.ACC = .ACC + (current_time - last_time) last_time = current_time
Examine .ACC
.ACC .PRE
.ACC < .PRE
.DN is cleared
.TT bit is cleared
.EN bit is cleared
Rung-condition-in is true
Postscan
.ACC Value Rolls Over
Yes
.ACC = 2,147,483,647
No
The .EN, .TT, and .DN bits are set.
The .ACC value is cleared.
The rung-condition-out is set to true.
The rung-condition-out is set to false.
Rung-condition-out is set to false.
End
122
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Timer and Counter Instructions (TON, TOF, RTO, TONR, TOFR, RTOR, CTU, CTD, CTUD, RES)
Chapter 3
Example:
When
limit_switch_2 is cleared, light_2 is on for 180 ms (timer_2 is timing).
When timer_2.acc reaches 180, light_2 goes off and light_3 goes on. Light_3 remains on until the TOF instruction is enabled. If
limit_switch_2 is set while
timer_2 is timing, light_2 goes off.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
123
Chapter 3
Timer and Counter Instructions (TON, TOF, RTO, TONR, TOFR, RTOR, CTU, CTD, CTUD, RES)
Retentive Timer On (RTO)
Operands:
The RTO instruction is a retentive timer that accumulates time when the instruction is enabled. This instruction is available in structured text and function block as RTOR.
Relay Ladder
Operand
Timer
Preset
Accum
Type
TIMER
DINT
DINT
Format
Tag
Immediate
Immediate
Description
Timer structure
How long to delay (accumulate time)
Number of milliseconds the timer has counted
Initial value is typically 0
Mnemonic
.EN
.TT
.DN
.PRE
.ACC
Data Type
BOOL
BOOL
BOOL
DINT
DINT
TIMER Structure
Description
The enable bit indicates that the RTO instruction is enabled.
The timing bit indicates that a timing operation is in process
The done bit indicates that .ACC .PRE.
The preset value specifies the value (1 ms units) that the accumulated value must reach before the instruction sets the .DN bit.
The accumulated value specifies the number of milliseconds that have elapsed since the RTO instruction was enabled.
124
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Timer and Counter Instructions (TON, TOF, RTO, TONR, TOFR, RTOR, CTU, CTD, CTUD, RES)
Chapter 3
Description:
The RTO instruction accumulates time until it is disabled. When the RTO instruction is disabled, it retains its .ACC value. You must clear the .ACC value, typically with a RES instruction referencing the same TIMER structure.
The time base is always 1 ms. For example, for a 2-second timer, enter 2000 for the .PRE value.
Rung-condition-in
Timer Enable Bit (.EN)
Rung Condition Controlling RES Instruction
Timer Timing Bit (.TT)
Timer Done Bit (.DN)
Preset
Timer Accumulated Value (.ACC)
IMPORTANT
16651
0
Timer did not reach .PRE value
A timer runs by subtracting the time of its last scan from the time now:
ACC = ACC + ( current_time - last_time_scanned)
After it updates the ACC, the timer sets last_time_scanned = current_time. This gets the timer ready for the next scan.
Make sure to scan the timer at least every 69 minutes while it runs. Otherwise, the ACC value won’t be correct.
The last_time_scanned value has a range of up to 69 minutes. The timer’s calculation rolls over if you don’t scan the timer within 69 minutes. The ACC value won’t be correct if this happens.
While a timer runs, scan it within 69 minutes if you put it in the following:
• A subroutine
• A section of code that is between JMP and LBL instructions
• A sequential function chart (SFC)
• An event or periodic task
• A state routine of a phase
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
125
Chapter 3
Timer and Counter Instructions (TON, TOF, RTO, TONR, TOFR, RTOR, CTU, CTD, CTUD, RES)
Condition
Prescan
Arithmetic Status Flags:
Not affected
Fault Conditions:
A major fault will occur if
.PRE < 0
.ACC < 0
Execution:
Rung-condition-in is false
Relay Ladder Action
The .EN, .TT, and .DN bits are cleared.
The .ACC value is not modified.
The rung-condition-out is set to false.
The .EN and .TT bits are cleared.
The .DN bit is not modified.
The .ACC value is not modified.
The rung-condition-out is set to false.
Rung-condition-in is true
Fault type
4
4
Postscan
126
Fault code
34
34
Examine .DN bit.
.DN Bit = 1
.DN Bit = 0
Examine .EN Bit.
.EN Bit = 0
.EN Bit = 1
.TT bit is set.
.ACC = .ACC + (current_time - last_time)
last_time = current_time
.EN bit is set.
.TT bit is set.
last_time = current_time
Examine .ACC
.ACC .PRE
.ACC < .PRE
.DN is set.
.TT bit is cleared.
.ACC value rolls over.
No
Yes
.ACC = 2,147,483,647
Rung-condition-out is set to true.
The rung-condition-out is set to false.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
End
Timer and Counter Instructions (TON, TOF, RTO, TONR, TOFR, RTOR, CTU, CTD, CTUD, RES)
Chapter 3
Example:
When
limit_switch_1 is set, light_1 is on for 180 ms (timer_2 is timing). When
timer_3.acc reaches 180, light_1 goes off and light_2 goes on. Light_2 remains until
timer_3 is reset. If limit_switch_2 is cleared while timer_3 is timing, light_1 remains on. When limit_switch_2 is set, the RES instruction resets timer_3
(clears status bits and .ACC value).
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
127
Chapter 3
Timer and Counter Instructions (TON, TOF, RTO, TONR, TOFR, RTOR, CTU, CTD, CTUD, RES)
Timer On Delay with Reset
(TONR)
Operands:
The TONR instruction is a non-retentive timer that accumulates time when
TimerEnable is set. This instruction is available in relay ladder as two separate instructions:
• TON (See
).
TONR(TONR_tag);
Structured Text
Variable
TONR tag
Type
FBD_TIMER
Format
Structure
Description
TONR structure
Input Parameter
EnableIn
Data Type
BOOL
TimerEnable
PRE
Reset
Output Parameter
EnableOut
ACC
EN
TT
DN
Status
InstructFault (Status.0)
PresetInv (Status.1)
BOOL
DINT
BOOL
BOOL
BOOL
DINT
BOOL
Data Type
BOOL
BOOL
BOOL
BOOL
Function Block
Operand
TONR tag
Type
FBD_TIMER
Format
Structure
Description
TONR structure
FBD_TIMER Structure
Description
Function Block
If cleared, the instruction does not execute and outputs are not updated.
If set, the instruction executes.
Default is set.
Structured Text
No effect. The instruction executes.
If set, this enables the timer to run and accumulate time.
Default is cleared.
Timer preset value. This is the value in 1ms units that ACC must reach before timing is finished. If invalid, the instruction sets the appropriate bit in Status and the timer does not execute.
Valid = 0 to maximum positive integer
Request to reset the timer. When set, the timer resets.
Default is cleared.
Description
The instruction produced a valid result.
Accumulated time in milliseconds.
Timer enabled output. Indicates the timer instruction is enabled.
Timer timing output. When set, a timing operation is in progress.
Timing done output. Indicates when the accumulated time is greater than or equal to the preset value.
Status of the function block.
The instruction detected one of the following execution errors. This is not a minor or major controller error. Check the remaining status bits to determine what occurred.
The preset value is invalid.
128
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Timer and Counter Instructions (TON, TOF, RTO, TONR, TOFR, RTOR, CTU, CTD, CTUD, RES)
Chapter 3
Description:
The TONR instruction accumulates time until the following occurs:
• TONR instruction is disabled
• ACC PRE
The time base is always 1 ms. For example, for a two-second timer, enter 2000 for the PRE value.
TimerEnable
Enable Bit (EN)
Timer Timing Bit (TT)
Timer Done Bit (DN)
Preset
ON
Delay
16649
Timer Accumulated Value (ACC)
0
Timer did not reach PRE value
Set the Reset input parameter to reset the instruction. If TimerEnable is set when
Reset is set, the TONR instruction begins timing again when Reset is cleared.
A timer runs by subtracting the time of its last scan from the time now:
ACC = ACC + (
current_time - last_time_scanned)
After it updates the ACC, the timer sets last_time_scanned = current_time. This gets the timer ready for the next scan.
IMPORTANT
Make sure to scan the timer at least every 69 minutes while it runs. Otherwise, the ACC value won’t be correct.
The last_time_scanned value has a range of up to 69 minutes. The timer’s calculation rolls over if you don’t scan the timer within 69 minutes. The ACC value won’t be correct if this happens.
While a timer runs, scan it within 69 minutes if you put it in the following:
• A subroutine
• A section of code that is between JMP and LBL instructions
• A sequential function chart (SFC)
• An event or periodic task
• A state routine of a phase
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
129
Chapter 3
Timer and Counter Instructions (TON, TOF, RTO, TONR, TOFR, RTOR, CTU, CTD, CTUD, RES)
Condition
Prescan
Instruction first scan
EnableIn is set
Reset
Postscan
Arithmetic Status Flags:
Not affected
Instruction first run
EnableIn is cleared
Fault Conditions:
None
Execution:
Function Block Action
No action taken.
EN, TT and DN are cleared.
ACC value is set to 0.
EN, TT and DN are cleared.
ACC value is set to 0.
EnableOut is cleared, the instruction does nothing, and the outputs are not updated.
When EnableIn transitions from cleared to set, the instruction initializes as described for instruction first scan.
The instruction executes.
EnableOut is set.
When the Reset input parameter is set, the instruction clears EN, TT and DN and sets
ACC = zero.
No action taken.
Structured Text Action
No action taken.
EN, TT and DN are cleared.
ACC value is set to 0.
EN, TT and DN are cleared.
ACC value is set to 0.
N/A
EnableIn is always set.
The instruction executes.
When the Reset input parameter is set, the instruction clears EN, TT and DN and sets
ACC = zero.
No action taken.
130
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Timer and Counter Instructions (TON, TOF, RTO, TONR, TOFR, RTOR, CTU, CTD, CTUD, RES)
Chapter 3
Example:
Each scan that limit_switch1 is set, the TONR instruction increments the ACC value by elapsed time until the ACC value reaches the PRE value. When
ACC PRE, the DN parameter is set, and timer_state is set.
Structured Text
TONR_01.Preset := 500;
TONR_01.Reset : = reset;
TONR_O1.TimerEnable := limit_switch1;
TONR(TONR_01); timer_state := TONR_01.DN;
Function Block Example
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
131
Chapter 3
Timer and Counter Instructions (TON, TOF, RTO, TONR, TOFR, RTOR, CTU, CTD, CTUD, RES)
Timer Off Delay with Reset
(TOFR)
Operands:
The TOFR instruction is a non-retentive timer that accumulates time when
TimerEnable is cleared. This instruction is available in relay ladder as two separate instructions:
TOFR(TOFR_tag);
Structured Text
Variable
TOFR tag
Type
FBD_TIMER
Format
Structure
Description
TOFR structure
Function Block Operands
Operand
TOFR tag
Type
FBD_TIMER
Format
Structure
Description
TOFR structure
Input Parameter
EnableIn
TimerEnable
PRE
Reset
Output Parameter
EnableOut
ACC
EN
TT
DN
Status
InstructFault (Status.0)
PresetInv (Status.1)
132
BOOL
DINT
BOOL
BOOL
BOOL
DINT
BOOL
Data Type
BOOL
BOOL
BOOL
BOOL
Data Type
BOOL
FBD_TIMER Structure
Description
Function Block
If cleared, the instruction does not execute and outputs are not updated.
If set, the instruction executes.
Default is set.
Structured Text
No effect. The instruction executes.
If cleared, this enables the timer to run and accumulate time.
Default is cleared.
Timer preset value. This is the value in 1ms units that ACC must reach before timing is finished. If invalid, the instructions sets the appropriate bit in Status and the timer does not execute.
Valid = 0 to maximum positive integer
Request to reset the timer. When set, the timer resets.
Default is cleared.
Description
The instruction produced a valid result.
Accumulated time in milliseconds.
Timer enabled output. Indicates the timer instruction is enabled.
Timer timing output. When set, a timing operation is in progress.
Timing done output. Indicates when accumulated time is greater than or equal to preset.
Status of the function block.
The instruction detected one of the following execution errors. This is not a minor or major controller error. Check the remaining status bits to determine what occurred.
The preset value is invalid.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Timer and Counter Instructions (TON, TOF, RTO, TONR, TOFR, RTOR, CTU, CTD, CTUD, RES)
Chapter 3
Description:
The TOFR instruction accumulates time until the following occurs:
• TOFR instruction is disabled
• ACC PRE
The time base is always 1 ms. For example, for a two-second timer, enter 2000 for the PRE value.
TimerEnable
Enable Bit (EN)
Timer Timing Bit (TT)
Timer Done Bit (DN)
OFF Delay
Preset
Timer Accumulated Value (ACC)
IMPORTANT
0
16650
Timer did not reach PRE value
Set the Reset input parameter to reset the instruction. If TimerEnable is cleared when Reset is set, the TOFR instruction does not begin timing again when Reset is cleared.
A timer runs by subtracting the time of its last scan from the time now:
ACC = ACC + (
current_time - last_time_scanned)
After it updates the ACC, the timer sets last_time_scanned = current_time.
This gets the timer ready for the next scan.
Make sure to scan the timer at least every 69 minutes while it runs. Otherwise, the ACC value won’t be correct.
The last_time_scanned value has a range of up to 69 minutes. The timer’s calculation rolls over if you don’t scan the timer within 69 minutes. The ACC value won’t be correct if this happens.
While a timer runs, scan it within 69 minutes if you put it in the following:
• A subroutine
• A section of code that is between JMP and LBL instructions
• A sequential function chart (SFC)
• An event or periodic task
• A state routine of a phase
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
133
Chapter 3
Timer and Counter Instructions (TON, TOF, RTO, TONR, TOFR, RTOR, CTU, CTD, CTUD, RES)
Condition
Prescan
Instruction first scan
EnableIn is set
Reset
Postscan
Arithmetic Status Flags:
Not affected
Instruction first run
EnableIn is cleared
Fault Conditions:
None
Execution:
Function Block Action
No action taken.
EN, TT and DN are cleared.
ACC value is set to PRE.
EN, TT and DN are cleared.
ACC value is set to PRE.
EnableOut is cleared, the instruction does nothing, and the outputs are not updated.
When EnableIn transitions from cleared to set, the instruction initializes as described for instruction first scan.
The instruction executes.
EnableOut is set.
When the Reset input parameter is set, the instruction clears EN, TT and DN and sets
ACC = PRE. Note that this is different than using a RES instruction on a
TOF instruction.
No action taken.
Structured Text Action
No action taken.
EN, TT and DN are cleared.
ACC value is set to PRE.
EN, TT and DN are cleared.
ACC value is set to PRE.
N/A
EnableIn is always set.
The instruction executes.
When the Reset input parameter is set, the instruction clears EN, TT and DN and sets
ACC = PRE. Note that this is different than using a RES instruction on a
TOF instruction.
No action taken.
134
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Timer and Counter Instructions (TON, TOF, RTO, TONR, TOFR, RTOR, CTU, CTD, CTUD, RES)
Chapter 3
Example:
Each scan after
limit_switch1 is cleared, the TOFR instruction increments the
ACC value by elapsed time until the ACC value reaches the PRE value. When
ACC PRE, the DN parameter is cleared, and
timer_state2 is set.
Structured Text
TOFR_01.Preset := 500
TOFR_01.Reset := reset;
TOFR_O1.TimerEnable := limit_switch1;
TOFR(TOFR_01); timer_state2 := TOFR_01.DN;
Function Block
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
135
Chapter 3
Timer and Counter Instructions (TON, TOF, RTO, TONR, TOFR, RTOR, CTU, CTD, CTUD, RES)
Retentive Timer On with
Reset (RTOR)
Operands:
The RTOR instruction is a retentive timer that accumulates time when
TimerEnable is set.
This instruction is available in relay ladder as two separate instructions:
).
RTOR(RTOR_tag);
Structured Text
Variable
RTOR tag
Type
FBD_TIMER
Format
Structure
Description
RTOR structure
Function Block Operands
Operand
RTOR tag
Type
FBD_TIMER
Format
Structure
Description
RTOR structure
Input Parameter
EnableIn
TimerEnable
PRE
Reset
Output Parameter
EnableOut
ACC
EN
TT
DN
Status
InstructFault (Status.0)
PresetInv (Status.1)
136
BOOL
DINT
BOOL
BOOL
BOOL
DINT
BOOL
BOOL
BOOL
Data Type
BOOL
DINT
Data Type
BOOL
FBD_TIMER Structure
Description
Function Block
If cleared, the instruction does not execute and outputs are not updated.
If set, the instruction executes.
Default is set.
Structured Text
No effect. The instruction executes.
If set, this enables the timer to run and accumulate time.
Default is cleared.
Timer preset value. This is the value in 1ms units that ACC must reach before timing is finished. If invalid, the instruction sets the appropriate bit in Status and the timer does not execute.
Valid = 0 to maximum positive integer
Request to reset the timer. When set, the timer resets.
Description
The instruction produced a valid result.
Accumulated time in milliseconds. This value is retained even while the TimerEnable input is cleared. This makes the behavior of this block different than the TONR block.
Timer enabled output. Indicates the timer instruction is enabled.
Timer timing output. When set, a timing operation is in progress.
Timing done output. Indicates when accumulated time is greater than or equal to preset.
Status of the function block.
The instruction detected one of the following execution errors. This is not a minor or major controller error. Check the remaining status bits to determine what occurred.
The preset value is invalid.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Timer and Counter Instructions (TON, TOF, RTO, TONR, TOFR, RTOR, CTU, CTD, CTUD, RES)
Chapter 3
Description:
The RTOR instruction accumulates time until it is disabled. When the RTOR instruction is disabled, it retains its ACC value. You must clear the .ACC value by using the Reset input.
The time base is always 1 ms. For example, for a two-second timer, enter 2000 for the PRE value.
TimerEnable
Enable Bit (EN)
Reset
Timer Timing Bit (TT)
Timer Done Bit (DN)
Timer Accumulated Value (ACC)
IMPORTANT
Preset
16651
0
Timer did not reach PRE value
Set the Reset input parameter to reset the instruction. If TimerEnable is set when
Reset is set, the RTOR instruction begins timing again when Reset is cleared.
A timer runs by subtracting the time of its last scan from the time now:
ACC = ACC + (
current_time - last_time_scanned)
After it updates the ACC, the timer sets last_time_scanned = current_time. This gets the timer ready for the next scan.
Make sure to scan the timer at least every 69 minutes while it runs. Otherwise, the ACC value won’t be correct.
The last_time_scanned value has a range of up to 69 minutes. The timer’s calculation rolls over if you don’t scan the timer within 69 minutes. The ACC value won’t be correct if this happens.
While a timer runs, scan it within 69 minutes if you put it in a:
• Subroutine
• Section of code that is between JMP and LBL instructions
• Sequential function chart (SFC)
• Event or periodic task
• State routine of a phase
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
137
Chapter 3
Timer and Counter Instructions (TON, TOF, RTO, TONR, TOFR, RTOR, CTU, CTD, CTUD, RES)
Condition
Prescan
Instruction first scan
Instruction first run
EnableIn is cleared
EnableIn is set
Reset
Postscan
Arithmetic Status Flags:
Not affected
Fault Conditions:
None
Execution:
Function Block Action
No action taken.
EN, TT and DN are cleared.
ACC value is not modified.
EN, TT and DN are cleared.
ACC value is not modified.
EnableOut is cleared, the instruction does nothing, and the outputs are not updated.
Function Block
When EnableIn transitions from cleared to set, the instruction initializes as described for instruction first scan.
The instruction executes.
EnableOut is set.
When the Reset input parameter is set, the instruction clears EN, TT and DN and sets
ACC = zero.
No action taken.
Structured Text Action
No action taken.
EN, TT and DN are cleared.
ACC value is not modified.
EN, TT and DN are cleared.
ACC value is not modified.
N/A
EnableIn is always set.
The instruction executes.
When the Reset input parameter is set, the instruction clears EN, TT and DN and sets
ACC = zero.
No action taken.
138
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Timer and Counter Instructions (TON, TOF, RTO, TONR, TOFR, RTOR, CTU, CTD, CTUD, RES)
Chapter 3
Example:
Each scan that
limit_switch1 is set, the RTOR instruction increments the ACC value by elapsed time until the ACC value reaches the PRE value. When
ACC PRE, the DN parameter is set, and
timer_state3 is set.
Structured Text
RTOR_01.Preset := 500
RTOR_01.Reset := reset;
RTOR_O1.TimerEnable := limit_switch1;
RTOR(RTOR_01); timer_state3 := RTOR_01.DN;
Function Block
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
139
Chapter 3
Timer and Counter Instructions (TON, TOF, RTO, TONR, TOFR, RTOR, CTU, CTD, CTUD, RES)
Count Up (CTU)
Operands:
The CTU instruction counts upward.
This instruction is available in structured text and function block as CTUD.
Relay Ladder
Operand
Counter
Preset
Accum
Type
COUNTER
DINT
DINT
Format
Tag
Immediate
Immediate
Description
Counter structure
How high to count
Number of times the counter has counted
Initial value is typically 0
.UN
.PRE
.ACC
Mnemonic
.CU
.DN
.OV
BOOL
DINT
DINT
Data Type
BOOL
BOOL
BOOL
COUNTER Structure
Description
The count up enable bit indicates that the CTU instruction is enabled.
The done bit indicates that .ACC .PRE.
The overflow bit indicates that the counter exceeded the upper limit of 2,147,483,647. The counter then rolls over to -
2,147,483,648 and begins counting up again.
The underflow bit indicates that the counter exceeded the lower limit of -2,147,483,648. The counter then rolls over to
2,147,483,647 and begins counting down again.
The preset value specifies the value that the accumulated value must reach before the instruction sets the .DN bit.
The accumulated value specifies the number of transitions the instruction has counted.
Description:
When enabled and the .CU bit is cleared, the CTU instruction increments the counter by one. When enabled and the .CU bit is set, or when disabled, the CTU instruction retains its .ACC value.
Rung-condition-in
Count-up Enable Bit (.CU)
Count-up Done Bit (.DN)
Preset
Counter Accumulated Value (.ACC)
16636
140
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Timer and Counter Instructions (TON, TOF, RTO, TONR, TOFR, RTOR, CTU, CTD, CTUD, RES)
Chapter 3
The accumulated value continues incrementing, even after the .DN bit is set. To clear the accumulated value, use a RES instruction that references the counter structure or write 0 to the accumulated value.
Arithmetic Status Flags:
Not affected
Fault Conditions:
None
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
141
Chapter 3
Timer and Counter Instructions (TON, TOF, RTO, TONR, TOFR, RTOR, CTU, CTD, CTUD, RES)
Execution:
Condition
Prescan
Rung-condition-in is false
Rung-condition-in is true
Relay Ladder Action
The .CU bit is set to prevent invalid increments during the first program scan.
The rung-condition-out is set to false.
The .CU bit is cleared.
The rung-condition-out is set to false.
Examine .CU bit.
.CU Bit = 1
.CU Bit = 0
Examine .UN Bit
.UN Bit = 0
.UN Bit = 1
.CU bit is set.
.ACC = .ACC + 1
.ACC Value rolls over
No
.UN bit = 1
Yes
Examine .UN Bit
.UN bit is cleared.
.DN Bit is cleared
OV bit is cleared
.UN bit = 0
Examine .OV Bit
.OV Bit = 0
.OV Bit = 1
Examine .ACC
.ACC < .PRE
.DN bit is cleared.
.ACC .PRE
.DN bit is set.
.OV bit is set.
Postscan The rung-condition-out is set to false.
Rung-condition-out is set to
true.
End
142
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Timer and Counter Instructions (TON, TOF, RTO, TONR, TOFR, RTOR, CTU, CTD, CTUD, RES)
Chapter 3
Example:
After
limit_switch_1 goes from disabled to enabled 10 times, the .DN bit is set and light_1 turns on. If limit_switch_1 continues to go from disabled to enabled,
counter_1 continues to increment its count and the .DN bit remains set. When
limit_switch_2 is enabled, the RES instruction resets counter_1 (clears the status bits and the .ACC value) and
light_1 turns off.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
143
.UN
.PRE
.ACC
Mnemonic
.CD
.DN
.OV
Chapter 3
Timer and Counter Instructions (TON, TOF, RTO, TONR, TOFR, RTOR, CTU, CTD, CTUD, RES)
Count Down (CTD)
Operands:
The CTD instruction counts downward.
This instruction is available in structured text and function block as CTUD.
Relay Ladder
Operand
Counter
Preset
Accum
Type
COUNTER
DINT
DINT
Format
Tag
Immediate
Immediate
Description
Counter structure
How low to count
Number of times the counter has counted
Initial value is typically 0
BOOL
DINT
DINT
Data Type
BOOL
BOOL
BOOL
COUNTER Structure
Description
The count down enable bit indicates that the CTD instruction is enabled.
The done bit indicates that .ACC .PRE.
The overflow bit indicates that the counter exceeded the upper limit of 2,147,483,647. The counter then rolls over to -
2,147,483,648 and begins counting up again.
The underflow bit indicates that the counter exceeded the lower limit of -2,147,483,648. The counter then rolls over to
2,147,483,647 and begins counting down again.
The preset value specifies the value that the accumulated value must reach before the instruction sets the .DN bit.
The accumulated value specifies the number of transitions the instruction has counted.
144
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Timer and Counter Instructions (TON, TOF, RTO, TONR, TOFR, RTOR, CTU, CTD, CTUD, RES)
Chapter 3
Description:
The CTD instruction is typically used with a CTU instruction that references the same counter structure.
When enabled and the .CD bit is cleared, the CTD instruction decrements the counter by one. When enabled and the .CD bit is set, or when disabled, the CTD instruction retains its .ACC value.
Rung-condition-in
Count-down Enable Bit (.CD)
Count-down Done Bit (.DN)
Counter Accumulated Value (.ACC)
Preset
16637
The accumulated value continues decrementing, even after the .DN bit is set. To clear the accumulated value, use a RES instruction that references the counter structure or write 0 to the accumulated value.
Arithmetic Status Flags:
Not affected
Fault Conditions:
None
Execution:
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
145
Chapter 3
Timer and Counter Instructions (TON, TOF, RTO, TONR, TOFR, RTOR, CTU, CTD, CTUD, RES)
Condition
Prescan
Rung-condition-in is false
Rung-condition-in is true
Relay Ladder Action
The .CD bit is set to prevent invalid decrements during the first program scan.
The rung-condition-out is set to false.
The .CD bit is cleared.
The rung-condition-out is set to false.
Examine .CD bit.
.CD bit = 1
.CD Bit = 0
.CD bit is set.
.ACC = .ACC - 1
.ACC Value Rolls Over
No
.OV bit = 1
Yes
Examine .OV Bit
.OV bit is cleared.
.DN bit is cleared.
.UN bit is cleared.
Examine .UN Bit.
.UN bit = 0
.UN Bit = 1
Examine .OV Bit
.OV Bit = 1
.OV Bit = 0
Examine .ACC
.ACC < .PRE
.DN bit is cleared.
.ACC .PRE
.DN bit is set.
.UN bit is set.
Postscan The rung-condition-out is set to false.
Rung-condition-out is set to
true.
End
146
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Timer and Counter Instructions (TON, TOF, RTO, TONR, TOFR, RTOR, CTU, CTD, CTUD, RES)
Chapter 3
Example:
A conveyor brings parts into a buffer zone. Each time a part enters,
limit_switch_1 is enabled and counter_1 increments by one. Each time a part leaves,
limit_switch_2 is enabled and counter_1 decrements by one. If there are
100 parts in the buffer zone ( counter_1.dn is set), conveyor_A turns on and stops the conveyor from bringing in any more parts until the buffer has room for more parts.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
147
Chapter 3
Timer and Counter Instructions (TON, TOF, RTO, TONR, TOFR, RTOR, CTU, CTD, CTUD, RES)
Count Up/Down (CTUD)
Operands:
The CTUD instruction counts up by one when CUEnable transitions from clear to set. The instruction counts down by one when CDEnable transitions from clear to set. This instruction is available in relay ladder as three separate instructions:
• RES (See
CTUD(CTUD_tag);
Structured Text
Variable
CTUD tag
Type
FBD_COUNTER
Format
Structure
Description
CTUD structure
Function Block
Operand
CTUD tag
Type
FBD_COUNTER
Format
Structure
Description
CTUD structure
Input Parameter
EnableIn
Data Type
BOOL
CUEnable
CDEnable
PRE
Reset
BOOL
BOOL
DINT
BOOL
FBD_COUNTER Structure
Description
Function Block
If cleared, the instruction does not execute and outputs are not updated.
If set, the instruction executes.
Default is set.
Structured Text
No effect. The instruction executes.
Enable up count. When input toggles from clear to set, accumulator counts up by one.
Default is cleared.
Enable down count. When input toggles from clear to set, accumulator counts down by one.
Default is cleared.
Counter preset value. This is the value the accumulated value must reach before DN is set.
Valid = any integer
Default is 0.
Request to reset the timer. When set, the counter resets.
Default is cleared.
148
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Timer and Counter Instructions (TON, TOF, RTO, TONR, TOFR, RTOR, CTU, CTD, CTUD, RES)
Chapter 3
CD
DN
OV
Output Parameter
EnableOut
ACC
CU
UN
Data Type
BOOL
DINT
BOOL
BOOL
BOOL
BOOL
BOOL
Description
The instruction produced a valid result.
Accumulated value.
Count up enabled.
Count down enabled.
Counting done. Set when accumulated value is greater than or equal to preset.
Counter overflow. Indicates the counter exceeded the upper limit of 2,147,483,647.
The counter then rolls over to 2,147,483,648 and begins counting down again.
Counter underflow. Indicates the counter exceeded the lower limit of 2,147,483,648.
The counter then rolls over to 2,147,483,647 and begins counting down again.
Description
When enabled and CUEnable is set, the CTUD instructions increments the counter by one. When enabled and CDEnable is set, the CTUD instruction decrements the counter by one. Both the CUEnable and CDEnable input parameters can both be toggled during the same scan. The instruction executes the count up prior to the count down.
Figure 2 - Counting Up
CUEnable
Count-up Enable Bit (CU)
Count-up Done Bit (DN)
Preset
Counter Accumulated Value (ACC)
16636
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
149
Chapter 3
Timer and Counter Instructions (TON, TOF, RTO, TONR, TOFR, RTOR, CTU, CTD, CTUD, RES)
Figure 3 - Counting Down
CDEnable
Count-down Enable Bit (CD)
Count-down Done Bit (DN)
Counter Accumulated Value (ACC)
Preset
16637
Condition
Prescan
Instruction first scan
Instruction first run
EnableIn is cleared
EnableIn is set
Reset
Postscan
When disabled, the CTUD instruction retains its accumulated value. Set the
Reset input parameter of the FBD_COUNTER structure to reset the instruction.
Arithmetic Status Flags:
Not affected
Fault Conditions:
None
Execution:
Function Block Action
No initialization required.
CUEnable n-1
and CDEnable n-1
are set.
CUEnable n-1
and CDEnable n-1
are set.
EnableOut is cleared, the instruction does nothing, and the outputs are not updated.
The instruction sets CUEnable n-1
and CDEnable n-1
.
On a cleared to set transition of EnableIn:
• the instruction executes.
• EnableOut is set.
When set, the instruction clears CUEnable n-1
, CDEnable n-1
, CU, CD,
DN, OV, and UN and sets
ACC = zero.
No action taken.
Structured Text Action
No initialization required.
CUEnable n-1
and CDEnable n-1
are set.
CUEnable n-1
and CDEnable n-1
are set.
N/A
The instruction sets CUEnable n-1
EnableIn is always set.
The instruction executes.
and CDEnable n-1
.
When set, the instruction clears CUEnable n-1
, CDEnable n-1
, CU, CD,
DN, OV, and UN and sets
ACC = zero.
No action taken.
150
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Timer and Counter Instructions (TON, TOF, RTO, TONR, TOFR, RTOR, CTU, CTD, CTUD, RES)
Chapter 3
Example:
When
limit_switch1 goes from cleared to set, CUEnable is set for one scan and the CTUD instruction increments the ACC value by 1. When
ACC PRE, the DN parameter is set, which enables the function block instruction following the CTUD instruction.
Structured Text
CTUD_01.Preset := 500;
CTUD_01.Reset := Restart;
CTUD_O1.CUEnable := limit_switch1;
CTUD(CTUD_01); counter_state := CTUD_01.DN;
Function Block
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
151
Chapter 3
Timer and Counter Instructions (TON, TOF, RTO, TONR, TOFR, RTOR, CTU, CTD, CTUD, RES)
Reset (RES)
The RES instruction resets a TIMER, COUNTER, or CONTROL structure.
Operands:
Relay Ladder
Operand
Structure
Type
TIMER
CONTROL
COUNTER
Format
Tag
Description
Structure to reset
Description:
When enabled the RES instruction clears these elements.
When using a RES instruction for a
TIMER
COUNTER
CONTROL
The instruction clears
.ACC value
Control status bits
.ACC value
Control status bits
.POS value
Control status bits
ATTENTION: Because the RES instruction clears the .ACC value, .DN bit, and .TT bit, do not use the RES instruction to reset a TOF timer.
Postscan
Arithmetic Status Flags:
Not affected
Fault Conditions:
None
Execution:
Condition
Prescan
Rung-condition-in is false
Rung-condition-in is true
Relay Ladder Action
The rung-condition-out is set to false.
The rung-condition-out is set to false.
The RES instruction resets the specified structure.
The rung-condition-out is set to true.
The rung-condition-out is set to false.
152
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Chapter
4
Input/Output Instructions
(MSG, GSV, SSV, IOT)
Topic
Specify the Configuration Details
Specify the Communication Details
Get System Value (GSV) and Set System Value (SSV)
Page
If you want to
Send data to or from another module
Get controller status information
Set controller status information
The input/output instructions read or write data to, or from, a controller or module.
Use this instruction
MSG
GSV
SSV
Send output values to an I/O module or consuming controller at a specific point in your logic.
Trigger an event task in another controller.
IOT
Available in these languages
Relay ladder
Structured text
Relay ladder
Structured text
Relay ladder
Structured text
Relay ladder
Structured text
Page
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
153
Chapter 4
Input/Output Instructions (MSG, GSV, SSV, IOT)
Message (MSG)
Operands:
The MSG instruction asynchronously reads or writes a block of data to another module on a network.
Relay Ladder
Operand Type
Message control MESSAGE
Format
Tag
Description
Message structure
MSG(MessageControl);
TIP
IMPORTANT
Structured Text
The operands are the same as those for the relay ladder MSG instruction.
MESSAGE Structure
We recommend that you always include an XIO of the MSG.EN bit as an in-series MSG rung precondition.
This guarantees that other ring preconditions cannot trigger the rung until the MSG completes or errors.
If modifying the default values for the UnconnectedTimeout or ConnectionRate, do not enter values lower than 1 second.
If values lower than 1 second are used, it may cause the controller to do the following:
• Drop off the backplane and require the controller to be power cycled to recover communications
• Experience a unrecoverable major fault
IMPORTANT
ATTENTION: The controller changes the DN, ER, EW, and ST bits asynchronous to the scan of your logic. If you check these status bits more than once in your program, use a copy of these bits and examine the state of the copied values, otherwise your logic may not work as expected.
One way to make a copy is to use the FLAGS word. Copy the FLAGS word to another tag and check the bits in the copy.
• DN
• EN
• ER
• EW
• ST
Do not change or manipulate the following status bits of a MSG instruction, as this may cause an unrecoverable fault to occur:
154
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Mnemonic
.FLAGS
.DN
.ST
.EN
.ERR
.EXERR
.REQ_LEN
.DN_LEN
.EW
.ER
.TO
.EN_CC
.ERR_SRC
.DestinationLink
.DestinationNode
.SourceLink
.Class
.Attribute
.Instance
Input/Output Instructions (MSG, GSV, SSV, IOT)
Chapter 4
SINT
INT
INT
INT
INT
INT
DINT
Data Type Description
INT The FLAGS member provides access to the status members (bits) in one 16-bit word.
This bit
2
Is this member
.EW
6
7
4
5
.ER
.DN
.ST
.EN
INT
INT
INT
INT
BOOL
8
9
.TO
.EN_CC
Important: Do not change or manipulate the EN, EW, ER, DN, or ST bits of the FLAGS member. For example, do not clear the entire
FLAGS word. The controller ignores the change and uses the internally-stored values of the bits.
If the .ER bit is set, the error code word identifies error codes for the MSG instruction. Manipulating these bits can cause an unrecoverable major fault in the controller. See
The extended error code word specifies additional error code information for some error codes. See
Extended Error Codes on page 162
.
The requested length specifies how many words the message instruction will attempt to transfer.
The done length identifies how many words actually transferred.
BOOL
BOOL
BOOL
BOOL
BOOL
BOOL
The enable waiting bit is set when the controller detects that a message request has entered the queue. The controller resets the .EW bit when the .ST bit is set.
Important: Do not change or manipulate the EW bit. The controller ignores the change and uses the internally-stored value of the bit. Manipulating these bits can cause an unrecoverable major fault in the controller.
The error bit is set when the controller detects that a transfer failed. The .ER bit is reset the next time the rung-condition-in goes from false to true.
Important: Do not change or manipulate the ER bit. Manipulating these bits can cause an unrecoverable major fault in the controller.
The done bit is set when the last packet of the message is successfully transferred. The .DN bit is reset the next time the rungcondition-in goes from false to true.
Important: Do not change or manipulate the DN bit. Manipulating these bits can cause an unrecoverable major fault in the controller.
The start bit is set when the controller begins executing the MSG instruction. The .ST bit is reset when the .DN bit or the .ER bit is set.
Important: Do not change or manipulate the ST bit. The controller ignores the change and uses the internally-stored value of the bit. Manipulating these bits can cause an unrecoverable major fault in the controller.
The enable bit is set when the rung-condition-in goes true and remains set until either the .DN bit or the .ER bit is set and the rungcondition-in is false. If the rung-condition-in goes false, but the .DN bit and the .ER bit are cleared, the .EN bit remains set.
Important: Do not change or manipulate the EN bit. Manipulating these bits can cause an unrecoverable major fault in the controller.
If you manually set the .TO bit, the controller stops processing the message and sets the .ER bit.
The enable cache bit determines how to manage the MSG connection.
Refer to Choose a Cache Option on page 186
Connections for
MSG instructions going out the serial port are not cached, even if the .EN_CC bit is set.
Used by Logix Designer application to show the error path on the Message Configuration dialog box
To change the Destination Link of a DH+ or CIP with Source ID message, set this member to the required value.
To change the Destination Node of a DH+ or CIP with Source ID message, set this member to the required value.
To change the Source Link of a DH+ or CIP with Source ID message, set this member to the required value.
To change the Class parameter of a CIP Generic message, set this member to the required value.
To change the Attribute parameter of a CIP Generic message, set this member to the required value.
To change the Instance parameter of a CIP Generic message, set this member to the required value.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
155
Chapter 4
Input/Output Instructions (MSG, GSV, SSV, IOT)
Mnemonic
.LocalIndex
.Channel
.Rack
.Group
.Slot
.Path
.RemoteIndex
.RemoteElement
.UnconnnectedTimeout
.ConnectionRate
.TimeoutMultiplier
Data Type Description
DINT If you use an asterisk [*] to designate the element number of the local array, the LocalIndex provides the element number. To change the element number, set this member to the required value.
If the message
Reads data
Then the local array is
Destination element
SINT
SINT
SINT
SINT
STRING
DINT
Writes data Source element
To send the message out a different channel of the 1756-DHRIO module, set this member to the required value. Use either the ASCII character A or B.
To change the rack number for a block transfer message, set this member to the required rack number (octal).
To change the group number for a block transfer message, set this member to the required group number (octal).
To change the slot number for a block transfer message, set this member to the required slot number.
If the message goes over this network
Then specify the slot number
Universal remote I/O
ControlNet
Octal
Decimal (0…15)
To send the message to a different controller, set this member to the new path.
• Enter the path as hexadecimal values.
• Omit commas [,]
For example, for a path of 1, 0, 2, 42, 1, 3, enter $01$00$02$2A$01$03.
To browse to a device and automatically create a portion or all of the new string, right-click a string tag and choose ‘Go to Message
Path Editor’.
If you use an asterisk [*] to designate the element number of the remote array, the RemoteIndex provides the element number. To change the element number, set this member to the required value.
STRING
DINT
DINT
SINT
If the message
Reads data
Then the remote array is
Source element
Writes data Destination element
To specify a different tag or address in the controller to which the message is sent, set this member to the required value. Enter the tag or address as ASCII characters.
If the message
Reads data
Then the remote array is
Source element
Writes data Destination element
Time out for an unconnected message or for making a connection. The default value is 30 seconds.
If the message is
Unconnected
Then
The ER bit turns on if the controller doesn’t get a response within the UnconnectedTimeout time.
Connected The ER bit turns on if the controller doesn’t get a response for making the connection within the
UnconnectedTimeout time.
Time out for a connected message once it has a connection. This time out is for the response from the other device about the sending of the data.
• This time out applies only after the connection is made.
• The time out = ConnectionRate x TimeoutMultiplier.
• The default ConnectionRate is 7.5 seconds.
• The default TimeoutMultiplier is 0 (which is a multiplication factor of 4).
• The default time out for connected messages is 30 seconds (7.5 seconds x 4 = 30 seconds).
• To change the time out, change the ConnectionRate and leave the TimeoutMultiplier at the default value.
156
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Input/Output Instructions (MSG, GSV, SSV, IOT)
Chapter 4
Description
The MSG instruction transfers elements of data.
This is a transitional instruction:
• In relay ladder, toggle the rung-condition-in from cleared to set each time the instruction should execute.
• In structured text, condition the instruction so that it executes only on a transition.
.
The size of each element depends on the data types you specify and the type of message command you use.
Connection with .EN_CC = 1
Rung-condition-in
.EN bit
.EW bit
Connection with .EN_CC = 0
.ST bit
.DN bit or .ER bit
41382
1 2 3 4 5 6 7
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
157
Chapter 4
Input/Output Instructions (MSG, GSV, SSV, IOT)
Where
1
2
Description
Rung-condition-in is true.
.EN is set.
.EW is set.
Connection is opened*.
Message is sent.
.ST is set.
.EW is cleared.
3
4
Condition
Prescan
Message is done or errored.
Rung-condition-in is false.
.DN or .ER is set.
.ST is cleared.
Connection is closed (if .EN_CC = 0).
.EN is cleared (rung-condition-in is false).
Rung-condition-in is true.
.DN or .ER was previously set.
.EN is set.
.EW is setCconnection is opened*.
.DN or .ER is cleared.
Execution:
Relay Ladder Action
The rung-condition-out is set to false.
N/A
Where
5
6
7
Description
Message is sent.
.ST is set.
.EW is cleared.
Message is done or errored.
Rung-condition-in is still true.
.DN or .ER is set.
.ST is cleared.
Connection is closed (if .EN_CC = 0).
Rung-condition-in goes false and .DN or .ER is set.
.EN is cleared.
N/A
Structured Text Action
No action taken.
158
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Input/Output Instructions (MSG, GSV, SSV, IOT)
Chapter 4
Condition
Rung-condition-in is false.
(does not apply to structured text)
Relay Ladder Action
.EN bit = 1
.EW bit = 1
Examine .EW Bit
.EW Bit = 0
.ST bit = 1
Examine .ST Bit
.ST Bit = 0
.DN bit = 1
Examine .DN Bit
.DN Bit = 0
.ER Bit = 1
Examine .ER Bit
.ER Bit = 0
.DN Bit = 1
Examine .DN Bit
.DN Bit = 0
.EN bit is cleared.
.ER Bit = 1
Examine .ER Bit
.ER Bit = 0
Examine .EN Bit
.EN Bit = 0
Block-transfer
Command
No
Yes
Yes
Execute message request.
.EW bit is set.
Structured Text Action
No
Module Path Valid
Yes
Module Connection
Running
No
.ER bit is set.
Rung-condition-out is set to false.
End
Rung-condition-in is true.
The instruction executes.
The rung-condition-out is set to true.
N/A
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
159
Chapter 4
Input/Output Instructions (MSG, GSV, SSV, IOT)
Condition
EnableIn is set.
Relay Ladder Action
N/A
Structured Text Action
EnableIn is always set.
The instruction executes.
Instruction execution
.EN Bit = 1 .EN Bit = 0
Examine .EN Bit
.EW Bit = 1
Examine .EW Bit
.EW Bit = 0
.ST Bit = 1
Examine .ST Bit
.ST Bit = 0
Examine .EW Bit
.EW Bit = 0
.EW bit = 1
Examine .ST Bit
.ST Bit = 0
.EW, .ST, .TO, .DN, and .ER Bits are cleared.
.EN bit is set.
.ST Bit = 1
.DN Bit = 1
Examine .DN Bit
.DN bit = 0
.ER Bit = 1
Examine .ER bit.
.ER Bit = 0
Block-transfer
Command
No
Yes
Yes
.EW, .ST, .TO, .DN, and .ER bits are cleared.
.EN bit is set.
Execute message request.
.EW bit is set.
Module Path Valid
Yes
Module Connection
Running
.EN bit is set.
No
No
.ER bit is set.
Rung-condition-out is set to false.
End
160
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Condition
Postscan
Relay Ladder Action
The rung-condition-out is set to false.
Arithmetic Status Flags:
Not affected
Fault Conditions:
None
Input/Output Instructions (MSG, GSV, SSV, IOT)
Chapter 4
Structured Text Action
No action taken.
MSG Error Codes
The error codes depend on the type of MSG instruction.
0012
0013
0014
0015
000E
000F
0010
0011
000A
000B
000C
000D
0006
0007
0008
0009
001A
001B
001C
Error Code (Hex)
0001
0002
0003
0004
0005
Error Codes
The Logix Designer application does not always display the full description.
Description
Connection failure (see extended error codes)
Insufficient resource
Invalid value
IOI syntax error (see extended error codes)
Destination unknown, class unsupported, instance undefined or structure element undefined (see extended error codes)
Insufficient packet space
Connection lost
Service unsupported
Error in data segment or invalid attribute value
Attribute list error
State already exists
Object model conflict
Object already exists
Attribute cannot be set
Permission denied
Device state conflict
Reply will not fit
Fragment primitive
Insufficient command data
Attribute not supported
Too much data
Bridge request too large
Bridge response too large
Attribute list shortage
Display In Software
Same as description
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
161
Chapter 4
Input/Output Instructions (MSG, GSV, SSV, IOT)
00FB
00FC
00FD
00FE
00FF
0027
0028
0029
00D1
Error Code (Hex)
001D
001E
001F
0022
0025
0026
Description
Invalid attribute list
Embedded service error
Connection related failure (see extended error codes)
Invalid reply received
Key segment error
Invalid IOI error
Unexpected attribute in list
DeviceNet error - invalid member ID
DeviceNet error - member not settable
Module not in run state
Message port not supported
Message unsupported data type
Message uninitialized
Message timeout
General error (see extended error codes)
Display In Software
Same as description
Unknown error
0116
0118
011A
0203
0204
0110
0111
0114
0115
0106
0107
0108
0109
Extended
Error Code
(Hex)
0100
0103
Description
Connection in use
Transport not supported
Ownership conflict
Connection not found
Invalid connection type
Invalid connection size
Module not configured
EPR not supported
Wrong module
Wrong device type
Wrong revision
Invalid configuration format
Application out of connections
Connection timeout
Unconnected message timeout
Extended Error Codes
The Logix Designer application does not display any text for the extended error codes.
These are the extended error codes for error code 0001.
0311
0312
0315
0317
0301
0302
0303
0305
Extended
Error Code
(Hex)
0205
0206
Description
Unconnected send parameter error
Message too large
No buffer memory
Bandwidth not available
No screeners available
Signature match
Port not available
Link address not available
Invalid segment type
Connection not scheduled
162
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Input/Output Instructions (MSG, GSV, SSV, IOT)
Chapter 4
2105
2106
2107
2108
2101
2102
2103
2104
2018
201B
201C
2100
Extended
Error Code
(Hex)
2001
2002
These are the extended error codes for error code 001F.
Extended Error Code (Hex) Description
0203 Connection timeout
These are the extended error codes for error code 0004 and 0005.
Extended Error Code (Hex) Description
0000 extended status out of memory
0001 extended status out of instances
Description
Excessive IOI
Bad parameter value
Semaphore reject
Size too small
Invalid size
Privilege failure
Invalid keyswitch position
Password invalid
No password issued
Address out of range
Address and how many out of range
Data in use
Type is invalid or not supported
Controller in upload or download mode
These are the extended error codes for error code 00FF.
2111
2112
2113
2114
210B
210E
210F
2110
Extended
Error Code
(Hex)
2109
210A
Description
Attempt to change number of array dimensions
Invalid symbol name
Symbol does not exist
Search failed
Task cannot start
Unable to write
Unable to read
Shared routine not editable
Controller in faulted mode
Run mode inhibited
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
163
Chapter 4
Input/Output Instructions (MSG, GSV, SSV, IOT)
PLC and SLC Error Codes (.ERR)
Logix firmware revision 10.x and later provides new error codes for errors that are associated with PLC and SLC™ message types (PCCC messages).
• This change lets RSLogix 5000 software display a more meaningful description for many of the errors. Previously the software did not give a description for any of the errors associated with the 00F0 error code.
• The change also makes the error codes more consistent with errors returned by other controllers, such as PLC-5® controllers.
00F0
00F0
00F0
00F0
00F0
00F0
00F0
00F0
00F0
0006
0007
0008
0009
000A
000B
000C
000D
000E
F006
F007
F008
F009
F00A
F00B
F00C
F00D
F00E
The following table shows the change in the error codes from R9.x and earlier to
R10.x and later. As a result of the change, the .ERR member returns a unique value for each PCCC error. The .EXERR is no longer required for these errors.
00F0
00F0
00F0
00F0
00F0
0070
0080
0090
00B0
0030
0040
0050
0060
R9.x And Earlier
.ERR
.EXERR
0010
0020
0001
0002
0003
0004
0005
Table 3 - PLC and SLC Error Codes (hex)
9000
B000
F001
F002
5000
6000
7000
8000
R10.x And Later
.ERR
.EXERR
1000
2000
3000
4000
F003
F004
F005
Description
Illegal command or format from local processor
Communication module not working
Remote node is missing, disconnected, or shut down
Processor connected but faulted (hardware)
Wrong station number
Requested function is not available
Processor is in Program mode
Processor’s compatibility file does not exist
Remote node cannot buffer command
Processor is downloading so it is not accessible
Processor incorrectly converted the address
Incomplete address
Incorrect address
Illegal address format - symbol not found
Illegal address format - symbol has 0 or greater than the maximum number of characters supported by the device
Address file does not exist in target processor
Destination file is too small for the number of words requested
Cannot complete request
Situation changed during multipacket operation
Data or file is too large
Memory unavailable
Target processor cannot put requested information in packets
Privilege error; access denied
Requested function is not available
Request is redundant
Command cannot be executed
164
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Input/Output Instructions (MSG, GSV, SSV, IOT)
Chapter 4
00F0
00F0
00F0
00F0
00F0
00F0
00F0
00F0
00F0
Table 3 - PLC and SLC Error Codes (hex) (Continued)
R9.x And Earlier
.ERR
.EXERR
00F0
00F0
00F0
00F0
00F0
00F0
000F
0010
0011
0012
0013
0014
R10.x And Later
.ERR
.EXERR
F00F
F010
F011
F012
F013
F014
0019
001A
001B
001C
001D
0015
0016
0017
0018
F019
F01A
F01B
F01C
F01D
F015
F016
F017
F018
Description
Overflow; histogram overflow
No access
Data type requested does not match data available
Incorrect command parameters
Address reference exists to deleted area
Command execution failure for unknown reason
PLC-3® histogram overflow
Data conversion error
The scanner is not available to communicate with a 1771 rack adapter
The adapter is no available to communicate with the module
The 1771 module response was not valid
Duplicate label
File owner active - the file is being used
Program owner active - someone is downloading or editing online
Disk file is write protected or otherwise not accessible (offline only)
Disk file is being used by another application
Update not performed (offline only)
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
165
Chapter 4
Input/Output Instructions (MSG, GSV, SSV, IOT)
00F7
00F8
00F9
00FA
00FB
00FC
00FD
00F0
00F3
00F5
00F6
00EC
00ED
00EE
00EF
00D3
00D6
00EA
00EB
Error Code (Hex)
00D0
00D1
00D2
Block-transfer Error Codes
These are the Logix5000 block-transfer specific error codes.
Description Display In Software
The scanner did not receive a block-transfer response from the block-transfer module within 3.5 seconds of the request Unknown error
The checksum from the read response did not match the checksum of the data stream
The scanner requested either a read or write but the block-transfer module responded with the opposite
The scanner requested a length and the block-transfer module responded with a different length
The scanner received a response from the block-transfer module indicating the write request failed
The scanner was not configured to communicate with the rack that would contain this block-transfer module
The logical slot specified is not available for the given rack size
There is currently a block-transfer request in progress and a response is required before another request can begin
The size of the block-transfer request is not consistent with valid block-transfer size requests
The type of block-transfer request is not consistent with the expected BT_READ or BT_WRITE
The scanner was unable to find an available slot in the block-transfer table to accommodate the block-transfer request
The scanner received a request to reset the remote I/O channels while there were outstanding block-transfers
Queues for remote block-transfers are full
No communication channels are configured for the requested rack or slot
No communication channels are configured for remote I/O
The block-transfer timeout, set in the instruction, timed out before completion
Error in block-transfer protocol - unsolicited block-transfer
Block-transfer data was lost due to a bad communication channel
The block-transfer module requested a different length than the associated block-transfer instruction
The checksum of the block-transfer read data was wrong
There was an invalid transfer of block-transfer write data between the adapter and the block-transfer module
The size of the block-transfer plus the size of the index in the block-transfer data table was greater than the size of the block-transfer data table file
166
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Specify the Configuration
Details
Input/Output Instructions (MSG, GSV, SSV, IOT)
Chapter 4
After you enter the MSG instruction and specify the MESSAGE structure, use the Message Configuration dialog box to specify the details of the message.
Click here to configure the MSG instruction
The details you configure depend on the message type you select.
Figure 4 - Message Configuration Tab
45634
If the target device is
Logix5000 controller
I/O module that you configure by using Logix Designer application
PLC-5 controller
SLC controller
MicroLogix™ controller
Block-transfer module
Select one of these message types
CIP Data Table Read
CIP Data Table Write
Module Reconfigure
CIP Generic
PLC5 Typed Read
PLC5 Typed Write
PLC5 Word Range Read
PLC5 Word Range Write
SLC Typed Read
SLC Typed Write
Block-Transfer Read
Block-Transfer Write
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Page
167
Chapter 4
Input/Output Instructions (MSG, GSV, SSV, IOT)
PLC-3 processor
For this property
Source Element
Source Length
Destination Element
PLC-2® processor
Select this command
CIP Data Table Read
CIP Data Table Write
PLC3 typed read
PLC3 typed write
PLC3 word range read
PLC3 word range write
PLC2 unprotected read
PLC2 unprotected write
Specify This Data for a Logix5000 Controller as a Target Device
Use this configuration information if a Logix5000 controller is the target device.
Specify
• If you select a read message type, the Source Element is the address of the data you want to read in the target device. Use the addressing syntax of the target device.
• If you select a write message type, the Source Tag is the first element of the tag that you want to send to the target device. If you select a write message type, the Source Tag is the first element of the tag that you want to send to the target device.
• The only source data type that is not supported is Boolean. All other data types—SINT, INT, DINT, LINT, REAL—can be used. Any structure type predefined, module-defined, or user-defined also can be used to send messages.
The number of elements you read/write depends on the type of data you are using. An element refers to one ‘chunk’ of related data. For example, tag timer1 is one element that consists of one timer control structure.
• If you select a read message type, the Destination Element is the first element of the tag in the
Logix5000 controller where you want to store the data you read from the target device.
• If you select a write message type, the Destination Element is the address of the location in the target device where you want to write the data.
Specify CIP Data Table Read and Write Messages
The CIP Data Table Read and Write message types transfer data between
Logix5000 controllers.
If you want to
Read data from another controller.
The Source and Destination types must match.
Write data to another controller.
The Source and Destination types must match.
168
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Input/Output Instructions (MSG, GSV, SSV, IOT)
Chapter 4
Reconfigure an I/O Module
Use the Module Reconfigure message to send new configuration information to an I/O module.
During the reconfiguration, the following occurs:
• Input modules continue to send input data to the controller.
• Output modules continue to control their output devices.
A Module Reconfigure message requires this configuration properties.
In this property
Message Type
Select
Module Reconfigure
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
169
Chapter 4
Input/Output Instructions (MSG, GSV, SSV, IOT)
Example:
Follow these steps to reconfigure an I/O module.
1. Set the required member of the configuration tag of the module to the new value.
2. Send a Module Reconfigure message to the module.
When
reconfigure[5] is set, set the high alarm to 60 for the local module in slot 4.
The Module Reconfigure message then sends the new alarm value to the module.
The one shot instruction prevents the rung from sending multiple messages to the module while the reconfigure[5] is on.
TIP
We recommend that you always include an XIO of the MSG.EN bit as an in-series MSG rung precondition.
Relay Ladder
Structured Text
IF reconfigure[5] AND NOT reconfigure[6]THEN
Local:4:C.Ch0Config.HAlarmLimit := 60;
IF NOT change_Halarm.EN THEN
MSG(change_Halarm);
END_IF;
END_IF; reconfigure[6] := reconfigure[5];
170
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Input/Output Instructions (MSG, GSV, SSV, IOT)
Chapter 4
Specify CIP Generic Messages
If you want to
Perform a pulse test on a digital output module
Get audit value
Get controller events monitored for changes
See
IMPORTANT
ControlLogix modules have services that can be invoked by using a MSG instruction and choosing the CIP Generic message type.
In this property
Message Type
Service Type
Source
Destination
Message Type
Service Type
Source Element
Source Length
Destination Element
Message Type
Service Type
Source Element
Source Length
Destination Element
Type or select
CIP Generic
Pulse Test tag_name of type INT [5]
This array contains
tag_name[0] tag_name[1] tag_name[2] tag_name[3]
Description
Bit mask of points to test (test only one point at a time)
Reserved, leave 0
Pulse width (hundreds of s, usually 20)
Zero cross delay for ControlLogix I/O (hundreds of s, usually 40)
Verify delay tag_name[4]
Blank
CIP Generic
Audit Value Get
Cannot change this field, blank
Cannot change this field, set to 0 bytes
This array contains
tag_name of type DINT[2] or
LINT
Description
This tag contains the Audit Value for the controller.
IMPORTANT: We recommend using the DINT[2] data type to avoid limitations when working with LINT data types in
Allen-Bradley® controllers.
CIP Generic
Changes to Detect Get
Cannot change this field, blank
Cannot change this field, set to 0 bytes
This array contains
tag_name of type DINT[2] or
LINT
Description
This tag represents a bit mask of the changes monitored for the controller.
IMPORTANT: We recommend using the DINT[2] data type to avoid limitations when working with LINT data types in
Allen-Bradley controllers.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
171
Chapter 4
Input/Output Instructions (MSG, GSV, SSV, IOT)
If you want to
Set controller events monitored for changes
See
In this property
Message Type
Service Type
Source Element
Reset electronic fuses on a digital output module
Source Length
Destination Element
Message Type
Service Type
Source
Destination
Reset latched diagnostics on a digital input module Message Type
Service Type
Source
Reset latched diagnostics on a digital output module Message Type
Service Type
Source
Unlatch the alarm of an analog input module Message Type
Service Type
Unlatch the alarm of an analog output module
Instance
Message Type
Service Type
Instance
Type or select
CIP Generic
Changes to Detect Set
This array contains
tag_name of type DINT[2] or
LINT
Description
This tag represents a bit mask of the changes monitored for the controller.
IMPORTANT: We recommend using the DINT[2] data type to avoid limitations when working with LINT data types in
Allen-Bradley controllers.
Cannot change this field, set to 8 bytes
Cannot change this field, blank
CIP Generic
Reset Electronic Fuse tag name of type DINT
This tag represents a bit mask of the points to reset fuses on.
Leave blank
CIP Generic
Reset Latched Diagnostics (I) tag_name of type DINT
This tag represents a bit mask of the points to reset diagnostics on.
CIP Generic
Reset Latched Diagnostics (O) tag_name of type DINT
This tag represents a bit mask of the points to reset diagnostics on.
CIP Generic
Select which alarm that you want to unlatch.
• Unlatch All Alarms (I)
• Unlatch Analog High Alarm (I)
• Unlatch Analog High High Alarm (I)
• Unlatch Analog Low Alarm (I)
• Unlatch Analog Low Low Alarm (I)
• Unlatch Rate Alarm (I)
Channel of the alarm that you want to unlatch
CIP Generic
Select which alarm that you want to unlatch.
• Unlatch All Alarms (O)
• Unlatch High Alarm (O)
• Unlatch Low Alarm (O)
• Unlatch Ramp Alarm (O)
Channel of the alarm that you want to unlatch
172
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Input/Output Instructions (MSG, GSV, SSV, IOT)
Chapter 4
Table 4 - Get/Set Controller Events Monitored for Changes Bit Definitions
Tag Names
Get Controller Events Monitored for Changes
Set Controller Events Monitored for Changes
Data Type
DINT[0]
Bit Definition
27
28
29
30
31
23
24
25
26
19
20
21
22
15
16
17
18
11
12
13
14
7
8
9
10
5
6
3
4
1
2
Bit
0
Meaning
Store to removable media through Logix Designer application
Online edits were accepted, tested, or assembled
Partial import online transaction completed
SFC Forces were enabled
SFC Forces were disabled
SFC Forces were removed
SFC Forces were modified
I/O Forces were enabled
I/O Forces were disabled
I/O Forces were removed
I/O Forces were changed
Firmware update from unconnected source
Firmware update via removable media
Mode change via workstation
Mode change via mode switch
A major fault occurred
Major faults were cleared
Major faults were cleared via mode switch
Task properties were modified
Program properties were modified
Controller timeslice options were modified
Removable media was removed
Removable media was inserted
Safety signature created
Safety signature deleted
Safety lock
Safety unlock
Constant tag value changed
Constant tag multiple values changed
Constant tag attribute cleared
Tag set as constant
Custom log entry added
DINT[1] 32
33
34
35…63
Change that affects correlation
Protect signature in Run mode attribute set
Protect signature in Run mode attribute cleared
Unused
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
173
Chapter 4
Input/Output Instructions (MSG, GSV, SSV, IOT)
IMPORTANT
Selecting the CIP Generic message type enables the Large Connection option on the Communication tab. Use large CIP
Generic connections when a message is greater than 480 bytes. (500 bytes is typical, but note that there are headers at the front of the message.) Large CIP connections can be used for messages up to 3980 bytes.
The Large Connection checkbox is enabled only when the Connected box is checked and CIP Generic is selected as the message type on the Configuration tab (see
The Large Connection option is available only in Logix Designer application, version 21.00.00 or later and RSLogix 5000 software, version 20.00.00 or later.
174
Select this command
PLC5 Typed Read
PLC5 Typed Write
PLC5 Word Range Read
PLC5 Word Range Write
Specify PLC-5 Messages
Use the PLC-5 message types to communicate with PLC-5 controllers.
If you want to
Read and Typed Write messages on page 175 .
Read and Typed Write messages on page 175
Read a contiguous range of 16-bit words in PLC-5 memory regardless of data type.
This command starts at the address specified as the Source Element and reads sequentially the number of 16-bit words requested.
The data from the Source Element is stored, starting at the address specified as the Destination Tag.
Write a contiguous range of 16-bit words from Logix5000 memory regardless of data type to PLC-5 memory.
This command starts at the address specified as the Source Tag and reads sequentially the number of 16-bit words requested.
The data from the Source Tag is stored, starting at the address specified as the Destination Element in the PLC-5 processor.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Input/Output Instructions (MSG, GSV, SSV, IOT)
Chapter 4
The following table shows the data types to use with PLC5 Typed Read and
PLC5 Typed Write messages.
Table 5 - Data types for PLC5 Typed Read and Typed Write messages
S
ST
F
N
For this PLC-5 data type
B
Use this Logix5000 data type
INT
REAL
INT
DINT (Only write DINT values to a PLC-5 controller if the value is
32,768 and
32,767.)
INT
STRING
The Typed Read and Typed Write commands also work with SLC 5/03 processors (OS303 and above), SLC 5/04 processors (OS402 and above), and SLC 5/05 processors.
Typed Read Command
The following diagrams show how the typed and word-range commands differ.
The example uses read commands from a PLC-5 processor to a Logix5000 controller.
Word-range Read Command
16-bit words in PLC-5 processor
32-bit words in Logix5000 controller 16-bit words in PLC-5 processor 32-bit words in Logix5000 controller
1
2
3
4
The typed commands maintain data structure and value.
1
2
3
4
1
2
3
4
2
4
1
3
The word-range commands fill the destination tag contiguously. Data structure and value change depending on the destination data type.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
175
Chapter 4
Input/Output Instructions (MSG, GSV, SSV, IOT)
Specify SLC Messages
Use the SLC message types to communicate with SLC and MicroLogix controllers. The following table shows which data types that the instruction lets you access. The table also shows the corresponding Logix5000 data type.
For this SLC or MicroLogix data type
F
L (MicroLogix 1200 and 1500 controllers)
N
Use this Logix5000 data type
REAL
DINT
INT
Specify Block-transfer Messages
The block-transfer message types are used to communicate with block-transfer modules over a Universal Remote I/O network.
If you want to
Read data from a block-transfer module
This message type replaces the BTR instruction
Write data to a block-transfer module
This message type replaces the BTW instruction
Select this command
Block-Transfer Read
Block-Transfer Write
To configure a block-transfer message, follow these guidelines:
• The source (for BTW) and destination (for BTR) tags must be large enough to accept the requested data, except for MESSAGE, AXIS, and
MODULE structures.
• Specify how many 16-bit integers (INT) to send or receive. You can specify from 0…64 integers.
If you want the
Block-transfer module to determine how many 16-bit integers to send (BTR)
Controller to send 64 integers (BTW)
Then specify
0 for the number of elements
176
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Input/Output Instructions (MSG, GSV, SSV, IOT)
Chapter 4
Select this command
PLC3 Typed Read
PLC3 Typed Write
PLC3 Word Range Read
PLC3 Word Range Write
Specify PLC-3 Messages
The PLC-3 message types are designed for PLC-3 processors.
If you want to
Read integer or REAL type data.
For integers, this command reads 16-bit integers from the PLC-3 processor and stores them in SINT, INT, or DINT data arrays in the Logix5000 controller and maintains data integrity.
This command also reads floating-point data from the PLC-3 and stores it in a REAL data type tag in the Logix5000 controller.
Write integer or REAL type data.
This command writes SINT or INT data, to the PLC-3 integer file and maintains data integrity. You can write DINT data as long as it fits within an INT data type (
32,768
data
32,767).
This command also writes REAL type data from the Logix5000 controller to a PLC-3 floating-point file.
Read a contiguous range of 16-bit words in PLC-3 memory regardless of data type.
This command starts at the address specified as the Source Element and reads sequentially the number of 16-bit words requested.
The data from the Source Element is stored, starting at the address specified as the Destination Tag.
Write a contiguous range of 16-bit words from Logix5000 memory regardless of data type to PLC-3 memory.
This command starts at the address specified as the Source Tag and reads sequentially the number of 16-bit words requested.
The data from the Source Tag is stored, starting at the address specified as the Destination Element in the PLC-3 processor.
The following diagrams show how the typed and word-range commands differ.
The example uses read commands from a PLC-3 processor to a Logix5000 controller.
Typed Read Command
16-bit words in PLC-3 processor 32-bit words in Logix5000 controller
Word-range Read Command
16-bit words in PLC-3 processor
32-bit words in Logix5000 controller
1
2
3
4
The typed commands maintain data structure and value.
1
2
3
4
1
2
3
4
2
4
1
3
The word-range commands fill the destination tag contiguously. Data structure and value change depending on the destination data type.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
177
Chapter 4
Input/Output Instructions (MSG, GSV, SSV, IOT)
Select this command
PLC2 Unprotected Read
PLC2 Unprotected Write
Specify PLC-2 Messages
The PLC-2 message types are designed for PLC-2 processors.
If you want to
Read 16-bit words from any area of the PLC-2 data table or the PLC-2 compatibility file of another processor.
Write 16-bit words to any area of the PLC-2 data table or the PLC-2 compatibility file of another processor.
The message transfer uses 16-bit words, so make sure the Logix5000 tag appropriately stores the transferred data (typically as an INTarray).
MSG Configuration Examples
The following examples show source and destination tags and elements for different controller combinations.
The table explains the path for MSG instructions originating from a Logix5000 controller and being writing to another controller.
Message Path
Logix5000
Logix5000
Logix5000
PLC-5
Logix5000
SLC
Logix5000
PLC-2
Example Source and Destination
Source tag
array_1[0]
Destination tag
array_2[0]
You can use an alias tag for the source tag (in originating Logix5000 controller).
You cannot use an alias for the destination tag. The destination must be a base tag.
Source tag
Destination element
array_1[0]
N7:10
You can use an alias tag for the source tag (in originating Logix5000 controller).
Source tag
array_1[0]
Destination element
010
Message Path
Logix5000
Logix5000
Logix5000
PLC-5
Logix5000
SLC
Logix5000
PLC-2
The table explains the path for MSG instructions originating from a
Logix5000 controller and reading from another controller.
Example Source and Destination
Source tag
array_1[0]
Destination tag
array_2[0]
You cannot use an alias tag for the source tag. The source must be a base tag.
You can use an alias tag for the destination tag (in originating Logix5000 controller).
Source element
Destination tag
N7:10 array_1[0]
You can use an alias tag for the destination tag (in originating Logix5000 controller).
Source element
010
Destination tag
array_1[0]
178
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Specify the
Communication Details
Input/Output Instructions (MSG, GSV, SSV, IOT)
Chapter 4
You typically set up a broadcast in ladder logic or structured text programs. In ladder logic, you can add a rung and click on the MSG property to access the
Message Configuration dialog box to set up a new message. In structured text, you type MSG (aMsg) and then right-click on aMsg to get the Message
Configuration dialog box to configure a message.
To configure a MSG instruction, you specify these details on the
Communication tab.
Specify a Communication Method or Module
Specify a Path
The path shows the route that the message takes to get to the destination. It uses either names from the I/O configuration of the controller, numbers that you type, or both. You can default the path by using the broadcast button, which must be enabled with the system protocol and message type.
If
The I/O configuration of the controller has the module that gets the message.
The I/O configuration of the controller has only the local communication module.
The I/O configuration of the controller doesn’t have any of the modules that you need for the message.
Then
Use Browse to select the module.
1. Use Browse to select the local communication module.
2. Type the rest of the path.
Type the path.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
179
Chapter 4
Input/Output Instructions (MSG, GSV, SSV, IOT)
Example
The I/O configuration of the controller has the module that gets the message.
Click Browse and select the module.
The I/O configuration of the controller has only the local communication module.
Go to the local communication module.
Go out the EtherNet/IP port…
...to the address of 10.10.10.10.
Go across the backplane…
...to the module in slot 0.
The I/O configuration of the controller doesn’t have any of the modules that you need for the message.
Go across the backplane…
...to the local communication module on slot 1
Go out the ControlNet port….
...to node 4
Go across the backplane…
...to the module in slot 0.
180
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Where
Port
Next_address
Input/Output Instructions (MSG, GSV, SSV, IOT)
Chapter 4
To type a path, use this format: port, next_address, port, next_address, …
Is
For this network
Backplane
DF1 (serial, serial channel 0)
ControlNet
EtherNet/IP
DH+ channel A
DH+ channel B
DF1 channel 1 (serial channel 1)
Backplane
DF1 (serial)
ControlNet
DH+
EtherNet/IP
Type
1
2
3
Slot number of the module
Station address (0-254)
Node number (1-99 decimal)
8# followed by the node number (1-77 octal)
For example, to specify the octal node address of 37, type 8#37.
You can specify a module on an EtherNet/IP network by using any of these formats:
IP address (for example, 10.10.10.10)
IP address:Port (for example, 10.10.10.10:24)
DNS name (for example, tanks)
DNS name:Port (for example, tanks:24)
Broadcast Button
This functionality for RSLogix 5000 software, beginning with version 18, enhances the ability to define the route and message type that are required to send a message to its destination. You still can type in a path, such as ‘2,255’.
However, manually entering a path is problematic for two reasons:
• The number entered into the path may be confusing.
• It’s error-prone, as you may forget to set up other conditions, such as system protocol and message type.
The Broadcast button, when enabled, allows you to default the path by selecting an available channel(s) in a combo box. The number of channels listed in the combo box depends on the current controller.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
181
Chapter 4
Input/Output Instructions (MSG, GSV, SSV, IOT)
By default, the Path radio button on the Communication tab is active (dot in radio button). Do these steps to enable the Broadcast button and select a channel to default a path for the message.
1. On the Controller Organizer, right-click Controller, and choose
Properties.
The Controller Properties dialog box appears.
2. Click the System Protocol tab.
3. Choose DF1 Master in the Protocol box.
The Polling mode defaults ‘Message Based’ (slave can initiate messages).
4. Click OK.
5. In ladder logic, click the box inside the MSG tag.
The Message Configuration dialog box appears with the Configuration tab open.
6. In the Message Type box, choose CIP Data Table Write.
(1)
for an example.
7. Click OK.
You have enabled the Broadcast button on the Communication tab.
8. Click the Communication tab.
9. Next to the Broadcast button, choose a channel in the combo box. The number of channels in the combo box depends on the controller.
When you select channel 0 or 1, the corresponding message path on the
Message Configuration dialog box defaults to 2,255 (channel 0) or
3,255 (channel 1). The Path grays out to not allow you to manually enter a path value.
10. Click OK.
182
(1) See system protocol instructions on
to enable the Broadcast button.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Input/Output Instructions (MSG, GSV, SSV, IOT)
Chapter 4
System Protocol Tab Configuration
To run broadcast in ControlLogix controllers in the Logix Designer application, you must configure the System Protocol tab in the Controller Properties dialog box. The protocol must be compatible with the message type of ‘write’ on the
Message Configuration dialog box.
See page 167 for an example in the Message Type box.
Follow these steps to set up the system protocol to be compatible with the broadcast feature.
1. Create or open an existing controller in the application.
2. On the Controller Organizer, right-click the controller name, and choose
Properties.
The Controller Properties dialog box appears.
3. Click System Protocol tab.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
183
Chapter 4
Input/Output Instructions (MSG, GSV, SSV, IOT)
4. Choose a protocol from the Protocol box.
IMPORTANT
The Message Type box on the Message Configuration Tab dialog box must be write-typed to be compatible with the system protocol.
Otherwise, the Broadcast button is disabled.
5. Enter the information on the System Protocol tab for each protocol outlined below.
Topic
Protocol
Station Address
Transmit Retries
ACK Timeout
Reply Message Wait
Polling Mode
Error Detection
Duplicate Detection
Description
DF-1 Master
Type controller station address number
3
50
5
Choose from the following modes:
· ‘Message Based’ to poll the slave using message instruction
· ‘Slave can initiate message’ for slave to slave broadcast
· ‘Standard’ to have the schedule poll for the slave
BCC
Enabled (checked)
Topic
Protocol
Station Address
Transmit Retries
Slave Poll Timeout
EOT Suppression
Error Detection
Duplicate Detection
Description
DF-1 Slave
Type controller station address number
3
3000
Disable (unchecked)
BCC
Enabled (checked)
Topic
Protocol
Station Address
Enable Store and Forward
Error Detection
6. Click OK.
Description
DF-1 Slave
Type controller station address number
Enable box (checkmark) to use store and forward tag
BCC
184
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Input/Output Instructions (MSG, GSV, SSV, IOT)
Chapter 4
For Block Transfers
For block transfer messages, add the following modules to the I/O configuration of the controller.
For block-transfers over this network Add these modules to the I/O configuration
ControlNet • Local communication module (for example, 1756-CNB module)
• Remote adapter module (for example, 1771-ACN module)
Universal remote I/O • Local communication module (for example, 1756-DHRIO module)
• One emote adapter module (for example, 1771-ASB module) for each rack, or portion of a rack, in the chassis
• Block-transfer module (optional)
Specify a Communication Method or Module Address
If the destination device is
Logix5000 controller
PLC-5 controller over an EtherNet/IP network
PLC-5 controller over a ControlNet network
SLC 5/05 controller
PLC-5 controller over a DH+ network
Then select
CIP
DH+
SLC controller over a DH+ network
Use the following table to select a communication method or module address for the message.
And specify
No other specifications required.
PLC-3 processor
PLC-2 processor
Application on a workstation that is receiving an unsolicited message routed over an EtherNet/IP or ControlNet network through
RSLinx software
CIP with Source ID
(This lets the application receive data from a controller.)
Block transfer module over a universal remote I/O network
Block transfer module over a ControlNet network
RIO
ControlNet
Channel
Source Link
Channel A or B of the 1756-DHRIO module that is connected to the DH+ network.
Link ID assigned to the backplane of the controller in the routing table of the 1756-DHRIO module. (The source node in the routing table is automatically the slot number of the controller.).
Destination Link
Destination Node
Link ID of the remote DH+ link where the target device resides.
Station address of the target device, in octal.
If there is only one DH+ link and you did not use the RSLinx software to configure the DH/RIO module for remote links, specify 0 for both the Source Link and the Destination Link.
Source Link
Destination Link
Remote ID of the topic in RSLinx software.
Virtual Link ID set up in RSLinx software (0…65535).
Rack
Group
Slot
Slot
Destination Node Destination ID (0…77 octal) provided by the application to
RSLinx software. For a DDE topic in RSLinx software, use 77.
The slot number of the ControlLogix controller is used as the Source Node.
Channel Channel A or B of the 1756-DHRIO module that is connected to the RIO network.
Rack number (octal) of the module.
Group number of the module.
Slot number that the module is in.
Slot number that the module is in.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
185
Chapter 4
Input/Output Instructions (MSG, GSV, SSV, IOT)
If the MSG instructions are to
Different devices
Same device
Choose a Cache Option
Depending on how you configure a MSG instruction, it may use a connection to send or receive data.
This type of message
CIP data table read or write
PLC-2, PLC-3, PLC-5, or SLC (all types)
And this communication method Uses a connection
Your option
(1)
CIP
CIP with Source ID
DH+
CIP generic
Block-transfer read or write
X
Your option
X
(2)
(1) CIP data table read or write messages can be connected or unconnected. But, for most applications, we recommend you leave CIP data table read or write messages connected.
(2) CIP generic messages can be connected or unconnected. But, for most applications, we recommend you leave CIP generic messages unconnected.
If a MSG instruction uses a connection, you have the option to leave the connection open (cache) or close the connection when the message is done transmitting.
If you
Cache the connection
Do not cache the connection
Then
The connection stays open after the MSG instruction is done. This optimizes execution time. Opening a connection each time the message executes increases execution time.
The connection closes after the MSG instruction is done. This frees up that connection for other uses.
The controller has the following limits on the number of connections that you can cache.
Then you can cache If you have this software and firmware revision
11.x or earlier
12.x or later
• Block transfer messages for up to 16 connections.
• Other types of messages for up to 16 connections.
Up to 32 connections.
If several messages go to the same device, the messages may be able to share a connection.
And they are
Enabled at the same time
NOT enabled at the same time
Then
Each MSG instruction uses 1 connection.
Each MSG instruction uses 1 connection.
The MSG instruction uses 1 connection and 1 cached buffer. They share the connection and the buffer.
186
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Input/Output Instructions (MSG, GSV, SSV, IOT)
Chapter 4
EXAMPLE
Share a Connection
If the controller alternates between sending a block-transfer read message and a block-transfer write message to the same module, then together both messages count as one connection. Caching both messages counts as one on the cache list.
Guidelines
As you plan and program your MSG instructions, follow these guidelines.
Guideline
1. For each MSG instruction, create a control tag.
Details
Each MSG instruction requires its own control tag.
• Data type = MESSAGE
• Scope = controller
2. Keep the source and/or destination data at the controller scope.
3. If your MSG is to a device that uses 16-bit integers, use a buffer of INTs in the MSG and DINTs throughout the project.
• The tag cannot be part of an array or a user-defined data type.
A MSG instruction can access only tags that are in the Controller Tags folder (controller scope).
If your message is to a device that uses 16-bit integers, such as a PLC-5 or SLC 500 controller, and it transfers integers
(not REALs), use a buffer of INTs in the message and DINTs throughout the project.
This increases the efficiency of your project because Logix controllers execute more efficiently and use less memory when working with 32-bit integers (DINTs).
To convert between INTs and DINTs, see the Logix5000 Controllers Common Procedures Programming Manual, publication 1756-PM001 .
4. Cache the connected MSGs that execute most frequently.
Cache the connection for those MSG instructions that execute most frequently, up to the maximum number permissible for your controller revision.
5. If you want to enable more than 16 MSGs at one time, use some type of management strategy.
6. Keep the number of unconnected and uncached MSGs less than the number of unconnected buffers.
This optimizes execution time because the controller does not have to open a connection each time the message executes.
If you enable more than 16 MSGs at one time, some MSG instructions may experience delays in entering the queue.
To guarantee the execution of each message, use one of these options:
• Enable each message in sequence.
• Enable the messages in groups.
• Program a message to communicate with multiple devices. For more information, see the Logix5000 Controllers
Common Procedures Programming Manual, publication 1756-PM001 .
• Program logic to coordinate the execution of messages. For more information, see the Logix5000 Controllers Common Procedures Programming Manual, publication 1756-PM001 .
The controller can have 10…40 unconnected buffers. The default number is 10.
• If all the unconnected buffers are in use when an instruction leaves the message queue, the instruction errors and does not transfer the data.
• You can increase the number of unconnected buffers (40 max), but continue to follow guideline
• To increase the number of unconnected buffers, see the Logix5000 Controllers Common Procedures
Programming Manual, publication 1756-PM001 .
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
187
Chapter 4
Input/Output Instructions (MSG, GSV, SSV, IOT)
Get System Value (GSV) and
Set System Value (SSV)
Operands:
The GSV/SSV instructions get and set controller system data that is stored in objects.
Relay Ladder
Operand
Class name
Instance name
Attribute Name
Destination (GSV)
Source (SSV)
Type
SINT
INT
DINT
REAL structure
SINT
INT
DINT
REAL structure
Format
Name
Name
Name
Tag
Tag
Description
Name of object.
Name of specific object, when object requires name.
Attribute of object.
Data type depends on the attribute you select.
Destination for attribute data.
Tag that contains data you want to copy to the attribute.
188
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Structured Text
GSV(ClassName,InstanceName,AttributeName,Dest);
SSV(ClassName,InstanceName,AttributeName,Source);
Input/Output Instructions (MSG, GSV, SSV, IOT)
Chapter 4
The operands for are the same as those for the relay ladder GSV and SSV instructions.
Description:
The GSV/SSV instructions get and set controller system data that is stored in objects. The controller stores system data in objects. There is no status file, as in the PLC-5 processor.
When enabled, the GSV instruction retrieves the specified information and places it in the destination. When enabled, the SSV instruction sets the specified attribute with data from the source.
When you enter a GSV/SSV instruction, the programming software displays the valid object classes, object names, and attribute names for each instruction. For the GSV instruction, you can get values for all the available attributes. For the
SSV instruction, the software displays only those attributes are allowed to set
(SSV).
ATTENTION: Use the GSV and SSV instructions carefully. Making changes to objects may cause unexpected controller operation or injury to personnel.
You must test and confirm that the instructions don’t change data that you don’t want them to change.
The GSV and SSV instructions write or read past a member into other members of a tag. If the tag is too small, the instructions don’t write or read the data. They log a minor fault instead.
Example 1
Member_A is too small for the attribute. So the GSV instruction writes the last value to Member_B.
Example 2
My_Tag is too small for the attribute. So the GSV instruction stops and logs a minor fault.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
189
Chapter 4
Input/Output Instructions (MSG, GSV, SSV, IOT)
Condition
Prescan
Rung-condition-in is false
Rung-condition-in is true
EnableIn is set
Instruction executes
Postscan
The GSV/SSV Objects section shows each object’s attributes and their associated data types. For example, the MajorFaultRecord attribute of the Program object needs a DINT[11] data type.
Arithmetic Status Flags:
Not affected
Fault Conditions:
A minor fault will occur if
Invalid object address
Specified an object that does not support
GSV/SSV
Invalid attribute
Did not supply enough information for an
SSV instruction
The GSV destination was not large enough to hold the requested data
4
4
Fault type
4
4
4
6
6
Fault code
5
6
7
Execution:
Relay Ladder Action
The rung-condition-out is set to false.
The rung-condition-out is set to false.
The instruction executes.
The rung-condition-out is set to true.
N/A
Get or set the specified value.
The rung-condition-out is set to false.
Structured Text Action
No action taken
N/A
N/A
EnableIn is always set.
The instruction executes.
Get or set the specified value.
No action taken.
190
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
GSV/SSV Objects
Input/Output Instructions (MSG, GSV, SSV, IOT)
Chapter 4
Controller
ControllerDevice
CoordinateSystem
CST
DF1
FaultLog
Message
Module
MotionGroup
Program
Redundancy
When you enter a GSV/SSV instruction, you specify the object and its attribute that you want to access. In some cases, there will be more than one instance of the same type of object, so you might also have to specify the object name. For example, there can be several tasks in your application. Each task has its own
TASK object that you access by the task name.
ATTENTION: For the GSV instruction, only the specified size of data is copied to the destination. For example, if the attribute is specified as a
SINT and the destination is a DINT, only the lower 8 bits of the DINT destination are updated, leaving the remaining 24 bits unchanged.
You can access these objects.
Table 6 - GSV/SSV Objects
For information about this object
AddOnInstructionDefinition
Axis
Axis_Consumed
Axis_Generic
Axis_Generic_Drive
Servo
Servo_Drive
Virtual
Axis_CIP_Drive
See this page or publication
See the SERCOS Motion Configuration and Startup User
Manual, publication MOTION-UM001 .
Routine
SafetyAddonInstructionDefinition, SafetyController,
SafetyProgram, SafetyRoutine, SafetyTask.
SerialPort
See the CIP Motion Configuration and Startup User
Manual, publication MOTION-UM003 .
See the Motion Coordinate System User Manual, publication MOTION-UM002 .
See the Motion Reference Manual, publication MOTION-RM001 .
See the ControlLogix Enhanced Redundancy System User
Manual, publication 1756-UM535 .
See the GuardLogix Controllers User Manual, publication
1756-UM020 .
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
191
Chapter 4
Input/Output Instructions (MSG, GSV, SSV, IOT)
Table 6 - GSV/SSV Objects
Task
TimeSynchronization
WallClockTime
See the Integrated Architecture and CIP Sync Configuration
Application Technique, publication IA-AT003 .
Attribute
LastEditDate
MajorRevision
MinorRevision
Name
RevisionExtendedText String
SafetySignature
ID
DINT
SignatureID
Vendor
DINT
String
LINT
DINT
DINT
String
Data Type
AddOnInstructionDefinition Attributes
The AddOnInstructionDefinition object lets you customize instructions for sets of commonly-used logic, provides a common interface to this logic, and provides documentation for the instruction.
For details, see the Logix5000 Controllers Add-On Instructions Programming
Manual, publication 1756-PM010.
GSV
GSV
GSV
GSV
Instruction within
Standard Task
GSV
GSV
None
GSV
None
None
Instruction within Safety
Task
None
None
Description
Date and time stamp of the last edit to an Add-On Instruction definition.
Major revision number of the Add-On Instruction.
Minor revision number of the Add-On Instruction.
Name of the Add-On Instruction.
Text describing the revision of the Add-On Instruction.
In a safety project, the ID number, date, and timestamp of an Add-On Instruction definition.
GSV
GSV
None
None
32-bit identification number of an Add-On Instruction definition.
Vendor that created the Add-On Instruction.
Attribute
Audit Value
ChangesToDetect
See
CanUseRPIFrom
Producer
ControllerLog
Execution
Modification
Count
Data Type
DINT[2], LINT
DINT[2], LINT
DINT
DINT
Controller Attributes
Instruction
GSV
GSV, SSV
GSV
GSV
SSV
The Controller object provides status information about controller execution.
Description
The audit value is a unique value that is generated when a project is downloaded to the controller or loaded from removable storage. When a change is detected, this value is updated.
To specify which changes are monitored, use the ChangesToDetect attribute.
Note: We recommend using the DINT[2] data type to avoid limitations when working with LINT data types in
Rockwell Automation controllers.
Used to specify which changes are monitored. When a monitored change occurs, the Audit Value is updated.
Note: We recommend using the DINT[2] data type to avoid limitations when working with LINT data types in
Rockwell Automation controllers.
Identifies whether to use the RPI specified by the producer.
ValueMeaning
0 Do not use the RPI specified by the producer
1 Use the RPI specified by the producer
Number of controller log entries that originated from a program/task properties change, an online edit, or a controller timeslice change. It can also be configured to include log entries originating from forces. The number will be reset if RAM enters a bad state. The number is not capped at the largest DINT, and a rollover can occur.
192
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Input/Output Instructions (MSG, GSV, SSV, IOT)
Chapter 4
Attribute
ControllerLog
TotalEntryCount
DataTablePad
Percentage
IgnoreArrayFaultsDurin gPostScan
Data Type
DINT
INT
SINT
InhibitAutomatic
FirmwareUpdate
KeepTestEditsOnSwitch over
Name
Redundancy
Enabled
ShareUnused
TimeSlice
TimeSlice
BOOL
SINT
String
SINT
INT
INT
Instruction
GSV
SSV
GSV
GSV
SSV
GSV
SSV
GSV
GSV
GSV
GSV
SSV
GSV
SSV
Description
Number of controller log entries since the last firmware upgrade. The number will be reset if RAM enters a bad state.
The number is capped at the largest DINT.
Percentage (0...100) of free data table memory set aside.
Used to configure the suppression of selected faults encountered when an SFC action is postscanned. Only valid when SFCs are configured for automatic reset.
ValueMeaning
0 Do not suppress faults during postscan execution
(default behavior - recommended).
1 Major faults 4/20 (Array subscript too large) and 4/83 (Value out of range) are automatically suppressed while postscanning SFC actions.
When a fault is suppressed, the controller uses an internal fault handler to automatically clear the fault. This causes the faulted instruction to be skipped, with execution resuming at the following instruction.
Because the fault handler is internal, you do not have to configure a fault handler to get this behavior. In fact, even if a fault handler is configured, a suppressed fault will not trigger it.
Identifies whether to enable the firmware supervisor.
ValueMeaning
0 Do not execute the firmware supervisor
1 Execute the firmware supervisor
Identifies whether to maintain test edits on controller switchover.
ValueMeaning
0 Automatically untest edits at switchover
1 Continue test edits at switchover
Name of the controller.
Identifies whether the controller is configured for redundancy.
ValueMeaning
0 Not configured for redundancy
1 Configured for redundancy
Identifies how the continuous task and the background tasks shared any unused timeslice.
ValueMeaning
0 The operating system will not give control to the continuous task even if background is done.
1 Continuous task still runs if the background tasks are done (default).
2 or greater will cause a minor fault to be logged and the setting remains unchanged.
Percentage of available CPU (10...90) that is assigned to communications. This value cannot be changed when the keyswitch is in the Run position.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
193
Chapter 4
Input/Output Instructions (MSG, GSV, SSV, IOT)
Attribute
DeviceName
ProductCode
ProductRev
SerialNumber
Status
Type
Vendor
INT
DINT
INT
Data Type
SINT[33]
INT
INT
INT
ControllerDevice Attributes
Instruction
GSV
GSV
GSV
GSV
GSV
GSV
GSV
The ControllerDevice object identifies the physical hardware of the controller.
Description
ASCII string that identifies the catalog number of the controller and memory board. The first byte contains a count of the number of ASCII characters returned in the array string.
Identifies the type of controller:
ValueMeaning
15SoftLogix5800
49PowerFlex® with DriveLogix5725
52PowerFlex with DriveLogix5730
53Emulator
541756-L61 ControlLogix
551756-L62 ControlLogix
561756-L63 ControlLogix
571756-L64 ControlLogix
641769-L31 CompactLogix
651769-L35E CompactLogix
671756-L61S GuardLogix
681756-L62S GuardLogix
691756-LSP GuardLogix
721768-L43 CompactLogix
741768-L45 CompactLogix
761769-L32C CompactLogix
771769-L32E CompactLogix
801769-L35CR CompactLogix
851756-L65 ControlLogix
861756-L63S GuardLogix
871769-L23E-QB1 CompactLogix
881769-L23-QBFC1 CompactLogix
891769-L23E-QBFC1 CompactLogix
Identifies the current product revision. Display should be hexadecimal. The low byte contains the major revision; the high byte contains the minor revision.
Serial number of the device. The serial number is assigned when the device is built.
Device Status BitsController Status Bits
7...4Meaning13...12Meaning
0000Reserved01Keyswitch in run
0001Flash update in progress10Keyswitch in program
0010Reserved11Keyswitch in remote
0011Reserved
0100Flash is bad15...14Meaning
0101Faulted modes01Controller is changing modes
0110Run10Debug mode if controller in run mode
0111Program
Fault Status Bits
11...8Meaning
0001Recoverable minor fault
0010Unrecoverable minor fault
0100Recoverable major fault
1000Unrecoverable major fault
Identifies the device as a controller. Controller = 14.
Identifies the vendor of the device. Allen-Bradley = 0001.
CST Attributes
The coordinated system time (CST) object provides coordinated system time for the devices in one chassis.
194
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Attribute
CurrentStatus
CurrentValue
Input/Output Instructions (MSG, GSV, SSV, IOT)
Chapter 4
Data Type
INT
DINT[2]
Instruction
GSV
GSV
Description
Current status of the coordinated system time.
BitMeaning
0 Timer hardware faulted: the device’s internal timer hardware is in a faulted
state
1 Ramping enabled: the current value of the timer’s lower 16+ bits ramp up to the requested value, rather than snap to the lower value.
2 System time master: the CST object is a master time source in the
ControlLogix system
3 Synchronized: the CST object’s 64-bit CurrentValue is synchronized by master
CST object via a system time update
4 Local network master: the CST object is the local network master time source
5 Relay mode: the CST object is acting in a time relay mode
6 Duplicate master detected: a duplicate local network time master was detected.
This bit is always 0 for time-dependent nodes.
7 Unused
8 -900 = time dependent node
01 = time master node
10 = time relay node
11 = Unused
10-15Unused
Current value of the timer. DINT[0] contains the lower 32; DINT[1] contains the upper 32 bits. The timer source is adjusted to match the value supplied in update services and from local communication network synchronization.
The adjustment is either a ramping to the requested value or an immediate setting to the request value, as reported in the CurrentStatus attribute.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
195
Chapter 4
Input/Output Instructions (MSG, GSV, SSV, IOT)
DF1 Attributes
The DF1 object provides an interface to the DF1 communication driver that you can configure for the serial port.
Instruction Description Attribute
ACKTimeout
Data Type
DINT GSV The amount of time to wait for an acknowledgment to a message transmission (point-to-point and master only).
Valid value 0-32,767. Delay in counts of 20 msec periods. Default is 50 (1 second).
Array of diagnostic counters for the DF1 communication driver.
Diagnostic
Counters
INT[19] GSV
Word offsetDF1 point-to-pointDF1 slaveMaster
0Signature (0x0043)Signature (0x0042)Signature (0x0044)
1Modem bitsModem bitsModem bits
2Packets sentPackets sentPackets sent
3Packets receivedPackets receivedPackets received
4Undelivered packetsUndelivered packetsUndelivered packets
5UnusedMessages retriedMessages retried
6NAKs receivedNAKs receivedUnused
7ENQs receivedPoll packets receivedUnused
8Bad packets NAKedBad packets not ACKedBad packets not ACKed
9No memory sent NAKNo memory not ACKedUnused
10Duplicate packets receivedDuplicate packets receivedDuplicate packets received
11Bad characters receivedUnusedUnused
12DCD recoveries countDCD recoveries countDCD recoveries count
13Lost modem countLost modem countLost modem count
14UnusedUnusedPriority scan time maximum
15UnusedUnusedPriority scan time last
16UnusedUnusedNormal scan time maximum
17UnusedUnusedNormal scant time last
18ENQs sentUnusedUnused
Duplicate
Detection
SINT GSV Enables duplicate message detection.
Value Meaning
0 Duplicate message detection disabled
Non zeroDuplicate message detection enabled
Embedded
ResponseEnable
SINT GSV
EnableStoreFwd
ENQTransmit
Limit
EOTSuppression
ErrorDetection
SINT
SINT
SINT
SINT
MasterMessageTransmit SINT
SINT
GSV
GSV
GSV
GSV
GSV
GSV
Enables embedded response functionality (point-to-point only).
Value Meaning
0 Initiated only after one is received (default)
1 Enabled unconditionally
Enables the store and forward behavior when receiving a message.
Value Meaning
0 Do not forward message
Non zero. See the store and forward table when receiving a message (default)
The number of inquiries (ENQs) to send after an ACK timeout (point-to-point only). Valid value 0-127. Default setting is 3.
Enable suppressing EOT transmissions in response to poll packets (slave only).
ValueMeaning
0 EOT suppression disabled (disabled)
Non zeroEOT suppression enabled
Specifies the error-detection scheme.
ValueMeaning
0 BCC (default)
1 CRC
Current value of the master message transmission (master only).
ValueMeaning
0 Between station polls (default)
1 In poll sequence (in place of master’s station number)
Current value (0...31) of the maximum node address on a DH-485 network. Default is 31.
MaxStation
Address
NAKReceiveLimit SINT GSV The number of NAKs received in response to a message before stopping transmission (point-to-point communication only). Valid value 0...127. Default is 3.
196
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Input/Output Instructions (MSG, GSV, SSV, IOT)
Chapter 4
ReplyMessage
Wait
SlavePollTimeout
DINT
DINT
StationAddress
TokenHoldFactor
TransmitRetries
PendingACK
Timeout
Pending
Duplicate
Detection
Pending
Embedded
ResponseEnable
PendingEnable
StoreFwd
PendingENQ
TransmitLimit
DINT
SINT
SINT
SINT
SINT
PendingEOT
Suppression
PendingError
Detection
PendingMaster
Message
Transmit
PendingMax
StationAddress
PendingNAK
ReceiveLimit
PendingNormal
PollGroupSize
PendingPolling
Mode
SINT
SINT
SINT
SINT
SINT
INT
SINT
PendingReply
MessageWait
DINT
PendingSlavePollTimeout DINT
INT
SINT
SINT
Attribute
NormalPollGroupSize
Data Type
INT
PollingMode SINT
Instruction Description
GSV Number of stations to poll in the normal poll node array after polling all the stations in the priority poll node array
(master only).
Valid value 0...255. Default is 0.
GSV Current polling mode (master only). Default setting is 1.
ValueMeaning
0Message-based, but don’t allow slaves to initiate messages
1Message-based, but allow slaves to initiate messages (default)
2Standard, single-message transfer per node scan
3Standard, multiple-message transfer per node scan
GSV
GSV
The time (acting as a master) to wait after receiving an ACK before polling the slave for a response (master only).
Valid value 0...65,535. Delay in counts of 20 msec periods. The default is 5 periods (100 msec).
The amount of time in msecs that the slave waits for the master to poll before the slave declares that it is unable to transmit because the master is inactive (slave only). Valid value 0...32,767. Delay in counts of 20 msec periods. The default is 3000 periods (1 minute).
GSV
GSV
GSV
SSV
Current station address of the serial port. Valid value 0...254. Default is 0.
Current value (1...4) of the maximum number of messages sent by this node before passing the token on a DH-485 network. Default is 1.
Number of times to resend a message without getting an acknowledgment (master and slave only).
Valid value 0...127. Default is 3.
Pending value for the ACKTimeout attribute.
SSV Pending value for the DuplicateDetection attribute.
SSV Pending value for the EmbeddedResponse attribute.
SSV
SSV
SSV
SSV
SSV
SSV
SSV
SSV
SSV
SSV
SSV
Pending value for the EnableStoreFwd attribute.
Pending value for the ENQTransmitLimit attribute.
Pending value for the EOTSuppression attribute.
Pending value for the ErrorDetection attribute.
Pending value for the MasterMessageTransmit attribute.
Pending value for the MaxStationAddress attribute.
Pending value for the NAKReceiveLimit attribute.
Pending value for the NormalPollGroupSize attribute.
Pending value for the PollingMode attribute.
Pending value for the ReplyMessageWait attribute.
Pending value for the SlavePollTimeout attribute.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
197
Chapter 4
Input/Output Instructions (MSG, GSV, SSV, IOT)
Attribute
PendingStation
Address
Data Type
INT
PendingToken
HoldFactory
SINT
PendingTransmitRetries SINT
Instruction Description
SSV Pending value for the StationAddress attribute.
SSV
SSV
Pending value for the TokenHoldFactor attribute.
Pending value for the TransmitRetries attribute.
FaultLog Attributes
Attribute
MajorEvents
MajorFaultBits
MinorEvents
MinorFaultBits
Data Type
INT
DINT
INT
DINT
The FaultLog object provides fault information about the controller.
Instruction Description
How many major faults have occurred since the last time this counter was reset.
GSV
SSV
GSV
SSV
Individual bits indicate the reason for the current major fault.
Bit
7
8
5
6
11
1
3
4
Meaning
Power loss
I/O
Instruction execution (program)
Fault Handler
Watchdog
Stack
Mode change
Motion
How many minor faults have occurred since the last time this counter was reset.
GSV
SSV
GSV
SSV
Individual bits indicate the reason for the current minor fault.
Bit
4
6
9
10
Meaning
Instruction execution (program)
Watchdog
Serial port
Battery/Energy Storage Module (ESM)
(1)
(1) Battery for 1756-L6x, 1769-L2x, and 1769-L3x controllers. ESM for 1756-L7x controllers and CompactLogix 5370 series controllers.
Attribute
ConnectionPath
ConnectionRate
Data Type
SINT[130]
DINT
Message Attributes
Instruction
GSV
SSV
GSV
SSV
You can access the Message object through the GSV/SSV instructions. Specify the message tag name to determine which Message object you want. The Message object provides an interface to setup and trigger peer-to-peer communications.
This object replaces the MG data type of the
PLC-5 processor.
Description
Data to setup the connection path. The first two bytes (low byte and high byte) are the length in bytes of the connection path.
Requested packet rate of the connection.
198
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Attribute
MessageType
Port
Timeout
Multiplier
Unconnected
Timeout
Attribute
EntryStatus
FaultCode
FaultInfo
Firmware
SupervisorStatus
INT
DINT
INT
Input/Output Instructions (MSG, GSV, SSV, IOT)
Chapter 4
Data Type
SINT
SINT
SINT
DINT
Instruction
GSV
SSV
GSV
SSV
GSV
SSV
GSV
SSV
Description
Specifies the type of message.
ValueMeaning
0Not initialized
Indicates which port the message should be sent on.
ValueMeaning
1Backplane
2Serial port
Determines when a connection should be considered timed out and closed.
ValueMeaning
0Connection will timeout in 4 times the update rate default)
1Connection will timeout in 8 times the update rate
2Connection will timeout in 16 times the update rate
Timeout in microseconds for all unconnected messages. The default is 30,000,000 microseconds (30 s).
Data Type
INT
Module Attributes
GSV
GSV
GSV
Instruction
The Module object provides status information about a module. To select a particular Module object, set the Object Name operand of the GSV/SSV instruction to the module name. The specified module must be present in the I/
O Configuration section of the controller organizer and must have a device name.
Description
GSV Specifies the current state of the specified map entry. The lower 12 bits should be masked when performing a comparison operation. Only bits 12...15 are valid.
ValueMeaning
16#0000Standby: the controller is powering up.
16#1000Faulted: any of the Module object’s connections to the associated module fail. This value should not be used to determine if the module failed because the Module object leaves this state periodically when trying to reconnect to the module. Instead, test for Running state (16#4000). Check for FaultCode not equal to 0 to determine if a module is faulted. When Faulted, the FaultCode and FaultInfo attributes are valid until the fault condition is corrected.
16#2000Validating: the Module object is verifying Module object integrity prior to establishing connections to the module.
16#3000Connecting: the Module object is initiating connections to the module.
16#4000Running: all connections to the module are established and data is transferring.
16#5000Shutting down: the Module object is in the process of shutting down all connections to the module.
16#6000Inhibited: the Module object is inhibited (the inhibit bit in the Mode attribute is set).
16#7000Waiting: the parent object upon which this Module object depends is not running.
A number that identifies a module fault, if one occurs.
Provides specific information about the Module object fault code.
Identifies current operating state of the firmware supervisor feature.
ValueMeaning
0Module updates are not being executed
1Module updates are being executed
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
199
Chapter 4
Input/Output Instructions (MSG, GSV, SSV, IOT)
Attribute
ForceStatus
Instance
LEDStatus
Mode
Data Type
INT
DINT
INT
INT
Instruction
GSV
GSV
GSV
GSV
SSV
Description
Specifies the status of forces.
BitMeaning
0Forces installed (1=yes, 0-no)
1Forces enabled (1=yes, 0=no)
Provides the instance number of this module object.
Specifies the current state of the I/O status indicator on the front of the controller.
(1)
ValueMeaning
0Status indicator off: No Module objects are configured for the controller.
(There are no modules in the I/O Configuration section of the controller organizer.)
1Flashing red: None of the Module objects are Running.
2Flashing green: At least one Module object is not Running.
3Solid green: All the Module objects are Running.
You do not enter an object name with this attribute because this attribute applies to the entire collection of modules.
Specifies the current mode of the Module object.
BitMeaning
0If set, causes a major fault to be generated if any of the Module object connections fault while the controller is in Run mode.
2If set, causes the Module object to enter Inhibited state after shutting down all the connections to the module.
(1) The 1756-L7x controllers do not have a status indicator display on the front of the controller, but do use this functionality.
Attribute
DisableFlag
Data Type
SINT
Program Attributes
The Program object provides status information about a program. Specify the program name to determine the Program object you want.
Instruction within
Standard Task
GSV
SSV
Instruction within Safety
Task
None
Description
Controls this program’s execution.
Value Meaning
0 Execution enabled non-zero) Execution disabled
LastScanTime
MajorFault
Record
DINT
DINT
DINT[11]
GSV
GSV
SSV
GSV
SSV
GSV
None
GSV
SSV
A non-zero value will disable.
Time it took to execute this program the last time it was executed. Time is in microseconds.
Records major faults for this program
We recommend that you create a user-defined structure to simplify access to the
MajorFaultRecord attribute:
Name
TimeLow
Data Type
DINT Decimal
Style Description
Lower 32 bits of fault timestamp value
TimeHighDINTDecimalUpper 32 bits of fault timestamp value
TypeINTDecimalFault type (program, I/O, and so forth)
CodeINTDecimalUnique code for the fault (depends on fault type)
InfoDINT[8]HexadecimalFault specific information (depends on fault type and code)
200
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Input/Output Instructions (MSG, GSV, SSV, IOT)
Chapter 4
Attribute
MinorFault
Record
Data Type
DINT[11]
Instruction within
Standard Task
GSV
SSV
Instruction within Safety
Task
GSV
SSV
Description
Records minor faults for this program
We recommend that you create a user-defined structure to simplify access to the
MinorFaultRecord attribute:
NameData TypeStyleDescription
TimeLowDINTDecimalLower 32 bits of fault timestamp value
TimeHighDINTDecimalUpper 32 bits of fault timestamp value
TypeINTDecimalFault type (program, I/O, and so forth)
CodeINTDecimalUnique code for the fault (depends on fault type)
InfoDINT[8]HexadecimalFault specific information (depends on fault type and code)
MaxScanTime DINT None
Name String
GSV
SSV
GSV GSV
Maximum recorded execution time for this program. Time is in microseconds.
Name of the program.
Attribute
Instance
Name
SFCPaused
SFCResuming
Data Type
DINT
String
INT
INT
Routine Attributes
The Routine object provides status information about a routine. Specify the routine name to determine which Routine object that you want.
Instruction within
Standard Task
GSV
GSV
GSV
Instruction within Safety
Task
GSV
GSV
None
GSV
SSV
None
Description
Provides the instance number for this routine object. Valid values are 0…65,535.
Name of the routine.
In an SFC routine, indicates whether the SFC is paused.
Value Meaning
0
1
SFC is not paused
SFC is paused
In an SFC routine, indicates whether the SFC is resuming execution.
Value
0
Meaning
SFC is not executing. This attribute is automatically set to 0 at the end of a scan in which the chart was executed
1 SFC is executing. Step and action timers will retain their previous value if configured to do so. This attribute is automatically set to 1 on the first scan after a chart is unpaused.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
201
Chapter 4
Input/Output Instructions (MSG, GSV, SSV, IOT)
Attribute
SafetyLocked
SafetyStatus
SafetySignature
Exists
SafetySignature
ID
SafetySignature
SafetyTaskFault
Record
Data Type
SINT
INT
SINT
DINT
String
DINT[11]
Safety Attributes
The Safety Controller object provides safety status and safety signature information. The SafetyTask and SafetyFaultRecord attributes can capture information about non-recoverable faults.
See the GuardLogix Controllers User Manual, publication 1756-UM020 .
Instruction within
Standard Task
GSV
GSV
Instruction within Safety
Task
None
None
GSV GSV
Description
Indicates whether the controller is safety locked or unlocked.
Specifies the safety status as:
Value Meaning
1000000000000000 Safety task OK.
1000000000000001 Safety task inoperable.
00000000000000000 Partner missing.
00000000000000001 Partner unavailable.
00000000000000010 Hardware incompatible.
00000000000000011 Firmware incompatible.
Indicates whether the safety task signature is present.
GSV None 32-bit identification number.
GSV
GSV
None
None
32-bit identification number.
Records safety task faults.
Attribute
BaudRate
ComDriverID
DataBits
DCDDelay
Parity
RTSOffDelay
RTSSendDelay
SINT
INT
INT
Data Type
DINT
SINT
INT
SINT
SerialPort Attributes
Instruction
GSV
GSV
GSV
GSV
GSV
GSV
GSV
The SerialPort object provides an interface to the serial communication port.
Description
Specifies the baud rate. Valid values are 110, 300, 600, 1200, 2400, 4800, 9600, and 19200 (default).
Specifies the specific driver.
Value
0xA2
0xA3
Meaning
DF1 (default)
ASCII
7
8
Specifies the number of bits of data per character.
Value Meaning
7 data bits (ASCII only)
8 data bits (default)
Specifies the amount of time to wait for the data carrier detect (DCD) to become low before erroring the packet. The delay is in counts of 1 s packets. Default is 0 counter.
0
1
Specifies the parity.
Value
2
Meaning
No parity (no default)
Odd parity (ASCII only)
Even parity
Amount of time to delay turning off the RTS line after the last character has been transmitted. Valid value
0...32,767. Delay in counts of 20 msec periods. The default is 0 msec.
Amount of time to delay transmitting the first character of a message after turning on the RTS line. Valid value
0...32,767. Delay in counts of 20 msec periods. The default is 0 msec.
202
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Input/Output Instructions (MSG, GSV, SSV, IOT)
Chapter 4
Attribute
StopBits
PendingBaudRate
PendingCOM
DriverID
PendingDataBits
DINT
SINT
PendingDCD
Delay
PendingParity
SINT
INT
PendingRTSOff
Delay
SINT
INT
PendingRTSSendDelay INT
PendingStopBits SINT
Data Type
SINT
SSV
SSV
SSV
SSV
SSV
SSV
SSV
SSV
Instruction
GSV
Description
Specifies the number of stop bits.
Value
1
2
Meaning
1 stop bit (default)
2 stop bits (ASCII only)
Pending value for the BaudRate attribute.
Pending value for the COMDriverID attribute.
Pending value for the DataBits attribute.
Pending value for the DCDDelay attribute.
Pending value for the Parity attribute.
Pending value for the RTSOffDelay attribute.
Pending value for the RTSSendDelay attribute.
Pending value for the StopBits attribute.
Attribute
DisableUpdate
Outputs
EnableTimeOut
InhibitTask
Instance
LastScanTime
MaximumInterval
DINT
DINT
DINT[2]
MaximumScan
Time
MinimumInterval
Name
DINT
DINT[2]
String
Data Type
DINT
DINT
DINT
Task Attributes
The Task object provides status information about a task. Specify the task name to determine which Task object that you want.
GSV
SSV
GSV
SSV
GSV
GSV
SSV
GSV
SSV
Instruction within
Standard Task
GSV
SSV
Instruction within Safety
Task
None
GSV
SSV
GSV
SSV
None
None
GSV
None
Description
Enables or disables the processing of outputs at the end of a task.
Value
0
Non zero
Meaning
Enable the processing of outputs at the end of the task
Disable the processing of outputs at the end of the task
Enables or disables the timeout function of an event task.
Value
0
Non zero
Meaning
Disable the timeout function
Enable the timeout function
Prevents the task from executing. If a task is inhibited, the controller still prescans the task when the controller transitions from program to run or test mode.
Value
0
Meaning
Enable the task 0 (default)
Non zero Inhibit (disable) the task
Provides the instance number of this task object. Valid values are 0...31.
Time it took to execute this task the last time it was executed. Time is in microseconds.
None
None
The maximum time interval between successive executions of the task. DINT[0] contains the lower 32 bits of the value; DINT[1] contains the upper 32 bits of the value. A value of 0 indicates
1 or less executions of the task.
Maximum recorded execution time for this program. Time is in microseconds.
GSV
None
GSV
The minimum time interval between successive executions of the task. DINT[0] contains the lower 32 bits of the value; DINT[1] contains the upper 32 bits of the value. A value of 0 indicates
1 or less executions of the task.
Name of the task.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
203
Attribute
OverlapCount
Priority
Rate
StartTime
Status
Chapter 4
Input/Output Instructions (MSG, GSV, SSV, IOT)
Watchdog
DINT
INT
DINT
DINT[2]
DINT
Data Type
DINT
GSV
SSV
GSV
SSV
Instruction within
Standard Task
GSV
SSV
GSV
SSV
GSV
SSV
Instruction within Safety
Task
GSV
SSV
GSV
GSV
None
None
GSV
SSV
GSV
Description
Number of times that the task was triggered while it was still executing. Valid for an event or a periodic task. To clear the count, set the attribute to 0.
Relative priority of this task as compared to the other tasks. Valid values 0...15.
The time interval between executions of the task. Time is in microseconds.
Value of WALLCLOCKTIME when the last execution of the task was started. DINT[0] contains the lower 32 bits of the value; DINT[1] contains the upper 32 bits of the value.
1
2
Status information about the task. Once the controller sets one of these bits, you must manually clear the bit.
Bit
0
Meaning
An EVENT instruction triggered the task (event task only)
A timeout triggered the task (event task only)
An overlap occurred for this task
Time limit for execution of all programs associated with this task. Time is in microseconds.
If you enter 0, these values are assigned:
Time
0.5 sec
5.0 sec
Task Type
Periodic
Continuous
204
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Attribute
ApplyDST
CSTOffset
CurrentValue
Data Type
SINT
DINT[2]
DINT[2]
DateTime DINT[7]
DSTAdjustment
LocalDateTime
INT
DINT[7]
TimeZoneString INT
Input/Output Instructions (MSG, GSV, SSV, IOT)
Chapter 4
WallClockTime Attributes
GSV
SSV
GSV
SSV
The WallClockTime object provides a timestamp that the controller can use for scheduling.
Instruction Description
GSV
SSV
GSV
SSV
GSV
SSV
GSV
SSV
Identifies whether to enable daylight savings time.
Value Meaning
0 non zero
Do not adjust for daylight savings time
Adjust for daylight savings time
Positive offset from the CurrentValue of the CST object (coordinated system time, see page 194
).
DINT[0] contains the lower 32 bits of the value; DINT[1] contains the upper 32 bits of the value. Value in
s. The default is 0.
Current value of the wall clock time. DINT[0] contains the lower 32 bits of the value; DINT[1] contains the upper 32 bits of the value. The value is the number of microseconds that have elapsed since 0000 hours 1 January 1972. The CST and WALLCLOCKTIME objects are mathematically related in the controller. For example, if you add the CST CurrentValue and the WALLCLOCKTIME CTSOffset, the result is the WALLCLOCKTIME CurrentValue.
The date and time.
Value
DINT[0]
DINT[1]
DINT[2]
DINT[3]
DINT[4]
DINT[5]
DINT[6]
Meaning
Year
Month (1...12)
Day (1...31)
Hour (0...23)
Minute (0...59)
Seconds (0...59)
Microseconds (0...999,999)
The number of minutes to adjust for daylight saving time.
GSV
SSV
Current adjusted local time.
Value Meaning
DINT[0]
DINT[1]
DINT[2]
DINT[3]
DINT[4]
DINT[5]
DINT[6]
Year
Month (1...12)
Day (1...31)
Hour (0...23)
Minute (0...59)
Seconds (0...59)
Microseconds (0...999,999)
Time zone for the time value.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
205
Chapter 4
Input/Output Instructions (MSG, GSV, SSV, IOT)
GSV/SSV Programming
Example
Get Fault Information
The following examples use GSV instructions to get fault information.
Example 1:
This example gets fault information from the I/O module disc_in_2 and places the data in a user-defined structure
disc_in_2_info.
Relay Ladder
Structured Text
GSV(MODULE,disc_in_2,FaultCode,disc_in_2_info.FaultCode);
GSV(MODULE,disc_in_2,FaultInfo,disc_in_2_info.FaultInfo);
GSV(MODULE,disc_in_2,Mode,disc_in_2info.Mode);
Example 2:
This example gets status information about program discrete and places the data in a user-defined structure
discrete_info.
Relay Ladder
206
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Input/Output Instructions (MSG, GSV, SSV, IOT)
Chapter 4
Structured Text
GSV(PROGRAM,DISCRETE,LASTSCANTIME, discrete_info.LastScanTime);
GSV(PROGRAM,DISCRETE,MAXSCANTIME,discrete_info.MaxScanTim
e);
Example 3:
This example gets status information about task IO_test and places the data in a user-defined structure io_test_info.
Relay Ladder
Structured Text
GSV(TASK,IO_TEST,LASTSCANTIME,io_test_info.LastScanTime);
GSV(TASK,IO_TEST,MAXSCANTIME,io_test_info.MaxScanTime);
GSV(TASK,IO_TEST,WATCHDOG,io_test_info.WatchDog);
Set Enable And Disable Flags
The following example uses the SSV instruction to enable or disable a program.
You could also use this method to enable or disable an I/O module, which is similar to using inhibit bits with a PLC-5 processor.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
207
Chapter 4
Input/Output Instructions (MSG, GSV, SSV, IOT)
Example:
Based on the status of
SW.1, place the appropriate value in the disableflag attribute of program discrete.
Relay Ladder
Structured Text
IF SW.1 THEN discrete_prog_flag := enable_prog;
ELSE discrete_prog_flag := disable_prog;
END_IF;
SSV(PROGRAM,DISCRETE,DISABLEFLAG,discrete_prog_flag);
208
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Input/Output Instructions (MSG, GSV, SSV, IOT)
Chapter 4
Immediate Output (IOT)
Operands:
The IOT instruction immediately updates the specified output data (output tag or produced tag).
Relay Ladder
Operand
Update Tag
Type Format
Tag
Description
Tag that you want to update, either:
• output tag of an I/O module
• produced tag
Do not choose a member or element of a tag. For example,
Local:5:0 is OK but Local:5:0.Data is not OK.
IOT(output_tag);
Structured Text
The operands are the same as those for the relay ladder IOT instruction.
Description:
The IOT instruction overrides the requested packet interval (RPI) of an output connection and sends fresh data over the connection:
• An output connection is a connection that is associated with the output tag of an I/O module or with a produced tag.
• If the connection is for a produced tag, the IOT instruction also sends the event trigger to the consuming controller. This lets the IOT instruction trigger an event task in the consuming controller.
To use an IOT instruction and a produced tag to trigger an event task in a consumer controller, configure the produced tag as shown below.
Check this box.
This configures the tag to update its event trigger only via an IOT instruction.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
209
Chapter 4
Input/Output Instructions (MSG, GSV, SSV, IOT)
With this controller
ControlLogix
SoftLogix5800
EtherNet/IP Network
Values loaded into produced tag
IOT instruction in the producing controller
Event task in the consuming controller
The type of network between the controllers determines when the consuming controller receives the new data and event trigger via the IOT instruction.
Over this network
Backplane
EtherNet/IP network
ControlNet network
You can produce and consume tags only over a ControlNet network.
The consuming device receives the data and event trigger
Immediately
Immediately
Within the actual packet interval (API) of the consumed tag (connection)
Within the actual packet interval (API) of the consumed tag (connection)
The following diagrams compare the receipt of data via an IOT instruction over
EtherNet/IP and ControlNet networks.
ControlNet Network
Values loaded into produced tag
IOT instruction in the producing controller
RPI of the produced tag
Event task in the consuming controller
EnableIn is set
Arithmetic Status Flags:
Not affected
Fault Conditions:
None
Execution:
Condition
Prescan
Rung-condition-in is false
Rung-condition-in is true
Relay Ladder Action
The rung-condition-out is set to false.
The rung-condition-out is set to false.
The instruction executes.
The rung-condition-out is set to true.
N/A
Instruction execution
Postscan
The instruction:
• updates the connection of the specified tag.
• resets the RPI timer of the connection.
The rung-condition-out is set to false.
Structured Text Action
No action taken.
N/A
N/A
EnableIn is always set.
The instruction executes.
No action taken.
210
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Input/Output Instructions (MSG, GSV, SSV, IOT)
Chapter 4
Example 1:
When the IOT instruction executes, it immediately sends the values of the
Local:5:0 tag to the output module.
Relay Ladder
Structured Text
IOT (Local:5:O);
Example 2:
This controller controls station 24 and produces data for the next station (station
25). To use an IOT instruction to signal the transmission of new data, the produced tag is configured as shown below:
Produced_Tag is configured to update its event trigger via an IOT instruction.
Relay Ladder
If New_Data = on, then the following occurs for one scan:
The CPS instruction sets Produced_Tag = Source_Tag.
The IOT instruction updates Produced_Tag and sends this update to the consuming controller (station 25). When the consuming controller receives this update, it triggers the associated event task in that controller.
Structured Text
IF New_Data AND NOT Trigger_Consumer THEN
CPS (Source_Tag,Produced_Tag,1);
IOT (Produced_Tag);
END_IF;
Trigger_Consumer := New_Data;
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
211
Chapter 4
Input/Output Instructions (MSG, GSV, SSV, IOT)
Notes:
212
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Chapter
5
Compare Instructions
(CMP, EQU, GEQ, GRT, LEQ, LES, LIM, MEQ, NEQ)
Topic
Greater Than or Equal To (GEQ)
Page
The compare instructions let you compare values by using an expression or a specific compare instruction.
If you want to
Compare values based on an expression
Test whether two values are equal
Test whether one value is greater than or equal to a second value
GEQ
Test whether one value is greater than a second value GRT
Use this instruction
CMP
EQU
Test whether one value is less than or equal to a second value LEQ
Test whether one value is less than a second value LES
Available in these languages
Relay ladder
Structured text
(1)
Relay ladder
Structured text
(2)
Function block
Relay ladder
Structured text
(1)
Function block
Relay ladder
Structured text
(1)
Function block
Relay ladder
Structured text
(1)
Function block
Relay ladder
Structured text
(1)
Function block
Page
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
213
Chapter 5
Compare Instructions (CMP, EQU, GEQ, GRT, LEQ, LES, LIM, MEQ, NEQ)
If you want to
Test whether one value is between two other values
Pass two values through a mask and test whether they are equal
Test whether one value is not equal to a second value
Use this instruction
LIM
MEQ
NEQ
Available in these languages
Relay ladder
Structured text
(1)
Function block
Relay ladder
Structured text
(1)
Function block
Relay ladder
Structured text
(1)
Function block
(1) There is no equivalent structured text instruction. Use other structured text programming to achieve the same result. See the description for the instruction.
(2) There is no equivalent structured text instruction. Use the operator in an expression.
Page
IMPORTANT
REAL values are rarely absolutely equal. If you need to determine the equality of two REAL values, use the LIM instruction.
You can compare values of different data types, such as floating point and integer.
For relay ladder instructions, bold data types indicate optimal data types. An instruction executes faster and requires less memory if all the operands of the instruction use the same optimal data type, typically DINT or REAL.
214
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Compare (CMP)
Compare Instructions (CMP, EQU, GEQ, GRT, LEQ, LES, LIM, MEQ, NEQ)
Chapter 5
Operands:
The CMP instruction performs a comparison on the arithmetic operations you specify in the expression.
Relay Ladder
Operand
Expression
Type
SINT
INT
DINT
REAL string
Format
Immediate Tag
Description
An expression consisting of tags and/or immediate values separated by operators.
A SINT or INT tag converts to a DINT value by sign-extension.
Structured Text
Structured text does not have a CMP instruction, but you can achieve the same results by using an IF...THEN construct and expression.
IF BOOL_expression THEN
<statement>;
END_IF;
See Structured Text Programming
for information on the syntax of constructs and expressions within structured text.
Description:
Define the CMP expression by using operators, tags, and immediate values. Use parentheses ( ) to define sections of more complex expressions.
The execution of a CMP instruction is slightly slower and uses more memory than the execution of the other comparison instructions. The advantage of the
CMP instruction is that it allows you to enter complex expressions in one instruction.
Arithmetic Status Flags:
The CMP instruction affects only the arithmetic status flags if the expression contains an operator (for example, +, , *, /) that affects the arithmetic status flags.
Fault Conditions:
None
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
215
Chapter 5
Compare Instructions (CMP, EQU, GEQ, GRT, LEQ, LES, LIM, MEQ, NEQ)
Execution:
Condition
Prescan
Rung-condition-in is false
Relay Ladder Action
The rung-condition-out is set to false.
The rung-condition-out is set to false.
Rung-condition-in is true
Postscan
Evaluate Expression
Expression is true.
Rung-condition-out is set to true.
Expression is false.
Rung-condition-out is set to false.
End
The rung-condition-out is set to false.
Examples:
If the CMP instruction finds the expression true, the rung-condition-out is set to true.
216
If you enter an expression without a comparison operator, such as
value_1 + value_2, or value_1, the instruction evaluates the expression as explained in the table.
If the expression is
Non-zero
Zero
The rung-condition-out is set to
True
False
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
ABS
ACS
AND
ASN
>
>=
<>
**
ATN
COS
DEG
FRD
/
=
<
<=
-
*
Operator:
+
Description
Add
Subtract/negate
Multiply
Divide
Equal
Less than
Less than or equal
Greater than
Greater than or equal
Not equal
Exponent (x to y)
Absolute value
Arc cosine
Bitwise AND
Arc sine
Arc tangent
Cosine
Radians to degrees
BCD to integer
Compare Instructions (CMP, EQU, GEQ, GRT, LEQ, LES, LIM, MEQ, NEQ)
Chapter 5
CMP Expressions
You program expressions in CMP instructions the same as expressions in FSC instructions. Use the following sections for information on valid operators, format, and order of operation, which are common to both instructions.
Valid Operators
DINT, REAL
DINT, REAL
DINT, REAL
DINT, REAL
DINT, REAL
REAL
DINT
REAL
Optimal
DINT, REAL
DINT, REAL
DINT, REAL
DINT, REAL
DINT, REAL
DINT, REAL
DINT, REAL
REAL
REAL
DINT, REAL
DINT
SIN
SQR
TAN
TOD
TRN
XOR
Operator:
LN
LOG
MOD
NOT
OR
RAD
Description
Natural log
Log base 10
Modulo-divide
Bitwise complement
Bitwise OR
Degrees to radians
Sine
Square root
Tangent
Integer to BCD
Truncate
Bitwise exclusive OR
Optimal
REAL
REAL
DINT, REAL
DINT
DINT
DINT, REAL
REAL
DINT, REAL
REAL
DINT
DINT, REAL
DINT
Format Expressions
For each operator that you use in an expression, you have to provide one or two operands (tags or immediate values). Use this table to format operators and operands within an expression
.
Operators that operate on
One operand
Two operands
Use this format
Operator (operand)
Operand_a operator operand_b
Examples
ABS(tag_a)
·tag_b + 5
·tag_c AND tag_d
·(tag_e ** 2) MOD (tag_f / tag_g)
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
217
Chapter 5
Compare Instructions (CMP, EQU, GEQ, GRT, LEQ, LES, LIM, MEQ, NEQ)
Determine the Order of Operation
7.
8.
9.
10.
5.
6.
3.
4.
Order
1.
2.
The operations you write into the expression are performed by the instruction in a prescribed order, not necessarily the order you write them. You can override the order of operation 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.
Operation
( )
ABS, ACS, ASN, ATN, COS, DEG, FRD, LN, LOG, RAD, SIN, SQR,
TAN, TOD, TRN
**
(negate), NOT
*, /, MOD
<, <=, >, >=, =
(subtract), +
AND
XOR
OR
218
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Compare Instructions (CMP, EQU, GEQ, GRT, LEQ, LES, LIM, MEQ, NEQ)
Chapter 5
Use Strings in an Expression
Use a relay ladder or structured text expression to compare string data types. To use strings in an expression, follow these guidelines:
• An expression lets you compare two string tags.
• You cannot enter ASCII characters directly into the expression.
• Only the following operators are permitted.
>
>=
<>
Operator
=
<
<=
Description
Equal
Less than
Less than or equal
Greater than
Greater than or equal
Not equal
• Strings are equal if their characters match.
• ASCII characters are case sensitive. Upper case ‘A’ ($41) is not equal to lower case ‘a’ ($61).
• The hexadecimal values of the characters determine if one string is less than or greater than another string. For the hex code of a character, see the back cover of this manual.
• When the two strings are sorted as in a telephone directory, the order of the strings determines which one is greater. s s
L e r e r t e e a r
G
AB
B a
1b
A
ASCII Characters
1ab ab
Hex Codes
$31$61$62
$31$62
$41
$41$42
$42
$61
$61$62
AB < B a > B
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
219
Chapter 5
Compare Instructions (CMP, EQU, GEQ, GRT, LEQ, LES, LIM, MEQ, NEQ)
Equal To (EQU)
The EQU instruction tests whether Source A is equal to Source B.
Operands:
IF sourceA = sourceB THEN
Relay Ladder
Operand
Source A
Source B
Type
SINT
INT
DINT
REAL string
SINT
INT
DINT
REAL string
Format
Immediate Tag
Immediate Tag
Description
Value to test against Source B
Value to test against Source A
• If you enter a SINT or INT tag, the value converts to a DINT value by sign-extension.
• REAL values are rarely absolutely equal. If you need to determine the equality of two REAL values, use the LIM instruction.
• String data types are:
– default STRING data type.
– any new string data type that you create.
• To test the characters of a string, enter a string tag for both Source A and
Source B.
Structured Text
Use the equal sign ‘’ as an operator within an expression. This expression evaluates whether sourceA is equal to sourceB.
See
Structured Text Programming for information on the syntax of expressions
within structured text.
Function Block
Operand
EQU tag
Type
FBD_COMPARE
Format
Structure
Description
EQU structure
220
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Compare Instructions (CMP, EQU, GEQ, GRT, LEQ, LES, LIM, MEQ, NEQ)
Chapter 5
Input Parameter
EnableIn
SourceA
SourceB
Output Parameter
EnableOut
Dest
Data Type
BOOL
REAL
REAL
Data Type
BOOL
BOOL
FBD_COMPARE Structure
Description
Enable input. If cleared, the instruction does not execute and outputs are not updated.
Default is set.
Value to test against SourceB.
Valid = any float
Value to test against SourceA.
Valid = any float
Description
The instruction produced a valid result.
Result of the instruction. This is equivalent to rung-condition-out of the relay ladder EQU instruction.
Description:
Use the EQU instruction to compare two numbers or two strings of ASCII characters. When you compare strings, note the following:
• Strings are equal if their characters match.
• ASCII characters are case sensitive. Upper case ‘A’ ($41) is not equal to lower case ‘a’ ($61).
Arithmetic Status Flags:
Not affected
Fault Conditions:
None
Execution:
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
221
Chapter 5
Compare Instructions (CMP, EQU, GEQ, GRT, LEQ, LES, LIM, MEQ, NEQ)
Condition
Prescan
Rung-condition-in is false
Rung-condition-in is true
Relay Ladder
Action
The rung-condition-out is set to false.
The rung-condition-out is set to false.
Postscan
Condition
Prescan
Instruction first scan
Instruction first run
EnableIn is cleared
EnableIn is set
Postscan
Source A = Source B
Yes
No
Rung-condition-out is set to false.
Rung-condition-out is set to true.
End
The rung-condition-out is set to false.
Function Block
Action
No action taken.
No action taken.
No action taken.
EnableOut is cleared.
The instruction executes.
EnableOut is set.
No action taken.
222
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Compare Instructions (CMP, EQU, GEQ, GRT, LEQ, LES, LIM, MEQ, NEQ)
Chapter 5
Example:
If
value_1 is equal to value_2, set light_a. If value_1 is not equal to value_2, clear
light_a.
Relay Ladder
Structured Text
light_a := (value_1 = value_2);
Function Block
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
223
Chapter 5
Compare Instructions (CMP, EQU, GEQ, GRT, LEQ, LES, LIM, MEQ, NEQ)
Greater Than or Equal To
(GEQ)
Operands:
The GEQ instruction tests whether Source A is greater than or equal to Source B.
IF sourceA >= sourceB THEN
Relay Ladder
Operand
Source A
Source B
Type
SINT
INT
DINT
REAL string
SINT
INT
DINT
REAL string
Format
Immediate Tag
Immediate Tag
Description
Value to test against Source B
Value to test against Source A
• If you enter a SINT or INT tag, the value converts to a DINT value by sign-extension.
• String data types are:
– default STRING data type.
– any new string data type that you create.
• To test the characters of a string, enter a string tag for both Source A and
Source B.
Structured Text
Use adjacent greater than and equal signs ‘>’ as an operator within an expression. This expression evaluates whether sourceA is greater than or equal to
sourceB.
See
Structured Text Programming for information on the syntax of expressions
within structured text.
224
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Function Block
Operand
GEQ tag
Type
FBD_COMPARE
Compare Instructions (CMP, EQU, GEQ, GRT, LEQ, LES, LIM, MEQ, NEQ)
Chapter 5
Format
Structure
Description
GEQ structure
Input Parameter
EnableIn
SourceA
SourceB
Output Parameter
EnableOut
Dest
Data Type
BOOL
REAL
REAL
Data Type
BOOL
BOOL
FBD_COMPARE Structure
Description
Enable input. If cleared, the instruction does not execute and outputs are not updated.
Default is set.
Value to test against SourceB.
Valid = any float
Value to test against SourceA.
Valid = any float
Description
The instruction produced a valid result.
Result of the instruction. This is equivalent to rung-condition-out for the relay ladder GEQ instruction.
Description:
The GEQ instruction tests whether Source A is greater than or equal to Source B.
When you compare strings, note the following:
• The hexadecimal values of the characters determine if one string is less than or greater than another string. For the hex code of a character, see the back cover of this manual.
• When the two strings are sorted as in a telephone directory, the order of the strings determines which one is greater. s s
L e r e r t e e a r
G
AB
B a
1b
A
ASCII Characters
1ab ab
Hex Codes
$31$61$62
$31$62
$41
$41$42
$42
$61
$61$62
AB < B a > B
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
225
Chapter 5
Compare Instructions (CMP, EQU, GEQ, GRT, LEQ, LES, LIM, MEQ, NEQ)
Arithmetic Status Flags:
Not affected
Fault Conditions:
None
Execution:
Condition
Prescan
Rung-condition-in is false
Rung-condition-in is true
Relay Ladder
Action
The rung-condition-out is set to false.
The rung-condition-out is set to false.
Postscan
Condition
Prescan
Instruction first scan
Instruction first run
EnableIn is cleared
EnableIn is set
Postscan
Source A Source B
Yes no
Rung-condition-out is set to false.
Rung-condition-out is set to true.
End
The rung-condition-out is set to false.
Function Block
Action
No action taken.
No action taken.
No action taken.
EnableOut is cleared.
The instruction executes.
EnableOut is set.
No action taken.
226
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Compare Instructions (CMP, EQU, GEQ, GRT, LEQ, LES, LIM, MEQ, NEQ)
Chapter 5
Example:
If
value_1 is greater than or equal to value_2, set light_b. If value_1 is less than
value_2, clear light_b.
Relay Ladder
Structured Text
light_b := (value_1 >= value_2);
Function Block
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
227
Chapter 5
Compare Instructions (CMP, EQU, GEQ, GRT, LEQ, LES, LIM, MEQ, NEQ)
Greater Than (GRT)
Operands:
The GRT instruction tests whether Source A is greater than Source B.
IF sourceA > sourceB THEN
Relay Ladder
Operand
Source A
Source B
Type
SINT
INT
DINT
REAL string
SINT
INT
DINT
REAL string
Format
Immediate Tag
Immediate Tag
Description
Value to test against Source B
Value to test against Source A
• If you enter a SINT or INT tag, the value converts to a DINT value by sign-extension.
• String data types are:
– default STRING data type.
– any new string data type that you create.
• To test the characters of a string, enter a string tag for both Source A and
Source B.
Structured Text
Use the greater than sign ‘>’ as an operator within an expression. This expression evaluates whether
sourceA is greater than sourceB.
See
Structured Text Programming for information on the syntax of expressions
within structured text.
Function Block
Operand
GRT tag
Type
FBD_COMPARE
Format
Structure
Description
GRT structure
228
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Compare Instructions (CMP, EQU, GEQ, GRT, LEQ, LES, LIM, MEQ, NEQ)
Chapter 5
Input Parameter
EnableIn
SourceA
SourceB
Output Parameter
EnableOut
Dest
Data Type
BOOL
REAL
REAL
Data Type
BOOL
BOOL
FBD_COMPARE Structure
Description
Enable input. If cleared, the instruction does not execute and outputs are not updated.
Default is set.
Value to test against SourceB.
Valid = any float
Value to test against SourceA.
Valid = any float
Description
The instruction produced a valid result.
Result of the instruction. This is equivalent to rung-condition-out for the relay ladder GRT instruction.
Description:
The GRT instruction tests whether Source A is greater than Source B.
When you compare strings, note the following:
• The hexadecimal values of the characters determine if one string is less than or greater than another string. For the hex code of a character, see the back cover of this manual.
• When the two strings are sorted as in a telephone directory, the order of the strings determines which one is greater. s s e
L r e r t e e a r
G
AB
B a
1b
A
ASCII Characters
1ab ab
Hex Codes
$31$61$62
$31$62
$41
$41$42
$42
$61
$61$62
AB < B a > B
Arithmetic Status Flags:
Not affected
Fault Conditions:
None
Execution:
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
229
Chapter 5
Compare Instructions (CMP, EQU, GEQ, GRT, LEQ, LES, LIM, MEQ, NEQ)
Condition
Prescan
Rung-condition-in is false
Relay Ladder
Action
The rung-condition-out is set to false.
The rung-condition-out is set to false.
Rung-condition-in is true
Postscan
Condition
Prescan
Instruction first scan
Instruction first run
EnableIn is cleared
EnableIn is set
Postscan
Source A Source B
Yes
No
Rung-condition-out is set to false.
Rung-condition-out is set to true.
End
The rung-condition-out is set to false.
Function Block
Action
No action taken.
No action taken.
No action taken.
EnableOut is cleared.
The instruction executes.
EnableOut is set.
No action taken.
230
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Compare Instructions (CMP, EQU, GEQ, GRT, LEQ, LES, LIM, MEQ, NEQ)
Chapter 5
Example:
If
value_1 is greater than value_2, set light_1. If value_1 is less than or equal to
value_2, clear light_1.
Relay Ladder
Structured Text
light_1 := (value_1 > value_2);
Function Block
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
231
Chapter 5
Compare Instructions (CMP, EQU, GEQ, GRT, LEQ, LES, LIM, MEQ, NEQ)
Less Than or Equal To (LEQ)
The LEQ instruction tests whether Source A is less than or equal to Source B.
Operands:
IF sourceA <= sourceB THEN
Relay Ladder
Operand
Source A
Source B
Type
SINT
INT
DINT
REAL string
SINT
INT
DINT
REAL string
Format
Immediate Tag
Immediate Tag
Description
Value to test against Source B
Value to test against Source A
• If you enter a SINT or INT tag, the value converts to a DINT value by sign-extension.
• String data types are:
– default STRING data type.
– any new string data type that you create.
• To test the characters of a string, enter a string tag for both Source A and
Source B.
Structured Text
Use adjacent less than and equal signs ‘<’ as an operator within an expression.
This expression evaluates whether
sourceA is less than or equal to sourceB.
See
Structured Text Programming for information on the syntax of expressions
within structured text.
Function Block
Operand
LEQ tag
Type
FBD_COMPARE
Format
Structure
Description
LEQ structure
232
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Compare Instructions (CMP, EQU, GEQ, GRT, LEQ, LES, LIM, MEQ, NEQ)
Chapter 5
Input Parameter
EnableIn
SourceA
SourceB
Output Parameter
EnableOut
Dest
Data Type
BOOL
REAL
REAL
Data Type
BOOL
BOOL
FBD_COMPARE Structure
Description
Enable input. If cleared, the instruction does not execute and outputs are not updated.
Default is set.
Value to test against SourceB.
Valid = any float
Value to test against SourceA.
Valid = any float
Description
The instruction produced a valid result.
Result of the instruction. This is equivalent to rung-condition-out for the relay ladder LEQ instruction.
Description:
The LEQ instruction tests whether Source A is less than or equal to Source B.
When you compare strings, note the following:
• The hexadecimal values of the characters determine if one string is less than or greater than another string. For the hex code of a character, see the back cover of this manual.
• When the two strings are sorted as in a telephone directory, the order of the strings determines which one is greater. s s
L e r e t a
G re r e
AB
B a
1b
A
ASCII Characters
1ab ab
Hex Codes
$31$61$62
$31$62
$41
$41$42
$42
$61
$61$62
AB < B a > B
Arithmetic Status Flags:
Not affected
Fault Conditions:
None
Execution:
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
233
Chapter 5
Compare Instructions (CMP, EQU, GEQ, GRT, LEQ, LES, LIM, MEQ, NEQ)
Condition
Prescan
Rung-condition-in is false
Rung-condition-in is true
Relay Ladder
Action
The rung-condition-out is set to false.
The rung-condition-out is set to false.
Postscan
Condition
Prescan
Instruction first scan
Instruction first run
EnableIn is cleared
EnableIn is set
Postscan
Source A Source B
Yes no
Rung-condition-out is set to false.
Rung-condition-out is set to true.
End
The rung-condition-out is set to false.
Function Block
Action
No action taken.
No action taken.
No action taken.
EnableOut is cleared.
The instruction executes.
EnableOut is set.
No action taken.
234
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Compare Instructions (CMP, EQU, GEQ, GRT, LEQ, LES, LIM, MEQ, NEQ)
Chapter 5
Example:
If
value_1 is less than or equal to value_2, set light_2. If value_1 is greater than
value_2, clear light_2.
Relay Ladder
Structured Text
light_2 := (value_1 <= value_2);
Function Block
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
235
Chapter 5
Compare Instructions (CMP, EQU, GEQ, GRT, LEQ, LES, LIM, MEQ, NEQ)
Less Than (LES)
The LES instruction tests whether Source A is less than Source B.
Operands:
IF sourceA < sourceB THEN
Relay Ladder
Operand
Source A
Source B
Type
SINT
INT
DINT
REAL string
SINT
INT
DINT
REAL string
Format
Immediate Tag
Immediate Tag
Description
Value to test against Source B
Value to test against Source A
• If you enter a SINT or INT tag, the value converts to a DINT value by sign-extension.
• String data types are:
– default STRING data type.
– any new string data type that you create.
• To test the characters of a string, enter a string tag for both Source A and
Source B.
Structured Text
Use the less than sign ‘<‘ as an operator within an expression. This expression evaluates whether
sourceA is less than sourceB.
See
Structured Text Programming for information on the syntax of expressions
within structured text.
Function Block
Operand
LES tag
Type
FBD_COMPARE
Format
Structure
Description
LES structure
236
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Compare Instructions (CMP, EQU, GEQ, GRT, LEQ, LES, LIM, MEQ, NEQ)
Chapter 5
Input Parameter
EnableIn
SourceA
SourceB
Output Parameter
EnableOut
Dest
Data Type
BOOL
REAL
REAL
Data Type
BOOL
BOOL
FBD_COMPARE Structure
Description
Enable input. If cleared, the instruction does not execute and outputs are not updated.
Default is set.
Value to test against SourceB.
Valid = any float
Value to test against SourceA.
Valid = any float
Description
The instruction produced a valid result.
Result of the instruction. This is equivalent to rung-condition-out for the relay ladder LES instruction.
Description:
The LES instruction tests whether Source A is less than Source B.
When you compare strings, note the following:
• The hexadecimal values of the characters determine if one string is less than or greater than another string. For the hex code of a character, see the back cover of this manual.
• When the two strings are sorted as in a telephone directory, the order of the strings determines which one is greater. s s
L e r e t a
G re r e
AB
B a
1b
A
ASCII Characters
1ab ab
Hex Codes
$31$61$62
$31$62
$41
$41$42
$42
$61
$61$62
AB < B a > B
Arithmetic Status Flags:
Not affected
Fault Conditions:
None
Execution:
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
237
Chapter 5
Compare Instructions (CMP, EQU, GEQ, GRT, LEQ, LES, LIM, MEQ, NEQ)
Condition
Prescan
Rung-condition-in is false
Rung-condition-in is true
Relay Ladder
Action
The rung-condition-out is set to false.
The rung-condition-out is set to false.
Postscan
Condition:
Prescan
Instruction first scan
Instruction first run
EnableIn is false
EnableIn is true
Postscan
Source A Source B
Yes no
Rung-condition-out is set to false.
Rung-condition-out is set to true.
End
The rung-condition-out is set to false.
Function Block
Action
No action taken.
No action taken.
No action taken.
EnableOut is cleared.
The instruction executes.
EnableOut is set.
No action taken.
238
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Compare Instructions (CMP, EQU, GEQ, GRT, LEQ, LES, LIM, MEQ, NEQ)
Chapter 5
Example:
If
value_1 is less than value_2, set light_3. If value_1 is greater than or equal to
value_2, clear light_3.
Relay Ladder
Structured Text
light_3 := (value_1 < value_2);
Function Block
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
239
Chapter 5
Compare Instructions (CMP, EQU, GEQ, GRT, LEQ, LES, LIM, MEQ, NEQ)
Limit (LIM)
Operands:
The LIM instruction tests whether the Test value is within the range of the Low
Limit to the High Limit.
Relay Ladder
Operand
Low limit
Test
High limit
Type
SINT
INT
DINT
REAL
Format
Immediate Tag
Description
Value of lower limit
A SINT or INT tag converts to a DINT value by sign-extension.
SINT
INT
DINT
REAL
Immediate Tag Value to test
A SINT or INT tag converts to a DINT value by sign-extension.
SINT
INT
DINT
REAL
Immediate Tag Value of upper limit
A SINT or INT tag converts to a DINT value by sign-extension.
Structured Text
Structured text does not have a LIM instruction, but you can achieve the same results by using structured text.
IF (LowLimit <= HighLimit AND
(Test >= LowLimit AND Test <= HighLimit)) OR
(LowLimit >= HighLimit AND
(Test <= LowLimit OR Test >= HighLimit)) THEN
< statement>;
END_IF;
Function Block
Operand
LIM tag
Type
FBD_LIMIT
Format
Structure
Description
LIM structure
240
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Input Parameter
EnableIn
LowLimit
Test
Output Parameter
EnableOut
Dest
HighLimit
Data Type
BOOL
REAL
REAL
Data Type
BOOL
BOOL
REAL
Compare Instructions (CMP, EQU, GEQ, GRT, LEQ, LES, LIM, MEQ, NEQ)
Chapter 5
FBD_LIMIT Structure
Description
If cleared, the instruction does not execute and outputs are not updated.
If set, the instruction executes as described under Execution.
Default is set.
Value of lower limit.
Valid = any float
Value to test against limits.
Valid = any float
Description
The instruction produced a valid result.
Result of the instruction. This is equivalent to rung-condition-out for the relay ladder LIM instruction.
Value of upper limit.
Valid = any float
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
241
Chapter 5
Compare Instructions (CMP, EQU, GEQ, GRT, LEQ, LES, LIM, MEQ, NEQ)
Description:
The LIM instruction tests whether the Test value is within the range of the Low
Limit to the High Limit.
If Low Limit
High Limit
High Limit
And Test Value Is
Equal to or between limits
Not equal to or outside limits
Equal to or outside limits
Not equal to or inside limits
The Rung-condition-out Is
True
False
True
False
Signed integers ‘roll over’ from the maximum positive number to the maximum negative number when the most significant bit is set. For example, in 16-bit integers (INT type), the maximum positive integer is 32,767, which is represented in hexadecimal as 16#7FFF (bits 0 …14 are all set). If you increment that number by one, the result is 16#8000 (bit 15 is set). For signed integers, hexadecimal 16#8000 is equal to -32,768 decimal. Incrementing from this point on until all 16 bits are set ends up at 16#FFFF, which is equal to -1 decimal.
This can be shown as a circular number line (see the following diagrams). The
LIM instruction starts at the Low Limit and increments clockwise until it reaches the High Limit. Any Test value in the clockwise range from the Low Limit to the
High Limit sets the rung-condition-out to true. Any Test value in the clockwise range from the High Limit to the Low Limit sets the rung-condition-out to false.
Low Limit
High Limit
The instruction is true if the test value is equal to or between the low and high limit
Low Limit
High Limit
The instruction is true if the test value is equal to or outside the low and high limit
1
0
+1
1
0
+1
Low Limit
High Limit
242
High Limit
n+1)
+n n = Maximum Value
Arithmetic Status Flags:
Not affected
Fault Conditions:
None
n+1)
+n n = Maximum Value
Low Limit
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Condition
Prescan
Rung-condition-in is false
Rung-condition-in is true
Compare Instructions (CMP, EQU, GEQ, GRT, LEQ, LES, LIM, MEQ, NEQ)
Chapter 5
Execution:
Relay Ladder
Action
The rung-condition-out is set to false.
The rung-condition-out is set to false.
Postscan
Condition
Prescan
Instruction first scan
Instruction first run
EnableIn is cleared
EnableIn is set
Postscan
Evaluate Limit
Comparison is true.
Comparison is false.
Rung-condition-out is set to false.
Rung-condition-out is set to true.
End
The rung-condition-out is set to false.
Function Block
Action
No action taken.
No action taken.
No action taken.
EnableOut is cleared, the instruction does nothing, and the outputs are not updated.
The instruction executes.
EnableOut is set.
No action taken.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
243
Chapter 5
Compare Instructions (CMP, EQU, GEQ, GRT, LEQ, LES, LIM, MEQ, NEQ)
Example 1:
Low Limit High Limit:
When 0
value 100, set light_1. If value < 0 or value >100, clear light_1.
Relay Ladder
Structured Text
IF (value <= 100 AND(value >= 0 AND value <= 100)) OR value >= 100 AND value <= 0 OR value >= 100)) THEN light_1 := 1;
ELSE light_1 := 0;
END_IF;
Function Block
244
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Compare Instructions (CMP, EQU, GEQ, GRT, LEQ, LES, LIM, MEQ, NEQ)
Chapter 5
Example 2:
Low Limit
High Limit:
When
value 0 or value 100, set light_1. If value < 0 or value >100, clear light_1.
Relay Ladder
Structured Text
IF (0 <= -100 AND value >= 0 AND value <= -100)) OR
(0 >= -100 AND(value <= 0 OR value >= -100)) THEN light_1 := 1;
ELSE light_1 := 0;
END_IF;
Function Block
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
245
Chapter 5
Compare Instructions (CMP, EQU, GEQ, GRT, LEQ, LES, LIM, MEQ, NEQ)
Mask Equal To (MEQ)
Operands:
The MEQ instruction passes the Source and Compare values through a Mask and compares the results.
Relay Ladder
Operand
Source
Mask
Compare
Type
SINT
INT
DINT
Format
Immediate Tag
Description
Value to test against Compare
A SINT or INT tag converts to a DINT value by zero-fill.
SINT
INT
DINT
Immediate Tag Defines which bits to block or pass
A SINT or INT tag converts to a DINT value by zero-fill.
SINT
INT
DINT
Immediate Tag Value to test against Source
A SINT or INT tag converts to a DINT value by zero-fill.
Structured Text
Structured text does not have an MEQ instruction, but you can achieve the same results by using structured text.
IF (Source AND Mask) = (Compare AND Mask) THEN
<
statement>;
END_IF;
246
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Compare Instructions (CMP, EQU, GEQ, GRT, LEQ, LES, LIM, MEQ, NEQ)
Chapter 5
Function Block
Operand
MEQ tag
Type
FBD_MASK_EQUAL
Format
Structure
Description
MEQ structure
Input Parameter
EnableIn
Source
Mask
Compare
Output Parameter
EnableOut
Dest
Data Type
BOOL
DINT
DINT
DINT
Data Type
BOOL
BOOL
FBD_MASK_EQUAL Structure
Description
If cleared, the instruction does not execute and outputs are not updated.
If set, the instruction executes as described under Execution.
Default is set.
Value to test against Compare.
Valid = any integer
Defines which bits to block (mask).
Valid = any integer
Compare value.
Valid = any integer
Description
The instruction produced a valid result.
Result of the instruction. This is equivalent to rung-condition-out for the relay ladder MEQ instruction.
Description:
A ‘1’ in the mask means the data bit is passed. A ‘0’ in the mask means the data bit is blocked. Typically, the Source, Mask, and Compare values are all the same data type.
If you mix integer data types, the instruction fills the upper bits of the smaller integer data types with 0s so that they are the same size as the largest data type.
Entering an Immediate Mask Value
When you enter a mask, the programming software defaults to decimal values. If you want to enter a mask by using another format, precede the value with the correct prefix.
Prefix
16#
8#
2#
Description
Hexadecimal
For example; 16#0F0F
Octal
For example; 8#16
Binary
For example; 2#00110011
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
247
Chapter 5
Compare Instructions (CMP, EQU, GEQ, GRT, LEQ, LES, LIM, MEQ, NEQ)
Arithmetic Status Flags:
Not affected
Fault Conditions:
None
Execution:
Condition
Prescan
Rung-condition-in is false
Relay Ladder
Action
The rung-condition-out is set to false.
The rung-condition-out is set to false.
Rung-condition-in is true
Postscan
Condition
Prescan
Instruction first scan
Instruction first run
EnableIn is cleared
EnableIn is set
Postscan
Masked Source =
Masked Compare no
Rung-condition-out is set to false.
Yes
Rung-condition-out is set to true.
End
The rung-condition-out is set to false.
Function Block
Action
No action taken.
No action taken.
No action taken.
EnableOut is cleared, the instruction does nothing, and the outputs are not updated.
The instruction executes.
EnableOut is set.
No action taken.
248
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Compare Instructions (CMP, EQU, GEQ, GRT, LEQ, LES, LIM, MEQ, NEQ)
Chapter 5
Example 1:
If the masked
value_1 is equal to the masked value_2, set light_1. If the masked
value_1 is not equal to the masked value_2, clear light_1. This example shows that the masked values are equal. A 0 in the mask restrains the instruction from comparing that bit (shown by x in the example).
0 1 0 1 0 1 0 1 1 1 1 1 1 1 1 1 value_2 0 1 0 1 0 1 0 1 1 1 1 1 0 0 0 0 value_1 mask_1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 mask_1 masked value_1 0 1 0 1 0 1 0 1 1 1 1 1 x x x x masked value_2
1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0
0 1 0 1 0 1 0 1 1 1 1 1 x x x x
Relay Ladder
Structured Text
light_1 := ((value_1 AND mask_1)=(value_2 AND mask_2));
Function Block
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
249
Chapter 5
Compare Instructions (CMP, EQU, GEQ, GRT, LEQ, LES, LIM, MEQ, NEQ)
Example 2:
If the masked
value_1 is equal to the masked value_2, set light_1. If the masked
value_1 is not equal to the masked value_2, clear light_1. This example shows that the masked values are not equal. A 0 in the mask restrains the instruction from comparing that bit (shown by x in the example).
0 1 0 1 0 1 0 1 1 1 1 1 1 1 1 1 value_2 0 1 0 1 0 1 0 1 1 1 1 1 0 0 0 0 value_1 mask_1 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 mask_1 masked value_1 x x x x x x x x x x x x 1 1 1 1 masked value_2
0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 x x x x x x x x x x x x 0 0 0 0
Relay Ladder
Structured Text
light_1 := ((value_1 AND mask_1)=(value_2 AND mask_2));
Function Block
250
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Compare Instructions (CMP, EQU, GEQ, GRT, LEQ, LES, LIM, MEQ, NEQ)
Chapter 5
Not Equal To (NEQ)
Operands:
The NEQ instruction tests whether Source A is not equal to Source B.
IF sourceA <> sourceB THEN
Relay Ladder
Operand
Source A
Source B
Type
SINT
INT
DINT
REAL string
SINT
INT
DINT
REAL string
Format
Immediate Tag
Immediate Tag
Description
Value to test against Source B
Value to test against Source A
• If you enter a SINT or INT tag, the value converts to a DINT value by sign-extension.
• String data types are:
– default STRING data type.
– any new string data type that you create.
• To test the characters of a string, enter a string tag for both Source A and
Source B.
Structured Text
Use the less than and greater than signs ‘<>’ together as an operator within an expression. This expression evaluates whether
sourceA is not equal to sourceB.
See Structured Text Programming
for information on the syntax of expressions within structured text.
Function Block
Operand
NEQ tag
Type
FBD_COMPARE
Format
Structure
Description
NEQ structure
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
251
Chapter 5
Compare Instructions (CMP, EQU, GEQ, GRT, LEQ, LES, LIM, MEQ, NEQ)
Input Parameter
EnableIn
SourceA
SourceB
Output Parameter
EnableOut
Dest
Data Type
BOOL
REAL
REAL
Data Type
BOOL
BOOL
FBD_COMPARE Structure
Description
Enable input. If cleared, the instruction does not execute and outputs are not updated.
Default is set.
Value to test against SourceB.
Valid = any float
Value to test against SourceA.
Valid = any float
Description
The instruction produced a valid result.
Result of the instruction. This is equivalent to rung-condition-out for the relay ladder NEQ instruction.
Description:
The NEQ instruction tests whether Source A is not equal to Source B.
When you compare strings:
• strings are not equal if any of their characters do not match.
• ASCII characters are case sensitive. Upper case ‘A’ ($41) is not equal to lower case ‘a’ ($61).
r se
L es at er
Gr e
AB
B a
1b
A
ASCII Characters
1ab ab
Hex Codes
$31$61$62
$31$62
$41
$41$42
$42
$61
$61$62
AB < B a > B
Arithmetic Status Flags:
Not affected
Fault Conditions:
None
Execution:
252
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Condition
Prescan
Rung-condition-in is false
Rung-condition-in is true
Relay Ladder
Compare Instructions (CMP, EQU, GEQ, GRT, LEQ, LES, LIM, MEQ, NEQ)
Chapter 5
Action
The rung-condition-out is set to false.
The rung-condition-out is set to false.
Postscan
Condition
Prescan
Instruction first scan
Instruction first run
EnableIn is cleared
EnableIn is set
Postscan
Source A = Source B
Yes no
Rung-condition-out is set to false.
Rung-condition-out is set to true.
End
The rung-condition-out is set to false.
Function Block
Action
No action taken.
No action taken.
No action taken.
EnableOut is cleared.
The instruction executes.
EnableOut is set.
No action taken.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
253
Chapter 5
Compare Instructions (CMP, EQU, GEQ, GRT, LEQ, LES, LIM, MEQ, NEQ)
Example:
If
value_1 is not equal to value_2, set light_4. If value_1 is equal to value_2, clear
light_4.
Relay Ladder
Structured Text
light_4 := (value_1 <> value_2);
Function Block
254
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Chapter
6
Compute/Math Instructions
(CPT, ADD, SUB, MUL, DIV, MOD, SQR, SQRT, NEG, ABS)
Topic
Page
If you want to
Evaluate an expression
Add two values
Subtract two values
Multiply two values
Divide two values
The compute/math instructions evaluate arithmetic operations by using an expression or a specific arithmetic instruction.
Use this instruction
CPT
ADD
SUB
MUL
DIV
Determine the remainder after one value is divided by another MOD
Available in these languages
Relay ladder
Structured text
(1)
Relay ladder
Structured text
(2)
Function block
Relay ladder
Structured text
(2)
Function block
Relay ladder
Structured text
(2)
Function block
Relay ladder
Structured text
(2)
Function block
Relay ladder
Structured text
(2)
Function block
Page
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
255
Chapter 6
Compute/Math Instructions (CPT, ADD, SUB, MUL, DIV, MOD, SQR, SQRT, NEG, ABS)
If you want to
Calculate the square root of a value
Take the opposite sign of a value
Take the absolute value of a value
Use this instruction
SQR
SQRT
(3)
NEG
ABS
Available in these languages
Relay ladder
Structured text
Function block
Relay ladder
Structured text
(2)
Function block
Relay ladder
Structured text
Function block
(1) There is no equivalent structured text instruction. Use other structured text programming to achieve the same result. See the description for the instruction.
(2) There is no equivalent structured text instruction. Use the operator in an expression.
(3) Structured text only.
Page
You can mix data types, but loss of accuracy and rounding error might occur and the instruction takes more time to execute. Check the S:V bit to see whether the result was truncated.
For relay ladder instructions, bold data types indicate optimal data types. An instruction executes faster and requires less memory if all the operands of the instruction use the same optimal data type, typically DINT or REAL.
256
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Compute (CPT)
Compute/Math Instructions (CPT, ADD, SUB, MUL, DIV, MOD, SQR, SQRT, NEG, ABS)
Chapter 6
The CPT instruction performs the arithmetic operations you define in the expression.
Operands:
IMPORTANT
If x**y is used, all variables (including constants) will be converted to REALs.
This can result in the Destination being rounded or the loss of precision/ resolution.
Relay Ladder
Operand
Destination
Expression
Type
SINT
INT
DINT
REAL
Format
Tag
Description
Tag to store the result
SINT
INT
DINT
REAL
Immediate Tag An expression consisting of tags and/or immediate values separated by operators
A SINT or INT tag converts to a DINT value by sign-extension.
Structured Text
Structured text does not have a CPT instruction, but you can achieve the same results by using an assignment and expression. destination :=
numeric_expression;
See Structured Text Programming
for information on the syntax of assignments and expressions within structured text.
Description:
The CPT instruction performs the arithmetic operations you define in the expression. When enabled, the CPT instruction evaluates the expression and places the result in the Destination.
The execution of a CPT instruction is slightly slower and uses more memory than the execution of the other compute/math instructions. The advantage of the
CPT instruction is that it allows you to enter complex expressions in one instruction.
TIP
There is no limit to the length of an expression.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
257
Chapter 6
Compute/Math Instructions (CPT, ADD, SUB, MUL, DIV, MOD, SQR, SQRT, NEG, ABS)
Arithmetic Status Flags:
Arithmetic status flags are affected.
Fault Conditions:
None
Execution:
Condition
Prescan
Rung-condition-in is false
Rung-condition-in is true
Postscan
Relay Ladder Action
The rung-condition-out is set to false.
The rung-condition-out is set to false.
The instruction evaluates the Expression and places the result in the Destination.
The rung-condition-out is set to true.
The rung-condition-out is set to false.
Example 1:
When enabled, the CPT instruction evaluates
value_1 multiplied by 5 and divides that result by the result of value_2 divided by 7 and places the final result in
result_1.
Example 2:
When enabled, the CPT instruction truncates float_value_1 and float_value_2, raises the truncated
float_value_2 to the power of two and divides the truncated
float_value_1 by that result, and stores the remainder after the division in
float_value_result_cpt.
258
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
ACS
AND
ASN
/
**
ABS
ATN
COS
DEG
FRD
LN
LOG
Operator
-
+
*
Description
add subtract/negate multiply divide exponent (x to y) absolute value arc cosine bitwise AND arc sine arc tangent cosine radians to degrees
BCD to integer natural log log base 10
Compute/Math Instructions (CPT, ADD, SUB, MUL, DIV, MOD, SQR, SQRT, NEG, ABS)
Chapter 6
Valid Operators
Optimal
DINT, REAL
DINT, REAL
DINT, REAL
DINT, REAL
DINT, REAL
DINT, REAL
REAL
DINT
REAL
REAL
REAL
DINT, REAL
DINT
REAL
REAL
TAN
TOD
TRN
RAD
SIN
SQR
XOR
Operator
MOD
NOT
OR
Description
modulo-divide bitwise complement bitwise OR degrees to radians sine square root tangent integer to BCD truncate bitwise exclusive OR
Optimal
DINT, REAL
DINT
DINT
DINT, REAL
REAL
DINT, REAL
REAL
DINT
DINT, REAL
DINT
Format Expressions
For each operator that you use in an expression, you have to 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
One operand
Two operands
Use this format
Operator(operand)
Operand_a operator operand_b
Examples
ABS(tag_a)
·tag_b + 5
·tag_c AND tag_d
·(tag_e ** 2) MOD (tag_f / tag_g)
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
259
Chapter 6
Compute/Math Instructions (CPT, ADD, SUB, MUL, DIV, MOD, SQR, SQRT, NEG, ABS)
Determine the Order of Operation
6.
7.
4.
5.
8.
9.
The operations you write into the expression are performed by the instruction in a prescribed order, not necessarily the order you write them. You can override the order of operation 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
1.
2.
3.
AND
XOR
OR
Operation
( )
ABS, ACS, ASN, ATN, COS, DEG, FRD, LN, LOG, RAD, SIN, SQR,
TAN, TOD, TRN
**
IMPORTANT: If x**y is used, the CPT instruction will be calculated using REALs. This may result in the Destination being rounded or the loss of precision/resolution.
(negate), NOT
*, /, MOD
(subtract), +
260
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Add (ADD)
dest := sourceA + sourceB;
Compute/Math Instructions (CPT, ADD, SUB, MUL, DIV, MOD, SQR, SQRT, NEG, ABS)
Chapter 6
Operands:
The ADD instruction adds Source A to Source B and places the result in the
Destination.
Relay Ladder
Operand
Source A
Source B
Destination
Type
SINT
INT
DINT
REAL
Format
Immediate Tag
Description
Value to add to Source B
A SINT or INT tag converts to a DINT value by sign-extension.
SINT
INT
DINT
REAL
Immediate Tag Value to add to Source A
A SINT or INT tag converts to a DINT value by sign-extension.
SINT
INT
DINT
REAL
Tag Tag to store the result
Structured Text
Use the plus sign “” as an operator within an expression. This expression adds
sourceA to sourceB and stores the result in dest.
See Structured Text Programming
for information on the syntax of expressions within structured text.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
261
Chapter 6
Compute/Math Instructions (CPT, ADD, SUB, MUL, DIV, MOD, SQR, SQRT, NEG, ABS)
Function Block
Operand
ADD tag
Type
FBD_MATH
Input Parameter
EnableIn
SourceA
SourceB
Output Parameter
EnableOut
Dest
Format
Structure
Description
ADD structure
Data Type
BOOL
REAL
REAL
Data Type
BOOL
REAL
FBD_MATH Structure
Description
Enable input. If cleared, the instruction does not execute and outputs are not updated.
Default is set.
Value to add to SourceB.
Valid = any float
Value to add to SourceA.
Valid = any float
Description
The instruction produced a valid result.
Result of the math instruction. Arithmetic status flags are set for this output.
Description:
The ADD instruction adds Source A to Source B and places the result in the
Destination.
262
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Compute/Math Instructions (CPT, ADD, SUB, MUL, DIV, MOD, SQR, SQRT, NEG, ABS)
Chapter 6
Arithmetic Status Flags:
Arithmetic status flags are affected.
Fault Conditions:
None
Execution:
Condition
Prescan
Rung-condition-in is false
Rung-condition-in is true
Postscan
Relay Ladder
Action
The rung-condition-out is set to false.
The rung-condition-out is set to false.
Destination = Source A + Source B
The rung-condition-out is set to true.
The rung-condition-out is set to false.
Condition
Prescan
Instruction first scan
Instruction first run
EnableIn is cleared
EnableIn is set
Postscan
Function Block
Action
No action taken.
No action taken.
No action taken.
EnableOut is cleared.
The instruction executes.
EnableOut is set.
No action taken.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
263
Chapter 6
Compute/Math Instructions (CPT, ADD, SUB, MUL, DIV, MOD, SQR, SQRT, NEG, ABS)
Example:
Add
float_value_1 to float_value_2 and place the result in add_result.
Relay Ladder
Structured Text
add_result := float_value_1 + float_value_2;
Function Block
264
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Subtract (SUB)
dest := sourceA - sourceB;
Compute/Math Instructions (CPT, ADD, SUB, MUL, DIV, MOD, SQR, SQRT, NEG, ABS)
Chapter 6
Operands:
The SUB instruction subtracts Source B from Source A and places the result in the Destination.
Relay Ladder
Operand
Source A
Source B
Destination
Type
SINT
INT
DINT
REAL
Format
Immediate Tag
Description
Value from which to subtract Source B
A SINT or INT tag converts to a DINT value by sign-extension.
SINT
INT
DINT
REAL
Immediate Tag Value to subtract from Source A
A SINT or INT tag converts to a DINT value by sign-extension.
SINT
INT
DINT
REAL
Tag Tag to store the result
Structured Text
Use the minus sign “” as an operator in an expression. This expression subtracts
sourceB from sourceA and stores the result in dest.
See Structured Text Programming
for information on the syntax of expressions within structured text.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
265
Chapter 6
Compute/Math Instructions (CPT, ADD, SUB, MUL, DIV, MOD, SQR, SQRT, NEG, ABS)
Function Block
Operand
SUB tag
Type
FBD_MATH
Format
structure
Description
SUB structure
Input Parameter
EnableIn
SourceA
SourceB
Output Parameter
EnableOut
Dest
Data Type
BOOL
REAL
REAL
Data Type
BOOL
REAL
FBD_MATH Structure
Description
Enable input. If cleared, the instruction does not execute and outputs are not updated.
Default is set.
Value from which to subtract SourceB.
Valid = any float
Value to subtract from SourceA.
Valid = any float
Description
The instruction produced a valid result.
Result of the math instruction. Arithmetic status flags are set for this output.
Description:
The SUB instruction subtracts Source B from Source A and places the result in the Destination.
Arithmetic Status Flags:
Arithmetic status flags are affected.
Fault Conditions:
None
Execution:
Condition
Prescan
Rung-condition-in is false
Rung-condition-in is true
Postscan
Relay Ladder
Action
The rung-condition-out is set to false.
The rung-condition-out is set to false.
Destination = Source B - Source A
The rung-condition-out is set to true.
The rung-condition-out is set to false.
266
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Condition
Prescan
Instruction first scan
Instruction first run
EnableIn is cleared
EnableIn is set
Postscan
Compute/Math Instructions (CPT, ADD, SUB, MUL, DIV, MOD, SQR, SQRT, NEG, ABS)
Chapter 6
Function Block
Action
No action taken.
No action taken.
No action taken.
EnableOut is cleared.
The instruction executes.
EnableOut is set.
No action taken.
Example:
Subtract
float_value_2 from float_value_1 and place the result in subtract_result.
Relay Ladder
Structured Text
subtract_result := float_value_1 - float_value_2;
Function Block
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
267
Chapter 6
Compute/Math Instructions (CPT, ADD, SUB, MUL, DIV, MOD, SQR, SQRT, NEG, ABS)
Multiply (MUL)
Operands:
The MUL instruction multiplies Source A with Source B and places the result in the Destination.
Relay Ladder
Operand
Source A
Source B
Destination
Type
SINT
INT
DINT
REAL
Format
Immediate Tag
Description
Value of the multiplicand
A SINT or INT tag converts to a DINT value by sign-extension.
SINT
INT
DINT
REAL
Immediate Tag Value of the multiplier
A SINT or INT tag converts to a DINT value by sign-extension.
SINT
INT
DINT
REAL
Tag Tag to store the result dest := sourceA * sourceB;
Structured Text
Use the multiply sign “” as an operator in an expression. This expression multiplies sourceA by sourceB and stores the result in dest.
See
Structured Text Programming for information on the syntax of expressions
within structured text.
268
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Compute/Math Instructions (CPT, ADD, SUB, MUL, DIV, MOD, SQR, SQRT, NEG, ABS)
Chapter 6
Function Block
Operand
MUL tag
Type
FBD_MATH
Format
Structure
Description
MUL structure
Input Parameter
EnableIn
Source A
Source B
Output Parameter
EnableOut
Dest
Data Type
BOOL
REAL
REAL
Data Type
BOOL
REAL
FBD_MATH Structure
Description
Enable input. If cleared, the instruction does not execute and outputs are not updated.
Default is set.
Value of the multiplicand.
Valid = any float
Value of the multiplier.
Valid = any float
Description
The instruction produced a valid result.
Result of the math instruction. Arithmetic status flags are set for this output.
Description:
The MUL instruction multiplies Source A with Source B and places the result in the Destination.
Arithmetic Status Flags:
Arithmetic status flags are affected.
Fault Conditions:
None
Execution:
Condition
Prescan
Rung-condition-in is false
Rung-condition-in is true
Postscan
Relay Ladder
Action
The rung-condition-out is set to false.
The rung-condition-out is set to false.
Destination = Source B x Source A
The rung-condition-out is set to true.
The rung-condition-out is set to false.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
269
Chapter 6
Compute/Math Instructions (CPT, ADD, SUB, MUL, DIV, MOD, SQR, SQRT, NEG, ABS)
Condition
Prescan
Instruction first scan
Instruction first run
EnableIn is cleared
EnableIn is set
Postscan
Function Block
Action
No action taken.
No action taken.
No action taken.
EnableOut is cleared.
The instruction executes.
EnableOut is set.
No action taken.
Example:
Multiply
float_value_1 by float_value_2 and place the result in multiply_result.
Relay Ladder
Structured Text
multiply_result := float_value_1 float_value_2;
Function Block
270
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Divide (DIV)
dest := sourceA / sourceB;
Compute/Math Instructions (CPT, ADD, SUB, MUL, DIV, MOD, SQR, SQRT, NEG, ABS)
Chapter 6
Operands:
The DIV instruction divides Source A by Source B and places the result in the
Destination.
Relay Ladder
Operand
Source A
Source B
Destination
Type
SINT
INT
DINT
REAL
Format
Immediate Tag
Description
Value of the dividend
A SINT or INT tag converts to a DINT value by sign-extension.
SINT
INT
DINT
REAL
Immediate Tag Value of the divisor
A SINT or INT tag converts to a DINT value by sign-extension.
SINT
INT
DINT
REAL
Tag Tag to store the result
Structured Text
Use the divide sign ‘’ as an operator in an expression. This expression divides
sourceA by sourceB and stores the result in dest.
See Structured Text Programming
for information on the syntax of expressions within structured text.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
271
Chapter 6
Compute/Math Instructions (CPT, ADD, SUB, MUL, DIV, MOD, SQR, SQRT, NEG, ABS)
Function Block
Operand
DIV tag
Type
FBD_MATH
Format
structure
Description
DIV structure
Input Parameter
EnableIn
Source A
Source B
Output Parameter
EnableOut
Dest
Data Type
BOOL
REAL
REAL
Data Type
BOOL
REAL
FBD_MATH Structure
Description
Enable input. If cleared, the instruction does not execute and outputs are not updated.
Default is set.
Value of the dividend.
Valid = any float
Value of the divisor.
Valid = any float
Description
The instruction produced a valid result.
Result of the math instruction. Arithmetic status flags are set for this output.
Description:
If the Destination is not a REAL, the instruction handles the fractional portion of the result as follows:
If source A
And Source B are not REALs
Or Source B is a REAL
Then the fractional portion of the result
Truncates
Rounds
Example
Source A
Source B
Destination
Source A
Source B
Destination
DINT
DINT
DINT
REAL
DINT
DINT
3
2
5
3
1
5.0
If source B is zero and
All operands are integers (SINT, INT, or DINT)
The destination is set as follows.
If Source B (the divisor) is zero:
• A minor fault occurs:
– Type 4: program fault
– Code 4: arithmetic overflow
• The destination is set as follows:
And the destination is a And the result is Then the destination is set to
Source A
272
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Compute/Math Instructions (CPT, ADD, SUB, MUL, DIV, MOD, SQR, SQRT, NEG, ABS)
Chapter 6
If source B is zero and
At least one operand is a REAL
And the destination is a
SINT, INT, or DINT
REAL
And the result is
Positive
Negative
Positive
Negative
Then the destination is set to
-1
0
1.$ (positive infinity)
-1.$ (negative infinity)
To detect a possible divide-by-zero, examine the minor fault bit (S:MINOR). See
Logix5000 Controllers Common Procedures Programming Manual, publication
1756-PM001 .
Arithmetic Status Flags:
Arithmetic status flags are affected.
Fault Conditions:
A minor fault occurs if
The divisor is zero
Fault type
4
Fault code
4
Execution:
Condition
Prescan
Rung-condition-in is false
Rung-condition-in is true
Postscan
Relay Ladder
Action
The rung-condition-out is set to false.
The rung-condition-out is set to false.
Destination = Source A / Source B
The rung-condition-out is set to true.
The rung-condition-out is set to false.
Condition
Prescan
Instruction first scan
Instruction first run
EnableIn is cleared
EnableIn is set
Postscan
Function Block
Action
No action taken.
No action taken.
No action taken.
EnableOut is cleared.
The instruction executes.
EnableOut is set.
No action taken.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
273
Chapter 6
Compute/Math Instructions (CPT, ADD, SUB, MUL, DIV, MOD, SQR, SQRT, NEG, ABS)
Example 1:
Divide
float_value_1 by float_value_2 and place the result in divide_result.
Relay Ladder
Structured Text
divide_result := float_value_1 / float_value_2;
Function Block
274
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Compute/Math Instructions (CPT, ADD, SUB, MUL, DIV, MOD, SQR, SQRT, NEG, ABS)
Chapter 6
Example 2:
The DIV and MOV instructions work together to divide two integers, round the result, and place the result in an integer tag:
• The DIV instruction divides dint_a by dint_b.
• To round the result, the Destination is a REAL tag. (If the destination was an integer tag (SINT, INT, or DINT), the instruction would truncate the result.)
• The MOV instruction moves the rounded result ( real_temp) from the
DIV to
divide_result_rounded.
• Since
divide_result_rounded is a DINT tag the value from real_temp is rounded and placed in the DINT destination.
Relay Ladder
43009
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
275
Chapter 6
Compute/Math Instructions (CPT, ADD, SUB, MUL, DIV, MOD, SQR, SQRT, NEG, ABS)
Modulo (MOD)
Operands:
The MOD instruction divides Source A by Source B and places the remainder in the Destination.
Relay Ladder
Operand
Source A
Source B
Destination
Type
SINT
INT
DINT
REAL
Format
Immediate Tag
Description
Value of the dividend
A SINT or INT tag converts to a DINT value by sign-extension.
SINT
INT
DINT
REAL
Immediate Tag Value of the divisor
A SINT or INT tag converts to a DINT value by sign-extension.
SINT
INT
DINT
REAL
Tag Tag to store the result dest := sourceA MOD sourceB;
Structured Text
Use MOD as an operator in an expression. This expression divides
sourceA by
sourceB and stores the remainder in dest.
See
Structured Text Programming for information on the syntax of expressions
within structured text.
276
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Compute/Math Instructions (CPT, ADD, SUB, MUL, DIV, MOD, SQR, SQRT, NEG, ABS)
Chapter 6
Function Block
Operand
MOD tag
Type
FBD_MATH
Format
Structure
Description
MOD structure
Input Parameter
EnableIn
Source A
Source B
Output Parameter
EnableOut
Dest
Data Type
BOOL
REAL
REAL
Data Type
BOOL
REAL
FBD_MATH Structure
Description
Enable input. If cleared, the instruction does not execute and outputs are not updated.
Default is set.
Value of the dividend.
Valid = any float
Value of the divisor.
Valid = any float
Description
The instruction produced a valid result.
Result of the math instruction. Arithmetic status flags are set for this output.
Description:
If Source B (the divisor) is zero, the following happens:
• A minor fault occurs:
– Type 4: program fault
– Code 4: arithmetic overflow
• The destination is set as follows.
And the destination is a And the result is If source B is zero and
All operands are integers (SINT, INT, or DINT)
At least one operand is a REAL SINT, INT, or DINT
REAL
Positive
Negative
Positive
Negative
Then the destination is set to
Source A
-1
The S:N and S:Z flags are not set.
0
1.$ (positive infinity)
-1.$ (negative infinity)
IMPORTANT
The MOD instruction does not capture an overflow that may have occurred during the calculation. If an overflow occurs, a minor fault will be generated, but the S:V bit will not be set.
To detect a possible divide-by-zero, examine the minor fault bit (S:MINOR).
See Logix5000 Controllers Common Procedures Programming Manual, publication 1756-PM001 .
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
277
Chapter 6
Compute/Math Instructions (CPT, ADD, SUB, MUL, DIV, MOD, SQR, SQRT, NEG, ABS)
Arithmetic Status Flags:
Arithmetic status flags are affected.
Fault Conditions:
A minor fault occurs if
The divisor is zero
Fault type
4
Execution:
Condition
Prescan
Rung-condition-in is false
Rung-condition-in is true
Postscan
Relay Ladder
Action
The rung-condition-out is set to false.
The rung-condition-out is set to false.
Destination = Source A – (TRN ( Source A / Source B) * Source B )
The rung-condition-out is set to true.
The rung-condition-out is set to false.
Condition
Prescan
Instruction first scan
Instruction first run
EnableIn is cleared
Postscan
Function Block
Action
No action taken.
No action taken.
No action taken.
EnableOut is cleared.
No action taken.
Fault code
4
278
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Compute/Math Instructions (CPT, ADD, SUB, MUL, DIV, MOD, SQR, SQRT, NEG, ABS)
Chapter 6
Example:
Divide
dividend by divisor and place the remainder in remainder. In this example, three goes into 10 three times, with a remainder of one.
Relay Ladder
Structured Text
remainder := dividend MOD divisor;
Function Block
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
279
Chapter 6
Compute/Math Instructions (CPT, ADD, SUB, MUL, DIV, MOD, SQR, SQRT, NEG, ABS)
Square Root (SQR)
Operands:
The SQR instruction computes the square root of the Source and places the result in the Destination.
Relay Ladder
Operand
Source
Destination
Type
SINT
INT
DINT
REAL
Format
Immediate Tag
Description
Find the square root of this value
A SINT or INT tag converts to a DINT value by sign-extension.
SINT
INT
DINT
REAL
Tag Tag to store the result dest := SQRT(source);
Structured Text
Use SQRT as a function. This expression computes the square root of source and stores the result in
dest.
Input Parameter
EnableIn
Source
Output Parameter
EnableOut
Dest
280
Data Type
BOOL
REAL
Data Type
BOOL
REAL
See
Structured Text Programming for information on the syntax of expressions
within structured text.
Function Block
Operand
SQR tag
Type
FBD_MATH_ADVANCED
Format
Structure
Description
SQR structure
FBD_MATH_ADVANCED Structure
Description
Enable input. If cleared, the instruction does not execute and outputs are not updated.
Default is set.
Find the square root of this value.
Valid = any float
Description
The instruction produced a valid result.
Result of the math instruction. Arithmetic status flags are set for this output.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Postscan
Compute/Math Instructions (CPT, ADD, SUB, MUL, DIV, MOD, SQR, SQRT, NEG, ABS)
Chapter 6
Description:
If the Destination is not a REAL, the instruction handles the fractional portion of the result as follows:
If the source is
Not a REAL
A REAL
Then the fractional portion of the result
Truncates
Rounds
Example
Source
Destination
Source
Destination
DINT
DINT
REAL
DINT
3
1
3.0
2
If the Source is negative, the instruction takes the absolute value of the Source before calculating the square root.
Arithmetic Status Flags:
Arithmetic status flags are affected.
Fault Conditions:
None
Execution:
Condition
Prescan
Rung-condition-in is false
Rung-condition-in is true
Relay Ladder
Action
The rung-condition-out is set to false.
The rung-condition-out is set to false.
Destination
=
Source
The rung-condition-out is set to true.
The rung-condition-out is set to false.
Condition
Prescan
Instruction first scan
Instruction first run
EnableIn is cleared
EnableIn is set
Postscan
Function Block
Action
No action taken.
No action taken.
No action taken.
EnableOut is cleared.
The instruction executes.
EnableOut is set.
No action taken.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
281
Chapter 6
Compute/Math Instructions (CPT, ADD, SUB, MUL, DIV, MOD, SQR, SQRT, NEG, ABS)
Example:
Calculate the square root of
value_1 and place the result in sqr_result.
Relay Ladder
Structured Text
sqr_result := SQRT(value_1);
Function Block
282
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Negate (NEG)
dest := -source;
Compute/Math Instructions (CPT, ADD, SUB, MUL, DIV, MOD, SQR, SQRT, NEG, ABS)
Chapter 6
Operands:
The NEG instruction changes the sign of the Source and places the result in the
Destination.
Relay Ladder
Operand
Source
Destination
Type
SINT
INT
DINT
REAL
Format
Immediate Tag
Description
Value to negate
A SINT or INT tag converts to a DINT value by sign-extension.
SINT
INT
DINT
REAL
Tag Tag to store the result
Structured Text
Use the minus sign ‘’ as an operator in an expression. This expression changes the sign of
source and stores the result in dest.
Input Parameter
EnableIn
Source
Output Parameter
EnableOut
Dest
Data Type
BOOL
REAL
Data Type
BOOL
REAL
See Structured Text Programming
for information on the syntax of expressions within structured text.
Function Block
Operand
NEG tag
Type
FBD_MATH_ADVANCED
Format
Structure
Description
NEG structure
FBD_MATH Structure
Description
Enable input. If cleared, the instruction does not execute and outputs are not updated.
Default is set.
Value to negate.
Valid = any float
Description
The instruction produced a valid result.
Result of the math instruction. Arithmetic status flags are set for this output.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
283
Chapter 6
Compute/Math Instructions (CPT, ADD, SUB, MUL, DIV, MOD, SQR, SQRT, NEG, ABS)
Description:
If you negate a negative value, the result is positive. If you negate a positive value, the result is negative.
Arithmetic Status Flags:
Arithmetic status flags are affected.
Fault Conditions:
None
Execution:
Condition
Prescan
Rung-condition-in is false
Rung-condition-in is true
Postscan
Relay Ladder
Action
The rung-condition-out is set to false.
The rung-condition-out is set to false.
Destination = 0 Source
The rung-condition-out is set to true.
The rung-condition-out is set to false.
Condition
Prescan
Instruction first scan
Instruction first run
EnableIn is cleared
EnableIn is set
Postscan
Function Block
Action
No action taken.
No action taken.
No action taken.
EnableOut is cleared.
The instruction executes.
EnableOut is set.
No action taken.
284
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Compute/Math Instructions (CPT, ADD, SUB, MUL, DIV, MOD, SQR, SQRT, NEG, ABS)
Chapter 6
Example:
Change the sign of
value_1 and place the result in negate_result.
Relay Ladder
Structured Text
negate_result := -value_1;
Function Block
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
285
Chapter 6
Compute/Math Instructions (CPT, ADD, SUB, MUL, DIV, MOD, SQR, SQRT, NEG, ABS)
Absolute Value (ABS)
Operands:
The ABS instruction takes the absolute value of the Source and places the result in the Destination.
Relay Ladder
Operand
Source
Destination
Type
SINT
INT
DINT
REAL
Format
Immediate Tag
Description
Value of which to take the absolute value
A SINT or INT tag converts to a DINT value by sign-extension.
SINT
INT
DINT
REAL
Tag Tag to store the result dest := ABS(source);
Structured Text
Use ABS as a function. This expression computes the absolute value of source and stores the result in
dest.
Input Parameter
EnableIn
Source
Output Parameter
EnableOut
Dest
286
Data Type
BOOL
REAL
Data Type
BOOL
REAL
See
Structured Text Programming for information on the syntax of expressions
within structured text.
Function Block
Operand
ABS tag
Type
FBD_MATH_ADVANCED
Format
structure
Description
ABS structure
FBD_MATH_ADVANCED Structure
Description
Enable input. If cleared, the instruction does not execute and outputs are not updated.
Default is set.
Value of which to take the absolute value.
Valid = any float
Description
The instruction produced a valid result.
Result of the math instruction. Arithmetic status flags are set for this output.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Compute/Math Instructions (CPT, ADD, SUB, MUL, DIV, MOD, SQR, SQRT, NEG, ABS)
Chapter 6
Description:
The ABS instruction takes the absolute value of the Source and places the result in the Destination.
Arithmetic Status Flags:
Arithmetic status flags are affected.
Fault Conditions:
None
Execution:
Condition
Prescan
Rung-condition-in is false
Rung-condition-in is true
Postscan
Relay Ladder
Action
The rung-condition-out is set to false.
The rung-condition-out is set to false.
Destination = | Source |
The rung-condition-out is set to true.
The rung-condition-out is set to false.
Condition
Prescan
Instruction first scan
Instruction first run
EnableIn is cleared
EnableIn is set
Postscan
Function Block
Action
No action taken.
No action taken.
No action taken.
EnableOut is cleared.
The instruction executes.
EnableOut is set.
No action taken.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
287
Chapter 6
Compute/Math Instructions (CPT, ADD, SUB, MUL, DIV, MOD, SQR, SQRT, NEG, ABS)
Example:
Place the absolute value of
value_1 into value_1_absolute. In this example, the absolute value of negative four is positive four.
Relay Ladder
Structured Text
value_1_absolute := ABS(value_1);
Function Block
288
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Chapter
7
Move/Logical Instructions
(MOV, MVM, BTD, MVMT, BTDT, CLR, SWPB, AND, OR, XOR, NOT, BAND,
BOR, BXOR, BNOT)
Topic
Masked Move with Target (MVMT)
Bit Field Distribute with Target (BTDT)
Page
The move instructions modify and move its, and the logical instructions perform operations on bits.
You can mix data types, but loss of accuracy and rounding error might occur and the instruction takes more time to execute. Check the S:V bit to see whether the result was truncated.
For relay ladder instructions, bold data types indicate optimal data types. An instruction executes faster and requires less memory if all the operands of the instruction use the same optimal data type, typically DINT or REAL.
The move instructions modify and move bits.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
289
Chapter 7
Move/Logical Instructions (MOV, MVM, BTD, MVMT, BTDT, CLR, SWPB, AND, OR, XOR, NOT, BAND, BOR, BXOR, BNOT)
If you want to
Copy a value
Copy a specific part of an integer
Copy a specific part of an integer in function block
Move bits within an integer or between integers
Move bits within an integer or between integers in function block
Clear a value
Rearrange the bytes of a INT, DINT, or REAL tag
Use this instruction
MOV
MVM
MVMT
BTD
BTDT
CLR
SWPB
Available in these languages
Relay ladder
Structured text
(1)
Relay ladder
Structured text
Function block
Relay ladder
Structured text
Function block
Structured text
(1)
Relay ladder
Relay ladder
Structured text
(1) There is no equivalent structured text instruction. Use other structured text programming to achieve the same result. See the description for the instruction.
If you want to
Bitwise AND Operation
Bitwise OR operation
Bitwise, exclusive OR operation
Bitwise NOT operation
Logically AND as many as eight boolean inputs.
Logically OR as many as eight boolean inputs.
Perform an exclusive OR on two boolean inputs.
Complement a boolean input.
The logical instructions perform operations on bits.
Use this instruction Available in these languages
Bitwise AND
&
(1)
Bitwise OR
Bitwise XOR
Bitwise NOT
Boolean AND (BAND)
Boolean OR (BOR)
Boolean Exclusive OR (BXOR)
Boolean NOT (BNOT)
Relay ladder
Structured text
(2)
Function block
Relay ladder
Structured text
(2)
Function block
Relay ladder
Structured text
(2)
Function block
Relay ladder
Structured text
(2)
Function block
Structured text
(2)
Function block
Structured text
(2)
Function block
Structured text
(2)
Function block
Structured text
(2)
Function block
(1) Structured text only.
(2) In structured text, the AND, OR, XOR, and NOT operations can be bitwise or logical.
Page
Page
290
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Move (MOV)
dest := source;
Move/Logical Instructions (MOV, MVM, BTD, MVMT, BTDT, CLR, SWPB, AND, OR, XOR, NOT, BAND, BOR, BXOR, BNOT)
Chapter 7
Operands:
The MOV instruction copies the Source to the Destination. The Source remains unchanged.
Relay Ladder
Operand
Source
Destination
Type
SINT
INT
DINT
REAL
Format
Immediate
Tag
Description
Value to move (copy)
A SINT or INT tag converts to a DINT value by sign-extension.
SINT
INT
DINT
REAL
Tag Tag to store the result
Structured Text
Use an assignment ‘:=’ with an expression. This assignment moves the value in
source to dest.
See
for information on the syntax of expressions and assignments within structured text.
Description:
The MOV instruction copies the Source to the Destination. The Source remains unchanged.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
291
Chapter 7
Move/Logical Instructions (MOV, MVM, BTD, MVMT, BTDT, CLR, SWPB, AND, OR, XOR, NOT, BAND, BOR, BXOR, BNOT)
Arithmetic Status Flags:
Arithmetic status flags are affected.
Fault Conditions:
None
Execution:
Condition
Prescan
Rung-condition-in is false
Rung-condition-in is true
Postscan
Relay Ladder Action
The rung-condition-out is set to false.
The rung-condition-out is set to false.
The instruction copies the Source into the Destination.
The rung-condition-out is set to true.
The rung-condition-out is set to false.
Example:
Move the data in
value_1 to value_2.
Relay Ladder
Structured Text
value_2 := value _1;
292
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Move/Logical Instructions (MOV, MVM, BTD, MVMT, BTDT, CLR, SWPB, AND, OR, XOR, NOT, BAND, BOR, BXOR, BNOT)
Chapter 7
Masked Move (MVM)
Operands:
The MVM instruction copies the Source to a Destination and allows portions of the data to be masked.
This instruction is available in structured text and function block as MVMT, see
Relay Ladder
Operand
Source
Mask
Destination
Type
SINT
INT
DINT
Format
Immediate
Tag
Description
Value to move
A SINT or INT tag converts to a DINT value by zero-fill.
SINT
INT
DINT
Immediate
Tag
Which bits to block or pass
A SINT or INT tag converts to a DINT value by zero-fill.
SINT
INT
DINT
Tag Tag to store the result
Structured Text
dest := (Dest AND NOT (Mask))
OR (Source AND Mask);
This instruction is available in structured text as MVMT. Or you can combine bitwise logic within an expression and assign the result to the destination. This expression performs a masked move on
Source.
See Structured Text Programming
for information on the syntax of expressions and assignments within structured text.
Description:
The MVM instruction uses a Mask to either pass or block Source data bits. A ‘1’ in the mask means the data bit is passed. A ‘0’ in the mask means the data bit is blocked.
If you mix integer data types, the instruction fills the upper bits of the smaller integer data types with 0s so that they are the same size as the largest data type.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
293
Chapter 7
Move/Logical Instructions (MOV, MVM, BTD, MVMT, BTDT, CLR, SWPB, AND, OR, XOR, NOT, BAND, BOR, BXOR, BNOT)
Enter an Immediate Mask Value
When you enter a mask, the programming software defaults to decimal values. If you want to enter a mask by using another format, precede the value with the correct prefix.
Prefix
16#
8#
2#
Description
Hexadecimal
For example; 16#0F0F
Octal
For example; 8#16
Binary
For example; 2#00110011
Postscan
Arithmetic Status Flags
Arithmetic status flags are affected.
Fault Conditions
None
Execution:
Condition
Prescan
Rung-condition-in is false
Rung-condition-in is true
Relay Ladder Action
The rung-condition-out is set to false.
The rung-condition-out is set to false.
The instruction passes the Source through the Mask and copies the result into the Destination. Unmasked bits in the
Destination remain unchanged.
The rung-condition-out is set to true.
The rung-condition-out is set to false.
Example:
Copy data from
value_a to value_b, while allowing data to be masked (a 0 masks the data in value_a).
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1
1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0
0 1 0 1 1 1 1 1 0 1 0 1 1 1 1 1 0 1 0 1 1 1 1 1 0 1 0 1 1 1 1 1
The shaded boxes show the bits that changed in value_b.
294
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Move/Logical Instructions (MOV, MVM, BTD, MVMT, BTDT, CLR, SWPB, AND, OR, XOR, NOT, BAND, BOR, BXOR, BNOT)
Chapter 7
Relay Ladder
Structured Text
value_b := (value_b AND NOT (mask_2)) OR
(value_a AND mask_2);
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
295
Chapter 7
Move/Logical Instructions (MOV, MVM, BTD, MVMT, BTDT, CLR, SWPB, AND, OR, XOR, NOT, BAND, BOR, BXOR, BNOT)
Masked Move with Target
(MVMT)
The MVMT instruction first copies the Target to the Destination. Then the instruction compares the masked Source to the Destination and makes any required changes to the Destination. The Target and the Source remain unchanged.
Operands:
This instruction is available in relay ladder as MVM, see
MVMT(MVMT_tag);
Structured Text
Variable
MVMT tag
Type
FBD_MASKED_MOVE
Format
Structure
Description:
MVMT structure
Function Block
Operand
MVMT tag
Type
FBD_MASKED_MOVE
Format
Structure
Description
MVMT structure
Input Parameter
EnableIn
Data Type
BOOL
Source
Mask
Target
Output Parameter
EnableOut
Dest
DINT
DINT
DINT
Data Type
BOOL
DINT
FBD_MASKED_MOVE Structure
Description
Function Block
If cleared, the instruction does not execute and outputs are not updated.
If set, the instruction executes.
Default is set.
Structured Text
No effect. The instruction executes.
Input value to move to Destination based on value of Mask.
Valid = any integer
Mask of bits to move from Source to Dest. All bits set to one cause the corresponding bits to move from Source to Dest. All bits that are set to zero cause the corresponding bits not to move from Source to Dest.
Valid = any integer
Input value to move to Dest prior to moving Source bits through the Mask.
Valid = any integer
Description
The instruction produced a valid result.
Result of masked move instruction. Arithmetic status flags are set for this output.
296
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Move/Logical Instructions (MOV, MVM, BTD, MVMT, BTDT, CLR, SWPB, AND, OR, XOR, NOT, BAND, BOR, BXOR, BNOT)
Chapter 7
Description:
When enabled, the MVMT instruction uses a Mask to either pass or block
Source data bits. A ‘1’ in the mask means the data bit is passed. A ‘0’ in the mask means the data bit is blocked.
If you mix integer data types, the instruction fills the upper bits of the smaller integer data types with 0s so that they are the same size as the largest data type.
Enter an Immediate Mask Value by Using an Input Reference
When you enter a mask, the programming software defaults to decimal values. If you want to enter a mask by using another format, precede the value with the correct prefix.
Prefix
16#
8#
2#
Description
Hexadecimal
For example; 16#0F0F
Octal
For example; 8#16
Binary
For example; 2#00110011
Condition
Prescan
Instruction first scan
Instruction first run
EnableIn is cleared
EnableIn is set
Postscan
Arithmetic Status Flags:
Arithmetic status flags are affected.
Fault Conditions:
None
Execution:
Function Block Action
No action taken.
No action taken.
No action taken.
EnableOut is cleared, the instruction does nothing, and the outputs are not updated.
The instruction executes.
EnableOut is set.
No action taken.
Structured Text Action
No action taken.
No action taken.
No action taken.
N/A
EnableIn is always set.
The instruction executes.
No action taken.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
297
Chapter 7
Move/Logical Instructions (MOV, MVM, BTD, MVMT, BTDT, CLR, SWPB, AND, OR, XOR, NOT, BAND, BOR, BXOR, BNOT)
Target
Dest
Example:
1. Copy Target into Dest.
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Source
Mask1
Dest
2. Mask Source and compare it to Dest. Any required changes are made in
Dest. Source and Target remain unchanged. A 0 in the mask restrains the instruction from comparing that bit (shown by x in the example).
0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1
1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0
0 1 0 1 1 1 1 1 0 1 0 1 1 1 1 1 0 1 0 1 1 1 1 1 0 1 0 1 1 1 1 1
The shaded boxes show the bits that changed.
Structured Text
MVMT_01.Source := value_1;
MVMT_01.Mask := mask1;
MVMT_01.Target := target;
MVMT(MVMT_01); value_masked := MVMT_01.Dest;
Function Block
298
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Move/Logical Instructions (MOV, MVM, BTD, MVMT, BTDT, CLR, SWPB, AND, OR, XOR, NOT, BAND, BOR, BXOR, BNOT)
Chapter 7
Bit Field Distribute (BTD)
Operands:
The BTD instruction copies the specified bits from the Source, shifts the bits to the appropriate position, and writes the bits into the Destination.
This instruction is available in structured text and function block as BTDT,
.
Relay Ladder
Operand
Source
Type
SINT
INT
DINT
Format
Immediate
Tag
Description
Tag that contains the bits to move
Source bit
A SINT or INT tag converts to a DINT value by zero-fill.
DINT Immediate
(0-31 DINT)
(0-15 INT)
(0-7 SINT)
Number of the bit (lowest bit number) from where to start the move
Must be within the valid range for the Source data type
Tag Tag where to move the bits Destination SINT
INT
DINT
Destination bit DINT
Length DINT
Immediate
(0-31 DINT)
(0-15 INT)
(0-7 SINT)
Immediate (1-
32)
The number of the bit (lowest bit number) where to start copying bits from the Source
Must be within the valid range for the Destination data type
Number of bits to move
Description:
When enabled, the BTD instruction copies a group of bits from the Source to the
Destination. The group of bits is identified by the Source bit (lowest bit number of the group) and the Length (number of bits to copy). The Destination bit identifies the lowest bit number bit to start with in the Destination. The Source remains unchanged.
If the length of the bit field extends beyond the Destination, the instruction does not save the extra bits. Any extra bits do not wrap to the next word.
If you mix integer data types, the instruction fills the upper bits of the smaller integer data types with 0s so that they are the same size as the largest data type.
Arithmetic Status Flags:
Not affected
Fault Conditions:
None
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
299
Chapter 7
Move/Logical Instructions (MOV, MVM, BTD, MVMT, BTDT, CLR, SWPB, AND, OR, XOR, NOT, BAND, BOR, BXOR, BNOT)
Condition
Prescan
Rung-condition-in is false
Rung-condition-in is true
Postscan
Execution:
Relay Ladder Action
The rung-condition-out is set to false.
The rung-condition-out is set to false.
The instruction copies and shifts the Source bits to the Destination.
The rung-condition-out is set to true.
The rung-condition-out is set to false.
Example 1:
When enabled, the BTD instruction moves bits within
value_1.
Destination Bit
Source Bit
value_1 Before BTD Instruction 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0
value_1 After BTD Instruction 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
The shaded boxes show the bits that changed in value_1.
300
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Move/Logical Instructions (MOV, MVM, BTD, MVMT, BTDT, CLR, SWPB, AND, OR, XOR, NOT, BAND, BOR, BXOR, BNOT)
Chapter 7
Example 2:
When enabled, the BTD instruction moves 10 bits from
value_1 to value_2.
value_1
source bit
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 destination bit
value_2 Before BTD Instruction 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 value_2 After BTD Instruction 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0
The shaded boxes show the bits that changed in value_2.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
301
Chapter 7
Move/Logical Instructions (MOV, MVM, BTD, MVMT, BTDT, CLR, SWPB, AND, OR, XOR, NOT, BAND, BOR, BXOR, BNOT)
Bit Field Distribute with
Target (BTDT)
The BTDT instruction first copies the Target to the Destination. Then the instruction copies the specified bits from the Source, shifts the bits to the appropriate position, and writes the bits into the Destination. The Target and
Source remain unchanged.
Operands:
This instruction is available in relay ladder as BTD, see
BTDT(BTDT_tag);
Structured Text
Variable
BTDT tag
Type
FBD_BIT_FIELD_DISTRIBUTE
Format
Structure
Description
BTDT structure
Function Block
Operand
BTDT tag
Type
FBD_BIT_FIELD_DISTRIBUTE
Format
Structure
Description
BTDT structure
302
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Input Parameter
EnableIn
Source
SourceBit
Length
DestBit
Target
Output Parameter
EnableOut
Dest
Move/Logical Instructions (MOV, MVM, BTD, MVMT, BTDT, CLR, SWPB, AND, OR, XOR, NOT, BAND, BOR, BXOR, BNOT)
Chapter 7
FBD_BIT_FIELD_DISTRIBUTE Structure
Data Type
BOOL
DINT
DINT
DINT
DINT
DINT
Data Type
BOOL
DINT
Description
Function Block:
If cleared, the instruction does not execute and outputs are not updated.
If set, the instruction executes.
Default is set.
Structured Text:
No effect. The instruction executes.
Input value containing the bits to move to Destination.
Valid = any integer
The bit position in Source (lowest bit number from where to start the move).
Valid = 0…31
Number of bits to move.
Valid = 1…32
The bit position in Dest (lowest bit number to start copying bits into).
Valid = 0…31
Input value to move to Dest prior to moving bits from the Source.
Valid = any integer
Description
The instruction produced a valid result.
Result of the bit move operation. Arithmetic status flags are set for this output.
Description:
When enabled, the BTD instruction copies a group of bits from the Source to the
Destination. The group of bits is identified by the Source bit (lowest bit number of the group) and the Length (number of bits to copy). The Destination bit identifies the lowest bit number bit to start with in the Destination. The Source remains unchanged.
If the length of the bit field extends beyond the Destination, the instruction does not save the extra bits. Any extra bits do not wrap to the next word.
Arithmetic Status Flags:
Arithmetic status flags are affected
Fault Conditions:
None
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
303
Chapter 7
Move/Logical Instructions (MOV, MVM, BTD, MVMT, BTDT, CLR, SWPB, AND, OR, XOR, NOT, BAND, BOR, BXOR, BNOT)
Condition
Prescan
Instruction first scan
Instruction first run
EnableIn is cleared
EnableIn is set
Postscan
Target
Dest
Execution:
Function Block Action
No action taken.
No action taken.
No action taken.
EnableOut is cleared, the instruction does nothing, and the outputs are not updated.
The instruction executes.
EnableOut is set.
No action taken.
Structured Text Action
No action taken.
No action taken.
No action taken.
N/A
EnableIn is always set.
The instruction executes.
No action taken.
Example:
1. The controller copies Target into Dest.
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0
Source
2. The SourceBit and the Length specify which bits in Source to copy into
Dest, starting at DestBit. Source and Target remain unchanged.
DestBit
SourceBit
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0
Dest
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
304
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Move/Logical Instructions (MOV, MVM, BTD, MVMT, BTDT, CLR, SWPB, AND, OR, XOR, NOT, BAND, BOR, BXOR, BNOT)
Chapter 7
Structured Text
BTDT_01.Source := source;
BTDT_01.SourceBit := source_bit;
BTDT_01.Length := length;
BTDT_01.DestBit := dest_bit;
BTDT_01.Target := target;
BTDT(BTDT_01); distributed_value := BTDT_01.Dest;
Function Block
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
305
Chapter 7
Move/Logical Instructions (MOV, MVM, BTD, MVMT, BTDT, CLR, SWPB, AND, OR, XOR, NOT, BAND, BOR, BXOR, BNOT)
Clear (CLR)
The CLR instruction clears all the bits of the Destination.
Operands:
Relay Ladder
Operand
Destination
Type
SINT
INT
DINT
REAL
Format
Tag
Description
Tag to clear dest := 0;
Structured Text
Postscan
Structured text does not have a CLR instruction. Instead, assign 0 to the tag you want to clear. This assignment statement clears
dest.
See
Structured Text Programming for information on the syntax of expressions
and assignment statements within structured text.
Description:
The CLR instruction clears all the bits of the Destination.
Arithmetic Status Flags:
Arithmetic status flags are affected.
Fault Conditions:
None
Execution:
Condition
Prescan
Rung-condition-in is false
Rung-condition-in is true
Relay Ladder Action
The rung-condition-out is set to false.
The rung-condition-out is set to false.
The instruction clears the Destination.
The rung-condition-out is set to true.
The rung-condition-out is set to false.
306
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Move/Logical Instructions (MOV, MVM, BTD, MVMT, BTDT, CLR, SWPB, AND, OR, XOR, NOT, BAND, BOR, BXOR, BNOT)
Chapter 7
Example:
Clear all the bits of
value to 0.
Relay Ladder
Structured Text
value := 0;
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
307
Chapter 7
Move/Logical Instructions (MOV, MVM, BTD, MVMT, BTDT, CLR, SWPB, AND, OR, XOR, NOT, BAND, BOR, BXOR, BNOT)
Swap Byte (SWPB)
The SWPB instruction rearranges the bytes of a value.
Operands:
Relay Ladder
Operand
Source
Order Mode
Destination
Type
INT
DINT
REAL
INT
DINT
REAL
Format
Tag
Tag
Enter
Tag that contains the bytes that you want to rearrange
If the source is an And you want to change the bytes to this pattern (each letter represents a different byte)
INT
DINT
REAL
N/A
ABCD DCBA
ABCD CDAB
ABCD BADC
Tag to store the bytes in the new order
If the source is an Then the destination must be an
INT INT
DINT
DINT
REAL
DINT
REAL
Then select
Any of the options
REVERSE (or enter 0)
WORD (or enter 1)
HIGH/LOW (or enter 2)
SWPB(Source,OrderMode,Dest);
Structured Text
The operands are the same as those for the relay ladder SWPB instruction. If you select the HIGH/LOW order mode, enter it as HIGHLOW or HIGH_LOW
(without the slash).
308
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Move/Logical Instructions (MOV, MVM, BTD, MVMT, BTDT, CLR, SWPB, AND, OR, XOR, NOT, BAND, BOR, BXOR, BNOT)
Chapter 7
Description:
The SWPB instruction rearranges the order of the bytes of the Source. It places the result in the Destination.
When you read or write ASCII characters, you typically do not need to swap characters. The ASCII read and write instructions (ARD, ARL, AWA, AWT) automatically swap characters, as shown below.
bar code reader
B A
Tag Name
bar_code[0]
Value
AB
Style
ASCII
Type
INT
42969
42968
A B
Arithmetic Status Flags:
Not affected
Fault Conditions:
None
Execution:
Condition
Prescan
Rung-condition-in is false
Rung-condition-in is true
EnableIn is set
Instruction execution
Postscan
Relay Ladder Action
The rung-condition-out is set to false.
The rung-condition-out is set to false.
The rung-condition-out is set to true.
N/A
The instruction rearranges the specified bytes.
The rung-condition-out is set to false.
Structured Text Action
No action taken
N/A
N/A
EnableIn is always set.
The instruction executes.
The instruction rearranges the specified bytes.
No action taken.
Example 1:
The three SWPB instructions each reorder the bytes of
DINT_1 according to a different order mode. The display style is ASCII, and each character represents one byte. Each instruction places the bytes, in the new order, in a different
Destination.
Relay Ladder
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
309
Chapter 7
Move/Logical Instructions (MOV, MVM, BTD, MVMT, BTDT, CLR, SWPB, AND, OR, XOR, NOT, BAND, BOR, BXOR, BNOT)
Structured Text
SWPB(DINT_1,REVERSE,DINT_1_reverse);
SWPB(DINT_1,WORD,DINT_1_swap_word);
SWPB(DINT_1,HIGHLOW,DINT_1_swap_high_low);
Example 2:
The following example reverses the bytes in each element of an array. For an
RSLogix 5000 project that contains this example, open the
RSLogix 5000\Projects\Samples folder, Swap_Bytes_in_Array.ACD file.
1. Initialize the tags. The SIZE instruction finds the number of elements in
array and stores that value in array_length. A subsequent instruction uses this value to determine when the routine has acted on all the elements in the array.
2. Reverse the bytes in one element of array.
• The SWPB instruction reverses the bytes of the element number that is indicated by the value of
index. For example, when index equals 0, the
SWPB instruction acts on array[0].
• The ADD instruction increments index. The next time the instruction executes, the SWPB instruction acts on the next element in
array.
3. Determine when the SWPB instruction has acted on all the elements in the array.
• If
index is less then the number of elements in the array (array_length), then continue with the next element in the array.
• If index equals array_length, then the SWPB has acted on all the elements in the array.
310
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Move/Logical Instructions (MOV, MVM, BTD, MVMT, BTDT, CLR, SWPB, AND, OR, XOR, NOT, BAND, BOR, BXOR, BNOT)
Chapter 7
Relay Ladder
Initialize the tags.
Reverse the bytes.
Determine whether the SWPB instruction has acted on all the elements in the array.
Structured Text
index := 0;
SIZE (array[0],0,array_length);
REPEAT
SWPB(array[index],REVERSE,array_bytes_reverse[index]); index := index + 1;
UNTIL(index >= array_length)END_REPEAT;
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
311
Chapter 7
Move/Logical Instructions (MOV, MVM, BTD, MVMT, BTDT, CLR, SWPB, AND, OR, XOR, NOT, BAND, BOR, BXOR, BNOT)
Bitwise AND (AND)
Operands:
The AND instruction performs a bitwise AND operation by using the bits in
Source A and Source B and places the result in the Destination.
To perform a logical AND, see page 327
.
Relay Ladder
Operand
Source A
Source B
Destination
Type
SINT
INT
DINT
Format
Immediate
Tag
Description
Value to AND with Source B
A SINT or INT tag converts to a DINT value by zero-fill.
SINT
INT
DINT
Immediate
Tag
Value to AND with Source A
A SINT or INT tag converts to a DINT value by zero-fill.
SINT
INT
DINT
Tag Stores the result dest := sourceA AND sourceB
Structured Text
Use AND or the ampersand sign ‘&’ as an operator within an expression. This expression evaluates
sourceA AND sourceB.
See
Structured Text Programming for information on the syntax of expressions
within structured text.
Function Block
Operand
AND tag
Type
FBD_LOGICAL
Format
Structure
Description
AND structure
312
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Move/Logical Instructions (MOV, MVM, BTD, MVMT, BTDT, CLR, SWPB, AND, OR, XOR, NOT, BAND, BOR, BXOR, BNOT)
Chapter 7
Input Parameter
EnableIn
SourceA
SourceB
Output Parameter
EnableOut
Dest
Data Type
BOOL
DINT
DINT
Data Type
BOOL
DINT
FBD_LOGICAL Structure
Description
Enable input. If cleared, the instruction does not execute and outputs are not updated.
Default is set.
Value to AND with SourceB.
Valid = any integer
Value to AND with SourceA.
Valid = any integer
Description
The instruction produced a valid result.
Result of the instruction. Arithmetic status flags are set for this output.
Description:
When enabled, the instruction evaluates the AND operation.
1
1
0
0
If the bit in Source A is
0
1
0
1
And the bit in Source
B is
0
1
0
0
The bit in the destination is
Arithmetic Status Flags:
Arithmetic status flags are affected.
Fault Conditions:
None
Execution:
If you mix integer data types, the instruction fills the upper bits of the smaller integer data types with 0s so that they are the same size as the largest data type.
Condition
Prescan
Rung-condition-in is false
Rung-condition-in is true
Postscan
Relay Ladder
Action
The rung-condition-out is set to false.
The rung-condition-out is set to false.
The instruction performs a bitwise AND operation.
The rung-condition-out is set to true.
The rung-condition-out is set to false.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
313
Chapter 7
Move/Logical Instructions (MOV, MVM, BTD, MVMT, BTDT, CLR, SWPB, AND, OR, XOR, NOT, BAND, BOR, BXOR, BNOT)
Condition
Prescan
Instruction first scan
Instruction first run
EnableIn is cleared
EnableIn is set
Postscan
SourceA
SourceB
Dest
Function Block
Action
No action taken.
No action taken.
No action taken.
EnableOut is cleared.
The instruction executes.
EnableOut is set.
No action taken.
Example:
When enabled, the AND instruction performs a bitwise AND operation on
SourceA and SourceB and places the result in the Dest.
0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 1 0 1 0 1 0 1 1 1 1 1 1 1 1 1
0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0
314
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Move/Logical Instructions (MOV, MVM, BTD, MVMT, BTDT, CLR, SWPB, AND, OR, XOR, NOT, BAND, BOR, BXOR, BNOT)
Chapter 7
Relay Ladder
Structured Text
value_result_and := value_1 AND value_2;
Function Block
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
315
Chapter 7
Move/Logical Instructions (MOV, MVM, BTD, MVMT, BTDT, CLR, SWPB, AND, OR, XOR, NOT, BAND, BOR, BXOR, BNOT)
Bitwise OR (OR)
Operands:
The OR instruction performs a bitwise OR operation by using the bits in Source
A and Source B and places the result in the Destination.
Relay Ladder
Operand
Source A
Source B
Destination
Type
SINT
INT
DINT
Format
Immediate
Tag
Description
Value to OR with Source B
A SINT or INT tag converts to a DINT value by zero-fill.
SINT
INT
DINT
Immediate
Tag
Value to OR with Source A
A SINT or INT tag converts to a DINT value by zero-fill.
SINT
INT
DINT
Tag Stores the result dest := sourceA OR sourceB
Structured Text
Use OR as an operator within an expression. This expression evaluates sourceA
OR
sourceB.
See
Structured Text Programming for information on the syntax of expressions
within structured text.
Function Block
Operand
OR tag
Type
FBD_LOGICAL
Format:
Structure
Description
OR structure
316
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Move/Logical Instructions (MOV, MVM, BTD, MVMT, BTDT, CLR, SWPB, AND, OR, XOR, NOT, BAND, BOR, BXOR, BNOT)
Chapter 7
Input Parameter
EnableIn
SourceA
SourceB
Output Parameter
EnableOut
Dest
Data Type
BOOL
DINT
DINT
Data Type
BOOL
DINT
FBD_LOGICAL Structure
Description
Enable input. If cleared, the instruction does not execute and outputs are not updated.
Default is set.
Value to OR with SourceB.
Valid = any integer
Value to OR with SourceA.
Valid = any integer
Description
The instruction produced a valid result.
Result of the instruction. Arithmetic status flags are set for this output.
Description:
When enabled, the instruction evaluates the OR operation.
1
1
0
0
If the bit in Source A is
0
1
0
1
And the bit in Source
B is
1
1
0
1
The bit in the destination is
Arithmetic Status Flags
Arithmetic status flags are affected.
Fault Conditions:
None
Execution:
If you mix integer data types, the instruction fills the upper bits of the smaller integer data types with 0s so that they are the same size as the largest data type.
Condition
Prescan
Rung-condition-in is false
Rung-condition-in is true
Postscan
Relay Ladder
Action
The rung-condition-out is set to false.
The rung-condition-out is set to false.
The instruction performs a bitwise OR operation.
The rung-condition-out is set to true.
The rung-condition-out is set to false.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
317
Chapter 7
Move/Logical Instructions (MOV, MVM, BTD, MVMT, BTDT, CLR, SWPB, AND, OR, XOR, NOT, BAND, BOR, BXOR, BNOT)
Condition
Prescan
Instruction first scan
Instruction first run
EnableIn is cleared
EnableIn is set
Postscan
SourceA
SourceB
Dest
Function Block
Action
No action taken.
No action taken.
No action taken.
EnableOut is cleared.
The instruction executes.
EnableOut is set.
No action taken.
Example:
When enabled, the OR instruction performs a bitwise OR operation on SourceA and SourceB and places the result in Dest.
0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 1 0 1 0 1 0 1 1 1 1 1 1 1 1 1
0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 0 1 0 1 1 1 1 1 1 1 1 1
318
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Move/Logical Instructions (MOV, MVM, BTD, MVMT, BTDT, CLR, SWPB, AND, OR, XOR, NOT, BAND, BOR, BXOR, BNOT)
Chapter 7
Relay Ladder
Structured Text
value_result_or := value_1 OR value_2;
Function Block
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
319
Chapter 7
Move/Logical Instructions (MOV, MVM, BTD, MVMT, BTDT, CLR, SWPB, AND, OR, XOR, NOT, BAND, BOR, BXOR, BNOT)
Bitwise Exclusive OR (XOR)
The XOR instruction performs a bitwise XOR operation by using the bits in
Source A and Source B and places the result in the Destination.
To perform a logical XOR, see page 333
.
Operands:
Relay Ladder
Operand
Source A
Source B
Destination
Type
SINT
INT
DINT
Format
Immediate
Tag
Description
Value to XOR with Source B
A SINT or INT tag converts to a DINT value by zero-fill.
SINT
INT
DINT
Immediate
Tag
Value to XOR with Source A
A SINT or INT tag converts to a DINT value by zero-fill.
SINT
INT
DINT
Tag Stores the result dest := sourceA XOR sourceB
Structured Text
Use XOR as an operator within an expression. This expression evaluates sourceA
XOR
sourceB.
See
Structured Text Programming for information on the syntax of expressions
within structured text.
Function Block
Operand
XOR tag
Type
FBD_LOGICAL
Format
Structure
Description
XOR structure
320
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Move/Logical Instructions (MOV, MVM, BTD, MVMT, BTDT, CLR, SWPB, AND, OR, XOR, NOT, BAND, BOR, BXOR, BNOT)
Chapter 7
Input Parameter
EnableIn
SourceA
SourceB
Output Parameter:
EnableOut
Dest
Data Type
BOOL
DINT
DINT
Data Type
BOOL
DINT
FBD_LOGICAL Structure
Description
Enable input. If cleared, the instruction does not execute and outputs are not updated.
Default is set.
Value to XOR with SourceB.
Valid = any integer
Value to XOR with SourceA.
Valid = any integer
Description
The instruction produced a valid result.
Result of the instruction. Arithmetic status flags are set for this output.
Description:
When enabled, the instruction evaluates the XOR operation.
1
1
0
0
If the bit in Source A is
0
1
0
1
And the bit in Source
B is
1
0
0
1
The bit in the destination is
Arithmetic Status Flags
Arithmetic status flags are affected.
Fault Conditions:
None
Execution:
If you mix integer data types, the instruction fills the upper bits of the smaller integer data types with 0s so that they are the same size as the largest data type.
Condition
Prescan
Rung-condition-in is false
Rung-condition-in is true
Postscan
Relay Ladder
Action
The rung-condition-out is set to false.
The rung-condition-out is set to false.
The instruction performs a bitwise OR operation.
The rung-condition-out is set to true.
The rung-condition-out is set to false.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
321
Chapter 7
Move/Logical Instructions (MOV, MVM, BTD, MVMT, BTDT, CLR, SWPB, AND, OR, XOR, NOT, BAND, BOR, BXOR, BNOT)
Condition
Prescan
Instruction first scan
Instruction first run
EnableIn is cleared
EnableIn is set
Postscan
value_1 value_2 value_result_xor
Function Block
Action
No action taken.
No action taken.
No action taken.
EnableOut is cleared.
The instruction executes.
EnableOut is set.
No action taken.
Example:
When enabled, the XOR instruction performs a bitwise XOR operation on
SourceA and SourceB and places the result in the destination tag.
0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 1 0 1 0 1 0 1 1 1 1 1 1 1 1 1
0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 1 0 1 0 0 1 0 1 1 1 1 1 1 1 1 1
322
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Move/Logical Instructions (MOV, MVM, BTD, MVMT, BTDT, CLR, SWPB, AND, OR, XOR, NOT, BAND, BOR, BXOR, BNOT)
Chapter 7
Relay Ladder
Structured Text
value_result_xor := value_1 XOR value_2;
Function Block
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
323
Chapter 7
Move/Logical Instructions (MOV, MVM, BTD, MVMT, BTDT, CLR, SWPB, AND, OR, XOR, NOT, BAND, BOR, BXOR, BNOT)
Bitwise NOT (NOT)
Operands:
The NOT instruction performs a bitwise NOT operation by using the bits in the
Source and places the result in the Destination.
To perform a logical NOT, see
Relay Ladder
Operand
Source
Destination
Type
SINT
INT
DINT
Format
Immediate
Tag
Description
Value to NOT
A SINT or INT tag converts to a DINT value by zero-fill.
SINT
INT
DINT
Tag Stores the result dest := NOT source
Structured Text
Use NOT as an operator within an expression. This expression evaluates NOT
source.
See
Structured Text Programming for information on the syntax of expressions
within structured text.
Function Block
Operand
NOT tag
Type
FBD_LOGICAL
Format
Structure
Description
NOT structure
324
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Move/Logical Instructions (MOV, MVM, BTD, MVMT, BTDT, CLR, SWPB, AND, OR, XOR, NOT, BAND, BOR, BXOR, BNOT)
Chapter 7
FBD_LOGICAL Structure
Input Parameter
EnableIn
Source
Output Parameter
EnableOut
Dest
Data Type
BOOL
DINT
Data Type
BOOL
DINT
Description
Enable input. If cleared, the instruction does not execute and outputs are not updated.
default is set
Value to NOT.
valid = any integer
Description
The instruction produced a valid result.
Result of the instruction. Arithmetic status flags are set for this output.
Description:
When enabled, the instruction evaluates the NOToperation.
0
1
If the bit in the
Source is
1
0
The bit in the destination is
If you mix integer data types, the instruction fills the upper bits of the smaller integer data types with 0s so that they are the same size as the largest data type.
Arithmetic Status Flags:
Arithmetic status flags are affected.
Fault Conditions:
None
Execution:
Condition
Prescan
Rung-condition-in is false
Rung-condition-in is true
Postscan
Relay Ladder
Action
The rung-condition-out is set to false.
The rung-condition-out is set to false.
The instruction performs a bitwise NOT operation.
The rung-condition-out is set to true.
The rung-condition-out is set to false.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
325
Chapter 7
Move/Logical Instructions (MOV, MVM, BTD, MVMT, BTDT, CLR, SWPB, AND, OR, XOR, NOT, BAND, BOR, BXOR, BNOT)
Condition
Prescan
Instruction first scan
Instruction first run
EnableIn is cleared
EnableIn is set
Postscan
value_1 value_result_not
Function Block
Action
No action taken.
No action taken.
No action taken.
EnableOut is cleared.
The instruction executes.
EnableOut is set.
No action taken.
Example:
When enabled, the NOT instruction performs a bitwise NOT operation on
Source and places the result in Dest
.
0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 1 0 1 0 1 0 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 0 1 0 1 0 1 0 1 0 0 0 0 0 0 0 0 0
Relay Ladder
Structured Text
value_result_not := NOT value_1;
Function Block
326
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
In4
In5
In2
In3
Input Parameter
EnableIn
In1
In6
In7
In8
Output Parameter
EnableOut
Out
Move/Logical Instructions (MOV, MVM, BTD, MVMT, BTDT, CLR, SWPB, AND, OR, XOR, NOT, BAND, BOR, BXOR, BNOT)
Chapter 7
Boolean AND (BAND)
Operands:
The BAND instruction logically AND as many as eight boolean inputs.
To perform a bitwise AND, see
Structured Text
IF operandA AND operandB THEN
<statement>;
Use AND or the ampersand sign ‘&’ as an operator within an expression. The operands must be BOOL values or expressions that evaluate to BOOL values.
This expression evaluates whether
operandA and operandB are both set (true).
for information on the syntax of expressions within structured text.
Function Block
Operand
BAND tag
Type
FBD_BOOLEAN_AND
Format
Structure
Description
BAND structure
BOOL
BOOL
BOOL
BOOL
Data Type
BOOL
BOOL
BOOL
BOOL
BOOL
Data Type
BOOL
BOOL
FBD_BOOLEAN_AND Structure
Description
Enable input. If cleared, the instruction does not execute and outputs are not updated.
Default is set.
First boolean input.
Default is set.
Second boolean input.
Default is set.
Third boolean input.
Default is set.
Fourth boolean input.
Default is set.
Fifth boolean input.
default is set.
Sixth boolean input.
Default is set.
Seventh boolean input.
Default is set.
Eighth boolean input.
Default is set.
Description
Enable output.
The output of the instruction.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
327
Chapter 7
Move/Logical Instructions (MOV, MVM, BTD, MVMT, BTDT, CLR, SWPB, AND, OR, XOR, NOT, BAND, BOR, BXOR, BNOT)
Condition
Prescan
Instruction first scan
Instruction first run
EnableIn is cleared
EnableIn is set
Postscan
Description:
The BAND instruction ANDs as many as eight boolean inputs. If an input is not used, it defaults to set (1).
Out = In1 AND In2 AND In3 AND In4 AND In5 AND In6 AND In7 AND
In8
Arithmetic Status Flags:
Not affected
Fault Conditions:
None
Execution:
Function Block Action
No action taken.
No action taken.
No action taken.
EnableOut is cleared.
The instruction executes.
EnableOut is set.
No action taken.
Example 1:
This example ANDs bool_in1 and bool_in2 and places the result in
value_result_and.
0
1
If BOOL_IN1 is
0
1
1
0
If BOOL_IN2 is
0
1
0
0
0
Then VALUE_RESULT_AND is
1
Structured Text
value_result_and := bool_in1 AND bool_in2;
328
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Move/Logical Instructions (MOV, MVM, BTD, MVMT, BTDT, CLR, SWPB, AND, OR, XOR, NOT, BAND, BOR, BXOR, BNOT)
Chapter 7
Function Block
Example 2:
If both bool_in1 and bool_in2 are set (true), light1 is set (on). Otherwise, light1 is cleared (off ).
Structured Text
IF bool_in1 AND bool_in2 THEN light1 := 1;
ELSE light1 := 0;
END_IF;
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
329
In4
In5
In2
In3
Input Parameter
EnableIn
In1
In6
In7
In8
Output Parameter
EnableOut
Out
Chapter 7
Move/Logical Instructions (MOV, MVM, BTD, MVMT, BTDT, CLR, SWPB, AND, OR, XOR, NOT, BAND, BOR, BXOR, BNOT)
Boolean OR (BOR)
Operands:
The BOR instruction logically OR as many as eight boolean inputs.
To perform a bitwise OR, see
IF operandA OR operandB THEN
<statement>;
Structured Text
Use OR as an operator within an expression. The operands must be BOOL values or expressions that evaluate to BOOL values. This expression evaluates whether
operandA or operandB or both are set (true).
See
for information on the syntax of expressions within structured text.
Function Block
Operand
BOR tag
Type
FBD_BOOLEAN_OR
Format
Structure
Description
BOR structure
BOOL
BOOL
BOOL
BOOL
Data Type
BOOL
BOOL
BOOL
BOOL
BOOL
Data Type
BOOL
BOOL
FBD_BOOLEAN_OR Structure
Description
Enable input. If cleared, the instruction does not execute and outputs are not updated.
Default is set.
First boolean input.
Default is cleared.
Second boolean input.
Default is cleared.
Third boolean input.
Default is cleared.
Fourth boolean input.
Default is cleared.
Fifth boolean input.
Default is cleared.
Sixth boolean input.
Default is cleared.
Seventh boolean input.
Default is cleared.
Eighth boolean input.
Default is cleared.
Description
Enable output.
The output of the instruction.
330
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Move/Logical Instructions (MOV, MVM, BTD, MVMT, BTDT, CLR, SWPB, AND, OR, XOR, NOT, BAND, BOR, BXOR, BNOT)
Chapter 7
Condition
Prescan
Instruction first scan
Instruction first run
EnableIn is cleared
EnableIn is set
Postscan
Description:
The BOR instruction ORs as many as eight boolean inputs. If an input is not used, it defaults to cleared (0).
Out = In1 OR In2 OR In3 OR In4 OR In5 OR In6 OR In7 OR In8
Arithmetic Status Flags:
Not affected
Fault Conditions:
None
Execution:
Function Block Action
No action taken.
No action taken.
No action taken.
EnableOut is cleared.
The instruction executes.
EnableOut is set.
No action taken.
Example 1:
This example ORs bool_in1 and bool_in2 and places the result in value_result_or.
0
1
If BOOL_IN1 is
0
1
1
0
If BOOL_IN2 is
0
1
1
1
Then VALUE_RESULT_OR is
0
1
Structured Text
value_result_or := bool_in1 OR bool_in2;
Function Block
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
331
Chapter 7
Move/Logical Instructions (MOV, MVM, BTD, MVMT, BTDT, CLR, SWPB, AND, OR, XOR, NOT, BAND, BOR, BXOR, BNOT)
Example 2:
In this example,
light1 is set (on) if the following occurs:
• Only
bool_in1 is set (true)
• Only
bool_in2 is set (true)
• Both
bool_in1 and bool_in2 are set (true)
Otherwise,
light1 is cleared (off ).
Structured Text
IF bool_in1 OR bool_in2 THEN light1 := 1;
ELSE light1 := 0;
END_IF;
332
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Move/Logical Instructions (MOV, MVM, BTD, MVMT, BTDT, CLR, SWPB, AND, OR, XOR, NOT, BAND, BOR, BXOR, BNOT)
Chapter 7
Boolean Exclusive OR (BXOR)
The BXOR performs an exclusive OR on two boolean inputs.
To perform a bitwise XOR, see
Operands:
Structured Text
IF operandA XOR operandB THEN
<statement>;
END_IF;
Use XOR as an operator within an expression. The operands must be BOOL values or expressions that evaluate to BOOL values. This expression evaluates whether only
operandA or only operandB is set (true).
for information on the syntax of expressions within structured text.
Function Block
Operand
BXOR tag
Type
FBD_BOOLEAN_XOR
Format
Structure
Description
BXOR structure
Input Parameter
EnableIn
In1
In2
Output Parameter
EnableOut
Out
Data Type
BOOL
BOOL
BOOL
Data Type
BOOL
BOOL
FBD_BOOLEAN_XOR Structure
Description
Enable input. If cleared, the instruction does not execute and outputs are not updated.
Default is set.
First boolean input.
Default is cleared.
Second boolean input.
Default is cleared.
Description
Enable output.
The output of the instruction.
Description:
The BXOR instruction performs an exclusive OR on two boolean inputs.
Out = In1 XOR In2
Arithmetic Status Flags:
Not affected
Fault Conditions:
None
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
333
Chapter 7
Move/Logical Instructions (MOV, MVM, BTD, MVMT, BTDT, CLR, SWPB, AND, OR, XOR, NOT, BAND, BOR, BXOR, BNOT)
Condition
Prescan
Instruction first scan
Instruction first run
EnableIn is cleared
EnableIn is set
Postscan
Execution:
Function Block Action
No action taken.
No action taken.
No action taken.
EnableOut is cleared.
The instruction executes.
EnableOut is set.
No action taken.
Example 1:
This example performs an exclusive OR on
bool_in1 and bool_in2 and places the result in
value_result_xor.
0
1
If BOOL_IN1 is
0
1
1
0
If BOOL_IN2 is
0
1
1
1
Then VALUE_RESULT_XOR is
0
0
Structured Text
value_result_xor := bool_in1 XOR bool_in2;
Function Block
334
Example 2:
In this example, light1 is set (on) if :
• Only bool_in1 is set (true)
• Only bool_in2 is set (true)
Otherwise, light1 is cleared (off ).
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Move/Logical Instructions (MOV, MVM, BTD, MVMT, BTDT, CLR, SWPB, AND, OR, XOR, NOT, BAND, BOR, BXOR, BNOT)
Chapter 7
Structured Text
IF bool_in1 XOR bool_in2 THEN light1 := 1;
ELSE light1 := 0;
END_IF;
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
335
Chapter 7
Move/Logical Instructions (MOV, MVM, BTD, MVMT, BTDT, CLR, SWPB, AND, OR, XOR, NOT, BAND, BOR, BXOR, BNOT)
Boolean NOT (BNOT)
Operands:
The BNOT instruction complements a boolean input.
To perform a bitwise NOT, see page 324
.
IF NOT operand THEN
<statement>;
Structured Text
Use NOT as an operator within an expression. The operand must be a BOOL values or expressions that evaluate to BOOL values. This expression evaluates whether
operand is cleared (false).
See
Structured Text Programming for information on the syntax of expressions
within structured text.
Function Block
Operand
BNOT tag
Type
FBD_BOOLEAN_NOT
Format
Structure
Description
BNOT structure
FBD_BOOLEAN_NOT Structure
Input Parameter
EnableIn
In
Output Parameter
EnableOut
Out
Data Type
BOOL
BOOL
Data Type
BOOL
BOOL
Description
Enable input. If cleared, the instruction does not execute and outputs are not updated.
Default is set.
Input to the instruction.
Default is set.
Description:
Enable output.
The output of the instruction.
Description:
The BNOT instruction complements a boolean input.
Out = NOT In
Arithmetic Status Flags:
Not affected
Fault Conditions:
None
336
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Condition
Prescan
Instruction first scan
Instruction first run
EnableIn is cleared
EnableIn is set
Postscan
Move/Logical Instructions (MOV, MVM, BTD, MVMT, BTDT, CLR, SWPB, AND, OR, XOR, NOT, BAND, BOR, BXOR, BNOT)
Chapter 7
Execution:
Function Block Action
No action taken.
No action taken.
No action taken.
EnableOut is cleared.
The instruction executes.
EnableOut is set.
No action taken.
Example 1:
This example complements
bool_in1 and places the result in value_result_not.
If BOOL_IN1 is
0
1
Then VALUE_RESULT_NOT is
1
0
Structured Text
value_result_not := NOT bool_in1;
Function Block
Example 2:
If
bool_in1 is cleared, light1 is cleared (off ). Otherwise, light1 is set (on).
Structured Text
IF NOT bool_in1 THEN light1 := 0;
ELSE light1 := 1;
END_IF;
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
337
Chapter 7
Move/Logical Instructions (MOV, MVM, BTD, MVMT, BTDT, CLR, SWPB, AND, OR, XOR, NOT, BAND, BOR, BXOR, BNOT)
Notes:
338
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Array (file)/Misc. Instructions
(FAL, FSC, COP, CPS, FLL, AVE, SRT, STD, SIZE)
Topic
File Arithmetic and Logic (FAL)
Copy File (COP) Synchronous Copy File (CPS)
Page
The file/miscellaneous instructions operate on arrays of data.
If you want to
Perform arithmetic, logic, shift, and function operations on values in arrays
Search for and compare values in arrays
Copy the contents of one array into another array
Copy the contents of one array into another array without interruption
Fill an array with specific data
Calculate the average of an array of values
Sort one dimension of array data into ascending order
Calculate the standard deviation of an array of values
Find the size of a dimension of an array
Use this instruction
FAL
FSC
COP
CPS
FLL
AVE
SRT
STD
SIZE
Available in these languages
Relay ladder
Structured text
(1)
Relay ladder
Relay ladder
Structured text
Relay ladder
Structured text
Relay ladder
Structured text
(1)
Relay ladder
Structured text
(1)
Relay ladder
Structured text
Relay ladder
Structured text
(1)
Relay ladder
Structured text
(1) There is no equivalent structured text instruction. Use other structured text programming to achieve the same result. See the description for the instruction.
Page
Chapter
8
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
339
Chapter 8
Array (file)/Misc. Instructions (FAL, FSC, COP, CPS, FLL, AVE, SRT, STD, SIZE)
You can mix data types, but loss of accuracy and rounding error might occur and the instruction takes more time to execute. Check the S:V bit to see whether the result was truncated.
For relay ladder instructions, bold data types indicate optimal data types. An instruction executes faster and requires less memory if all the operands of the instruction use the same optimal data type, typically DINT or REAL.
Selecting Mode of Operation
For FAL and FSC instructions, the mode tells the controller how to distribute the array operation.
If You Want To
Operate on all of the specified elements in an array before continuing on to the next instruction
Distribute array operation over a number of scans
Enter the number of elements to operate on per scan (1-2147483647)
Manipulate one element of the array each time the rung-condition-in goes from false to true
Select This Mode
All
Numerical
Incremental
All Mode
In All mode, all the specified elements in the array are operated on before continuing on to the next instruction. The operation begins when the instruction’s rung-condition-in 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 the .LEN value.
Data Array
One Scan
16639
340
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Rung-condition-in
.EN Bit
.DN Bit
Scan Of The Instruction
Operation Complete
Array (file)/Misc. Instructions (FAL, FSC, COP, CPS, FLL, AVE, SRT, STD, SIZE)
Chapter 8
The following timing diagram shows the relationship between status bits and instruction operation. When the instruction execution is complete, the .DN bit is set. The .DN bit, the .EN bit, and the .POS value are cleared when the rungcondition-in is false. Only then can another execution of the instruction be triggered by a false-to-true transition of rung-condition-in.
One
Scan
Clears status bits and clears .POS value.
No execution occurs.
40010
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
341
Chapter 8
Array (file)/Misc. Instructions (FAL, FSC, COP, CPS, FLL, AVE, SRT, STD, SIZE)
Numerical Mode
Numerical mode distributes the array operation over a number of scans. This mode is useful when working with non-time-critical data or large amounts of data. You enter the number of elements to operate on for each scan, which keeps scan time shorter.
Execution is triggered when the rung-condition-in 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, rungcondition-in can change repeatedly without interrupting execution of the instruction.
One Scan
Second Scan
Next Scan
16641
IMPORTANT
Avoid using the results of a file instruction operating in numerical mode until the .DN bit is set.
342
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Array (file)/Misc. Instructions (FAL, FSC, COP, CPS, FLL, AVE, SRT, STD, SIZE)
Chapter 8
The following timing diagram shows the relationship between status bits and instruction operation. When the instruction execution is complete, the .DN bit is set.
Rung is True at Completion
Rung is False at Completion
Multiple Scans
Multiple Scans
Rung-condition-in
.EN Bit
.DN Bit
Scan Of The Instruction
Operation Complete
Clears Status Bits And clears .POS
Value
Operation Complete
40013
Clears Status Bits And clears .POS
Value
If the rung-condition-in is true at completion, the .EN and .DN bit are set until the rung-condition-in goes false. When the rung-condition-in goes false, these bits are cleared and the .POS value is cleared.
If the rung-condition-in 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 rung-condition-in goes from false to true.
1st Instruction Enable
2nd Instruction Enable
3rd Instruction Enable
Last Instruction Enable
16643
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
343
Chapter 8
Array (file)/Misc. Instructions (FAL, FSC, COP, CPS, FLL, AVE, SRT, STD, SIZE)
The following timing diagram shows the relationship between status bits and instruction operation. Execution occurs only in a scan in which the rungcondition-in goes from false to true. Each time this occurs, only one element of the array is manipulated. If the rung-condition-in remains true for more than one scan, the instruction only executes during the first scan.
One
Scan
Rung-condition-in
.EN Bit
.DN Bit
Scan Of The Instruction
Operation Complete
40014
Clears Status Bits And clears .POS
Value
The .EN bit is set when rung-condition-in 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 rung-condition-in 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 as follows:
• Numerical mode with any number of elements per scan requires only one false-to-true transition of the rung-condition-in to start execution. The instruction continues to execute the specified number of elements each scan until completion regardless of the state of the rung-condition-in.
• Incremental mode requires the rung-condition-in to change from false to true to manipulate one element in the array.
344
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Array (file)/Misc. Instructions (FAL, FSC, COP, CPS, FLL, AVE, SRT, STD, SIZE)
Chapter 8
File Arithmetic and Logic
(FAL)
Operands:
The FAL instruction performs copy, arithmetic, logic, and function operations on data stored in an array.
Relay Ladder
Operand
Control
Length
Position
Mode
Destination
Expression
Type
CONTROL
DINT
DINT
Format
Tag
Immediate
Immediate
Description
Control structure for the operation
Number of elements in the array to be manipulated
Current element in array
Initial value is typically 0
DINT Immediate How to distribute the operation
Select INC, ALL, or enter a number
Tag to store the result SINT
INT
DINT
REAL
SINT
INT
DINT
REAL
Tag
Immediate
Tag
An expression consisting of tags and/or immediate values separated by operators
A SINT or INT tag converts to a DINT value by sign-extension.
Structured Text
Structured text does not have an FAL instruction, but you can achieve the same results by using a SIZE instruction and a FOR...DO or other loop construct.
SIZE(destination,0,length-1);
FOR position = 0 TO length DO destination[position] :=
numeric_expression;
END_FOR;
See Structured Text Programming
for information on the syntax of constructs within structured text.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
345
Chapter 8
Array (file)/Misc. Instructions (FAL, FSC, COP, CPS, FLL, AVE, SRT, STD, SIZE)
Mnemonic
.EN
.DN
.ER
.LEN
.POS
Data Type
BOOL
BOOL
BOOL
DINT
DINT
CONTROL Structure
Description
The enable bit indicates that the FAL instruction is enabled.
The done bit is set when the instruction has operated on the last element (.POS = .LEN).
The error bit is set if the expression generates an overflow (S:V is set). The instruction stops executing until the program clears the .ER bit. The .POS value contains the position of the element that caused the overflow.
The length specifies the number of elements in the array on which the FAL instruction operates.
The position contains the position of the current element that the instruction is accessing.
Description:
The FAL instruction performs the same operations on arrays as the CPT instruction performs on elements.
The examples that start on page 352 show how to use the .POS value to step through an array. If a subscript in the expression of the Destination is out of range, the FAL instruction generates a major fault (type 4, code 20).
Arithmetic Status Flags:
Arithmetic status flags are affected.
Fault Conditions:
A major fault will occur if
Subscript is out of range
.POS < 0 or .LEN < 0
Fault type
4
4
Fault code
20
21
346
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Condition
Prescan
Rung-condition-in is false.
Array (file)/Misc. Instructions (FAL, FSC, COP, CPS, FLL, AVE, SRT, STD, SIZE)
Chapter 8
Execution:
Relay Ladder Action
The rung-condition-out is set to false.
Examine .DN Bit
.DN Bit = 0
.DN Bit = 1
.EN bit is cleared.
.ER bit is cleared.
.DN bit is cleared.
.POS value is cleared.
INC Mode
Yes
.EN bit is cleared.
No
Internal bit is cleared
ALL Mode
Yes
No
.LEN < 0 Or
.POS < 0
No
Yes
.POS = .POS + 1
Major Fault
.POS = 0
No
.POS = .POS - 1
Yes
.DN bit is set .
.EN bit is set.
.DN bit is set.
.EN bit is cleared.
Yes
No
.LEN = 0
No
.POS < .LEN
Yes
.LEN > Mode
No
Yes
Mode = .LEN
Numeric
Mode page 351
Rung-condition-out is set to
false.
End
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
347
Chapter 8
Array (file)/Misc. Instructions (FAL, FSC, COP, CPS, FLL, AVE, SRT, STD, SIZE)
Condition Relay Ladder Action
Rung-condition-in is true.
Examine .ER Bit
.ER Bit = 0
.ER Bit = 1
Examine .DN Bit
.DN Bit = 1
.DN Bit = 0
.LEN < 0 or .POS
< 0
Yes
No
.LEN = 0
No
.DN bit is set.
.EN bit is set.
Yes
Common
Major Fault
INC mode
Yes
INC
Mode page 349
No
No
ALL Mode
Yes
ALL
Mode page 350 page 351
Numeric
Mode
Loop_count =
Loop_count - 1
Loop_count < 0
No
Yes
.POS = .POS + 1
.POS = .POS + 1
Evaluate Expression
Examine S:V
Yes
.ER bit is set.
No
.POS = .LEN
No
.DN bit is set.
.EN bit is set.
Yes
.POS = .POS + 1
Rung-condition-out is set to
true.
End
348
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Relay Ladder Action
Array (file)/Misc. Instructions (FAL, FSC, COP, CPS, FLL, AVE, SRT, STD, SIZE)
Chapter 8
Condition
INC
Mode
Examine .EN Bit
.EN Bit = 1
.EN Bit = 0
Examine internal bit.
Bit = 0
Bit = 1
.POS = .POS + 1
Internal bit is set.
.POS .LEN
No
.EN bit is set.
.POS = .POS - 1
Yes
.POS = 0
No
.POS = .POS - 1
Yes
.DN bit is set.
.EN bit is set.
Common page 348
Rung-condition-out is set to
true.
End
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
349
Chapter 8
Array (file)/Misc. Instructions (FAL, FSC, COP, CPS, FLL, AVE, SRT, STD, SIZE)
Condition Relay Ladder Action
ALL
Mode
Examine .EN bit.
.EN Bit = 0
.EN Bit = 1
.POS = .POS + 1
Examine internal bit.
Bit = 0
.EN bit is set.
Bit = 1
.POS .LEN
No
Loop_count = .LEN - .POS
.POS = .POS - 1
Yes
.POS = 0
No
.POS = .POS - 1
Yes
Common page 348
.DN bit is set .
.EN bit is set.
Rung-condition-out is set to
true.
end
350
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Condition Relay Ladder Action
Array (file)/Misc. Instructions (FAL, FSC, COP, CPS, FLL, AVE, SRT, STD, SIZE)
Chapter 8
Numeric
Mode
.POS = .POS + 1
.EN Bit = 1
Examine .EN bit.
.EN Bit = 0
Examine internal bit.
Bit = 0
Bit = 1
Internal bit is set.
Mode = .LEN
.POS .LEN
No
No
.LEN mode
Yes
.EN bit is set.
loop_count = .LEN - .POS
.POS = .POS - 1
Yes
.POS = 0
.DN bit is set.
.EN bit is set.
No
.POS = .POS - 1
Yes
Rung-condition-out is set to
true.
End
Mode
loop_count
No
Yes
Common page 348
Postscan The rung-condition-out is set to false.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
351
Chapter 8
Array (file)/Misc. Instructions (FAL, FSC, COP, CPS, FLL, AVE, SRT, STD, SIZE)
Example 1:
When enabled, the FAL instruction copies each element of
array_2 into the same position within array_1.
Array-to-Array Copy
Expression:
array_2[control_2.pos]
Destination:
array_1[control_2.pos]
Example 2:
When enabled, the FAL instruction copies value_1 into the first 10 positions of the second dimension of array_2.
Element-to-Array Copy
Expression:
value_1
Destination:
array_2[0,control_2.pos]
Example 3:
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.
Array-to-Element Copy
Expression:
array_1[control_1.pos]
Destination:
value_1
Example 4:
When enabled, the FAL instruction adds value_1 and value_2 and stores the result in the current position of array_1.
Arithmetic Operation: (Element + Element) to Array
Expression:
value_1 + value_2
Destination:
array_1[control_1.pos]
352
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Array (file)/Misc. Instructions (FAL, FSC, COP, CPS, FLL, AVE, SRT, STD, SIZE)
Chapter 8
Example 5:
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.
Arithmetic Operation: (Array / Array) to Array
Expression:
array_2[control_2.pos] / array_3[control_2.pos]
Destination:
array_1[control_2.pos]
Example 6:
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.
Arithmetic Operation: (Array + eEement) to Array
Expression:
array_1[control_1.pos] + value_1
Destination:
array_3[control_1.pos]
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
353
Chapter 8
Array (file)/Misc. Instructions (FAL, FSC, COP, CPS, FLL, AVE, SRT, STD, SIZE)
Example 7:
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.
Arithmetic Operation: (Element + Array) to Element
Expression:
value_1 + array_1[control_1.pos]
Destination:
value_2
Example 8:
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.
Arithmetic Operation: (Array Array) to Element
Expression:
array_1[control_1.pos] * array_3[control_1.pos]
Destination:
value_1
354
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
DEG
FRD
LN
LOG
AND
ASN
ATN
COS
/
**
ABS
ACS
-
*
Operator
+
Description
Add
Subtract/negate
Multiply
Divide
Exponent (x to y)
Absolute value
Arc cosine
Bitwise AND
Arc sine
Arc tangent
Cosine
Radians to degrees
BCD to integer
Natural log
Log base 10
Array (file)/Misc. Instructions (FAL, FSC, COP, CPS, FLL, AVE, SRT, STD, SIZE)
Chapter 8
FAL Expressions
You program expressions in FAL instructions the same as expressions in CPT instructions. Use the following sections for information on valid operators, format, and order of operation, which are common to both instructions.
Valid Operators
DINT
REAL
REAL
REAL
DINT, REAL
DINT
REAL
REAL
Optimal
DINT, REAL
DINT, REAL
DINT, REAL
DINT, REAL
DINT, REAL
DINT, REAL
REAL TAN
TOD
TRN
XOR
OR
RAD
SIN
SQR
Operator
MOD
NOT
Description
Modulo-divide
Bitwise complement
Bitwise OR
Degrees to radians
Sine
Square root
Tangent
Integer to BCD
Truncate
Bitwise exclusive OR
Optimal
DINT, REAL
DINT
DINT
DINT, REAL
REAL
DINT, REAL
REAL
DINT
DINT, REAL
DINT
Format Expressions
For each operator that you use in an expression, you have to 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
One operand
Two operands
Use this format
Operator(operand)
Operand_a operator operand_b
Examples
ABS(tag_a)
• tag_b + 5
• tag_c AND tag_d
• (tag_e ** 2) MOD (tag_f / tag_g)
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
355
Chapter 8
Array (file)/Misc. Instructions (FAL, FSC, COP, CPS, FLL, AVE, SRT, STD, SIZE)
Determine the Order of Operation
7.
8.
9.
5.
6.
3.
4.
Order
1.
2.
The operations you write into the expression are performed by the instruction in a prescribed order, not necessarily the order you write them. You can override the order of operation 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.
Operation
( )
ABS, ACS, ASN, ATN, COS, DEG, FRD, LN, LOG, RAD, SIN, SQR,
TAN, TOD, TRN
**
(negate), NOT
*, /, MOD
(subtract), +
AND
XOR
OR
356
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Array (file)/Misc. Instructions (FAL, FSC, COP, CPS, FLL, AVE, SRT, STD, SIZE)
Chapter 8
File Search and Compare
(FSC)
Operands:
The FSC instruction compares values in an array, element by element.
Relay Ladder
Operand
Control
Length
Position
Type
CONTROL
DINT
DINT
Format
Tag
Immediate
Immediate
Description
Control structure for the operation
Number of elements in the array to be manipulated
Offset into array
Initial value is typically 0
.ER
.IN
.FD
.LEN
.POS
Mnemonic
.EN
.DN
Data Type
BOOL
BOOL
BOOL
BOOL
BOOL
DINT
DINT
CONTROL Structure
Description
The enable bit indicates that the FSC instruction is enabled.
The done bit is set when the instruction has operated on the last element
(.POS = .LEN).
The error bit is not modified.
The inhibit bit indicates that the FSC instruction detected a true comparison. You must clear this bit to continue the search operation.
The found bit indicates that the FSC instruction detected a true comparison.
The length specifies the number of elements in the array on which the instruction operates.
The position contains the position of the current element that the instruction is accessing.
Description:
When the FSC instruction is enabled and the comparison is true, the instruction sets the .FD bit and the .POS bit reflects the array position where the instruction found the true comparison. The instruction sets the .IN bit to prevent further searching.
Arithmetic Status Flags:
Arithmetic status flags are affected.
Fault Conditions:
A Major Fault Will Occur If
.POS < 0 or .LEN < 0
Fault Type
4
Fault Code
21
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
357
Chapter 8
Array (file)/Misc. Instructions (FAL, FSC, COP, CPS, FLL, AVE, SRT, STD, SIZE)
Execution:
Condition
Prescan
Rung-condition-in is false.
Relay Ladder Action
The rung-condition-out is set to false.
Examine .DN bit. .DN Bit = 0
.DN Bit = 1
.EN bit is cleared.
.ER bit is cleared.
.DN bit is cleared.
.POS value is cleared.
INC Mode
Yes
.EN bit is cleared.
No
Internal bit is cleared.
ALL Mode
Yes
No
.LEN < 0 or
.POS < 0
No
Yes
.POS = .POS + 1
Major Fault
Rung-condition-out is set to
false.
End
.POS = 0
No
.POS = .POS - 1
Yes
.DN bit is set.
.EN bit is set.
.DN bit is set.
.EN bit is cleared.
Yes
No
.LEN = 0
No
.POS < .LEN
Yes
.LEN > mode
No
Yes
Mode = .LEN
Numeric
Mode page 351
358
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Array (file)/Misc. Instructions (FAL, FSC, COP, CPS, FLL, AVE, SRT, STD, SIZE)
Chapter 8
Condition Relay Ladder Action
Rung-condition-in is true.
Examine .ER bit.
.ER Bit = 0
.ER Bit = 1
.DN Bit = 1
Examine .IN bit.
.IN Bit = 0
.DN Bit = 0
.LEN < 0 or .POS
< 0
Yes
No
.LEN = 0
No
Yes
.DN bit is set.
.EN bit is set.
.DN Bit = 1
Examine .DN bit.
Common
.DN Bit = 0
Loop_count =
Loop_count - 1
Major Fault
INC Mode yes
INC
Mode page 349
No
No
ALL mode
Yes
ALL
Mode page 350 page 351
Numeric
Mode
Postscan
Loop_count < 0 No yes
.POS = .POS + 1
.POS = .POS + 1
Evaluate Comparison
Match
Yes
.EN bit is set.
.FD bit is set.
.IN bit is set.
No
.POS = .LEN
.DN bit is set.
.EN bit is set.
Yes
No
The rung-condition-out is set to false.
.POS = .POS + 1
Rung-condition-out is set to true.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
359
Chapter 8
Array (file)/Misc. Instructions (FAL, FSC, COP, CPS, FLL, AVE, SRT, STD, SIZE)
Example 1:
Search for a match between two arrays. When enabled, the FSC instruction compares each of the first 10 elements in array_1 to the corresponding elements in
array_2.
Array_1
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000001111111111111111
11111111111111111111111111111111
11111111111111111111111111111111
11111111111111111111111111111111
11111111111111111111111111111111
11111111111111111111111111111111
Array_2
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
11111111111111110000000000000000
11111111111111111111111111111111
11111111111111111111111111111111
11111111111111111111111111111111
11111111111111111111111111111111
11111111111111111111111111111111
Control_3.pos
6
7
4
5
8
9
2
3
0
1
The FSC instruction finds that these elements are not equal. The instruction sets the .FD and .IN bits. The
.POS value (4) indicates the position of the elements that are not equal. To continue comparing the rest of the array, clear the .IN bit.
360
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Array (file)/Misc. Instructions (FAL, FSC, COP, CPS, FLL, AVE, SRT, STD, SIZE)
Chapter 8
Example 2:
Search for a match in an array. When enabled, the FSC instruction compares the
MySearchKey to 10 elements in array_1.
Code
SAM
MySearchKey
11111111111111110000000000000000
Reference
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
11111111111111110000000000000000
11111111111111111111111111111111
11111111111111111111111111111111
11111111111111111111111111111111
11111111111111111111111111111111
11111111111111111111111111111111
Control_3.pos
6
7
4
5
8
9
2
3
0
1
The FSC instruction finds that this array element equals MySearchKey. The instruction sets the .FD and
.IN bits. The .POS (4) value indicates the position of the equal element. To continue comparing the rest of the array, clear the .IN bit.
Example 3:
Search for a string in an array of strings. When enabled, the FSC instruction compares the characters in code to 10 elements in code_table.
Code_table
SAM
FQG
CLE
CAK
AFG
BEH
HUO
SAK
DET
BWG
Code_table_search.POS
6
7
4
5
8
9
2
3
0
1
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
The FSC instruction finds that this array element equals code. The instruction sets the .FD and .IN bits.
The .POS (4) value indicates the position of the equal element. To continue comparing the rest of the array, clear the .IN bit.
361
Chapter 8
Array (file)/Misc. Instructions (FAL, FSC, COP, CPS, FLL, AVE, SRT, STD, SIZE)
FSC Expressions
You program expressions in FSC instructions the same as expressions in CMP instructions. Use the following sections for information on valid operators, format, and order of operation, which are common to both instructions.
ABS
ACS
AND
ASN
>
>=
<>
**
ATN
COS
DEG
FRD
/
=
<
<=
-
*
Operator
+
Description
Add
Subtract/negate
Multiply
Divide
Equal
Less than
Less than or equal
Greater than
Greater than or equal
Not equal
Exponent (x to y)
Absolute value
Arc cosine
Bitwise AND
Arc sine
Arc tangent
Cosine
Radians to degrees
BCD to integer
Valid Operators
DINT, REAL
DINT, REAL
DINT, REAL
DINT, REAL
DINT, REAL
REAL
DINT
REAL
Optimal
DINT, REAL
DINT, REAL
DINT, REAL
DINT, REAL
DINT, REAL
DINT, REAL
DINT, REAL
REAL
REAL
DINT, REAL
DINT
SIN
SQR
TAN
TOD
TRN
XOR
Operator
LN
LOG
MOD
NOT
OR
RAD
Description
Natural log
Log base 10
Modulo-divide
Bbitwise complement
Bitwise OR
Degrees to radians
Sine
Square root
Tangent
Integer to BCD
Truncate
Bitwise exclusive OR
Optimal
REAL
REAL
DINT, REAL
DINT
DINT
DINT, REAL
REAL
DINT, REAL
REAL
DINT
DINT, REAL
DINT
Format Expressions
For each operator that you use in an expression, you have to 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
One operand
Two operands
Use this format
Operator(operand)
Operand_a operator operand_b
Examples
ABS(tag_a)
• tag_b + 5
• tag_c AND tag_d
• (tag_e ** 2) MOD (tag_f / tag_g)
362
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Array (file)/Misc. Instructions (FAL, FSC, COP, CPS, FLL, AVE, SRT, STD, SIZE)
Chapter 8
Determine the Order of Operation
7.
8.
9.
10.
5.
6.
3.
4.
Order
1.
2.
The operations you write into the expression are performed by the instruction in a prescribed order, not necessarily the order you write them. You can override the order of operation 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.
Operation
( )
ABS, ACS, ASN, ATN, COS, DEG, FRD, LN, LOG, RAD, SIN, SQR,
TAN, TOD, TRN
**
(negate), NOT
*, /, MOD
<, <=, >, >=, =
(subtract), +
AND
XOR
OR
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
363
Chapter 8
Array (file)/Misc. Instructions (FAL, FSC, COP, CPS, FLL, AVE, SRT, STD, SIZE)
Use Strings in an Expression
To use strings of ASCII characters in an expression, follow these guidelines:
• An expression lets you compare two string tags.
• You cannot enter ASCII characters directly into the expression.
• Only the following operators are permitted.
>
>=
<>
Operator
=
<
<=
Description
Equal
Less than
Less than or equal
Greater than
Greater than or equal
Not equal
• Strings are equal if their characters match.
• ASCII characters are case sensitive. Upper case ‘A’ ($41) is not equal to lower case ‘a’ ($61).
• The hexadecimal values of the characters determine if one string is less than or greater than another string. For the hex code of a character, see the back cover of this manual.
• When the two strings are sorted as in a telephone directory, the order of the strings determines which one is greater. r ss e
L e r t e e a r
G
AB
B a
1b
A
ASCII Characters
1ab ab
Hex Codes
$31$61$62
$31$62
$41
$41$42
$42
$61
$61$62
AB < B a > B
364
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Array (file)/Misc. Instructions (FAL, FSC, COP, CPS, FLL, AVE, SRT, STD, SIZE)
Chapter 8
Copy File (COP) Synchronous
Copy File (CPS)
Operands:
The COP and CPS instructions copy the value(s) in the Source to the
Destination. The Source remains unchanged.
Relay Ladder
Operand
Source
Destination
Length
Type
SINT
INT
DINT
REAL string
structure
SINT
INT
DINT
REAL string
structure
DINT
Format
Tag
Tag
Description
Initial element to copy.
Important: the Source and Destination operands should be the same data type, or unexpected results may occur.
Initial element to be overwritten by the Source
Important: the Source and Destination operands should be the same data type, or unexpected results may occur.
Immediate
Tag
Number of Destination elements to copy.
Structured Text
COP(Source,Dest,Length);
The operands are the same as those for the relay ladder COP and
CPS instructions.
Description:
During execution of the COP and CPS instructions, other controller actions may try to interrupt the copy operation and change the source or destination data.
If the source or destination is
• Produced tag
• Consumed tag
• I/O data
• Data that another task can overwrite
And you want to
Prevent the data from changing during the copy operation
Then select
CPS
Notes
• Tasks that attempt to interrupt a CPS instruction are delayed until the instruction is done.
• To estimate the execution time of the CPS instruction, see ControlLogix System User Manual, publication 1756-UM001.
None of the above
Allow the data to change during the copy operation
COP
COP
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
365
Chapter 8
Array (file)/Misc. Instructions (FAL, FSC, COP, CPS, FLL, AVE, SRT, STD, SIZE)
The number of bytes copied is:
Byte Count = Length (number of bytes in the Destination data type)
ATTENTION: If the byte count is greater than the length of the Source, unpredictable data is copied for the remaining elements.
IMPORTANT
You must test and confirm that the instruction doesn’t change data that you don’t want it to change.
The COP and CPS instructions operate on contiguous memory. They do a straight byte-to-byte memory copy. In some cases, they write past the array into other members of the tag. This happens if the length is too big and the tag is a user-defined data type.
If the tag is
User-defined data type
NOT user-defined data type
Then
If the Length is too big, the instruction writes past the end of the array into other members of the tag. It stops at the end of the tag. No major fault is generated.
If the Length is too big, the instruction stops at the end of the array. No major fault is generated.
The Length is too big if it is more than the total number of elements in the Destination array.
Arithmetic Status Flags:
Not affected
Fault Conditions:
None
366
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Array (file)/Misc. Instructions (FAL, FSC, COP, CPS, FLL, AVE, SRT, STD, SIZE)
Chapter 8
Condition
Prescan
Rung-condition-in is false
Rung-condition-in is true
EnableIn is set
Execution:
Relay Ladder Action
The rung-condition-out is set to false.
The rung-condition-out is set to false.
The instruction executes.
The rung-condition-out is set to true.
N/A
Instruction Execution
End_address = start_address + (Length number of bytes in a destination element)
Structured Text Action
No action taken.
N/A
N/A
EnableIn is always set.
The instruction executes.
End_address > end of destination array
No
Source_address = Source
Yes
Destination_address =
end_address
No
Yes
Copy data in source_address to destination _address.
Source_address = source _address + 1
Destination_address = destination_address + 1
End_address = end of destination array
Rung-condition-out is set to true.
End
Postscan The rung-condition-out is set to false.
No action taken.
Example 1:
Both
array_4 and array_5 are the same data type. When enabled, the COP instruction copies the first 10 elements of array_4 into the first 10 elements of
array_5.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
367
Chapter 8
Array (file)/Misc. Instructions (FAL, FSC, COP, CPS, FLL, AVE, SRT, STD, SIZE)
Relay Ladder
Structured Text
COP(array_4[0],array_5[0],10);
Example 2:
When enabled, the COP instruction copies the structure timer_1 into element 5 of
array_timer. The instruction copies only one structure to one array element.
Relay Ladder
Structured Text
COP(timer_1,array_timer[5],1);
368
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Array (file)/Misc. Instructions (FAL, FSC, COP, CPS, FLL, AVE, SRT, STD, SIZE)
Chapter 8
Example 3:
The
project_data array (100 elements) stores a variety of values that change at different times in the application. To send a complete image of project_data at one instance in time to another controller, the CPS instruction copies
project_data to
produced_array.
• While the CPS instruction copies the data, no I/O updates or other tasks can change the data.
• The
produced_array tag produces the data on a ControlNet network for consumption by other controllers.
• To use the same image of data (that is, a synchronized copy of the data), the consuming controller (s) uses a CPS instruction to copy the data from the consumed tag to another tag for use in the application.
Relay Ladder
Structured Text
CPS(project_data[0],produced_array[0],100);
Example 4:
Local:0:I.Data stores the input data for the DeviceNet network that is connected to the 1756-DNB module in slot 0. To synchronize the inputs with the application, the CPS instruction copies the input data to
input_buffer.
• While the CPS instruction copies the data, no I/O updates can change the data.
• As the application executes, it uses for its inputs the input data in
input_buffer.
Relay Ladder
Structured Text
CPS(Local:0:I.Data[0],input_buffer[0],20);
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
369
Chapter 8
Array (file)/Misc. Instructions (FAL, FSC, COP, CPS, FLL, AVE, SRT, STD, SIZE)
Example 5:
This example initializes an array of timer structures. When enabled, the MOV instructions initialize the .PRE and .ACC values of the first array_timer element.
When enabled, the COP instruction copies a contiguous block of bytes, starting at array_timer[0]. The length is nine timer structures.
Array_timer[0] First the instruction copies timer[0] values to timer[1].
Array_timer[1]
Array_timer[2]
Array_timer[3]
Then the instruction copies timer[1] values to timer[2].
Then the instruction copies timer[2] values to timer[3].
Then the instruction copies timer[3] values to timer[4].
Array_timer[4]
•
•
•
Array_timer[9]
Array_timer[10]
Finally, the instruction copies timer[9] values to timer[10].
Relay Ladder
370
Structured Text
IF S:FS THEN array_timer[0].pre := 500; array_timer[0].acc := 0;
COP(array_timer[0],array_timer[1],10);
END_IF;
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
File Fill (FLL)
Array (file)/Misc. Instructions (FAL, FSC, COP, CPS, FLL, AVE, SRT, STD, SIZE)
Chapter 8
Operands:
The FLL instruction fills elements of an array with the Source value. The Source remains unchanged.
Relay Ladder
Operand
Source
Destination
Length
Type
SINT
INT
DINT
REAL
SINT
INT
DINT
REAL structure
DINT
Format:
Immediate
Tag
Tag
Immediate
Description
Element to copy.
Important: the Source and Destination operands should be the same data type, or unexpected results may occur.
Initial element to be overwritten by the Source
Important: the Source and Destination operands should be the same data type, or unexpected results may occur
The preferred way to initialize a structure is to use the COP instruction.
Number of elements to fill.
Structured Text
Structured text does not have an FLL instruction, but you can achieve the same results by using a SIZE instruction and a FOR...DO or other loop construct.
SIZE(destination,0,length);
FOR position = 0 TO length-1 DO destination[position] := source;
END_FOR;
See Structured Text Programming
for information on the syntax of constructs within structured text.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
371
Chapter 8
Array (file)/Misc. Instructions (FAL, FSC, COP, CPS, FLL, AVE, SRT, STD, SIZE)
Description:
The number of bytes filled is:
Byte count = Length (number of bytes in the Destination data type)
IMPORTANT
You must test and confirm that the instruction doesn’t change data that you don’t want it to change.
The FLL instruction operates on contiguous data memory. In some cases, the instruction writes past the array into other members of the tag. This happens if the length is too big and the tag is a userdefined data type.
If the tag is
User-defined data type
NOT user-defined data type
Then
If the Length is too big, the instruction writes past the end of the array into other members of the tag. It stops at the end of the tag. No major fault is generated.
If the Length is too big, the instruction stops at the end of the array. No major fault is generated.
The Length is too big if it is more than the total number of elements in the Destination array.
For best results, the Source and Destination should be the same type. If you want to fill a structure, use the COP instruction (see example 3 on
mix data types for the Source and Destination, the Destination elements are filled with converted Source values.
If The Source Is
SINT
INT
DINT
REAL
SINT, INT, DINT, or REAL
SINT, INT, DINT, or REAL
SINT, INT, DINT, or REAL
SINT, INT, DINT, or REAL
And The Destination Is
SINT
INT
DINT
REAL
Structure
Structure
Structure
Structure
The Source Is Converted To
SINT
INT
DINT
REAL
SINT (not converted)
INT (not converted)
DINT (not converted)
REAL (not converted)
Arithmetic Status Flags:
Not affected
Fault Conditions:
None
Execution:
372
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Condition
Prescan
Rung-condition-in is false
Rung-condition-in is true.
End_address = start_address + (Length number of bytes in a destination element)
Array (file)/Misc. Instructions (FAL, FSC, COP, CPS, FLL, AVE, SRT, STD, SIZE)
Chapter 8
Relay Ladder Action
The rung-condition-out is set to false.
The rung-condition-out is set to false.
End_address > end of destination array
Yes
No
End_address = end of destination array
Source_address = Source
Destination_address =
end_address
Yes
No
Copy data in source_address to destination
_address
Destination_address = destination_address +
1
Rung-condition-out is set to true.
End
Postscan The rung-condition-out is set to false.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
373
Chapter 8
Array (file)/Misc. Instructions (FAL, FSC, COP, CPS, FLL, AVE, SRT, STD, SIZE)
Example:
The FLL instruction copies the value in
value_1 into dest_1
Relay Ladder
Source (value_1) Data
Type
SINT
DINT
SINT
REAL
SINT
Source (value_1) Value Destination (dest_1)
Data Type
16#80 (-128)
16#1234 5678
16#01
2.0
16#01
DINT
SINT
REAL
INT
TIMER
INT
DINT
16#0001
16#0000 0001
TIMER
TIMER
Destination (dest_1)
Value After FLL
16#FFFF FF80 (-128)
16#78
1.0
16#0002
16#0101 0101
16#0101 0101
16#0101 0101
16#0001 0001
16#0001 0001
16#0001 0001
16#0000 0001
16#0000 0001
16#0000 0001
Structured Text
dest_1 := value_1;
374
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
File Average (AVE)
Operands:
Array (file)/Misc. Instructions (FAL, FSC, COP, CPS, FLL, AVE, SRT, STD, SIZE)
Chapter 8
The AVE instruction calculates the average of a set of values.
Relay Ladder
Operand
Array
Dimension to vary
Type
SINT
INT
DINT
REAL
DINT
Format
Array tag
Immediate
(0, 1, 2)
Tag
Description
Find the average of the values in this array
Specify the first element of the group of elements to average
Do not use CONTROL.POS in the subscript
Which dimension to use
Depending on the number of dimensions, the order is: array[dim_0,dim_1,dim_2] array[dim_0,dim_1] array[dim_0]
Result of the operation Destination
Control
Length
Position
SINT
INT
DINT
REAL
CONTROL
DINT
DINT
Tag
Immediate
Immediate
Control structure for the operation
Number of elements of the array to average
Current element in the array
Initial value is typically 0
Structured Text
Structured text does not have an AVE instruction, but you can achieve the same results by using a SIZE instruction and a FOR...DO or other loop construct.
SIZE(array,0,length); sum := 0;
FOR position = 0 TO length-1 DO sum := sum + array[position];
END_FOR; destination := sum / length;
See Structured Text Programming
for information on the syntax of constructs within structured text.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
375
Chapter 8
Array (file)/Misc. Instructions (FAL, FSC, COP, CPS, FLL, AVE, SRT, STD, SIZE)
Mnemonic
.EN
.DN
.ER
.LEN
.POS
Data Type
BOOL
BOOL
BOOL
DINT
DINT
CONTROL Structure
Description
The enable bit indicates that the AVE instruction is enabled.
The done bit is set when the instruction has operated on the last element in the array (.POS = .LEN).
The error bit is set if the instruction generates an overflow. The instruction stops executing until the program clears the .ER bit. The position of the element that caused the overflow is stored in the .POS value.
The length specifies the number of elements in the array on which the instruction operates.
The position contains the position of the current element that the instruction is accessing.
Description:
The AVE instruction calculates the average of a set of values.
IMPORTANT
Make sure the Length does not cause the instruction to exceed the specified
Dimension to vary. If this happens, the Destination will be incorrect.
Arithmetic Status Flags:
Arithmetic status flags are affected.
Fault Conditions:
A Major Fault Will Occur If
.POS < 0 or .LEN < 0
Dimension to vary does not exist for the specified array 4
Fault Type
4
Fault Code
21
20
376
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Condition
Prescan
Rung-condition-in is false.
Array (file)/Misc. Instructions (FAL, FSC, COP, CPS, FLL, AVE, SRT, STD, SIZE)
Chapter 8
Execution:
Relay Ladder Action
The .EN bit is cleared.
The .DN bit is cleared.
The .ER bit is cleared.
The rung-condition-out is set to false.
Examine .DN Bit
.DN Bit = 1
.DN Bit = 0
.EN bit is cleared.
.ER bit is cleared.
.DN bit is cleared.
.POS value is cleared.
Rung-condition-out is set to false.
End
Rung-condition-in is true
Postscan
The AVE instruction calculates the average by adding all the specified elements in the array and dividing by the number of elements.
Internally, the instruction uses a FAL instruction to calculate the average:
Expression = average calculation
Mode = ALL
For details on how the FAL instruction executes, see page 347 .
The rung-condition-out is set to false.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
377
Chapter 8
Array (file)/Misc. Instructions (FAL, FSC, COP, CPS, FLL, AVE, SRT, STD, SIZE)
Dimension 0
Subscr ipt s
0 20
1
15
0
2
10
3
5
Example 1:
Average
array_dint, which is DINT[4,5].
19
14
Dimension 1
1 2
18
13
9 8
17
12
3
7
16
11
4
6
AVE
=
19
dint_ave = 12
+ 14
4
+ 9 + 4
=
46
11.5
4
=
4 3 2 1
Relay Ladder
Structured Text
SIZE(array_dint,0,length); sum := 0;
FOR position = 0 TO (length-1) DO sum := sum + array_dint[position];
END_FOR; dint_ave := sum / length;
378
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Array (file)/Misc. Instructions (FAL, FSC, COP, CPS, FLL, AVE, SRT, STD, SIZE)
Chapter 8
Dimension 0
Subs cripts
0 20
1
15
0
2
Example 2:
Average
array_dint, which is DINT[4,5].
10
19
14
Dimension 1
1 2
18
13
9 8
17
12
3
7
16
11
4
6
AVE
=
5
dint_ave = 3
+ 4 + 3
5
+ 2 + 1
=
15
3
5
=
3
5 4 3 2 1
Relay Ladder
Structured Text
SIZE(array_dint,1,length); sum := 0;
FOR position = 0 TO (length-1) DO sum := sum + array_dint[position];
END_FOR; dint_ave := sum / length;
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
379
Chapter 8
Array (file)/Misc. Instructions (FAL, FSC, COP, CPS, FLL, AVE, SRT, STD, SIZE)
File Sort (SRT)
Operands:
The SRT instruction sorts a set of values in one dimension (Dim to vary) of the
Array into ascending order.
Relay Ladder
Operand
Array
Dimension to vary
Type
SINT
INT
DINT
REAL
DINT
Control
Length
Position
CONTROL
DINT
DINT
Format
Array tag
Immediate
(0, 1, 2)
Tag
Immediate
Immediate
Description
Array to sort
Specify the first element of the group of elements to sort
Do not use CONTROL.POS in the subscript
Which dimension to use
Depending on the number of dimensions, the order is: array[dim_0,dim_1,dim_2] array[dim_0,dim_1] array[dim_0]
Control structure for the operation
Number of elements of the array to sort
Current element in the array
Initial value is typically 0
SRT(Array,Dimtovary,
Control);
Mnemonic
.EN
.DN
.ER
.LEN
.POS
Data Type
BOOL
BOOL
BOOL
DINT
DINT
Structured Text
The operands are the same as those for the relay ladder SRT instruction.
However, you specify the Length and Position values by accessing the .LEN and
.POS members of the CONTROL structure, rather than by including values in the operand list.
CONTROL Structure
Description
The enable bit indicates that the SRT instruction is enabled.
The done bit is set when the specified elements have been sorted.
The error bit is set when either .LEN < 0 or .POS < 0. Either of these conditions also generates a major fault.
The length specifies the number of elements in the array on which the instruction
The position contains the position of the current element that the instruction is accessing.
380
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Array (file)/Misc. Instructions (FAL, FSC, COP, CPS, FLL, AVE, SRT, STD, SIZE)
Chapter 8
Description:
The SRT instruction sorts a set of values in one dimension (Dim to vary) of the
Array into ascending order.
IMPORTANT
You must test and confirm that the instruction doesn’t change data that you don’t want it to change.
The SRT instruction operates on contiguous memory. In some cases, the instruction changes data in other members of the tag. This happens if the length is too big and the tag is a user-defined data type.
IMPORTANT
Make sure the Length does not cause the instruction to exceed the specified Dimension to vary. If this happens, unexpected results will occur.
This is a transitional instruction:
• In relay ladder, toggle the rung-condition-in from cleared to set each time the instruction should execute.
• In structured text, condition the instruction so that it only executes on a transition. See
Arithmetic Status Flags:
Arithmetic status flags are affected.
Fault Conditions:
A Major Fault Will Occur If
.POS < 0 or .LEN < 0
Dimension to vary does not exist for the specified array 4
Instruction tries to access data outside of the array boundaries
4
Fault Type
4
20
20
Fault Code
21
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
381
Chapter 8
Array (file)/Misc. Instructions (FAL, FSC, COP, CPS, FLL, AVE, SRT, STD, SIZE)
Condition
Prescan
Execution:
Relay Ladder Action
The .EN bit is cleared.
The .DN bit is cleared.
The .ER bit is cleared.
The rung-condition-out is set to false.
Rung-condition-in is false.
Examine .DN Bit
.DN Bit = 1
.DN Bit = 0
.EN bit is cleared.
.ER bit is cleared.
.DN bit is cleared.
.POS value is cleared.
Rung-condition-out is set to false.
End
Structured Text Action
The .EN bit is cleared.
The .DN bit is cleared.
The .ER bit is cleared.
N/A
Rung-condition-in is true
EnableIn is set
Instruction execution
Postscan
The instruction executes.
The rung-condition-out is set to true.
N/A
The instruction sorts the specified elements of the array into ascending order.
The rung-condition-out is set to false.
N/A
EnableIn is always set.
The instruction executes.
The instruction sorts the specified elements of the array into ascending order.
No action taken.
382
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Array (file)/Misc. Instructions (FAL, FSC, COP, CPS, FLL, AVE, SRT, STD, SIZE)
Chapter 8
Before
Dimension 0
Subscr ipts
0 20
1
15
Example 1:
Sort
int _array, which is DINT[4,5].
After
Dimension 1
Subs cripts
0 1 2 3 4
19
14
18
13
17
12
16
11
Dimension 0
0 20
1
15
0
2
10 9 8 7 6
2
10
3
5 4 3 2 1
3
5
9
4
19
14
Dimension 1
1 2
3
8
13
18
7
2
17
12
3
6
1
16
11
4
Relay Ladder
Structured Text
Before
Dimension 0 control_1.LEN := 4; control_1.POS := 0;
SRT(int_array[0,2],0,control_1);
Subs cripts
0 20
1
15
Example 2:
Sort int _array, which is DINT[4,5].
After
Dimension 1
0 1 2 3 4
Subs cripts
19
14
18
13
17
12
16
11
Dimension 0
0 20
1
15
0
2
10 9 8 7 6 2
6
3
5 4 3 2 1
3
5
7
4
19
14
Dimension 1
1 2
18
13
8
3
9
2
17
12
3
10
1
16
11
4
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
383
Chapter 8
Array (file)/Misc. Instructions (FAL, FSC, COP, CPS, FLL, AVE, SRT, STD, SIZE)
Relay Ladder
Structured Text
control_1.LEN := 5; control_1.POS := 0;
SRT(int_array[2,0],1,control_1);
384
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Array (file)/Misc. Instructions (FAL, FSC, COP, CPS, FLL, AVE, SRT, STD, SIZE)
Chapter 8
File Standard Deviation (STD)
The STD instruction calculates the standard deviation of a set of values in one dimension of the Array and stores the result in the Destination.
Operands:
Relay Ladder
Operand
Array
Dimension to vary
Destination
Control
Length
Position
Type
SINT
INT
DINT
REAL
Format
Array tag
Description
Find the standard deviation of the values in this array
Specify the first element of the group of elements to use in calculating the standard deviation
Do not use CONTROL.POS in the subscript
A SINT or INT tag converts to a DINT value by sign-extension.
DINT Immediate
(0, 1, 2)
Which dimension to use
Depending on the number of dimensions, the order is: array[dim_0,dim_1,dim_2] array[dim_0,dim_1] array[dim_0]
REAL
CONTROL
DINT
Tag
Tag
Immediate
Result of the operation
Control structure for the operation
DINT Immediate
Number of elements of the array to use in calculating the standard deviation
Current element in the array
Initial value is typically 0
Mnemonic
.EN
.DN
.ER
.LEN
.POS
Data Type
BOOL
BOOL
BOOL
DINT
DINT
CONTROL Structure
Description
The enable bit indicates that the STD instruction is enabled.
The done bit is set when the calculation is complete.
The error bit is set when the instruction generates an overflow. The instruction stops executing until the program clears the
.ER bit. The position of the element that caused the overflow is stored in the .POS value.
The length specifies the number of elements in the array on which the instruction operates.
The position contains the position of the current element that the instruction is accessing.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
385
Chapter 8
Array (file)/Misc. Instructions (FAL, FSC, COP, CPS, FLL, AVE, SRT, STD, SIZE)
Structured Text
Structured text does not have an STD instruction, but you can achieve the same results by using a SIZE instruction and a FOR...DO or other loop construct.
SIZE(array,0,length); sum := 0;
FOR position = 0 TO length-1 DO sum := sum + array[position];
END_FOR; average := sum / length; sum := 0;
FOR position = 0 TO length-1 DO sum := sum + ((array[position] - average)**2);
END_FOR; destination := SQRT(sum /(length-1));
See
Structured Text Programming for information on the syntax of constructs
within structured text.
386
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Array (file)/Misc. Instructions (FAL, FSC, COP, CPS, FLL, AVE, SRT, STD, SIZE)
Chapter 8
Description:
The standard deviation is calculated according to this formula:
Standard Deviation =
IMPORTANT
N
i
= 1
X
start
+
i
–
AVE
2
N
– 1
Where:
• start = dimension-to-vary subscript of the array operand
• x i
= variable element in the array
• N = number of specified elements in the array
• AVE =
N
i
= 1
x
start
+
i
-----------------------------------------
N
Make sure the length does not cause the instruction to exceed the specified dimension to vary. If this happens, the destination will be incorrect.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
387
Chapter 8
Array (file)/Misc. Instructions (FAL, FSC, COP, CPS, FLL, AVE, SRT, STD, SIZE)
Condition
Prescan
Arithmetic Status Flags:
Arithmetic status flags are affected.
Fault Conditions:
A major fault will occur if
.POS < 0 or .LEN < 0
Dimension to vary does not exist for the specified array 4
Fault type
4
Execution:
Relay Ladder Action
The .EN bit is cleared.
The .DN bit is cleared.
The .ER bit is cleared.
The rung-condition-out is set to false.
Rung-condition-in is false.
Examine .DN bit.
.DN Bit = 1
.DN Bit = 0
.EN bit is cleared.
.ER bit is cleared.
.DN bit is cleared.
Fault code
21
20
Rung-condition-out is set to
End
Rung-condition-in is true
Postscan
The STD instruction calculates the standard deviation of the specified elements.
Internally, the instruction uses a FAL instruction to calculate the average:
Expression = standard deviation calculation
Mode = ALL
For details on how the FAL instruction executes, see page 347 .
The rung-condition-out is set to false.
388
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Array (file)/Misc. Instructions (FAL, FSC, COP, CPS, FLL, AVE, SRT, STD, SIZE)
Chapter 8
Example 1:
Calculate the standard deviation of
dint_array, which is DINT[4,5].
Sub scripts
0
Dimension 1
1 2 3
0 20
1
15
Dimension 0
19
14
18
13
17
12
AVE
=
16 + 11
4
+ 6 + 1
=
34
8.5
4
=
2
10
3
5
9
4
8
3
7
2
6
1
16
11
4
STD
=
16 – 8.5
2
+
11 – 8.5
2
+
4 – 1
6 – 8.5
2
+
1 – 8.5
2
= 6.454972
real_std = 6.454972
Relay Ladder
Structured Text
SIZE(dint_array,0,length); sum := 0;
FOR position = 0 TO (length-1) DO sum := sum + dint_array[position];
END_FOR; average := sum / length; sum := 0;
FOR position = 0 TO (length-1) DO sum := sum + ((dint_array[position] - average)**2);
END_FOR; real_std := SQRT(sum / (length-1));
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
389
Chapter 8
Array (file)/Misc. Instructions (FAL, FSC, COP, CPS, FLL, AVE, SRT, STD, SIZE)
Example 2:
Calculate the standard deviation of d int_array, which is DINT[4,5].
Sub scripts
0
Dimension 1
1 2 3
0 20
1
15
Dimension 0
19
14
18
13
17
12
2
10 9 8 7
AVE
=
20 + 19 + 18
5
+ 17 + 16
=
90
18
5
=
3
5 4 3 2
6
1
16
11
4
STD
=
20 – 18
2
+
19 – 18
2
+
18
– 18
5 – 1
2
+
17 – 18
2
+
16 – 18
2
= 1.581139
real_std = 1.581139
Relay Ladder
390
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Array (file)/Misc. Instructions (FAL, FSC, COP, CPS, FLL, AVE, SRT, STD, SIZE)
Chapter 8
Structured Text
SIZE(dint_array,1,length); sum := 0;
FOR position = 0 TO (length-1) DO sum := sum + dint_array[position];
END_FOR; average := sum / length; sum := 0;
FOR position = 0 TO (length-1) DO sum := sum + ((dint_array[position] - average)**2);
END_FOR; real_std := SQRT(sum / (length-1));
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
391
Chapter 8
Array (file)/Misc. Instructions (FAL, FSC, COP, CPS, FLL, AVE, SRT, STD, SIZE)
Size In Elements (SIZE)
Operands:
The SIZE instruction finds the size of a dimension of an array.
Relay Ladder
Operand
Source
Dimension to
Vary
Type
SINT
INT
DINT
REAL structure string
DINT
Format
Array tag
Description
Array on which the instruction is to operate
Size SINT
INT
DINT
REAL
Immediate (0, 1,
2)
Dimension to use:
Tag
For The Size Of
First dimension
Second dimension
Third dimension
1
2
Enter
0
Tag to store the number of elements in the specified dimension of the array
Structured Text
SIZE(Source,Dimtovary,Size);
The operands are the same as those for the relay ladder SIZE instruction.
Description:
The SIZE instruction finds the number of elements (size) in the designated dimension of the Source array and places the result in the Size operand.
–
• The instruction finds the size of one dimension of an array.
• The instruction operates on an:
– Array
– Array in a structure
Array that is part of a larger array
Arithmetic Status Flags:
Not affected
Fault Conditions:
None.
392
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Condition
Prescan
Rung-condition-in is false
Rung-condition-in is true
EnableIn is set
Instruction execution
Postscan
Array (file)/Misc. Instructions (FAL, FSC, COP, CPS, FLL, AVE, SRT, STD, SIZE)
Chapter 8
Execution:
Relay Ladder Action
The rung-condition-out is set to false.
The rung-condition-out is set to false.
The instruction executes.
The rung-condition-out is set to true.
N/A
The instruction finds the size of a dimension.
The rung-condition-out is set to false.
Structured Text Action
No action taken.
N/A
N/A
EnableIn is always set.
The instruction executes.
The instruction finds the size of a dimension.
No action taken.
Example 1:
Find the number of elements in dimension 0 (first dimension) of array_a. Store the size in
array_a_size. In this example, dimension 0 of array_a has 10 elements.
Relay Ladder
SIZE
Size in Elements
Source array_a[0]
255
Dim. To Vary
Size
0 array_a_size
10
Structured Text
SIZE(array_a,0,array_a_size);
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
393
Chapter 8
Array (file)/Misc. Instructions (FAL, FSC, COP, CPS, FLL, AVE, SRT, STD, SIZE)
Example 2:
Find the number of elements in the DATA member of
string_1, which is a string.
Store the size in string_1_size. In this example, the DATA member of string_1 has
82 elements. (The string uses the default STRING data type.) Since each element holds one character, string_1 can contain up to 82 characters.
Relay Ladder
SIZE
Size in Elements
Source string_1.DATA[0]
'$00'
Dim. To Vary 0
Size string_1_size
82
Structured Text
SIZE(string_1.DATA[0],0,string_1_size);
394
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Array (file)/Misc. Instructions (FAL, FSC, COP, CPS, FLL, AVE, SRT, STD, SIZE)
Chapter 8
Example 3:
Strings_a is an array of string structures. The SIZE instruction finds the number of elements in the DATA member of the string structure and stores the size in
data_size_a. In this example, the DATA member has 24 elements. (The string structure has a user-specified length of 24.)
Relay Ladder
SIZE
Size in Elements
Source strings_a[0].DATA[0]
'$00'
Dim. To Vary 0
Size data_size_a
24
Structured Text
SIZE(strings_a[0].DATA[0],0,data_size_a);
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
395
Chapter 8
Array (file)/Misc. Instructions (FAL, FSC, COP, CPS, FLL, AVE, SRT, STD, SIZE)
Notes:
396
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Chapter
9
Array (file)/Shift Instructions
(BSL, BSR, FFL, FFU, LFL, LFU)
Topic
Page
If you want to
Load bits into, shift bits through, and unload bits from a bit array one bit at a time
Load and unload values in the same order
Load and unload values in reverse order
Use the array (file)/shift instructions to modify the location of data within arrays.
FFU
LFL
LFU
Use this instruction
BSL
BSR
FFL
Available in these languages
Relay ladder
Relay ladder
Relay ladder
Relay ladder
Relay ladder
Relay ladder
Page
You can mix data types, but loss of accuracy and rounding errors might occur.
For relay ladder instructions, bold data types indicate optimal data types. An instruction executes faster and requires less memory if all the operands of the instruction use the same optimal data type, typically DINT or REAL.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
397
Chapter 9
Array (file)/Shift Instructions (BSL, BSR, FFL, FFU, LFL, LFU)
Bit Shift Left (BSL)
The BSL instruction shifts the specified bits within the Array one position left.
Operands:
Relay Ladder
Operand
Array
Type
DINT
Control
Source bit
Length
CONTROL
BOOL
DINT
Format
Array tag
Tag
Tag
Immediate
Description
Array to modify
Specify the element where to begin the shift
Do not use CONTROL.POS in the subscript
Control structure for the operation
Bit to load
Number of bits in the array to shift
Mnemonic
.EN
.DN
.UL
.ER
.LEN
Data Type
BOOL
BOOL
BOOL
BOOL
DINT
CONTROL Structure
Description
The enable bit indicates that the BSL instruction is enabled.
The done bit is set to indicate that bits shifted one position to the left.
The unload bit is the instruction’s output. The .UL bit stores the status of the bit that was shifted out of the range of bits.
The error bit is set when .LEN < 0.
The length specifies the number of array bits to shift.
Description:
When enabled, the instruction unloads the uppermost bit of the specified bits to the .UL bit, shifts the remaining bits one position left, and loads Source bit into bit 0 of Array.
IMPORTANT
You must test and confirm that the instruction doesn’t change data that you don’t want it to change.
The BSL instruction operates on contiguous memory. If an Array is a member array, such as contained within a structure, it is possible that the instruction could shift beyond the Array’s boundary into other members following it. You must take care in choosing a length whereby this does not happen.
Arithmetic Status Flags:
Not affected
Fault Conditions:
A major fault will occur if
Length exceeds the size of Array's storage area.
Fault type
4
Fault code
20
398
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Condition
Prescan
Execution:
Rung-condition-in is false
Array (file)/Shift Instructions (BSL, BSR, FFL, FFU, LFL, LFU)
Chapter 9
Relay Ladder Action
The .EN bit is cleared.
The .DN bit is cleared.
The .ER bit is cleared.
The .POS value is cleared.
The rung-condition-out is set to false.
The .EN bit is cleared.
The .DN bit is cleared.
The .ER bit is cleared.
The .POS value is cleared.
The rung-condition-out is set to false.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
399
Chapter 9
Array (file)/Shift Instructions (BSL, BSR, FFL, FFU, LFL, LFU)
Condition
Rung-condition-in is true.
Relay Ladder Action
Examine .EN Bit
.EN Bit = 0
.EN bit is set.
.EN Bit = 1
.LEN = 0
Yes
No
.LEN < 0
Yes
No
Shift array one position to the left.
.UL Bit
Array
Source
Bit
.ER bit is set.
Postscan
.DN bit is set.
.POS = .LEN
.DN bit is set.
Examine Source Bit
.Source Bit = 1
.UL bit remains set.
.Source Bit = 0
.UL bit is set.
Rung-condition-out is set to
true.
End
The rung-condition-out is set to false.
400
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Array (file)/Shift Instructions (BSL, BSR, FFL, FFU, LFL, LFU)
Chapter 9
Example 1:
When enabled, the BSL instruction starts at bit 0 in array_dint[0]. The instruction unloads array_dint[0].9 into the .UL bit, shifts the remaining bits, and loads input_1 into array_dint[0].0. The values in the remaining bits (10…31) are invalid.
array_dint[0]
Before shift
9 8 7 6 5 4 3 2 1 0
1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0
0
.UL bit
These bits shift left
array_dint[0]
After shift
9 8 7 6 5 4 3 2 1 0
0 1 1 1 1 0 0 0 0 1
Example 2:
When enabled, the BSL instruction starts at bit 0 in array_dint[0]. The instruction unloads array_dint[1].25 into the .UL bit, shifts the remaining bits, and loads input_1 into array_dint[0].0. The values in the remaining bits (31…26 in array_dint[1]) are invalid. Note how array_dint[0].31 shifts across words to array_dint[1].0.
1
input_1
31
array_dint[0] 1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0
0
31
array_dint[1]
These bits shift left
0
0 0 1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0
1
input_1
0
.UL bit
These bits shift left
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
401
Chapter 9
Array (file)/Shift Instructions (BSL, BSR, FFL, FFU, LFL, LFU)
Bit Shift Right (BSR)
Operands:
The BSR instruction shifts the specified bits within the Array one position right.
Relay Ladder
Operand
Array
Type
DINT
Control
Source bit
Length
CONTROL
BOOL
DINT
Format
Array tag
Tag
Tag
Immediate
Description
Array to modify
Specify the element where to begin the shift
Do not use CONTROL.POS in the subscript
Control structure for the operation
Bit to load
Number of bits in the array to shift
Mnemonic
.EN
.DN
.UL
.ER
.LEN
Data Type
BOOL
BOOL
BOOL
BOOL
DINT
CONTROL Structure
Description
The enable bit indicates that the BSR instruction is enabled.
The done bit is set to indicate that bits shifted one position to the right.
The unload bit is the instruction’s output. The .UL bit stores the status of the bit that was shifted out of the range of bits.
The error bit is set when .LEN < 0.
The length specifies the number of array bits to shift.
Description:
When enabled, the instruction unloads the value at bit 0 of Array to the .UL bit, shifts the remaining bits one position right, and loads Source bit into the uppermost bit of the specified bits.
IMPORTANT
You must test and confirm that the instruction doesn’t change data that you don’t want it to change.
The BSR instruction operates on contiguous memory. If an Array is a member array, such as contained within a structure, it is possible that the instruction could shift beyond the Array’s boundary into other members following it. You must take care in choosing a length whereby this does not happen.
402
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Arithmetic Status Flags:
Not affected
Fault Conditions:
A major fault will occur if
Length exceeds the size of Array's storage area.
Execution:
Condition
Prescan
Array (file)/Shift Instructions (BSL, BSR, FFL, FFU, LFL, LFU)
Chapter 9
Fault type
4
Fault code
20
Rung-condition-in is false
Relay Ladder Action
The .EN bit is cleared.
The .DN bit is cleared.
The .ER bit is cleared.
The .POS value is cleared.
The rung-condition-out is set to false.
The .EN bit is cleared.
The .DN bit is cleared.
The .ER bit is cleared.
The .POS value is cleared.
The rung-condition-out is set to false.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
403
Chapter 9
Array (file)/Shift Instructions (BSL, BSR, FFL, FFU, LFL, LFU)
Condition
Rung-condition-in is true.
Relay Ladder Action
Examine .EN bit.
.EN Bit is set.
.EN Bit = 0
.EN Bit = 1
.LEN = 0
Yes
No
.LEN < 0
Yes
No
Shift array one position to the right.
Array
.UL Bit
.ER bit is set.
.DN bit is set.
.POS = .LEN
.DN bit is set.
Examine source bit.
.UL bit is set.
.Source Bit = 0
.Source Bit = 1
.UL bit remains set.
Rung-condition-out is set to
true.
End
Postscan The rung-condition-out is set to false.
404
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Array (file)/Shift Instructions (BSL, BSR, FFL, FFU, LFL, LFU)
Chapter 9
Example 1:
When enabled, the BSR instruction starts at bit 9 in
array_dint[0]. The instruction unloads array_dint[0].0 into the .UL bit, shifts the remaining bits right, and loads
input_1 into array_dint[0].9. The values in the remaining bits
(10…31) are invalid.
array_dint[0]
Before shift
9 8 7 6 5 4 3 2 1 0
1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0
These bits shift right
1
input_1
array_dint[0]
After shift
9 8 7 6 5 4 3 2 1 0
1 0 0 1 1 1 1 0 0 0
0
.UL bit
Example 2:
When enabled, the BSR instruction starts at bit 25 in
array_dint[1]. The instruction unloads array_dint[0].0 into the .UL bit, shifts the remaining bits right, and loads
input_1 into array_dint[1].25. The values in the remaining bits
(31…26 in dint_array[1]) are invalid. Note how array_dint[1].0 shifts across words into
array_dint[0].31.
31
array_dint[0] 1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0
0
These bits shift right
0
.UL bit
31
array_dint[1]
0
0 0 1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0
These bits shift right
1
input_1
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
405
Chapter 9
Array (file)/Shift Instructions (BSL, BSR, FFL, FFU, LFL, LFU)
FIFO Load (FFL)
The FFL instruction copies the Source value to the FIFO.
Operands:
Relay Ladder
Operand
Source
FIFO
Control
Length
Position
INT
DINT
REAL string structure
CONTROL
Type
SINT
INT
DINT
Format
Immediate
Tag
Description
Data to be stored in the FIFO
REAL string structure
The Source converts to the data type of the array tag. A smaller integer converts to a larger integer by sign-extension.
SINT Array tag FIFO to modify
Specify the first element of the FIFO
Do not use CONTROL.POS in the subscript
Tag
DINT
DINT
Immediate
Immediate
Control structure for the operation
Typically use the same CONTROL as the associated FFU
Maximum number of elements the FIFO can hold at one time
Next location in the FIFO where the instruction loads data
Initial value is typically 0
If you use a user-defined structure as the data type for the Source or FIFO operand, use the same structure for both operands.
406
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Array (file)/Shift Instructions (BSL, BSR, FFL, FFU, LFL, LFU)
Chapter 9
Mnemonic
.EN
.DN
.EM
.LEN
.POS
CONTROL Structure
Data Type
BOOL
BOOL
BOOL
DINT
DINT
Description
The enable bit indicates that the FFL instruction is enabled.
The done bit is set to indicate that the FIFO is full (.POS = .LEN). The .DN bit inhibits loading the FIFO until .POS < .LEN.
The empty bit indicates that the FIFO is empty. If .LEN 0 or .POS < 0, both the .EM bit and .DN bit are set.
The length specifies the maximum number of elements the FIFO can hold at one time.
The position identifies the location in the FIFO where the instruction will load the next value.
Description:
Use the FFL instruction with the FFU instruction to store and retrieve data in a first-in/first-out order. When used in pairs, the FFL and FFU instructions establish an asynchronous shift register.
Typically, the Source and the FIFO are the same data type.
When enabled, the FFL instruction loads the Source value into the position in the FIFO identified by the .POS value. The instruction loads one value each time the instruction is enabled, until the FIFO is full.
IMPORTANT
You must test and confirm that the instruction doesn’t change data that you don’t want it to change.
The FFL instruction operates on contiguous memory. In some cases, the instruction loads data past the array into other members of the tag. This happens if the length is too big and the tag is a user-defined data type.
Arithmetic Status Flags:
Not affected
Fault Conditions:
A major fault will occur if
(starting element + .POS) > FIFO array size
Fault type
4
Fault code
20
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
407
Chapter 9
Array (file)/Shift Instructions (BSL, BSR, FFL, FFU, LFL, LFU)
Execution:
Condition Relay Ladder Action
Prescan
.EN bit is set to prevent a false load when scan begins.
.LEN < 0
Yes
No
.POS < 0
.EM is cleared.
.DN is cleared.
No
Yes
.POS = 0
No
Yes
.EM is set.
.POS
.LEN
No
Yes
Rung-condition-out is set to
false.
End
.DN is set.
408
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
.EM is set.
.DN is set.
Condition Relay Ladder Action
Rung-condition-in is false.
.EN bit is cleared.
.LEN < 0
Yes
No
.POS < 0
.EM is cleared.
.DN is cleared.
No
Yes
.POS = 0
No
Yes
.EM is set.
.POS
.LEN
No
Yes
Rung-condition-out is set to
false.
End
.DN is set.
Array (file)/Shift Instructions (BSL, BSR, FFL, FFU, LFL, LFU)
Chapter 9
.EM is set.
.DN is set.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
409
Chapter 9
Array (file)/Shift Instructions (BSL, BSR, FFL, FFU, LFL, LFU)
Relay Ladder Action Condition
Rung-condition-in is true.
Examine .EN bit.
.EN = 0
.EN = 1
.LEN < 0
No
Yes
.POS < 0
No
.EM bit is cleared.
.DN is cleared.
Yes
.EN bit is set.
.EM bit is set.
.DN is set.
.LEN < 0
No
Yes
.POS < 0
No
.EM bit is cleared.
.DN is cleared.
.POS = .POS + 1
Yes
.POS
.LEN
No
Yes
.DN bit is set.
.POS = 0
No
Yes
.EM bit is set.
.POS or .LEN >
Size Of Array
Yes
No
Major Fault
.POS
.LEN
No
Yes
.DN bit is set.
.POS > .LEN
Yes
No
.POS = .POS - 1
FIFO[.POS - 1] = Source
.EM bit is set.
.DN is set.
Postscan
Rung-condition-out is set to
true.
End
The rung-condition-out is set to false.
410
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Array (file)/Shift Instructions (BSL, BSR, FFL, FFU, LFL, LFU)
Chapter 9
Example:
When enabled, the FFL instruction loads
value_1 into the next position in the
FIFO, which is array_dint[5] in this example.
array_dint[0] array_dint[5]
00000
00000
00000
00000
Before FIFO load
00000
11111
22222
33333
44444
00000
control_1.pos = 5 value_1 = 55555
00000
00000
00000
00000
After FIFO load
00000
11111
22222
33333
44444
55555
control_1.pos = 6
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
411
Chapter 9
Array (file)/Shift Instructions (BSL, BSR, FFL, FFU, LFL, LFU)
FIFO Unload (FFU)
Operands:
The FFU instruction unloads the value from position 0 (first position) of the
FIFO and stores that value in the Destination. The remaining data in the FIFO shifts down one position.
Relay Ladder
Operand
FIFO
Destination
Control
Length
Position
Type
SINT
INT
DINT
REAL string structure
SINT
Format
Array tag
Tag
Description
FIFO to modify
Specify the first element of the FIFO
Do not use CONTROL.POS in the subscript
Value that exits the FIFO
INT
DINT
REAL string structure
The Destination value converts to the data type of the Destination tag. A smaller integer converts to a larger integer by sign-extension.
CONTROL Tag Control structure for the operation
DINT
DINT
Immediate
Immediate
Typically use the same CONTROL as the associated FFL
Maximum number of elements the FIFO can hold at one time
Next location in the FIFO where the instruction unloads data
Initial value is typically 0
If you use a user-defined structure as the data type for the FIFO or Destination operand, use the same structure for both operands.
412
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Array (file)/Shift Instructions (BSL, BSR, FFL, FFU, LFL, LFU)
Chapter 9
Mnemonic
.EU
.DN
.EM
.LEN
.POS
Data Type
BOOL
BOOL
BOOL
DINT
DINT
CONTROL Structure
Description
The enable unload bit indicates that the FFU instruction is enabled. The .EU bit is set to preset a false unload when the program scan begins.
The done bit is set to indicate that the FIFO is full (.POS = .LEN).
The empty bit indicates that the FIFO is empty. If .LEN 0 or .POS < 0, the .EM bit and .DN bits are set.
The length specifies the maximum number of elements in the FIFO.
The position identifies the end of the data that has been loaded into the FIFO.
Description:
Use the FFU instruction with the FFL instruction to store and retrieve data in a first-in/first-out order.
When enabled, the FFU instruction unloads data from the first element of the
FIFO and places that value in the Destination. The instruction unloads one value each time the instruction is enabled, until the FIFO is empty. If the FIFO is empty, the FFU returns 0 to the Destination.
IMPORTANT
You must test and confirm that the instruction doesn’t change data that you don’t want it to change.
The FFU instruction operates on contiguous memory. In some cases, the instruction unloads data from other members of the tag. This happens if the length is too big and the tag is a user-defined data type.
Arithmetic Status Flags:
Not affected
Fault Conditions:
A major fault will occur if
Length > FIFO array size
Fault type
4
Fault code
20
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
413
Chapter 9
Array (file)/Shift Instructions (BSL, BSR, FFL, FFU, LFL, LFU)
Execution:
Condition Relay Ladder Action
Prescan
.EU bit is set to prevent a false unload when scan begins.
.LEN < 0
No
Yes
.EM is cleared.
.DN is cleared.
.POS < 0
No
Yes
.POS = 0
No
Yes
.EM is set.
.POS
.LEN
No
Yes
Rung-condition-out is set to
false.
End
.DN is set.
414
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
.EM is set.
.DN is set.
Condition Relay Ladder Action
Rung-condition-in is false.
.EU bit is cleared.
.LEN < 0
No
Yes
Yes
.EM is cleared.
.DN is cleared.
.POS < 0
No
.POS = 0
No
Yes
.EM is set.
.POS
.LEN
No
Yes
Rung-condition-out is set to
false.
End
.DN is set.
Array (file)/Shift Instructions (BSL, BSR, FFL, FFU, LFL, LFU)
Chapter 9
.EM is set.
.DN is set.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
415
Chapter 9
Array (file)/Shift Instructions (BSL, BSR, FFL, FFU, LFL, LFU)
Relay Ladder Action Condition
Rung-condition-in is true.
Examine .EU bit.
.EU = 1
.EU = 0
.LEN < 0
Yes
No
.POS < 0
No
.EM bit is cleared.
.DN is cleared.
Yes
.EU bit is set.
.EM bit is set.
.DN is set.
.POS = 0
No
Yes
.EM bit is set.
.POS
.LEN
No
Yes
.DN bit is set.
.LEN < 0
No
Yes
.POS < 0
No
.EM bit is cleared.
.DN is cleared.
Yes
.LEN > Size
Of Array
No
Yes
Major Fault
.POS
1
No
Yes
.EM bit is set.
.POS < 1
No
.POS = .POS -1
Destination = FIFO[0]
Yes
FIFO[i - 1] = FIFO[i] i = i +1
Destination = 0 i < .LEN
No
Yes
Rung-condition-out is set to
true.
End
.EM bit is set.
Postscan The rung-condition-out is set to false.
416
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Array (file)/Shift Instructions (BSL, BSR, FFL, FFU, LFL, LFU)
Chapter 9
Example:
When enabled, the FFU instruction unloads
array_dint[0] into value_2 and shifts the remaining elements in array_dint.
array_dint[0] array_dint[5]
Before FIFO unload
00000
00000
00000
00000
00000
11111
22222
33333
44444
55555
control_1.pos = 6
After FIFO unload
11111
00000
00000
00000
00000
22222
33333
44444
55555
00000
control_1.pos = 5 value_2 = 00000
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
417
Chapter 9
Array (file)/Shift Instructions (BSL, BSR, FFL, FFU, LFL, LFU)
LIFO Load (LFL)
The LFL instruction copies the Source value to the LIFO.
Operands:
Relay Ladder
Operand
Source
LIFO
Control
Length
Position
INT
DINT
REAL string structure
CONTROL
Type
SINT
INT
DINT
Format
Immediate
Tag
Description
Data to be stored in the LIFO
REAL string structure
The Source converts to the data type of the array tag. A smaller integer converts to a larger integer by sign-extension.
SINT
Array tag LIFO to modify
Specify the first element of the LIFO
Do not use CONTROL.POS in the subscript
Tag
DINT
DINT
Immediate
Immediate
Control structure for the operation
Typically use the same CONTROL as the associated LFU
Maximum number of elements the LIFO can hold at one time
Next location in the LIFO where the instruction loads data initial value is typically 0
If you use a user-defined structure as the data type for the Source or LIFO operand, use the same structure for both operands.
418
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Array (file)/Shift Instructions (BSL, BSR, FFL, FFU, LFL, LFU)
Chapter 9
Mnemonic
.EN
.DN
.EM
.LEN
.POS
CONTROL Structure
Data Type
BOOL
BOOL
BOOL
DINT
DINT
Description:
The enable bit indicates that the LFL instruction is enabled.
The done bit is set to indicate that the LIFO is full (.POS = .LEN). The .DN bit inhibits loading the LIFO until .POS < .LEN.
The empty bit indicates that the LIFO is empty. If .LEN 0 or .POS < 0, both the .EM bit and .DN bit are set.
The length specifies the maximum number of elements the LIFO can hold at one time.
The position identifies the location in the LIFO where the instruction will load the next value.
Description:
Use the LFL instruction with the LFU instruction to store and retrieve data in a last-in/first-out order. When used in pairs, the LFL and LFU instructions establish an asynchronous shift register.
Typically, the Source and the LIFO are the same data type.
When enabled, the LFL instruction loads the Source value into the position in the LIFO identified by the .POS value. The instruction loads one value each time the instruction is enabled, until the LIFO is full.
IMPORTANT
Arithmetic Status Flags:
Not affected
Fault Conditions:
A major fault will occur if
(starting element + .POS) > LIFO array size
You must test and confirm that the instruction doesn’t change data that you don’t want it to change.
The LFL instruction operates on contiguous memory. In some cases, the instruction loads data past the array into other members of the tag. This happens if the length is too big and the tag is a user-defined data type.
Fault type
4
Fault code
20
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
419
Chapter 9
Array (file)/Shift Instructions (BSL, BSR, FFL, FFU, LFL, LFU)
Execution:
Condition
Prescan
.EN bit is set to prevent a false load when scan begins.
.LEN < 0
Yes
No
.POS < 0
.EM is cleared.
.DN is cleared.
No
Yes
.POS = 0
No
Yes
.EM is set.
Relay Ladder Action
.EM is set.
.DN is set.
.POS
.LEN
No
Yes
Rung-condition-out is set to
false.
End
.DN is set.
420
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Condition
Rung-condition-in is false.
.EN bit is cleared.
.LEN < 0
No
.POS < 0
.EM is cleared.
.DN is cleared.
No
Yes
Yes
.POS = 0
No
Yes
.EM is set.
.POS
.LEN
No
Yes
Rung-condition-out is set to
false.
End
.DN is set.
Array (file)/Shift Instructions (BSL, BSR, FFL, FFU, LFL, LFU)
Chapter 9
Relay Ladder Action
.EM is set.
.DN is set.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
421
Chapter 9
Array (file)/Shift Instructions (BSL, BSR, FFL, FFU, LFL, LFU)
Condition
Rung-condition-in is true.
Examine .EN bit.
.EN = 0
.EN = 1
.LEN < 0
No
Yes
.POS < 0
Yes
No
.EM bit is cleared.
.DN is cleared.
Relay Ladder Action
.POS = 0
No
Yes
.EM bit is set.
.POS
.LEN
No
Yes
.DN bit is set.
.EN bit is set.
.LEN < 0
No
Yes
.POS < 0
No
.EM bit is cleared.
.DN is cleared.
.POS = .POS + 1
Yes
.EM bit is set.
.DN is set.
.POS
.LEN
No
Yes
.DN bit is set.
.POS or .LEN >
Size Of Array
Yes
No
Major Fault
.POS > .LEN
No
Yes
.POS = .POS - 1
FIFO[.POS - 1] = Source
.EM bit is set.
.DN is set.
Rung-condition-out is set to
true.
End
422
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Array (file)/Shift Instructions (BSL, BSR, FFL, FFU, LFL, LFU)
Chapter 9
Example:
When enabled, the LFL instruction loads
value_1 into the next position in the
LIFO, which is array_dint[5] in this example.
array_dint[0] array_dint[5]
00000
00000
00000
00000
Before LIFO load
00000
11111
22222
33333
44444
00000
control_1.pos = 5 value_1 = 55555
00000
00000
00000
00000
After LIFO load
00000
11111
22222
33333
44444
55555
control_1.pos = 6
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
423
Chapter 9
Array (file)/Shift Instructions (BSL, BSR, FFL, FFU, LFL, LFU)
LIFO Unload (LFU)
Operands:
The LFU instruction unloads the value at .POS of the LIFO and stores 0 in that location.
Relay Ladder
Operand
LIFO
Destination
Control
Length
Position
Type
SINT
INT
DINT
REAL string structure
SINT
Format
Array tag
Tag
Description
LIFO to modify
Specify the first element of the LIFO
Do not use CONTROL.POS in the subscript
Value that exits the LIFO
INT
DINT
REAL string structure
The Destination value converts to the data type of the Destination tag. A smaller integer converts to a larger integer by sign-extension.
CONTROL Tag Control structure for the operation
DINT
DINT
Immediate
Immediate
Typically use the same CONTROL as the associated LFL
Maximum number of elements the LIFO can hold at one time
Next location in the LIFO where the instruction unloads data
Initial value is typically 0
If you use a user-defined structure as the data type for the LIFO or Destination operand, use the same structure for both operands.
424
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Array (file)/Shift Instructions (BSL, BSR, FFL, FFU, LFL, LFU)
Chapter 9
Mnemonic
.EU
.DN
.EM
.LEN
.POS
Data Type:
BOOL
BOOL
BOOL
DINT
DINT
CONTROL Structure
Description
The enable unload bit indicates that the LFU instruction is enabled. The .EU bit is set to preset a false unload when the program scan begins.
The done bit is set to indicate that the LIFO is full (.POS = .LEN).
The empty bit indicates that the LIFO is empty. If .LEN 0 or .POS < 0, both the .EM bit and .DN bit are set.
The length specifies the maximum number of elements the LIFO can hold at one time.
The position identifies the end of the data that has been loaded into the LIFO.
Description:
Use the LFU instruction with the LFL instruction to store and retrieve data in a last-in/first-out order.
When enabled, the LFU instruction unloads the value at .POS of the LIFO and places that value in the Destination. The instruction unloads one value and replaces it with 0 each time the instruction is enabled, until the LIFO is empty. If the LIFO is empty, the LFU returns 0 to the Destination.
IMPORTANT
You must test and confirm that the instruction doesn’t change data that you don’t want it to change.
The LFU instruction operates on contiguous memory. In some cases, the instruction unloads data from other members of the tag. This happens if the length is too big and the tag is a user-defined data type.
Arithmetic Status Flags:
Not affected
Fault Conditions:
A major fault will occur if
Length > LIFO array size
Fault type
4
Fault code
20
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
425
Chapter 9
Array (file)/Shift Instructions (BSL, BSR, FFL, FFU, LFL, LFU)
Condition
Prescan
.EU bit is set to prevent a false unload when scan begins.
Execution:
Relay Ladder Action
.LEN < 0
No
.POS < 0
.EM is cleared.
.DN is cleared
No
Yes
Yes
.EM is set
.DN is set
.POS = 0
No
Yes
.EM is set.
.POS
.LEN
no
Yes
rung-condition-out is set to
false.
End
.DN is set.
426
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Condition
Rung-condition-in is false.
.EU bit is cleared.
Relay Ladder Action
.LEN < 0
No
.POS < 0
.EM is cleared.
.DN is cleared.
No
Yes
Yes
.POS = 0
No
Yes
.EM is set.
.EM is set.
.DN is set.
Array (file)/Shift Instructions (BSL, BSR, FFL, FFU, LFL, LFU)
Chapter 9
.POS
.LEN
No
Yes
Rung-condition-out is set to
false.
End
.DN is set.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
427
Chapter 9
Array (file)/Shift Instructions (BSL, BSR, FFL, FFU, LFL, LFU)
Condition
Rung-condition-in is true.
Examine .EU bit.
.EU = 1
.EU = 0
Yes
.LEN < 0
No
.POS < 0
No
.EM bit is cleared
.DN is cleared
Yes
.EU bit is set.
Relay Ladder Action
.LEN < 0
No
Yes
.POS < 0
No
.EM bit is cleared.
.DN is cleared.
Yes
.POS = 0
No
Yes
.EM bit is set.
.POS
.LEN
No
Yes
.DN bit is set.
.EM bit is set.
.DN is set.
.POS
1
No
Yes
.EM bit is set.
Yes
.POS < 1
No
.POS
LEN
.POS = .POS -1
No
Yes
Destination = 0
.POS = .LEN
.LEN > Size Of
Array
Yes
No
Destination = LIFO[control.POS]
LIFO[control.POS) = 0
Major Fault
.EM bit is set.
.DN is set.
Postscan
Rung-condition-out is set to
true.
End
The rung-condition-out is set to false.
428
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Array (file)/Shift Instructions (BSL, BSR, FFL, FFU, LFL, LFU)
Chapter 9
Example:
When enabled, the LFU instruction unloads
array_dint[5] into value_2.
array_dint[0] array_dint[5]
Before LIFO unload
00000
55555
00000
00000
00000
00000
11111
22222
33333
44444
control_1.pos = 6
After LIFO unload
00000
00000
00000
00000
00000
00000
11111
22222
33333
44444
control_1.pos = 5
value_2 = 55555
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
429
Chapter 9
Array (file)/Shift Instructions (BSL, BSR, FFL, FFU, LFL, LFU)
Notes:
430
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Chapter
10
Sequencer Instructions
(SQI, SQO, SQL)
If you want to
Detect when a step is complete
Set output conditions for the next step
Load reference conditions into sequencer arrays
Topic
Page
No action taken. Sequencer instructions monitor consistent and repeatable operations.
Use this instruction
SQI
SQO
SQL
Available in these languages
Relay ladder
Relay ladder
Relay ladder
Page
For relay ladder instructions, bold data types indicate optimal data types. An instruction executes faster and requires less memory if all the operands of the instruction use the same optimal data type, typically DINT or REAL.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
431
Chapter 10
Sequencer Instructions (SQI, SQO, SQL)
Sequencer Input (SQI)
Operands:
The SQI instruction detects when a step is complete in a sequence pair of SQO/
SQI instructions.
Relay Ladder
Operand
Array
Mask
Source
Control
Length
Position
Type
DINT
Format
Array tag
Description
Sequencer array
Specify the first element of the sequencer array
Do not use CONTROL.POS in the subscript
Which bits to block or pass SINT
INT
DINT
Tag
Immediate
A SINT or INT tag converts to a DINT value by sign-extension.
SINT
INT
DINT
Tag Input data for the sequencer array
A SINT or INT tag converts to a DINT value by sign-extension.
CONTROL Tag Control structure for the operation
Typically use the same CONTROL as the SQO and SQL instructions
DINT Immediate
DINT Immediate
Number of elements in the Array (sequencer table) to compare
Current position in the array initial value is typically 0
Mnemonic
.ER
.LEN
.POS
Data Type
BOOL
DINT
DINT
CONTROL Structure
Description
The error bit is set when .LEN 0, .POS < 0, or .POS > .LEN.
The length specifies the number of steps in the sequencer array.
The position identifies the element that the instruction is currently comparing.
Description:
When enabled, the SQI instruction compares a Source element through a Mask to an Array element for equality.
Typically use the same CONTROL structure as the SQO and SQL instructions.
The SQI instruction operates on contiguous memory.
432
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Sequencer Instructions (SQI, SQO, SQL)
Chapter 10
Enter an Immediate Mask Value
When you enter a mask, the programming software defaults to decimal values. If you want to enter a mask by using another format, precede the value with the correct prefix.
Prefix
16#
8#
2#
Description
Hexadecimal
For example; 16#0F0F
Octal
For example; 8#16
Binary
For example; 2#00110011
Arithmetic Status Flags:
Not affected
Fault Conditions:
None
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
433
Chapter 10
Sequencer Instructions (SQI, SQO, SQL)
Execution:
Condition:
Prescan
Rung-condition-in is false
Relay Ladder Action
The rung-condition-out is set to false.
The rung-condition-out is set to false.
Rung-condition-in is true.
.LEN 0 .POS < 0 or
.POS > .LEN
.ER bit is set.
Yes
No
.ER bit is cleared.
Rung-condition-out is set to false.
No
Masked Source =
MaskedArray[.POS] yes
Rung-condition-out is set to true.
End
Postscan The rung-condition-out is set to false.
434
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Sequencer Instructions (SQI, SQO, SQL)
Chapter 10
Example:
When enabled, the SQI instruction passes
value_2 through the mask to determine whether the result is equal to the current element in array_dint. The masked comparison is true, so the rung-condition-out goes true.
SQI Operand
Source
Mask
Array
Example Values (DINTs Displayed In Binary) xxxxxxxx xxxxxxxx xxxx0101 xxxx1010
00000000 00000000 00001111 00001111 xxxxxxxx xxxxxxxx xxxx0101 xxxx1010
A 0 in the mask means the bit is not compared (designated by sextets in this example).
Use SQI without SQO
If you use the SQI instruction without a paired SQO instruction, you have to externally increment the sequencer array.
The SQI instruction compares the source value. The ADD instruction increments the sequencer array. The GRT determined whether another value is available to check in the sequencer array. The MOV instruction resets the position value after completely stepping through the sequencer array one time.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
435
Chapter 10
Sequencer Instructions (SQI, SQO, SQL)
Sequencer Output (SQO)
Operands:
The SQO instruction sets output conditions for the next step of a sequence pair of SQO/SQI instructions.
Mnemonic
.EN
.DN
.ER
.LEN
.POS
Relay Ladder
Operand
Array
Mask
Destination
Control
Length
Position
Type
DINT
Format
Array tag
Description
Sequencer array
Specify the first element of the sequencer array
Do not use CONTROL.POS in the subscript
Which bits to block or pass SINT
INT
DINT
Tag
Immediate
A SINT or INT tag converts to a DINT value by sign-extension.
DINT Tag Output data from the sequencer array
CONTROL Tag Control structure for the operation typically use the same CONTROL as the SQI and SQL instructions
DINT
DINT
Immediate
Immediate
Number of elements in the Array (sequencer table) to output
Current position in the array
Initial value is typically 0
Data Type
BOOL
BOOL
BOOL
DINT
DINT
CONTROL Structure
Description
The enable bit indicates that the SQO instruction is enabled.
The done bit is set when all the specified elements have been moved to the Destination.
The error bit is set when .LEN 0, .POS < 0, or .POS > .LEN.
The length specifies the number of steps in the sequencer array.
The position identifies the element that the controller is currently manipulating.
Description:
When enabled, the SQO instruction increments the position, moves the data at the position through the Mask, and stores the result in the Destination. If .POS >
.LEN, the instruction wraps around to the beginning of the sequencer array and continues with .POS = 1.
Typically, use the same CONTROL structure as the SQI and SQL instructions.
The SQO instruction operates on contiguous memory.
436
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Sequencer Instructions (SQI, SQO, SQL)
Chapter 10
Enter an Immediate Mask Value
When you enter a mask, the programming software defaults to decimal values. If you want to enter a mask by using another format, precede the value with the correct prefix.
Prefix
16#
8#
2#
Description
Hexadecimal
For example; 16#0F0F
Octal
For example; 8#16
Binary
For example; 2#00110011
Arithmetic Status Flags
Not affected
Fault Conditions:
None
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
437
Chapter 10
Sequencer Instructions (SQI, SQO, SQL)
Execution:
Condition
Prescan
Rung-condition-in is false
Rung-condition-in is true.
.LEN 0 or
.POS < 0
No
Yes
.POS = .LEN
No
Yes
.DN bit is set.
Examine .EN bit.
.EN = 1
.EN = 0
Relay Ladder Action
The .EN bit is set to prevent a false load when the program scan begins.
The rung-condition-out is set to false.
The .EN bit is cleared.
The rung-condition-out is set to false.
.EN bit is set.
.ER bit is cleared.
.DN bit is set.
.POS .LEN
No
.POS = .POS + 1
Yes
.POS = 1
.POS Value rolls over
No
Yes
Goto
Error
Postscan
.POS = .LEN
Yes
No
.POS > .LEN No
Yes
.DN bit is set.
Error
.ER bit is set.
Destination = (Destination AND (NOT(Mask))) OR
(Array[control.POS] AND Mask)
Rung-condition-out is set to true.
The rung-condition-out is set to false.
438
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Sequencer Instructions (SQI, SQO, SQL)
Chapter 10
Example:
When enabled, the SQO instruction increments the position, passes the data at that position in array_dint through the mask, and stores the result in value_1.
SQO Operand
Array
Mask
Destination
Example Values (Using INTS Displayed In Binary) xxxxxxxx xxxxxxxx xxxx0101 xxxx1010
00000000 00000000 00001111 00001111 xxxxxxxx xxxxxxxx xxxx0101 xxxx1010
A 0 in the mask means the bit is not compared (designated by xxxx in this example).
Using SQI with SQO
If you pair an SQI instruction with an SQO instruction, make sure that both instructions use the same Control, Length, and Position values.
Resetting the Position of SQO
Each time the controller goes from Program to Run mode, the SQO instruction clears (initializes) the .POS value. To reset .POS to the initialization value (.POS = 0), use a RES instruction to clear the position value. This example uses the status of the first-scan bit to clear the .POS value.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
439
Chapter 10
Sequencer Instructions (SQI, SQO, SQL)
Sequencer Load (SQL)
Operands:
The SQL instruction loads reference conditions into a sequencer array.
Relay Ladder
Operand
Array
Source
Control
Length
Position
Type
DINT
Format
Array tag
Description
Sequencer array
Specify the first element of the sequencer array
Do not use CONTROL.POS in the subscript
Input data to load into the sequencer array SINT
INT
DINT
Tag
Immediate
A SINT or INT tag converts to a DINT value by sign-extension.
CONTROL Tag Control structure for the operation
Typically use the same CONTROL as the SQI and SQO instructions
DINT
DINT
Immediate
Immediate
Number of elements in the Array (sequencer table) to load
Current position in the array
Initial value is typically 0
Mnemonic
.EN
.DN
.ER
.LEN
.POS
CONTROL Structure
Data Type
BOOL
BOOL
BOOL
DINT
DINT
Description
The enable bit indicates that the SQL instruction is enabled.
The done bit is set when all the specified elements have been loaded into Array.
The error bit is set when .LEN 0, .POS < 0, or .POS > .LEN.
The length specifies the number of steps in the sequencer array.
The position identifies the element that the controller is currently manipulating.
Description:
When enabled, the SQL instruction increments to the next position in the sequencer array and loads the Source value into that position. If the .DN bit is set or if .POS .LEN, the instruction sets .POS=1.
Typically use the same CONTROL structure as the SQI and SQO instructions.
IMPORTANT
You must test and confirm that the instruction doesn’t change data that you don’t want it to change.
The SQL instruction operates on contiguous memory. In some cases, the instruction loads data past the array into other members of the tag. This happens if the length is too big and the tag is a user-defined data type.
Arithmetic Status Flags:
Not affected
440
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Sequencer Instructions (SQI, SQO, SQL)
Chapter 10
Condition
Prescan
Rung-condition-in is false
Fault Conditions:
A major fault will occur if
Length > size of Array
Execution:
Fault type
4
Relay Ladder Action
The .EN bit is set to prevent a false load when the program scan begins.
The rung-condition-out is set to false.
The .EN bit is cleared.
The rung-condition-out is set to false.
Fault code
20
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
441
Chapter 10
Sequencer Instructions (SQI, SQO, SQL)
Condition
Rung-condition-in is true.
Relay Ladder Action
.LEN 0 or
.POS < 0
Yes
No
.POS = .LEN
.DN bit is set.
Yes
No examine .EN bit
.EN = 1
.EN = 0
.EN bit is set.
.ER bit is cleared.
.DN bit is set.
.POS .LEN
No
.POS = .POS + 1
Yes
.POS Value
Rolls Over
No
Yes
.POS = 1
Goto
Error
Postscan
442
Error
.ER bit is set.
.POS = .LEN
No
Yes
.POS > .LEN
Yes
No
.DN bit is set.
.LEN > size of array
Yes
No
Major Fault
Array[control.POS] = Source
Rung-condition-out is set to
true.
end
The rung-condition-out is set to false.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Sequencer Instructions (SQI, SQO, SQL)
Chapter 10
Example:
When enabled, the SQL instruction loads
value_3 into the next position in the sequencer array, which is array_dint[5] in this example.
array_dint[0] array_dint[5]
33333
44444
00000
00000
Before load
00000
11111
22222
00000
00000
00000
control_1.pos = 5
value_3 = 55555
33333
44444
55555
00000
After load
00000
11111
22222
00000
00000
00000
control_1.pos = 6
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
443
Chapter 10
Sequencer Instructions (SQI, SQO, SQL)
Notes:
444
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Chapter
11
Program Control Instructions
(JMP, LBL, JSR, RET, SBR, JXR, TND, MCR, UID, UIE, AFI, NOP, EOT, SFP,
SFR, EVENT)
Topic Page
Jump to Label (JMP) Label (LBL) 447
Jump to Subroutine (JSR) Subroutine (SBR) Return (RET) 449
Jump to External Routine (JXR)
Master Control Reset (MCR) 464
User Interrupt Disable (UID) User Interrupt Enable (UIE) 466
Always False Instruction (AFI)
Use the program control instructions to change the flow of logic.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
445
Chapter 11
Program Control Instructions (JMP, LBL, JSR, RET, SBR, JXR, TND, MCR, UID, UIE, AFI, NOP, EOT, SFP, SFR, EVENT)
If you want to
Jump over a section of logic that does not always need to be executed
Jump to a separate routine, pass data to the routine, execute the routine, and return results
Jump to an external routine (SoftLogix5800 controller only)
Mark a temporary end that halts routine execution
Use this instruction
JMP
LBL
JSR
SBR
RET
JXR
TND
Disable all the rungs in a section of logic
Disable user tasks
MCR
UID
Enable user tasks
Disable a rung
Insert a placeholder in the logic
End a transition for a sequential function chart
UIE
AFI
NOP
EOT
Pause a sequential function chart
Reset a sequential function chart
Trigger the execution of an event task
SFP
SFR
EVENT
Available in these languages
Relay ladder
Relay ladder
Function block
Structured text
Relay ladder
Relay ladder
Structured text
Relay ladder
Relay ladder
Structured text
Relay ladder
Structured text
Relay ladder
Relay ladder
Relay ladder
Structured text
Relay ladder
Structured text
Relay ladder
Structured text
Relay ladder
Structured text
Page
436
446
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Program Control Instructions (JMP, LBL, JSR, RET, SBR, JXR, TND, MCR, UID, UIE, AFI, NOP, EOT, SFP, SFR, EVENT)
Chapter 11
Jump to Label (JMP)
Label (LBL)
Operands:
The JMP and LBL instructions skip portions of ladder logic.
Relay Ladder
Operand
JMP instruction
Label name
LBL instruction
Label name
Type Format
Label name
Description
Enter name for associated LBL instruction
Label name Execution jumps to LBL instruction with referenced label name
Description:
When enabled, the JMP instruction skips to the referenced LBL instruction and the controller continues executing from there. When disabled, the JMP instruction does not affect ladder execution.
The JMP instruction can move ladder execution forward or backward. Jumping forward to a label saves program scan time by omitting a logic segment until it’s needed. Jumping backward lets the controller repeat iterations of logic.
Be careful not to jump backward an excessive number of times. The watchdog timer could time out because the controller never reaches the end of the logic, which in turn faults the controller.
ATTENTION: Jumped logic is not scanned. Place critical logic outside the jumped zone.
The LBL instruction is the target of the JMP instruction that has the same label name. Make sure the LBL instruction is the first instruction on its rung.
A label name must be unique within a routine. The name can include the following:
• Have as many as 40 characters
• Contain letters, numbers, and underscores (_)
Arithmetic Status Flags:
Not affected
Fault Conditions:
A major fault will occur if
Label does not exist 4
Fault type Fault code
42
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
447
Chapter 11
Program Control Instructions (JMP, LBL, JSR, RET, SBR, JXR, TND, MCR, UID, UIE, AFI, NOP, EOT, SFP, SFR, EVENT)
Condition:
Prescan
Rung-condition-in is false
Rung-condition-in is true
Postscan
Execution:
Relay Ladder Action
The rung-condition-out is set to false.
The rung-condition-out is set to false.
The rung-condition-out is set to true.
Execution jumps to the rung that contains the LBL instruction with the referenced label name.
The rung-condition-out is set to false.
Example:
When the JMP instruction is enabled, execution jumps over successive rungs of logic until it reaches the rung that contains the LBL instruction with
label_20.
[Other Rungs of Code]
448
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Program Control Instructions (JMP, LBL, JSR, RET, SBR, JXR, TND, MCR, UID, UIE, AFI, NOP, EOT, SFP, SFR, EVENT)
Chapter 11
Jump to Subroutine (JSR)
Subroutine (SBR) Return
(RET)
JSR Operands:
The JSR instruction jumps execution to a different routine. The SBR and RET instructions are optional instructions that exchange data with the JSR instruction.
Relay Ladder
Operand Type
Routine name ROUTINE
Input parameter BOOL
SINT
INT
DINT
REAL
Structure
Return parameter
BOOL
SINT
INT
DINT
REAL
Structure
Format
Name
Immediate
Tag
Array tag
Description
Routine to execute (that is, subroutine)
Data from this routine that you want to copy to a tag in the subroutine
• Input parameters are optional.
• Enter multiple input parameters, if needed.
Tag
Array tag
Tag in this routine to which you want to copy a result of the subroutine
• Return parameters are optional.
• Enter multiple return parameters, if needed.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
449
Chapter 11
Program Control Instructions (JMP, LBL, JSR, RET, SBR, JXR, TND, MCR, UID, UIE, AFI, NOP, EOT, SFP, SFR, EVENT)
JSR Operands Continued:
JSR(RoutineName,InputCount,
InputPar,ReturnPar);
Structured Text
Operand Type
Routine name ROUTINE
Input count SINT
INT
DINT
REAL
Input parameter BOOL
SINT
INT
DINT
REAL
Structure
Return parameter
BOOL
SINT
INT
DINT
REAL
Structure
Format
Name
Immediate
Description
Routine to execute (that is, subroutine)
Number of input parameters
Immediate
Tag
Array tag
Data from this routine that you want to copy to a tag in the subroutine
• Input parameters are optional.
• Enter multiple input parameters, if needed.
Tag
Array tag
Tag in this routine to which you want to copy a result of the subroutine
• Return parameters are optional.
• Enter multiple return parameters, if needed.
Function Block
Input Parameters
❇
Return Parameters
❇
450
The operands are the same as those for the relay ladder JSR instruction.
ATTENTION: For each parameter in a SBR or RET instruction, use the same data type (including any array dimensions) as the corresponding parameter in the JSR instruction. Using different data types may produce unexpected results.
SBR Operands:
The SBR instruction must be the first instruction in a relay ladder or structured text routine.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
SBR(InputPar);
Program Control Instructions (JMP, LBL, JSR, RET, SBR, JXR, TND, MCR, UID, UIE, AFI, NOP, EOT, SFP, SFR, EVENT)
Chapter 11
Relay Ladder
Operand Type
Input parameter BOOL
SINT
INT
DINT
REAL
Structure
Format
Tag
Array tag
Description
Tag in this routine into which you want to copy the corresponding input parameter from the JSR instruction
Structured Text
The operands are the same as those for the relay ladder SBR instruction.
Function Block
Parameters
❇
RET Operands:
The operands are the same as those for the relay ladder SBR instruction.
Relay Ladder
Operand
Return parameter
Type
BOOL
SINT
INT
DINT
REAL structure
Format
Immediate
Tag
Array tag
Description
Data from this routine that you want to copy to the corresponding return parameter in the JSR instruction
RET(ReturnPar);
Structured Text
The operands are the same as those for the relay ladder RET instruction.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
451
Chapter 11
Program Control Instructions (JMP, LBL, JSR, RET, SBR, JXR, TND, MCR, UID, UIE, AFI, NOP, EOT, SFP, SFR, EVENT)
Function Block
Parameters
❇
The operands are the same as those for the relay ladder RET instruction.
Description:
The JSR instruction initiates the execution of the specified routine, which is referred to as a subroutine.
• The subroutine executes one time.
• After the subroutine executes, logic execution returns to the routine that contains the JSR instruction.
Use these guidelines to program a jump to a subroutine.
IMPORTANT
Do not use a JSR instruction to call (execute) the main routine.
• You can put a JSR instruction in the main routine or any other routine.
• If you use a JSR instruction to call the main routine and then put a RET instruction in the main routine, a major fault occurs (type 4, code 31).
452
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
JSR
1. If you want to copy data to a tag in the subroutine, enter an input parameter.
2. If you want to copy a result of the subroutine to a tag in this routine, enter a return parameter.
3. Enter as many input and return parameters as you need.
Program Control Instructions (JMP, LBL, JSR, RET, SBR, JXR, TND, MCR, UID, UIE, AFI, NOP, EOT, SFP, SFR, EVENT)
Chapter 11
The following diagram illustrates how the instructions operate.
Calling Routine
JSR
Subroutine
SBR
RET
SBR
1. If the JSR instruction has an input parameter, enter an SBR instruction.
2. Place the SBR instruction as the first instruction in the routine.
3. For each input parameter in the JSR instruction, enter the tag into which you want to copy the data.
RET
42974
RET
1. If the JSR instruction has a return parameter, enter an RET instruction.
2. Place the RET instruction as the last instruction in the routine.
3. For each return parameter in the JSR instruction, enter a return parameter to send to the JSR instruction.
4. In a ladder routine, place additional RET instructions to exit the subroutine based on different input conditions, if required.
(Function block routines only permit one RET instruction.)
Main Routine
action_1
JSR
There are no restrictions, other than controller memory, on the number of nested routines you can have or the number of parameters you pass or return.
Level 1 subroutine action_1
Level 2 subroutine action_2
Level 3 subroutine action_3
SBR SBR SBR
action_2
JSR
action_3
JSR
RET RET RET
Arithmetic Status Flags:
Arithmetic status flags are affected.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
453
Chapter 11
Program Control Instructions (JMP, LBL, JSR, RET, SBR, JXR, TND, MCR, UID, UIE, AFI, NOP, EOT, SFP, SFR, EVENT)
Fault Conditions:
A Major Fault Will Occur If
JSR instruction has fewer input parameters than SBR instruction
JSR instruction jumps to a fault routine
RET instruction has fewer return parameters than JSR instruction
Main routine contains a RET instruction
Execution:
Fault Type
4
4 or user-supplied
4
4
Fault Code
31
0 or user-supplied
31
31
Condition
Prescan
Rung-condition-in is false to the
JSR instruction
Rung-condition-in is true
EnableIn is set
Relay Ladder and Structured Text
Relay Ladder Action
The subroutine does not execute.
Outputs in the subroutine remain in their last state.
The rung-condition-out is set to false.
Structured Text Action
The controller executes all subroutines regardless of rung condition. To ensure that all rungs in the subroutine are prescanned, the controller ignores RET instructions. (that is, RET instructions do not exit the subroutine.)
• Release 6.x and earlier, input and return parameters are passed.
• Release 7.x and later, input and return parameters are not passed.
If recursive calls exist to the same subroutine, the subroutine is prescanned only the first time. If multiple calls exist (non-recursive) to the same subroutine, the subroutine is prescanned each time.
The rung-condition-out is set to false (relay ladder only).
N/A
The instruction executes.
The rung-condition-out is set to true.
N/A
N/A
EnableIn is always set.
The instruction executes.
454
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Condition
Instruction execution.
Program Control Instructions (JMP, LBL, JSR, RET, SBR, JXR, TND, MCR, UID, UIE, AFI, NOP, EOT, SFP, SFR, EVENT)
Chapter 11
Relay Ladder Action Structured Text Action
Input Parameters
No
Logic execution begins in routine identified by JSR.
Yes
JSR copies input parameters to appropriate SBR tags.
RET Instruction
No
Yes
Return Parameters
No
Yes
RET copies return parameters to appropriate JSR tags.
Postscan
Condition
Prescan
Instruction first scan
Instruction first run
Normal execution
Postscan
End Of Subroutine
No
Rung-condition-out is set to false.
Continue executing routine.
Yes
Same action as prescan described above.
Rung-condition-out is set to true.
Logic execution returns to JSR.
End
Same action as prescan described above.
Function Block
Action
No action taken.
No action taken.
No action taken.
1. If the routine contains an SBR instruction, the controller first executes the SBR instruction.
2. The controller latches all data values in IREFs.
3. The controller executes the other function blocks in the order that is determined by their wiring. This includes other JSR instructions.
4. The controller writes outputs in OREFs.
5. If the routine contains an RET instruction, the controller executes the RET instruction last.
The subroutine is called.
If the routine is an SFC routine, the routine in initialized the same as it is during prescan.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
455
Chapter 11
Program Control Instructions (JMP, LBL, JSR, RET, SBR, JXR, TND, MCR, UID, UIE, AFI, NOP, EOT, SFP, SFR, EVENT)
Example 1:
The JSR instruction passes
value_1 and value_2 to routine_1.
The SBR instruction receives
value_1 and value_2 from the JSR instruction and copies those values to value_a and value_b, respectively. Logic execution continues in this routine.
The RET instruction sends
float_a to the JSR instruction. The JSR instruction receives float_a and copies the value to float_value_1. Logic execution continues with the next instruction following the JSR instruction.
Routine
Main routine
Relay Ladder
Program
Subroutine
[Other rungs of code]
Routine
Main routine
Subroutine
Structured Text
Program
JSR(routine_1,2,value_1,value_2,float_value_1);
SBR(value_a,value_b);
<statements>;
RET(float_a);
456
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Example 2:
Program Control Instructions (JMP, LBL, JSR, RET, SBR, JXR, TND, MCR, UID, UIE, AFI, NOP, EOT, SFP, SFR, EVENT)
Chapter 11
Relay Ladder
MainRoutine
When abc is on, subroutine_1 executes, calculates the number of cookies, and places a value in cookies_1.
Adds the value in cookies_1 to cookies_2 and stores the result in total_cookies.
Subroutine_1
When def is on, the RET instruction returns value_1 to the JSR cookies_1 parameter and the rest of the subroutine is not scanned.
When def is off (previous rung) and ghi is on, the RET instruction returns value_2 to the JSR cookies_1 parameter and the rest of the subroutine is not scanned.
When both def and ghi are off (previous rungs), the RET instruction returns value_3 to the JSR cookies_1 parameter.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
457
Chapter 11
Program Control Instructions (JMP, LBL, JSR, RET, SBR, JXR, TND, MCR, UID, UIE, AFI, NOP, EOT, SFP, SFR, EVENT)
Example 3:
Function Block
JSR instruction in Routine_A
42972
1.The values in Add_Input_1,
Add_Input_2, and
Add_Input_3 are copied to
Input_A, Input_B, and
Input_C, respectively.
Function blocks of the Add_Three_Inputs routine
3.The value of Sum_A_B_C is copied to Add_Three_Result.
2.The ADD instructions add Input_A, Input_B, and Input_C and place the result in Sum_A_B_C.
42973
458
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Program Control Instructions (JMP, LBL, JSR, RET, SBR, JXR, TND, MCR, UID, UIE, AFI, NOP, EOT, SFP, SFR, EVENT)
Chapter 11
Jump to External Routine
(JXR)
Operands:
The JXR instruction executes an external routine. This instruction is only supported by the SoftLogix5800 controllers.
Relay Ladder
Operand
External routine name
External routine control
Parameter
Return parameter
Type
ROUTINE
Format
Name
BOOL
SINT
INT
DINT
REAL
EXT_ROUTINE_CONT
ROL
BOOL
SINT
INT
DINT
REAL structure
Tag
Immediate
Tag
Array tag
Tag
.
Description
External routine to execute
Control structure
Data from this routine that you want to copy to a variable in the external routine
• Parameters are optional.
• Enter multiple parameters, if needed.
• You can have as many as 10 parameters.
Tag in this routine to which you want to copy a result of the external routine
• The return parameter is optional.
• You can have only one return parameter
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
459
Chapter 11
Program Control Instructions (JMP, LBL, JSR, RET, SBR, JXR, TND, MCR, UID, UIE, AFI, NOP, EOT, SFP, SFR, EVENT)
Mnemonic
ErrorCode
NumParams
ParameterDefs
ReturnParamDef
EN
ReturnsValue
DN
ER
FirstScan
EnableOut
EnableIn
User1
User0
ScanType1
ScanType0
BOOL
BOOL
BOOL
Data Type
SINT
SINT
EXT_ROUTINE_
PARAMETERS[10]
EXT_ROUTIN_
PARAMETERS
BOOL
BOOL
BOOL
BOOL
BOOL
BOOL
BOOL
BOOL
EXT_ROUTINE_CONTROL Structure
Description
If an error occurs, this value identifies the error. Valid values are from 0-255.
This value indicates the number of parameters associated with this instruction.
This array contains definitions of the parameters to pass to the external routine. The instruction can pass as many as 10 parameters.
This value contains definitions of the return parameter from the external routine. There is only one return parameter.
When set, the enable bit indicates that the JXR instruction is enabled.
If set, this bit indicates that a return parameter was entered for the instruction. If cleared, this bit indicates that no return parameter was entered for the instruction.
The done bit is set when the external routine has executed once to completion.
The error bit is set if an error occurs. The instruction stops executing until the program clears the error bit.
This bit identifies whether this is the first scan after switching the controller to Run mode. Use FirstScan to initialize the external routine, if needed.
Enable output.
Enable input.
These bits are available for the user. The controller does not initialize these bits.
Implementation
There are no predefined error codes. The developer of the external routine must provide the error codes.
Display only - this information is derived from the instruction entry.
Display only - this information is derived from the instruction entry.
Display only - this information is derived from the instruction entry.
The external routine sets this bit.
Display only - this information is derived from the instruction entry.
The external routine sets this bit.
The external routine sets this bit.
The controller sets this bit to reflect scan status.
The external routine sets this bit.
The controller sets this bit to reflect rung-condition-in. The instruction executes regardless of rung condition. The developer of the external routine should monitor this status and act accordingly.
Either the external routine or the user program can set these bits.
These bits identify the current scan type:
Bit Values:
00
Scan Type:
Normal
01
10
Pre Scan
Post Scan (not applicable to relay ladder programs)
The controller sets these bits to reflect scan status.
Description:
Use the Jump to External Routine (JXR) instruction to call the external routine from a ladder routine in your project. The JXR instruction supports multiple parameters so you can pass values between the ladder routine and the external routine.
The JXR instruction is similar to the Jump to Subroutine (JSR) instruction. The
JXR instruction initiates the execution of the specified external routine:
• The external routine executes one time.
• After the external routine executes, logic execution returns to the routine that contains the JXR instruction.
Arithmetic Status Flags:
Arithmetic status flags are not affected.
460
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Program Control Instructions (JMP, LBL, JSR, RET, SBR, JXR, TND, MCR, UID, UIE, AFI, NOP, EOT, SFP, SFR, EVENT)
Chapter 11
Fault Conditions:
A major fault will occur if
• An exception occurs in the external routine DLL.
• The DLL could not be loaded.
• The entry point was not found in the DLL.
Fault Type
4
Fault Code:
88
Execution:
The JXR can be synchronous or asynchronous depending on the implementation of the DLL. The code in the DLL also determines how to respond to scan status, rung-condition-in status, and rung-condition-out status.
For more information on using the JXR instruction and creating external routines, see the SoftLogix5800 System User Manual, publication 1789-UM002 .
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
461
Chapter 11
Program Control Instructions (JMP, LBL, JSR, RET, SBR, JXR, TND, MCR, UID, UIE, AFI, NOP, EOT, SFP, SFR, EVENT)
Temporary End (TND)
Operands:
The TND instruction acts as a boundary.
Relay Ladder Operands
None
EnableIn is set
TND();
Structured Text
None
You must enter the parentheses () after the instruction mnemonic, even though there are no operands.
Description:
When enabled, the TND instruction lets the controller execute logic only up to this instruction.
When enabled, the TND instruction acts as the end of the routine. When the controller scans a TND instruction, the controller moves to the end of the current routine. If the TND instruction is in a subroutine, control returns to the calling routine. If the TND instruction is in a main routine, control returns to the next program within the current task.
Arithmetic Status Flags:
Not affected
Fault Conditions:
None
Execution:
Condition
Prescan
Rung-condition-in is false
Rung-condition-in is true
Relay Ladder Action
The rung-condition-out is set to false.
The rung-condition-out is set to false.
The instruction executes.
The rung-condition-out is set to true.
N/A
Structured Text Action
No action taken.
N/A
N/A
Instruction execution
Postscan
The current routine terminates.
The rung-condition-out is set to false.
EnableIn is always set.
The instruction executes.
The current routine terminates.
No action taken.
Example:
You can use the TND instruction when debugging or troubleshooting to execute logic up to a certain point. Progressively move the TND instruction through the logic as you debug each new section.
462
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Program Control Instructions (JMP, LBL, JSR, RET, SBR, JXR, TND, MCR, UID, UIE, AFI, NOP, EOT, SFP, SFR, EVENT)
Chapter 11
When the TND instruction is enabled, the controller stops scanning the current routine.
Relay Ladder
Structured Text
TND();
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
463
Chapter 11
Program Control Instructions (JMP, LBL, JSR, RET, SBR, JXR, TND, MCR, UID, UIE, AFI, NOP, EOT, SFP, SFR, EVENT)
Master Control Reset (MCR)
The MCR instruction, used in pairs, creates a program zone that can disable all rungs within the MCR instructions.
Operands:
Relay Ladder
None
Description:
When the MCR zone is enabled, the rungs in the MCR zone are scanned for normal true or false conditions. When disabled, the controller still scans rungs within an MCR zone, but scan time is reduced because non-retentive outputs in the zone are disabled. The rung-condition-in is false for all the instructions inside of the disabled MCR zone.
When you program an MCR zone, note the following:
• You must end the zone with an unconditional MCR instruction.
• You cannot nest one MCR zone within another.
• Do not jump into an MCR zone. If the zone is false, jumping into the zone activates the zone from the point to which you jumped to the end of the zone.
• If an MCR zone continues to the end of the routine, you do not have to program an MCR instruction to end the zone.
The MCR instruction is not a substitute for a hard-wired master control relay that provides emergency-stop capability. You should still install a hard-wired master control relay to provide emergency I/O power shutdown.
ATTENTION: Do not overlap or nest MCR zones. Each MCR zone must be separate and complete. If they overlap or nest, unpredictable machine operation could occur with possible damage to equipment or injury to personnel.
ATTENTION: Place critical operations outside the MCR zone. If you start instructions such as timers in a MCR zone, instruction execution stops when the zone is disabled and the timer is cleared.
Arithmetic Status Flags:
Not affected
Fault Conditions:
None
464
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Condition
Prescan
Rung-condition-in is false
Rung-condition-in is true
Postscan
Program Control Instructions (JMP, LBL, JSR, RET, SBR, JXR, TND, MCR, UID, UIE, AFI, NOP, EOT, SFP, SFR, EVENT)
Chapter 11
Execution:
Relay Ladder Action
The rung-condition-out is set to false.
The rung-condition-out is set to false.
The instructions in the zone are scanned, but the rung-condition-in is false and non-retentive outputs in the zone are disabled.
The rung-condition-out is set to true.
The instructions in the zone are scanned normally.
The rung-condition-out is set to false.
Example:
When the first MCR instruction is enabled (
input_1, input_2, and input_3 are set), the controller executes the rungs in the MCR zone (between the two MCR instructions) and sets or clears outputs, depending on input conditions.
When the first MCR instruction is disabled (
input_1, input_2, and input_3 are not all set), the controller executes the rungs in the MCR zone (between the two
MCR instructions) and the rung-condition-in goes false for all the rungs in the
MCR zone, regardless of input conditions.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
465
Chapter 11
Program Control Instructions (JMP, LBL, JSR, RET, SBR, JXR, TND, MCR, UID, UIE, AFI, NOP, EOT, SFP, SFR, EVENT)
User Interrupt Disable (UID)
User Interrupt Enable (UIE)
Operands:
The UID instruction and the UIE instruction work together to prevent a small number of critical rungs from being interrupted by other tasks.
Relay Ladder
None
UID();
Structured Text
None
You must enter the parentheses () after the instruction mnemonic, even though there are no operands.
Description:
When the rung-condition-in is true, the:
• UID instruction prevents higher-priority tasks from interrupting the current task but does not disable execution of a fault routine or the
Controller Fault Handler.
• UIE instruction enables other tasks to interrupt the current task.
Follow these steps to prevent a series of rungs from being interrupted.
1. Limit the number of rungs that you do not want interrupted to as few as possible.
Disabling interrupts for a prolonged period of time can produce communication loss.
2. Above the first rung that you
do not want interrupted, enter a rung and a
UID instruction.
3. After the last rung in the series that you do not want interrupted, enter a rung and a UIE instruction.
4. If required, you can nest pairs of UID/UIE instructions.
Arithmetic Status Flags:
Not affected
Fault Conditions:
None
466
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Condition
Prescan
Rung-condition-in is false
Rung-condition-in is true
EnableIn is set
Instruction execution
Postscan error_bit error_check.FD
Program Control Instructions (JMP, LBL, JSR, RET, SBR, JXR, TND, MCR, UID, UIE, AFI, NOP, EOT, SFP, SFR, EVENT)
Chapter 11
Execution:
Relay Ladder Action
The rung-condition-out is set to false.
The rung-condition-out is set to false.
The instruction executes.
The rung-condition-out is set to true.
N/A
Structured Text Action
No action taken.
N/A
N/A
EnableIn is always set.
The instruction executes.
The UID instruction prevents interruption by higher-priority tasks.
The UIE instruction enables interruption by higher-priority tasks.
The rung-condition-out is set to false.
No action taken.
Example:
When an error occurs (
error_bit is on), the FSC instruction checks the error code against a list of critical errors. If the FSC instruction finds that the error is critical
(error_check.FD is on), an alarm is annunciated. The UID and UIE instructions prevent any other tasks from interrupting the error checking and alarming.
Relay Ladder
UID
FSC
File Search/Compare
Control
Length
Position
Mode
Expression error_check
10
8
ALL error_code=error_list[error_check.POS]
EN
DN
ER alarm
UIE
Structured Text
UID();
<statements>
UIE();
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
467
Chapter 11
Program Control Instructions (JMP, LBL, JSR, RET, SBR, JXR, TND, MCR, UID, UIE, AFI, NOP, EOT, SFP, SFR, EVENT)
Always False Instruction (AFI)
The AFI instruction sets its rung-condition-out to false.
Operands:
Relay Ladder
None
Description:
The AFI instruction sets its rung-condition-out to false.
Arithmetic Status Flags:
Not affected
Fault Conditions:
None
Execution:
Condition
Prescan
Rung-condition-in is false
Rung-condition-in is true
Postscan
Relay Ladder Action:
The rung-condition-out is set to false.
The rung-condition-out is set to false.
The rung-condition-out is set to false.
The rung-condition-out is set to false.
Example:
Use the AFI instruction to temporarily disable a rung while you are debugging a program.
When enabled, the AFI disables all the instructions on this rung.
468
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Program Control Instructions (JMP, LBL, JSR, RET, SBR, JXR, TND, MCR, UID, UIE, AFI, NOP, EOT, SFP, SFR, EVENT)
Chapter 11
No Operation (NOP)
Operands:
The NOP instruction functions as a placeholder.
Relay Ladder
None
Description:
You can place the NOP instruction anywhere on a rung. When enabled the NOP instruction performs no operation. When disabled, the NOP instruction performs no operation.
Arithmetic Status Flags:
Not affected
Fault Conditions:
None
Execution:
Condition
Prescan
Rung-condition-in is false
Rung-condition-in is true
Postscan
Relay Ladder Action
The rung-condition-out is set to false.
The rung-condition-out is set to false.
The rung-condition-out is set to true.
The rung-condition-out is set to false.
Example
This instruction is useful for locating unconditional branches when you place the
NOP instruction on the branch.
The NOP instruction bypasses the XIC instruction to enable the output.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
469
Chapter 11
Program Control Instructions (JMP, LBL, JSR, RET, SBR, JXR, TND, MCR, UID, UIE, AFI, NOP, EOT, SFP, SFR, EVENT)
End of Transition (EOT)
Operands:
The EOT instruction returns a boolean state to an SFC transition.
Relay Ladder
Operand
Data bit
Type
BOOL
Format
Tag
Description
State of the transition
(0=executing, 1=completed)
EOT(data_bit);
Structured Text
The operands are the same as those for the relay ladder EOT instruction.
Description:
Because the EOT instruction returns a boolean state, multiple SFC routines can share the same routine that contains the EOT instruction. If the calling routine is not a transition, the EOT instruction acts as a TND instruction
(see
The Logix implementation of the EOT instruction differs from that in a PLC-5 controller. In a PLC-5 controller, the EOT instruction has no parameters.
Instead, the PLC-5 EOT instruction returns rung condition as its state. In a
Logix controller, the return parameter returns the transition state since rung condition is not available in all Logix programming languages.
Arithmetic Status Flags:
Not affected
Fault Conditions:
None
Execution:
Condition
Prescan
Rung-condition-in is false
Rung-condition-in is true
EnableIn is set
Relay Ladder Action
The rung-condition-out is set to false.
The rung-condition-out is set to false.
The instruction executes.
The rung-condition-out is set to true.
N/A
Structured Text Action
No action taken.
N/A
N/A
EnableIn is always set.
The instruction executes.
Instruction execution
Postscan
The instruction returns the data bit value to the calling routine.
The rung-condition-out is set to false.
No action taken.
Example:
When both
limit_switch1 and interlock_1 are set, set state. After timer_1 completes, EOT returns the value of state to the calling routine.
470
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Program Control Instructions (JMP, LBL, JSR, RET, SBR, JXR, TND, MCR, UID, UIE, AFI, NOP, EOT, SFP, SFR, EVENT)
Chapter 11
Relay Ladder
Structured Text
state := limit_switch1 AND interlock_1;
IF timer_1.DN THEN
EOT(state);
END_IF;
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
471
Chapter 11
Program Control Instructions (JMP, LBL, JSR, RET, SBR, JXR, TND, MCR, UID, UIE, AFI, NOP, EOT, SFP, SFR, EVENT)
SFC Pause (SFP)
The SFP instruction pauses an SFC routine.
Operands:
Relay Ladder
Operand
SFCRoutine
Name
TargetState
Type
ROUTINE
DINT
Format
Name
Immediate
Tag
Description
SFC routine to pause
Select one:
Executing (or enter 0)
Paused (or enter 1)
Structured Text
SFP(SFCRoutineName,
TargetState);
The operands are the same as those for the relay ladder SFP instruction.
Description:
The SFP instruction lets you pause an executing SFC routine. If an SFC routine is in the paused state, use the SFP instruction again to change the state and resume execution of the routine.
Also, use the SFP instruction to resume SFC execution after using an SFR instruction (see
page 474 ) to reset an SFC routine.
Arithmetic Status Flags:
Not affected
Fault Conditions:
Condition
Prescan
Rung-condition-in is false
Rung-condition-in is true
EnableIn is set
Instruction execution
Postscan
A major fault will occur if
Routine type is not an SFC routine
Fault type
4
Execution:
Relay Ladder Action
The rung-condition-out is set to false.
The rung-condition-out is set to false.
The instruction executes.
The rung-condition-out is set to true.
N/A
Structured Text Action
No action taken.
N/A
N/A
EnableIn is always set.
The instruction executes.
The instruction pauses or resumes execution of the specified SFC routine.
The rung-condition-out is set to false.
No action taken.
Fault code
85
Example:
If
sfc_en_p is set, pause the SFC routine named normal. Restart the SFC when
sfc_en_e is set.
472
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Pause the SFC routine.
Resume executing the SFC routine.
Program Control Instructions (JMP, LBL, JSR, RET, SBR, JXR, TND, MCR, UID, UIE, AFI, NOP, EOT, SFP, SFR, EVENT)
Chapter 11
Relay Ladder
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
473
Chapter 11
Program Control Instructions (JMP, LBL, JSR, RET, SBR, JXR, TND, MCR, UID, UIE, AFI, NOP, EOT, SFP, SFR, EVENT)
Structured Text
Pause the SFC routine:
IF (sfp_en_p) THEN
SFP(normal,paused); sfp_en_p := 0;
END_IF;
Resume executing the SFC routine:
IF (sfp_en_e) THEN
SFP(normal,executing); sfp_en_e := 0;
END_IF;
SFC Reset (SFR)
Operands:
The SFR instruction resets the execution of a SFC routine at a specified step.
Relay Ladder Operands
Operand
SFCRoutine
Name
Step Name
Type
ROUTINE
SFC_STEP
Format
Name
Tag
Description
SFC routine to reset
Target step where to resume execution
Structured Text
SFR(SFCRoutineName,StepName);
The operands are the same as those for the relay ladder SFR instruction.
Description:
When the SFR instruction is enabled:
• In the specified SFC routine, all stored actions stop executing (reset).
• The SFC begins executing at the specified step.
If the target step is 0, the chart will be reset to its initial step.
The Logix implementation of the SFR instruction differs from that in a PLC-5 controller. In the PLC-5 controller, the SFR executed when the rung condition
474
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Program Control Instructions (JMP, LBL, JSR, RET, SBR, JXR, TND, MCR, UID, UIE, AFI, NOP, EOT, SFP, SFR, EVENT)
Chapter 11
Condition
Prescan
Rung-condition-in is false
Rung-condition-in is true
EnableIn is set
Instruction execution
Postscan was true. After reset, the SFC would remain paused until the rung containing the
SFR became false. This allowed the execution following a reset to be delayed.
This pause/un-pause feature of the PLC-5 SFR instruction was decoupled from the rung condition and moved into the SFP instruction.
Arithmetic Status Flags:
Not affected
Fault Conditions:
A major fault will occur if
Routine type is not an SFC routine
Specified target step does not exist in the SFC routine 4
Fault type
4
Fault code
85
89
Execution:
Relay Ladder Action
The rung-condition-out is set to false.
The rung-condition-out is set to false.
The instruction executes.
The rung-condition-out is set to true.
N/A
The instruction resets the specified SFC routine.
The rung-condition-out is set to false.
Structured Text Action
No action taken.
N/A
N/A
EnableIn is always set.
The instruction executes.
The instruction resets the specified SFC routine.
No action taken.
Example:
If a specific condition occurs ( shutdown is set), restart the SFC at step initialize.
Relay Ladder
Structured Text
IF shutdown THEN
SFR(mySFC,initialize);
END_IF;
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
475
Chapter 11
Program Control Instructions (JMP, LBL, JSR, RET, SBR, JXR, TND, MCR, UID, UIE, AFI, NOP, EOT, SFP, SFR, EVENT)
Trigger Event Task (EVENT)
The EVENT instruction triggers one execution of an event task.
Operands:
Relay Ladder
Operand
Task
Type
TASK
Format
Name
Description
Event task to execute
The instruction lets you choose other types of tasks, but it does not execute them.
EVENT(task_name);
Structured Text
The operands are the same as those for the relay ladder EVENT instruction.
Description:
Use the EVENT instruction to programmatically execute an event task:
• Each time the instruction executes, it triggers the specified event task.
• Make sure that you give the event task enough time to complete its execution before you trigger it again. If not, an overlap occurs.
• If you execute an EVENT instruction while the event task is already executing, the controller increments the overlap counter but it does not trigger the event task.
Programmatically Determine if an EVENT Instruction Triggered a Task
To determine if an EVENT instruction triggered an event task, use a
Get SystemValue (GSV) instruction to monitor the Status attribute of the task.
Table 7 - Status Attribute of the TASK Object
Attribute
Status
Data Type
DINT
Instruction
GSV
SSV
Description
Provides status information about the task. Once the controller sets a bit, you must manually clear the bit to determine if another fault of that type occurred.
To determine if
An EVENT instruction triggered the task (event task only).
Examine this bit
0
A time-out triggered the task (event task only).
An overlap occurred for this task.
1
2
The controller does not clear the bits of the Status attribute once they are set.
• To use a bit for new status information, you must manually clear the bit.
• Use a Set System Value (SSV) instruction to set the attribute to a different value.
476
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Program Control Instructions (JMP, LBL, JSR, RET, SBR, JXR, TND, MCR, UID, UIE, AFI, NOP, EOT, SFP, SFR, EVENT)
Chapter 11
Condition
Prescan
Rung-condition-in is false
Rung-condition-in is true
EnableIn is set
Arithmetic Status Flags:
Not affected
Fault Conditions:
None
Execution:
Instruction execution
Postscan
Relay Ladder Action
The rung-condition-out is set to false.
The rung-condition-out is set to false.
The instruction executes.
The rung-condition-out is set to true.
N/A
The instruction triggers one execution of the specified event task
The rung-condition-out is set to false.
Structured Text Action
No action taken.
N/A
N/A
EnableIn is always set.
The instruction executes.
No action taken.
Example 1:
A controller uses multiple programs but a common shut down procedure. Each program uses a program-scoped tag named
Shut_Down_Line that turns on if the program detects a condition that requires a shut down. The logic in each program executes as follows:
If
Shut_Down_Line = on (conditions require a shut down) then
Execute the
Shut_Down task one time
Relay Ladder
Program A
Program B
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
477
Chapter 11
Program Control Instructions (JMP, LBL, JSR, RET, SBR, JXR, TND, MCR, UID, UIE, AFI, NOP, EOT, SFP, SFR, EVENT)
Structured Text
Program A
IF Shut_Down_Line AND NOT Shut_Down_Line_One_Shot THEN
EVENT (Shut_Down);
END_IF;
Shut_Down_Line_One_Shot := Shut_Down_Line;
Program B
IF Shut_Down_Line AND NOT Shut_Down_Line_One_Shot THEN
EVENT (Shut_Down);
END_IF;
Shut_Down_Line_One_Shot := Shut_Down_Line;
478
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Program Control Instructions (JMP, LBL, JSR, RET, SBR, JXR, TND, MCR, UID, UIE, AFI, NOP, EOT, SFP, SFR, EVENT)
Chapter 11
Example 2:
The following example uses an EVENT instruction to initialize an event task.
(Another type of event normally triggers the event task.)
Continuous task
If Initialize_Task_1 = 1 then
The ONS instruction limits the execution of the EVENT instruction to one scan.
The EVENT instruction triggers an execution of Task_1 (event task).
Task_1 (event task)
The GSV instruction sets Task_Status (DINT tag) = Status attribute for the event task. In the Instance Name attribute, THIS means the TASK object for the task that the instruction is in (that is, Task_1).
If Task_Status.0 = 1 then an EVENT instruction triggered the event task (that is, when the continuous task executes its EVENT instruction to initialize the event task).
The RES instruction resets a counter that the event task uses.
The controller does not clear the bits of the Status attribute once they are set. To use a bit for new status information, you must manually clear the bit.
If Task_Status.0 = 1 then clear that bit.
The OTU instruction sets Task_Status.0 = 0.
The SSV instruction sets the Status attribute of THIS task (Task_1) = Task_Status. This includes the cleared bit.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
479
Chapter 11
Program Control Instructions (JMP, LBL, JSR, RET, SBR, JXR, TND, MCR, UID, UIE, AFI, NOP, EOT, SFP, SFR, EVENT)
Notes:
480
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Chapter
12
For/Break Instructions
(FOR, FOR...DO, BRK, EXIT, RET)
If you want to
Repeatedly execute a routine
Terminate the repeated execution of a routine
Return to the FOR instruction
(1) Structured text only.
Topic
Page
Use the FOR instruction to repeatedly call a subroutine. Use the BRK instruction to interrupt the execution of a subroutine.
Use this instruction
FOR
FOR...DO
(1)
BRK
EXIT
(1)
RET
Available in these languages
Relay ladder
Structured text
Relay ladder
Structured text
Relay ladder
Page
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
481
Chapter 12
For/Break Instructions (FOR, FOR...DO, BRK, EXIT, RET)
For (FOR)
The FOR instruction executes a routine repeatedly.
Operands:
Relay Ladder
Operand
Routine name
Index
Initial value
Terminal value SINT
INT
DINT
Step size SINT
INT
DINT
Type
ROUTINE
DINT
SINT
INT
DINT
Format Description
Routine Name Routine to execute
Tag
Immediate
Tag
Counts how many times the routine has been executed
Value at which to start the index
Value at which to stop executing the routine Immediate
Tag
Immediate
Tag
Amount to add to the index each time the FOR instruction executes the routine
FOR
count:= initial_value TO
final_value BY increment DO
< statement>;
Description:
Structured Text
Use the FOR...DO construct. See Structured Text Programming
for information on structured text constructs.
IMPORTANT
Do not use a FOR instruction to call (execute) the main routine.
• You can put a FOR instruction in the main routine or any other routine.
• If you use a FOR instruction to call the main routine and then put a RET instruction in the main routine, a major fault occurs (type 4, code 31).
When enabled, the FOR instruction repeatedly executes the Routine until the
Index value exceeds the Terminal value. This instruction does not pass parameters to the routine.
Each time the FOR instruction executes the routine, it adds the Step size to the
Index.
482
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
For/Break Instructions (FOR, FOR...DO, BRK, EXIT, RET)
Chapter 12
Condition
Prescan
Be careful not to loop too many times in a single scan. An excessive number of repetitions can cause the controller’s watchdog to timeout, which causes a major fault.
Arithmetic Status Flags:
Not affected
Fault Conditions:
A major fault will occur if
Main routine contains a RET instruction
Fault Type
4
Fault Code
31
Execution:
Rung-condition-in is false
Relay Ladder Action
The rung-condition-out is set to false.
The controller executes the subroutine once.
If recursive FOR instruction0s exist to the same subroutine, the subroutine is prescanned only the first time. If multiple FOR instructions exist (non-recursive) to the same subroutine, the subroutine is prescanned each time.
The rung-condition-out is set to false.
Rung-condition-in is true.
Index = initial_value
Postscan
No
Step size < 0
Yes
Goto End
No
Index Terminal Value
Yes
Yes
Index Terminal Value
Execute Routine
index =(index + step_size)
No
Goto
End
End
Rung-condition-out is set to true.
End
The rung-condition-out is set to false.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
483
Chapter 12
For/Break Instructions (FOR, FOR...DO, BRK, EXIT, RET)
Example:
When enabled, the FOR instruction repeatedly executes
routine_2 and increments value_2 by 1 each time. When value_2 is 10 or a BRK instruction is enabled, the FOR instruction no longer executes
routine_2.
484
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Break (BRK)
For/Break Instructions (FOR, FOR...DO, BRK, EXIT, RET)
Chapter 12
Operands:
The BRK instruction interrupts the execution of a routine that was called by a
FOR instruction.
Relay Ladder
None
Postscan
EXIT;
Structured Text
Use the EXIT statement in a loop construct. See
for information on structured text constructs.
Description:
When enabled, the BRK instruction exits the routine and returns the controller to the instruction that follows the FOR.
If there are nested FOR instructions, a BRK instruction returns control to the innermost FOR instruction.
Arithmetic Status Flags:
Not affected
Fault Conditions:
None
Execution:
Condition
Prescan
Rung-condition-in is false
Rung-condition-in is true
Relay Ladder Action
The rung-condition-out is set to false.
The rung-condition-out is set to false.
The rung-condition-out is set to true.
Execution returns to the instruction that follows the calling FOR instruction.
The rung-condition-out is set to false.
Example:
When enabled, the BRK instruction stops executing the current routine and returns to the instruction that follows the calling FOR instruction.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
485
Chapter 12
For/Break Instructions (FOR, FOR...DO, BRK, EXIT, RET)
Return (RET)
The RET instruction returns to the calling FOR instruction.
Operands:
Relay Ladder
None
Description:
IMPORTANT
Do not place a RET instruction in the main routine. If you place a RET instruction in the main routine, a major fault occurs
(type 4, code 31).
When enabled, the RET instruction returns to the FOR instruction. The FOR instruction increments the Index value by the Step size and executes the subroutine again. If the Index value exceeds the Terminal value, the FOR instruction completes and execution moves on to the instruction that follows the
FOR instruction.
The FOR instruction does not use parameters. The FOR instruction ignores any parameters you enter in a RET instruction.
You could also use a TND instruction to end execution of a subroutine.
Arithmetic Status Flags:
Not affected
Fault Conditions:
A major fault will occur if
Main routine contains a RET instruction
Fault type
4
Fault code
31
Condition:
Prescan
Rung-condition-in is false
Rung-condition-in is true
Postscan
Execution:
Relay Ladder Action
The rung-condition-out is set to false.
The rung-condition-out is set to false.
Returns the specified parameters to the calling routine.
The rung-condition-out is set to true.
The rung-condition-out is set to false.
Example:
The FOR instruction repeatedly executes
routine_2 and increments value_2 by 1 each time. When value_2 is 10 or a BRK instruction is enabled, the FOR instruction no longer executes
routine_2.
486
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Calling Routine
For/Break Instructions (FOR, FOR...DO, BRK, EXIT, RET)
Chapter 12
The RET instruction returns to the calling FOR instruction. The FOR instruction either executes the subroutine again and increments the Index value by the Step size or, if the Index value exceeds the Terminal value, the FOR instruction is complete and execution moves on to the instruction that follows the FOR instruction.
Subroutine
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
487
Chapter 12
For/Break Instructions (FOR, FOR...DO, BRK, EXIT, RET)
Notes:
488
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Chapter
13
Special Instructions
(FBC, DDT, DTR, PID)
Topic
Proportional Integral Derivative (PID)
Page
The special instructions perform application-specific operations.
If you want to
Compare data against a known, good reference and record any mismatches
Compare data against a known, good reference, record any mismatches, and update the reference to match the source
Pass the source data through a mask and compare the result to reference data. Then write the source into the reference for the next comparison
Control a PID loop
Use this instruction
FBC
DDT
DTR
PID
Available in these languages
Relay ladder
Relay ladder
Relay ladder
Relay ladder
Structured text
Page
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
489
.ER
.LEN
.POS
Mnemonic
.EN
.DN
.FD
.IN
Chapter 13
Special Instructions (FBC, DDT, DTR, PID)
File Bit Comparison (FBC)
Operands:
The FBC instruction compares bits in a Source array with bits in a Reference array.
Relay Ladder
Operand
Source
Type
DINT
Reference
Result
Cmp control
Length
Position
Result control
Length
Position
DINT
DINT
CONTROL
DINT
DINT
CONTROL
DINT
DINT
Format
Array tag
Array tag
Array tag
Structure
Immediate
Immediate
Structure
Immediate
Immediate
Description:
Array to compare to the reference
Do not use CONTROL.POS in the subscript
Array to compare to the source
Do not use CONTROL.POS in the subscript
Array to store the result
Do not use CONTROL.POS in the subscripts
Control structure for the compare
Number of bits to compare
Current position in the source
Initial value is typically 0
Control structure for the results
Number of storage locations in the result
Current position in the result
Initial value is typically 0
BOOL
DINT
DINT
Data Type
BOOL
BOOL
BOOL
BOOL
ATTENTION: Use different tags for the compare control structure and the result control structure. Using the same tag for both could result in unpredictable operation, possibly causing equipment damage and/or injury to personnel.
COMPARE Structure
Description
The enable bit indicates that the FBC instruction is enabled.
The done bit is set when the FBC instruction compares the last bit in the Source and Reference arrays.
The found bit is set each time the FBC instruction records a mismatch (one-at-a-time operation) or after recording all mismatches (all-per-scan operation).
The inhibit bit indicates the FBC search mode.
0 = all mode
1 = one mismatch at a time mode
The error bit is set if the compare .POS < 0, the compare .LEN < 0, the result .POS < 0 or the result .LEN < 0. The instruction stops executing until the program clears the .ER bit.
The length value identifies the number of bits to compare.
The position value identifies the current bit.
490
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Mnemonic
.DN
.LEN
.POS
Special Instructions (FBC, DDT, DTR, PID)
Chapter 13
RESULT Structure
Data Type
BOOL
DINT
DINT
Description
The done bit is set when the Result array is full.
The length value identifies the number of storage locations in the Result array.
The position value identifies the current position in the Result array.
Description:
When enabled, the FBC instruction compares the bits in the Source array with the bits in the Reference array and records the bit number of each mismatch in the Result array.
IMPORTANT
You must test and confirm that the instruction doesn’t change data that you don’t want it to change.
The FBC instruction operates on contiguous memory. In some cases, the instruction searches or writes past the array into other members of the tag. This happens if a length is too big and the tag is a userdefined data type.
The difference between the DDT and FBC instructions is that each time the
DDT instruction finds a mismatch, the instruction changes the reference bit to match the source bit. The FBC instruction does not change the reference bit.
If you want to detect
One mismatch at a time
All mismatches
Select the Search Mode
Select this mode
Set the .IN bit in the compare CONTROL structure.
Each time the rung-condition-in goes from false to true, the FBC instruction searches for the next mismatch between the Source and Reference arrays. Upon finding a mismatch, the instruction sets the .FD bit, records the position of the mismatch, and stops executing.
Clear the .IN bit in the compare CONTROL structure.
Each time the rung-condition-in goes from false to true, the FSC instruction searches for all mismatches between the Source and Reference arrays.
Arithmetic Status Flags:
Not affected
Fault Conditions:
A major fault will occur if
Result.POS > Size of Result array
Fault type
4
Fault code
20
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
491
Chapter 13
Special Instructions (FBC, DDT, DTR, PID)
Condition
Execution:
Relay Ladder Action
Prescan.
Compare.EN bit is cleared.
Compare.FD bit is cleared.
Examine compare.DN bit.
Compare.DN = 0 compare.DN = 1
Compare.DN bit is cleared.
Compare.POS value is cleared.
Result.DN bit is cleared.
Result.POS value is cleared.
Rung-condition-out is set to
false.
End
492
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Condition Relay Ladder Action
Rung-condition-in is false.
Compare.EN bit is cleared.
Compare.FD bit is cleared.
Examine compare.DN bit.
Compare.DN = 0
Compare.DN = 1
Compare DN bit is cleared.
Compare.POS value is cleared.
Result.DN bit is cleared.
Result.POS value is cleared.
Rung-condition-out is set to
false.
End
Special Instructions (FBC, DDT, DTR, PID)
Chapter 13
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
493
Chapter 13
Special Instructions (FBC, DDT, DTR, PID)
Condition
Rung-condition-in is true.
Relay Ladder Action
Examine compare.EN bit.
Compare.EN = 1
Compare.EN = 0
Compare EN bit is set.
Goto
Exit
Examine compare.DN bit.
Compare.DN = 1
Compare.DN = 0
Compare.ER bit is cleared.
Compare.FD bit is cleared.
Compare.LEN 0
Goto
Exit
Yes
No
Exit
Compare.POS < 0
Yes
No
Compare.ER bit is set.
Rung-condition-out is set to true.
End
Compare page 495
Goto
Exit
494
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Special Instructions (FBC, DDT, DTR, PID)
Chapter 13
Condition Relay Ladder Action
Compare
Postscan
Compare.POS
Compare.LEN
No
Yes
Compare.POS = compare.LEN
Compare.DN bit is set.
Goto
Exit page 494
Source[compare.POS] =
Reference[compare.POS]
No
Compare.POS = compare.POS + 1
Yes
Compare.FD bit is set.
Major Fault bit.
Result.DN = 1
Examine result.DN
Result.DN = 0
Result.DN bit is cleared.
Result.POS value is cleared.
Yes
Result.POS < 0
No
Yes
Result.LEN 0
No
Yes
Result.POS > size of result array no
Result[result.POS] = compare.POS
result.POS = result.POS + 1
Compare.ER bit is set.
Goto
Exit page 494
No
Result.POS > result.LEN
yes
Result.DN bit is set.
The rung-condition-out is set to false.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
495
Chapter 13
Special Instructions (FBC, DDT, DTR, PID)
Example:
When enabled, the FBC instruction compares the source
array_dint1 to the reference array_dint2 and stores the locations of any mismatches in the result
array_dint3.
Source array_dint1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Reference array_dint2
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 0
Result array_dint3 5 3
496
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
.ER
.LEN
.POS
Mnemonic
.EN
.DN
.FD
.IN
Special Instructions (FBC, DDT, DTR, PID)
Chapter 13
Diagnostic Detect (DDT)
Operands:
The DDT instruction compares bits in a Source array with bits in a Reference array to determine changes of state.
Relay Ladder
Operand
Source
Type
DINT
Reference
Result
DINT
DINT
Cmp control
Length
Position
CONTROL
DINT
DINT
Result control CONTROL
Length DINT
Position DINT
Format
Array tag
Array tag
Array tag
Structure
Immediate
Immediate
Structure
Immediate
Immediate
Description
Array to compare to the reference
Do not use CONTROL.POS in the subscript
Array to compare to the source
Do not use CONTROL.POS in the subscript
Array to store the results
Do not use CONTROL.POS in the subscript
Control structure for the compare
Number of bits to compare
Current position in the source
Initial value typically 0
Control structure for the results
Number of storage locations in the result
Current position in the result
Initial value typically 0
BOOL
DINT
DINT
Data Type
BOOL
BOOL
BOOL
BOOL
ATTENTION: Use different tags for the compare control structure and the result control structure. Using the same tag for both could result in unpredictable operation, possibly causing equipment damage and/or injury to personnel.
COMPARE Structure
Description
The enable bit indicates that the DDT instruction is enabled.
The done bit is set when the DDT instruction compares the last bit in the Source and Reference arrays.
The found bit is set each time the DDT instruction records a mismatch (one-at-a-time operation) or after recording all mismatches (all-per-scan operation).
The inhibit bit indicates the DDT search mode.
0 = all mode
1 = one mismatch at a time mode
The error bit is set if the compare .POS < 0, the compare .LEN < 0, the result .POS < 0 or the result .LEN < 0. The instruction stops executing until the program clears the .ER bit.
The length value identifies the number of bits to compare.
The position value identifies the current bit.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
497
Chapter 13
Special Instructions (FBC, DDT, DTR, PID)
Mnemonic
.DN
.LEN
.POS
RESULT Structure
Data Type
BOOL
DINT
DINT
Description
The done bit is set when the Result array is full.
The length value identifies the number of storage locations in the Result array.
The position value identifies the current position in the Result array.
Description:
When enabled, the DDT instruction compares the bits in the Source array with the bits in the Reference array, records the bit number of each mismatch in the
Result array, and changes the value of the Reference bit to match the value of the corresponding Source bit.
IMPORTANT
You must test and confirm that the instruction doesn’t change data that you don’t want it to change.
The DDT instruction operates on contiguous memory. In some cases, the instruction searches or writes past the array into other members of the tag. This happens if a length is too big and the tag is a userdefined data type.
The difference between the DDT and FBC instructions is that each time the
DDT instruction finds a mismatch, the DDT instruction changes the reference bit to match the source bit. The FBC instruction does not change the reference bit.
If you want to detect
One mismatch at a time
All mismatches
Select the Search Mode
Select this mode
Set the .IN bit in the compare CONTROL structure.
Each time the rung-condition-in goes from false to true, the DDT instruction searches for the next mismatch between the Source and Reference arrays. Upon finding a mismatch, the instruction sets the .FD bit, records the position of the mismatch, and stops executing.
Clear the .IN bit in the compare CONTROL structure.
Each time the rung-condition-in goes from false to true, the DDT instruction searches for all mismatches between the Source and Reference arrays.
Arithmetic Status Flags:
Not affected
Fault Conditions:
A major fault will occur if
Result.POS > size of Result array
Fault type
4
Fault code
20
498
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Condition:
Execution:
Relay Ladder Action
Prescan
Compare.EN bit is cleared.
Compare.FD bit is cleared.
Examine
Compare.DN bit.
Compare.DN = 0
Compare.DN = 1
Compare.DN bit is cleared.
Compare.POS value is cleared.
Result.DN bit is cleared.
Result.POS value is cleared.
Rung-condition-out is set to
false.
End
Special Instructions (FBC, DDT, DTR, PID)
Chapter 13
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
499
Chapter 13
Special Instructions (FBC, DDT, DTR, PID)
Condition: Relay Ladder Action
Rung-condition-in is false.
Compare.EN bit is cleared.
Compare.FD bit is cleared.
Examine
Compare.DN bit.
Compare.DN = 0
Compare.DN = 1
Compare DN bit is cleared.
Compare.POS value is cleared.
Result.DN bit is cleared.
Result.POS value is cleared.
Rung-condition-out is set to
false.
End
500
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Special Instructions (FBC, DDT, DTR, PID)
Chapter 13
Condition:
Rung-condition-in is true.
Relay Ladder Action
Examine Compare.EN bit.
Compare.EN = 1
Compare.EN = 0
Compare EN bit is set.
Examine
Compare.DN bit.
Compare.DN bit = 1 compare.DN bit = 0
Compare.ER bit is cleared.
Compare.FD bit is cleared.
Compare.LEN 0
Goto
Exit
Goto
Exit
Yes
No
Exit
Compare.POS < 0
Yes
No
Compare.ER bit is set.
Rung-condition-out is set to true.
End
Compare page 502
Goto
Exit
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
501
Chapter 13
Special Instructions (FBC, DDT, DTR, PID)
Condition: Relay Ladder Action
Compare
Postscan
Compare.POS
Compare.LEN
No
Yes
Source[compare.POS] =
Reference[compare.POS]
No
Compare.POS =
Compare.POS + 1
Yes
Compare.FD bit is set.
Reference[compare.POS]
= Source[compare.POS]
Major Fault
Goto
Exit page 501
Examine result.DN bit.
Result.DN = 1
Result.DN = 0
Result.DN bit is cleared.
Result.POS value is cleared.
Yes
Result.POS < 0
No
Yes
Result.LEN 0 no
Yes
Result.POS >
Size of result array no
Result[result.POS] = Compare.POS
Result.POS = Result.POS + 1
Compare.ER bit is set.
Goto page 494
No
Result.POS
Result.LEN
Yes
Result.DN bit is set.
The rung-condition-out is set to false.
502
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Special Instructions (FBC, DDT, DTR, PID)
Chapter 13
Example:
When enabled, the DDT instruction compares the source
array_dint1 to the reference array_dint2 and stores the locations of any mismatches in the result
array_dint3. The controller also changes the mismatched bits in the reference
array_dint2 to match the source array_dint1.
Source array_dint1
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Reference (before compare) array_dint2
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 0
Result array_dint3
5 3
Reference (after compare) array_dint2
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
503
Chapter 13
Special Instructions (FBC, DDT, DTR, PID)
Data Transitional (DTR)
Operands:
The DTR instruction passes the Source value through a Mask and compares the result with the Reference value.
Relay Ladder
Operand
Source
Mask
Reference
Type
DINT
DINT
DINT
Format
Immediate
Tag
Immediate
Tag
Tag
Description
Array to compare to the reference
Which bits to block or pass
Array to compare to the source
Description:
The DTR instruction passes the Source value through a Mask and compares the result with the Reference value. The DTR instruction also writes the masked
Source value into the Reference value for the next comparison. The Source remains unchanged.
A ‘1’ in the mask means the data bit is passed. A ‘0’ in the mask means the data bit is blocked.
When the masked Source differs from the Reference, the rung-condition-out goes true for one scan. When the masked Source is the same as the Reference, the rung-condition-out is false.
ATTENTION: Online programming with this instruction can be dangerous. If the Reference value is different than the Source value, the rung-condition-out goes true. Use caution if you insert this instruction when the processor is in Run or Remote Run mode.
504
Enter an Immediate Mask Value
When you enter a mask, the programming software defaults to decimal values. If you want to enter a mask using another format, precede the value with the correct prefix.
Prefix
16#
8#
2#
Description
Hexadecimal
For example; 16#0F0F
Octal
For example; 8#16
Binary
For example; 2#00110011
Arithmetic Status Flags:
Not affected
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Condition
Prescan
Rung-condition-in is false
Fault Conditions:
None
Execution:
Relay Ladder Action
The Reference = Source AND Mask.
The rung-condition-out is set to false.
The Reference = Source AND Mask.
The rung-condition-out is set to false.
Rung-condition-in is true masked source = reference yes rung-condition-out is set to false no end
Postscan The rung-condition-out is set to false.
Special Instructions (FBC, DDT, DTR, PID)
Chapter 13
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
505
Chapter 13
Special Instructions (FBC, DDT, DTR, PID)
Example:
When enabled, the DTR instruction masks
value_1. If there is a difference in the two values, the rung-condition-out is set to true.
Example 1
7
1 8 3
Source
value_1
Example 2
9 1 8 7
0
0 0 0 1 1 1 1 1 1 1 1 1 1 1 1
Mask = 0FFF
0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1
Current Scan
0
Previous Scan 0 1
1
8
8
3
3
The rung remains false as long as the input value does not change.
Reference
value_2
0
0
1
1
8
8
7
3
The rung remains true for one scan when a change is detected.
Current Scan
Previous Scan
13385
A 0 in the mask leaves the bit unchanged.
506
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Special Instructions (FBC, DDT, DTR, PID)
Chapter 13
Proportional Integral
Derivative (PID)
Operands:
The PID instruction controls a process variable such as flow, pressure, temperature, or level.
Relay Ladder
Operand
PID
Type
PID
Process variable SINT
INT
DINT
REAL
Tieback SINT
INT
DINT
REAL
Control variable SINT
INT
DINT
REAL
PID master loop PID
Inhold bit BOOL
Inhold value
Setpoint
Process variable
Output %
SINT
INT
DINT
REAL
Format
Structure
Tag
Description
PID structure
Value you want to control
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
507
.SP
.KP
.KI
.KD
508
.BIAS
Chapter 13
Special Instructions (FBC, DDT, DTR, PID)
PID(PID,ProcessVariable,
Tieback,ControlVariable,
PIDMasterLoop,InholdBit,
InHoldValue);
Mnemonic:
.CTL
Data Type
DINT
REAL
REAL
REAL
REAL
REAL
Structured Text
The operands are the same as those for the relay ladder PID instruction.
However, you specify the Setpoint, Process Variable, and Output percent by accessing the .SP, .PV.and .OUT members of the PID structure, rather than by including values in the operand list.
PID Structure
09
08
11
10
13
12
15
14
07
Setpoint
Independent
Dependent
Independent
Dependent
Independent
Dependent
Feedforward or bias %
24
23
26
25
22
21
20
This bit
28
27
30
29
Description
The .CTL member provides access to the status members (bits) in one, 32-bit word. The PID instruction sets bits 07…15.
This bit
31
Is this member
.EN
.CT
.CL
.PVT
.DOE
.SWM
.CA
.MO
.PE
.NDF
.NOBC
.NOZC
Is this member, which the PID instruction sets
.EWD
.DVNA
.DVPA
.PVLA
.PVHA
.INI
.SPOR
.OLL
.OLH
Proportional gain (unitless)
Controller gain (unitless)
Integral gain (1/sec)
Reset time (minutes per repeat)
Derivative gain (seconds)
Rate time (minutes)
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
REAL
REAL
REAL
REAL
REAL
REAL
REAL
REAL
Data Type
REAL
REAL
REAL
REAL
REAL
REAL
REAL
REAL
REAL
REAL
REAL
REAL
REAL
REAL
REAL
.PVH
.PVL
.DVP
.DVN
.UPD
.PV
.ERR
.OUT
Mnemonic:
.MAXS
.MINS
.DB
.SO
.MAXO
.MINO
.PVDB
.DVDB
.MAXI
.MINI
.TIE
.MAXCV
.MINCV
.MINTIE
.MAXTIE
Description
Maximum engineering unit scaling value
Minimum engineering unit scaling value
Deadband engineering units
Set output %
Maximum output limit (% of output)
Minimum output limit (% of output)
Loop update time (seconds)
Scaled PV value
Scaled error value
Output %
Process variable high alarm limit
Process variable low alarm limit
Positive deviation alarm limit
Negative deviation alarm limit
Process variable alarm deadband
Deviation alarm deadband
Maximum PV value (unscaled input)
Minimum PV value (unscaled input)
Tieback value for manual control
Maximum CV value (corresponding to 100%)
Minimum CV value (corresponding to 0%)
Minimum tieback value (corresponding to 100%)
Maximum tieback value (corresponding to 0%)
Special Instructions (FBC, DDT, DTR, PID)
Chapter 13
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
509
Chapter 13
Special Instructions (FBC, DDT, DTR, PID)
Mnemonic:
.DATA
Data Type
REAL[17]
.DOE
.SWM
.CA
.MO
.EN
.CT
.CL
.PVT
.PE
.NDF
.NOBC
.NOZC
.INI
.SPOR
.OLL
.OLH
.EWD
.DVNA
BOOL
BOOL
BOOL
BOOL
BOOL
BOOL
BOOL
BOOL
BOOL
BOOL
BOOL
BOOL
BOOL
BOOL
BOOL
BOOL
BOOL
BOOL
.DATA[4]
.DATA[5]
.DATA[6]
.DATA[7]
.DATA[8]
.DATA[9]
.DATA[10]
.DATA[11]
Description
The .DATA member stores:
Element Description
.DATA[0]
.DATA[1]
.DATA[2]
.DATA[3]
Integral accumulation
Derivative smoothing temporary value
Previous .PV value
Previous .ERR value
Previous valid .SP value
Percent scaling constant
.PV scaling constant
Derivative scaling constant
Previous .KP value
Previous .KI value
Previous .KD value
Dependent gain .KP
.DATA[12]
.DATA[13]
.DATA[14]
.DATA[15]
Dependent gain .KI
Dependent gain .KD
Previous .CV value
.CV descaling constant
Tieback descaling constant .DATA[16]
Enabled
Cascade type (0=slave; 1=master)
Cascade loop (0=no; 1=yes)
Process variable tracking (0=no; 1=yes)
Derivative of (0=PV; 1=error)
Software manual mode (0=no-auto; 1=yes- sw manual)
Control action (0 means E=SP-PV; 1 means E=PV-SP)
Station mode (0=automatic; 1=manual)
PID equation (0=independent; 1=dependent)
No derivative smoothing
(0=derivative smoothing filter enabled; 1=derivative smoothing filter disabled)
No bias back calculation
(0=bias back calculation enabled; 1=bias back calculation disabled)
No zero crossing deadband
(0=deadband is zero crossing; 1=deadband is not zero crossing)
PID initialized (0=no; 1=yes)
Setpoint out of range (0=no; 1=yes)
CV is below minimum output limit (0=no; 1=yes)
CV is above maximum output limit (0=no; 1=yes)
Error is within deadband (0=no; 1=yes)
Deviation is alarmed low (0=no; 1=yes)
510
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Mnemonic:
.DVPA
.PVLA
.PVHA
Special Instructions (FBC, DDT, DTR, PID)
Chapter 13
Data Type
BOOL
BOOL
BOOL
Description
Deviation is alarmed high (0=no; 1=yes)
PV is alarmed low (0=no; 1=yes)
PV is alarmed high (0=no; 1=yes)
Description:
The PID instruction typically receives the process variable (PV) from an analog input module and modulates a control variable output (CV) on an analog output module in order to maintain the process variable at the desired setpoint.
The .EN bit indicates execution status. The .EN bit is set when the rungcondition-in transitions from false to true. The .EN bit is cleared when the rungcondition-in becomes false. The PID instruction does not use a .DN bit. The
PID instruction executes every scan as long as the rung-condition-in is true.
.EN bit
Rung State
Execution of the PID instruction
Condition
Prescan
Rung-condition-in is false
Rung-condition-in is true
EnableIn is set
Instruction execution
Postscan
Arithmetic Status Flags:
Not affected
Fault Conditions:
IMPORTANT
A minor fault will occur if
.UPD 0
Setpoint out of range
Execution:
Action
The rung-condition-out is set to false.
The rung-condition-out is set to false.
The instruction executes.
The rung-condition-out is set to true.
N/A
The instruction executes the PID loop.
The rung-condition-out is set to false.
These faults were major faults in the PLC-5 controller.
Fault type
4
4
Fault code
35
36
Action
No action taken.
N/A
N/A
EnableIn is always set.
The instruction executes.
The instruction executes the PID loop.
No action taken.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
511
Chapter 13
Special Instructions (FBC, DDT, DTR, PID)
Configure a PID Instruction
After you enter the PID instruction and specify the PID structure, you use the configuration tabs to specify how the PID instruction should function.
Click here to configure the PID instruction
In this field
Setpoint (SP)
Set output %
Output bias
Proportional gain (K p
)
Integral gain (K i
)
Derivative time (K d
)
Manual mode
Specify Tuning
Select the Tuning tab. Changes take affect as soon as you click on another field, click OK, click Apply, or press Enter.
Specify
Enter a setpoint value (.SP).
Enter a set output percentage (.SO).
In software manual mode, this value is used for the output.
In auto mode, this value displays the output %.
Enter an output bias percentage (.BIAS).
Enter the proportional gain (.KP).
For independent gains, it’s the proportional gain (unitless).
For dependent gains, it’s the controller gain (unitless).
Enter the integral gain (.KI).
For independent gains, it’s the integral gain (1/sec).
For dependent gains, it’s the reset time (minutes per repeat).
Enter the derivative gain (.KD).
For independent gains, it’s the derivative gain (seconds).
For dependent gains, it’s the rate time minutes).
Select either manual (.MO) or software manual (.SWM).
Manual mode overrides software manual mode if both are selected.
512
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Special Instructions (FBC, DDT, DTR, PID)
Chapter 13
Specify Configuration
Select the Configuration tab. You must click OK or Apply for any changes to take effect.
In this field
PID equation
Control action
Derivative of
Loop update time
CV high limit
CV low limit
Deadband value
No derivative smoothing
No bias calculation
No zero crossing in deadband
PV tracking
Cascade loop
Cascade type
Specify
Select independent gains or dependent gains (.PE).
Use independent when you want the three gains (P, I, and D) to operate independently. Use dependent when you want an overall controller gain that affects all three terms (P, I, and D).
Select either E=PV-SP or E=SP-PV for the control action (.CA).
Select PV or error (.DOE).
Use the derivative of PV to eliminate output spikes resulting from setpoint changes. Use the derivative of error for fast responses to setpoint changes when the algorithm can tolerate overshoots.
Enter the update time (.UPD) for the instruction.
Enter a high limit for the control variable (.MAXO).
(1)
Enter a low limit for the control variable (.MINO).
(1)
Enter a deadband value (.DB).
Enable or disable this selection (.NDF).
Enable or disable this selection (.NOBC).
Enable or disable this selection (.NOZC).
Enable or disable this selection (.PVT).
Enable or disable this selection (.CL).
If cascade loop is enabled, select either slave or master (.CT).
(1) When using the ladder-based PID instruction, if you set MAXO = MINO, the PID instruction will reset these values
to default. MAXO = 100.0 and MINO = 0.0
In this field
PV high
PV low
PV deadband
Positive deviation
Negative deviation
Deviation deadband
Specify Alarms
Select the Alarms tab. You must click OK or Apply for any changes to take effect.
Specify
Enter a PV high alarm value (.PVH).
Enter a PV low alarm value (.PVL).
Enter a PV alarm deadband value (.PVDB).
Enter a positive deviation value (.DVP).
Enter a negative deviation value (.DVN).
Enter a deviation alarm deadband value (.DVDB).
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
513
Chapter 13
Special Instructions (FBC, DDT, DTR, PID)
Specify Scaling
Select the Scaling tab. You must click OK or Apply for any changes to take effect.
In this field
PV unscaled maximum
PV unscaled minimum
PV engineering units maximum
PV engineering units minimum
CV maximum
CV minimum
Tieback maximum
Tieback minimum
Specify
Enter a maximum PV value (.MAXI) that equals the maximum unscaled value received from the analog input channel for the PV value.
Enter a minimum PV value (.MINI) that equals the minimum unscaled value received from the analog input channel for the PV value.
Enter the maximum engineering units corresponding to .MAXI (.MAXS)
(1)
Enter the minimum engineering units corresponding to .MINI (.MINS)
(1)
Enter a maximum CV value corresponding to 100% (.MAXCV).
Enter a minimum CV value corresponding to 0% (.MINCV).
Enter a maximum tieback value (.MAXTIE) that equals the maximum unscaled value received from the analog input channel for the tieback value.
Enter a minimum tieback value (.MINTIE) that equals the minimum unscaled value received from the analog input channel for the tieback value.
If you change scaling constants during Run mode, turn this off to reinitialize internal descaling values (.INI).
PID Initialized
(1) When using the ladder-based PID instruction, if you set MAXO = MINO, the PID instruction will reset these values
to default. MAXO = 100.0 and MINO = 0.0
Use PID Instructions
PID closed-loop control holds a process variable at a desired set point. The illustration shows an example of a flow-rate/fluid level.
Setpoint
-
Error
PID Equation
+
Flow Rate
Process Variable
Control Variable
514
Level Detector
14271
In the above example, the level in the tank is compared against the setpoint. If the level is higher than the setpoint, the PID equation increases the control variable and causes the outlet valve from the tank to open; thereby decreasing the level in the tank.
The PID equation used in the PID instruction is a positional form equation with the option of using either independent gains or dependent gains. When using independent gains, the proportional, integral, and derivative gains affect only their specific proportional, integral, or derivative terms respectively. When using dependent gains, the proportional gain is replaced with a controller gain that
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Gains Option
Dependent gains
(ISA standard)
Independent gains
Special Instructions (FBC, DDT, DTR, PID)
Chapter 13
affects all three terms. You can use either form of equation to perform the same type of control. The two equation types are merely provided to let you use the equation type with which you are most familiar.
Derivative Of
Error (E)
Equation
CV
=
K
C
E
+
t
1
T i
0
+
T d dt
+
BIAS
Process variable (PV)
E = SP - PV
CV
=
K
C
E
+
T i
0
t
–
d dt
+
BIAS
E = PV - SP
CV
=
K
C
E
+
t
1
T i
0
+
T d dt
+
BIAS
Error (E)
t
CV
=
K
P
E
+
K i
Edt
+
K d dt
0
+
BIAS
Process variable (PV)
E = SP - PV
t
CV
=
K
P
E
+
K i
–
d
0
dt
+
BIAS
E = PV - SP
t
CV
=
K
P
E
+
K i
Edt
+
K d
0
dt
+
BIAS
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
515
Chapter 13
Special Instructions (FBC, DDT, DTR, PID)
Manual Mode of Control
Software manual (.SWM)
Manual (.MO)
Where:
Variable
K
P
K i
K d
BIAS
CV dt
PV
E
K
C
T i
T d
SP
Description
Proportional gain (unitless)
K p
= K c
unitless
Integral gain (seconds
-1
To convert between K i
)
(integral gain) and T i
(reset time), use:
K i
=
K
-----------
60T
i
Derivative gain (seconds)
To convert between K
K d
= K c
(T d
) 60 d
(derivative gain) and T d
(rate time), use:
Controller gain (unitless)
Reset time (minutes/repeat)
Rate time (minutes)
Setpoint
Process variable
Error [(SP-PV) or (PV-SP)]
Feedforward or bias
Control variable
Loop update time
If you do not want to use a particular term of the PID equation, just set its gain to zero. For example if you want no derivative action, set K d
or T d
equal to zero.
Anti-reset Windup and Bumpless Transfer from Manual to Auto
The PID instruction automatically avoids reset windup by preventing the integral term from accumulating whenever the CV output reaches its maximum or minimum values, as set by .MAXO and .MINO. The accumulated integral term remains frozen until the CV output drops below its maximum limit or rises above its minimum limit. Then normal integral accumulation automatically resumes.
The PID instruction supports two manual modes of control.
Description
Also known as set output mode
Lets the user set the output % from the software
The set output (.SO) value is used as the output of the loop. The set output value typically comes from an operator input from an operator interface device.
Takes the tieback value, as an input, and adjusts its internal variables to generate the same value at the output
The tieback input to the PID instruction is scaled to 0-100% according to the values of .MINTIE and .MAXTIE and is used as the output of the loop. The tieback input typically comes from the output of a hardware hand/auto station that is bypassing the output from the controller.
Important: Manual mode overrides software manual mode if both mode bits are set on.
516
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Special Instructions (FBC, DDT, DTR, PID)
Chapter 13
The PID instruction also automatically provides bumpless transfers from software manual mode to auto mode or from manual to auto mode. The PID instruction back-calculates the value of the integral accumulation term required to make the CV output track either the set output (.SO) value in software manual mode or the tieback input in manual mode. In this manner, when the loop switches to auto mode, the CV output starts off from the set output or tieback value and no ‘bump’ in output value occurs.
The PID instruction can also automatically provide a bumpless transfer from manual to auto even if integral control is not used (that is K i
= 0). In this case the instruction modifies the .BIAS term to make the CV output track either the set output or tieback values. When automatic control is resumed, the .BIAS term will maintain its last value. You can disable back-calculation of the .BIAS term by setting the .NOBC bit in the PID data structure. Be aware that if you set .NOBC true, the PID instruction no longer provides a bumpless transfer from manual to auto when integral control is not used.
PID Instruction Timing
The PID instruction and the sampling of the process variable need to be updated at a periodic rate. This update time is related to the physical process you are controlling. For very slow loops, such as temperature loops, an update time of once per second or even longer is usually sufficient to obtain good control.
Somewhat faster loops, such as pressure or flow loops, may require an update time such as once every 250 ms. Only rare cases, such as tension control on an unwinder spool, require loop updates as fast as every 10 ms or faster.
Because the PID instruction uses a time base in its calculation, you need to synchronize execution of this instruction with sampling of the process variable (PV).
The easiest way to execute the PID instruction is to put the PID instruction in a periodic task. Set the loop update time (.UPD) equal to the periodic task rate and make sure that the PID instruction is executed every scan of the periodic task.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
517
Chapter 13
Special Instructions (FBC, DDT, DTR, PID)
Relay Ladder
Structured Text
PID(TIC101,Local:0:I.Ch0Data,Local:0:I.Ch1Data,
Local:1:O.Ch4Data,0,Local:1:I.Ch4InHold,
Local:1:I.Ch4Data);
When using a periodic task, make sure that the analog input used for the process variable is updated to the processor at a rate that is significantly faster than the rate of the periodic task. Ideally, the process variable should be sent to the processor at least five…10 times faster than the periodic task rate. This minimizes the time difference between actual samples of the process variable and execution of the PID loop. For example, if the PID loop is in a 250 ms periodic task, use a loop update time of 250 ms (.UPD = .25), and configure the analog input module to produce data at least about every 25…50 ms.
Another, somewhat less accurate, method of executing a PID instruction is to place the instruction in a continuous task and use a timer done bit to trigger execution of the PID instruction.
518
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Relay Ladder
Special Instructions (FBC, DDT, DTR, PID)
Chapter 13
Structured Text
PID_timer.pre := 1000
TONR(PID_timer);
IF PID_timer.DN THEN
PID(TIC101,Local:0:I.Ch0Data,Local:0:I.Ch1Data,
Local:1:O.Ch0Data,0,Local:1:I.Ch0InHold,
Local:1:I.Ch0Data);
END_IF;
In this method, the loop update time of the PID instruction should be set equal to the timer preset. As in the case of using a periodic task, you should set the analog input module to produce the process variable at a significantly faster rate than the loop update time. You should only use the timer method of PID execution for loops with loop update times that are at least several times longer than the worst-case execution time for your continuous task.
The most accurate way to execute a PID instruction is to use the real time sampling (RTS) feature of the 1756 analog input modules. The analog input module samples its inputs at the real time sampling rate you configure when you set up the module. When the module’s real time sample period expires, it updates its inputs and updates a rolling timestamp (represented by the
.RollingTimestamp member of the analog input data structure) produced by the module.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
519
Chapter 13
Special Instructions (FBC, DDT, DTR, PID)
The timestamp ranges from 0…32,767 ms. Monitor the timestamp. When it changes, a new process variable sample has been received. Every time a timestamp changes, execute the PID instruction once. Because the process variable sample is driven by the analog input module, the input sample time is very accurate, and the loop update time used by the PID instruction should be set equal to the RTS time of the analog input module.
To make sure that you do not miss samples of the process variable, execute your logic at a rate faster than the RTS time. For example, if the RTS time is 250 ms, you could put the PID logic in a periodic task that runs every
100 ms to make sure that you never miss a sample. You could even place the PID logic in a continuous task, as long as you make sure that the logic would be updated more frequently than once every 250 ms.
An example of the RTS method of execution is shown below. The execution of the PID instruction depends on receiving new analog input data. If the analog input module fails or is removed, the controller stops receiving rolling timestamps and the PID loop stops executing. You should monitor the status bit of the PV analog input and, if it shows bad status, force the loop into software manual mode, and execute the loop every scan. This lets the operator still manually change the output of the PID loop.
Relay Ladder
520
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Special Instructions (FBC, DDT, DTR, PID)
Chapter 13
Structured Text
IF (Local:0:I.Ch0Fault) THEN
TIC101.SWM [:=] 1;
ELSE
TIC101.SWM := 0;
END_IF;
IF (Local:0:I.RollingTimestamp<>PreviousTimestamp) OR
(Local:0:I.Ch0Fault) THEN
PreviousTimestamp := Local:0:I.RollingTimestamp;
PID(TIC101,Local:0:I.Ch0Data,Local:0:I.Ch1Data,
Local:1:O.Ch0Data,0,Local:1:I.Ch0InHold,
Local:1:I.Ch0Data);
END_IF;
Bumpless Restart
The PID instruction can interact with the 1756 analog output modules to support a bumpless restart when the controller changes from Program to Run mode or when the controller powers up.
When a 1756 analog output module loses communications with the controller or senses that the controller is in Program mode, the analog output module sets its outputs to the fault condition values you specified when you configured the module. When the controller then returns to Run mode or re-establishes communications with the analog output module, you can have the PID instruction automatically reset its control variable output equal to the analog output by using the Inhold bit and Inhold Value parameters on the
PID instruction.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
521
Chapter 13
Special Instructions (FBC, DDT, DTR, PID)
Instructions for setting a bumpless restart.
Do this
Configure the 1756 analog output module’s channel that receives the control variable from the PID instruction
Details
Select the “hold for initialization” checkbox on the properties page for the specific channel of the module.
This tells the analog output module that when the controller returns to Run mode or re-establishes communications with the module, the module should hold the analog output at its current value until the value sent from the controller matches (within 0.1% of span) the current value used by the output channel. The controller’s output will ramp to the currently held output value by making use of the .BIAS term. This ramping is similar to auto bumpless transfer.
Enter the Inhold bit tag and Inhold Value tag in the PID instruction The 1756 analog output module returns two values for each channel in its input data structure. The InHold status bit (.Ch2InHold, for example), when true, indicates that the analog output channel is holding its value.
The Data readback value (.Ch2Data, for example) shows the current output value in engineering units.
Enter the tag of the InHold status bit as the InHold bit parameter of the PID instruction. Enter the tag of the
Data readback value as the Inhold Value parameter.
When he Inhold bit goes true, the PID instruction moves the Inhold Value into the Control variable output and re-initializes to support a bumpless restart at that value. When the analog output module receives this value back from the controller, it turns off the InHold status bit, which allows the PID instruction to start controlling normally.
Derivative Smoothing
The derivative calculation is enhanced by a derivative smoothing filter. This first order, low pass, digital filter helps to minimize large derivative term spikes caused by noise in the PV. This smoothing becomes more aggressive with larger values of derivative gain. You can disable derivative smoothing if your process requires very large values of derivative gain (K d
> 10, for example). To disable derivative smoothing, select the “No derivative smoothing” option on the Configuration tab or set the .NDF bit in the PID structure.
Set the Deadband
The adjustable deadband lets you select an error range above and below the setpoint where output does not change as long as the error remains within this range. This deadband lets you control how closely the process variable matches the setpoint without changing the output. The deadband also helps to minimize wear and tear on your final control device.
+ Deadband
Setpoint
- Deadband
Error Within Deadband Range
Time
41026
522
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Special Instructions (FBC, DDT, DTR, PID)
Chapter 13
Zero-crossing is deadband control that lets the instruction use the error for computational purposes as the process variable crosses into the deadband until the process variable crosses the setpoint. Once the process variable crosses the setpoint (error crosses zero and changes sign) and as long as the process variable remains in the deadband, the output will not change.
The deadband extends above and below the setpoint by the value you specify.
Enter zero to inhibit the deadband. The deadband has the same scaled units as the setpoint. You can use the deadband without the zero-crossing feature by selecting the ‘no zero crossing for deadband’ option on the Configuration tab or set the .NOZC bit in the PID structure.
If you are using the deadband, the Control variable must be REAL or it will be forced to zero when the error is within the deadband.
Use Output Limiting
You can set an output limit (percentage of output) on the control output. When the instruction detects that the output has reached a limit, it sets an alarm bit and prevents the output from exceeding either the lower or upper limit.
Feedforward or Output Biasing
You can feedforward a disturbance from the system by feeding the .BIAS value into the PID instruction’s feedforward/bias value.
The feedforward value represents a disturbance fed into the PID instruction before the disturbance has a chance to change the process variable. Feedforward is often used to control processes with a transportation lag. For example, a feedforward value representing ‘cold water poured into a warm mix’ could boost the output value faster than waiting for the process variable to change as a result of the mixing.
A bias value is typically used when no integral control is used. In this case, the bias value can be adjusted to maintain the output in the range required to keep the PV near the setpoint.
Cascade Loops
The PID cascades two loops by assigning the output in percent of the master loop to the setpoint of the slave loop. The slave loop automatically converts the output of the master loop into the correct engineering units for the setpoint of the slave loop, based on the slave loop’s values for .MAXS
and .MINS.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
523
Chapter 13
Special Instructions (FBC, DDT, DTR, PID)
Relay Ladder
Structured Text
PID(master,pv_master,0,cv_master,0,0,0);
PID (slave,pv_slave,0,cv_slave,master,0,0);
Control a Ratio
You can maintain two values in a ratio by using these parameters:
• Uncontrolled value
• Controlled value (the resultant setpoint to be used by the PID instruction)
• Ratio between these two values
Relay Ladder
524
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Structured Text
pid_2.sp := uncontrolled_flow * ratio
PID(pid_2,pv_2,tieback_2,cv_2,0,0,0);
Special Instructions (FBC, DDT, DTR, PID)
Chapter 13
For this multiplication parameter
Destination
Source A
Source B
Enter this value
Controlled value
Uncontrolled value
Ratio
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
525
Chapter 13
Special Instructions (FBC, DDT, DTR, PID)
PID Theory
SP
The following figures show the process flow for PID instructions.
PID Process
SP
Displayed as EUs
Error Displayed as EUs
Auto
No
Manual
PVT
Software A/M or
A/M Station Mode
+
-
Control Action
SP-PV
(Error)
-1
PV-SP
Converts Units to %
Error X 100 maxs-mins
PV
Displayed as EUs
Yes
Converts Binary to
Engineering Units
(PV-mini)(maxs-mins) maxi-mini
+ mins
PID Calculation
(Out%)
Output
Bias %
+
Software A/M
Mode
Auto
Auto
Set Output %
Manual
Manual
A/M Station Mode
Output
Limiting
Output (CV)
Displayed as % of
EU Scale
Converts Tieback Units to
% tieback-mintie maxtie-mintie x 100
Set Output %
Convert % to CV Units
CV%(maxcv-mincv)
100
+ mincv
PV
PID Process with Master/Slave Loops
Master
Loop
SP
Slave Loop
Software A/M or
A/M Station Mode
Auto
Manual
No
PVT
+
-
Yes
Converts Binary to
Engineering Units
(PV-mini)(maxs-mins) maxi-mini
SP-PV
-1
+ mins
Control Action
(Error)
PV-SP
Error X 100 maxs-mins
SP
PV
Converts Units to %
PID Calculation
Set Output %
(Out%)
Output
Bias %
+
Software A/M
Mode
Auto
Auto
Manual
Manual
Software A/M
Mode
Auto
Converts Units to %
Error X 100 maxs-mins
Manual
Manual
A/M Station Mode
Output
Limiting
Set Output %
(Master.Out)
Items referenced in this box are parameters, units, and modes as they pertain to the designated Slave loop.
PV
(Master.Out)
100
Converts % to
Engineering Units
X (maxs-mins)
+ mins
(SP)
+
-
Converts Binary to
Engineering Units
(PV-mini)(maxs-mins) maxi-mini
Control Action
+ mins
SP-PV
-1
PV-SP
Converts Units to %
Error X 100 maxs-mins
PID Calculation
Output
Bias %
+
Software A/M
Mode
Auto
Auto
Set Output %
Manual
Manual
A/M Station Mode
Output
Limiting
Set Output %
Convert % to CV Units
CV%(maxcv-mincv)
100
+ mincv
Converts Tieback Units to
% tieback-mintie maxtie-mintie x 100
PV
CV
526
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
If you want to
Take the sine of a value
Take the cosine of a value
Take the tangent of a value
Take the arc sine of a value
Take the arc cosine of a value
Take the arc tangent of a value
(1) Structured text only.
Chapter
14
Trigonometric Instructions
(SIN, COS, TAN, ASN, ASIN, ACS, ACOS, ATN, ATAN)
Topic
Page
The trigonometric instructions evaluate arithmetic operations by using trigonometric operations.
Use this instruction
SIN
COS
TAN
ASN
ASIN
(1)
ACS
ACOS
(1)
ATN
ATAN
(1)
Available in these languages
Relay ladder
Structured text
Function block
Relay ladder
Structured text
Function block
Relay ladder
Structured text
Function block
Relay ladder
Structured text
Function block
Relay ladder
Structured text
Function block
Relay ladder
Structured text
Function block
Page
You can mix data types, but loss of accuracy and rounding error might occur and the instruction takes more time to execute. Check the overflow status bit (S:V) to see whether the result was truncated.
For relay ladder instructions, bold data types indicate optimal data types. An instruction executes faster and requires less memory if all the operands of the instruction use the same optimal data type, typically DINT or REAL.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
527
Chapter 14
Trigonometric Instructions (SIN, COS, TAN, ASN, ASIN, ACS, ACOS, ATN, ATAN)
Sine (SIN)
Operands:
The SIN instruction takes the sine of the Source value (in radians) and stores the result in the Destination.
Relay Ladder
Operand
Source
Destination
Type
SINT
INT
DINT
REAL
SINT
INT
DINT
REAL
Format
Immediate
Tag
Description
Find the sine of this value
Tag Tag to store the result dest := SIN(source);
Input Parameter
EnableIn
Source
Output Parameter
EnableOut
Dest
Data Type
BOOL
REAL
Data Type
BOOL
REAL
Structured Text
Use SIN as a function. This function computes the sine of source and stores the result in
dest.
See
Structured Text Programming for information on the syntax of expressions
within structured text.
Function Block
Operand
SIN tag
Type
FBD_MATH_ADVANCED
Format
Structure
Description
SIN structure
FBD_MATH_ADVANCED Structure
Description
Enable input. If cleared, the instruction does not execute and outputs are not updated.
Default is set.
Input to the math instruction.
Valid = any float
Description
The instruction produced a valid result.
Result of the math instruction. Arithmetic status flags are set for this output.
528
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Trigonometric Instructions (SIN, COS, TAN, ASN, ASIN, ACS, ACOS, ATN, ATAN)
Chapter 14
Description:
The Source must be greater than or equal to -205887.4 (-2x2
15
) and less than or equal to 205887.4 (2x2
15
). The resulting value in the Destination is always greater than or equal to -1 and less than or equal to 1.
Arithmetic Status Flags:
Arithmetic status flags are affected.
Fault Conditions:
None
Execution:
Condition
Prescan
Rung-condition-in is false
Rung-condition-in is true
Postscan
Relay Ladder
Action
The rung-condition-out is set to false.
The rung-condition-out is set to false.
The controller calculates the sine of the Source and places the result in the Destination.
The rung-condition-out is set to true.
The rung-condition-out is set to false.
Condition
Prescan
Instruction first scan
Iinstruction first run
EnableIn is cleared
EnableIn is set
Postscan
Function Block
Action
No action taken.
No action taken.
No action taken.
EnableOut is cleared.
The instruction executes.
EnableOut is set.
No action taken.
Example:
Calculate the sine of
value and place the result in result.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
529
Chapter 14
Trigonometric Instructions (SIN, COS, TAN, ASN, ASIN, ACS, ACOS, ATN, ATAN)
Relay Ladder
Structured Text
result := SIN(value);
Function Block
530
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Cosine (COS)
dest := COS(source);
Input Parameter
EnableIn
Source
Output Parameter
EnableOut
Dest
Data Type
BOOL
REAL
Data Type
BOOL
REAL
Trigonometric Instructions (SIN, COS, TAN, ASN, ASIN, ACS, ACOS, ATN, ATAN)
Chapter 14
Operands:
The COS instruction takes the cosine of the Source value (in radians) and stores the result in the Destination.
Relay Ladder
Operand
Source
Destination
Type
SINT
INT
DINT
REAL
SINT
INT
DINT
REAL
Format
Immediate
Tag
Description
Find the cosine of this value
Tag Tag to store the result
Structured Text
Use COS as a function. This function computes the cosine of source and stores the result in
dest.
See Structured Text Programming
for information on the syntax of expressions within structured text.
Function Block
Operand
COS tag
Type
FBD_MATH_ADVANCED
Format
Structure
Description
COS structure
FBD_MATH_ADVANCED Structure
Description
Enable input. If cleared, the instruction does not execute and outputs are not updated.
Default is set.
Input to the math instruction.
Valid = any float
Description
The instruction produced a valid result.
Result of the math instruction. Arithmetic status flags are set for this output.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
531
Chapter 14
Trigonometric Instructions (SIN, COS, TAN, ASN, ASIN, ACS, ACOS, ATN, ATAN)
Description:
The Source must be greater than or equal to -205887.4 (-2x2 equal to 205887.4 (2x2
15
) and less than or
15
). The resulting value in the Destination is always greater than or equal to -1 and less than or equal to 1.
Arithmetic Status Flags:
Arithmetic status flags are affected.
Fault Conditions:
None
Execution:
Condition
Prescan
Rung-condition-in is false
Rung-condition-in is true
Postscan
Relay Ladder
Action
The rung-condition-out is set to false.
The rung-condition-out is set to false.
The controller calculates the cosine of the Source and places the result in the Destination.
The rung-condition-out is set to true.
The rung-condition-out is set to false.
Condition
Prescan
Instruction first scan
Instruction first run
EnableIn is cleared
EnableIn is set
Postscan
Function Block
Action
No action taken.
No action taken.
No action taken.
EnableOut is cleared.
The instruction executes.
EnableOut is set.
No action taken.
Example:
Calculate the cosine of
value and place the result in result.
532
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Relay Ladder
Trigonometric Instructions (SIN, COS, TAN, ASN, ASIN, ACS, ACOS, ATN, ATAN)
Chapter 14
Structured Text
result := COS(value);
Function Block
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
533
Chapter 14
Trigonometric Instructions (SIN, COS, TAN, ASN, ASIN, ACS, ACOS, ATN, ATAN)
Tangent (TAN)
Operands:
The TAN instruction takes the tangent of the Source value (in radians) and stores the result in the Destination.
Relay Ladder
Operand
Source
Destination
Type
SINT
INT
DINT
REAL
SINT
INT
DINT
REAL
Format
Immediate
Tag
Description
Find the tangent of this value
Tag Tag to store the result dest := TAN(source);
Input Parameter
EnableIn
Source
Output Parameter
EnableOut
Dest
534
Structured Text
Use TAN as a function. This function computes the tangent of source and stores the result in
dest.
See
Structured Text Programming for information on the syntax of expressions
within structured text.
Function Block
Operand
TAN tag
Type
FBD_MATH_ADVANCED
Format
Structure
Description
TAN structure
FBD_MATH_ADVANCED Structure
Data Type
BOOL
REAL
Data Type
BOOL
REAL
Description
Enable input. If cleared, the instruction does not execute and outputs are not updated.
Default is set.
Input to the math instruction.
Valid = any float
Description
The instruction produced a valid result.
Result of the math instruction. Arithmetic status flags are set for this output.
Description:
The Source must be greater than or equal to -102943.7(-2x2 equal to 102943.7 (2x2
14
).
14
) and less than or
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Trigonometric Instructions (SIN, COS, TAN, ASN, ASIN, ACS, ACOS, ATN, ATAN)
Chapter 14
Arithmetic Status Flags:
Arithmetic status flags are affected.
Fault Conditions:
None
Execution:
Condition
Prescan
Rung-condition-in is false
Rung-condition-in is true
Postscan
Relay Ladder
Action
The rung-condition-out is set to false.
The rung-condition-out is set to false.
The controller calculates the tangent of the Source and places the result in the Destination.
The rung-condition-out is set to true.
The rung-condition-out is set to false.
Condition
Prescan
Instruction first scan
Instruction first run
EnableIn is cleared
EnableIn is set
Postscan
Function Block
Action
No action taken.
No action taken.
No action taken.
EnableOut is cleared.
The instruction executes.
EnableOut is set.
No action taken.
Example:
Calculate the tangent of
value and place the result in result.
Relay Ladder
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
535
Chapter 14
Trigonometric Instructions (SIN, COS, TAN, ASN, ASIN, ACS, ACOS, ATN, ATAN)
Structured Text
result := TAN(value);
Function Block
536
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Arc Sine (ASN)
Trigonometric Instructions (SIN, COS, TAN, ASN, ASIN, ACS, ACOS, ATN, ATAN)
Chapter 14
Operands:
The ASN instruction takes the arc sine of the Source value and stores the result in the Destination (in radians).
Relay Ladder
Operand
Source
Destination
Type
SINT
INT
DINT
REAL
SINT
INT
DINT
REAL
Format
Immediate
Tag
Description
Find the arc sine of this value
Tag Tag to store the result dest := ASIN(source);
Input Parameter
EnableIn
Source
Output Parameter
EnableOut
Dest
Structured Text
Use ASIN as a function. This function computes the arc sine of source and stores the result in
dest.
See Structured Text Programming
for information on the syntax of expressions within structured text.
Function Block
Operand
ASN tag
Type
FBD_MATH_ADVANCED
Format
Structure
Description
ASN structure
FBD_MATH_ADVANCED Structure
Data Type
BOOL
REAL
Data Type
BOOL
REAL
Description
Enable input. If cleared, the instruction does not execute and outputs are not updated.
Default is set.
Input to the math instruction.
Valid = any float
Description
The instruction produced a valid result.
Result of the math instruction. Arithmetic status flags are set for this output.
Description:
The Source must be greater than or equal to -1 and less than or equal to 1. The resulting value in the Destination is always greater than or equal to -/2 and less than or equal to /2 (where = 3.141593).
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
537
Chapter 14
Trigonometric Instructions (SIN, COS, TAN, ASN, ASIN, ACS, ACOS, ATN, ATAN)
Arithmetic Status Flags:
Arithmetic status flags are affected.
Fault Conditions:
None
Execution:
Condition
Prescan
Rung-condition-in is false
Rung-condition-in is true
Postscan
Relay Ladder
Action
The rung-condition-out is set to false.
The rung-condition-out is set to false.
The controller calculates the arc sine of the Source and places the result in the Destination.
The rung-condition-out is set to true.
The rung-condition-out is set to false.
Condition
Prescan
Instruction first scan
Instruction first run
EnableIn is cleared
EnableIn is set
Postscan
Function Block
Action
No action taken.
No action taken.
No action taken.
EnableOut is cleared.
The instruction executes.
EnableOut is set.
No action taken.
Example:
Calculate the arc sine of
value and place the result in result.
Relay Ladder
538
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Trigonometric Instructions (SIN, COS, TAN, ASN, ASIN, ACS, ACOS, ATN, ATAN)
Chapter 14
Structured Text
result := ASIN(value);
Function Block
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
539
Chapter 14
Trigonometric Instructions (SIN, COS, TAN, ASN, ASIN, ACS, ACOS, ATN, ATAN)
Arc Cosine (ACS)
Operands:
The ACS instruction takes the arc cosine of the Source value and stores the result in the Destination (in radians).
Relay Ladder
Operand
Source
Destination
Type
SINT
INT
DINT
REAL
SINT
INT
DINT
REAL
Format
Immediate
Tag
Description
Find the arc cosine of this value
Tag Tag to store the result dest := ACOS(source);
Input Parameter
EnableIn
Source
Output Parameter
EnableOut
Dest
540
Structured Text
Use ACOS as a function. This function computes the arc cosine of source and stores the result in
dest.
See
Structured Text Programming for information on the syntax of expressions
within structured text.
Function Block
Operand
ACS tag
Type
FBD_MATH_ADVANCED
Format
Structure
Description
ACS structure
FBD_MATH_ADVANCED Structure
Data Type
BOOL
REAL
Data Type
BOOL
REAL
Description:
Enable input. If cleared, the instruction does not execute and outputs are not updated.
Default is set.
Input to the math instruction.
Valid = any float
Description
The instruction produced a valid result.
Result of the math instruction. Arithmetic status flags are set for this output.
Description:
The Source must be greater than or equal to -1 and less than or equal to 1. The resulting value in the Destination is always greater than or equal to 0 or less than or equal to (where = 3.141593).
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Trigonometric Instructions (SIN, COS, TAN, ASN, ASIN, ACS, ACOS, ATN, ATAN)
Chapter 14
Arithmetic Status Flags:
Arithmetic status flags are affected.
Fault Conditions:
None
Execution:
Condition
Prescan
Rung-condition-in is false
Rung-condition-in is true
Postscan
Relay Ladder
Action
The rung-condition-out is set to false.
The rung-condition-out is set to false.
The controller calculates the arc cosine of the Source and places the result in the Destination.
The rung-condition-out is set to true.
The rung-condition-out is set to false.
Condition:
Prescan
Instruction first scan
Instruction first run
EnableIn is cleared
EnableIn is set
Postscan
Function Block
Action
No action taken.
No action taken.
No action taken.
EnableOut is cleared.
The instruction executes.
EnableOut is set.
No action taken.
Example:
Calculate the arc cosine of
value and place the result in result.
Relay Ladder
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
541
Chapter 14
Trigonometric Instructions (SIN, COS, TAN, ASN, ASIN, ACS, ACOS, ATN, ATAN)
Structured Text
result := ACOS(value);
Function Block
542
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Trigonometric Instructions (SIN, COS, TAN, ASN, ASIN, ACS, ACOS, ATN, ATAN)
Chapter 14
Arc Tangent (ATN)
Operands:
The ATN instruction takes the arc tangent of the Source value and stores the result in the Destination (in radians).
Relay Ladder
Operand:
Source
Destination
Type
SINT
INT
DINT
REAL
SINT
INT
DINT
REAL
Format
Immediate
Tag
Description
Find the arc tangent of this value
Tag Tag to store the result dest := ATAN(source);
Structured Text
Use ATAN as a function. This function computes the arc tangent of source and stores the result in
dest.
See Structured Text Programming
for information on the syntax of expressions within structured text.
Function Block
Operand
ATN tag
Type
FBD_MATH_ADVANCED
Format
Structure
Description
ATN structure
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
543
Chapter 14
Trigonometric Instructions (SIN, COS, TAN, ASN, ASIN, ACS, ACOS, ATN, ATAN)
FBD_MATH_ADVANCED Structure
Input Parameter
EnableIn
Source
Output Parameter
EnableOut
Dest
Data Type
BOOL
REAL
Data Type
BOOL
REAL
Description
Enable input. If cleared, the instruction does not execute and outputs are not updated.
Default is set.
Input to the math instruction.
Valid = any float
Description
The instruction produced a valid result.
Result of the math instruction. Arithmetic status flags are set for this output.
Description:
The resulting value in the Destination is always greater than or equal to -/2 and less than or equal to /2 (where = 3.141593).
Arithmetic Status Flags:
Arithmetic status flags are affected.
Fault Conditions:
None
Execution:
Condition
Prescan
Rrung-condition-in is false
Rung-condition-in is true
Postscan
Relay Ladder
Action
The rung-condition-out is set to false.
The rung-condition-out is set to false.
The controller calculates the arc tangent of the Source and places the result in the Destination.
The rung-condition-out is set to true.
The rung-condition-out is set to false.
Condition
Prescan
Instruction first scan
Instruction first run
EnableIn is cleared
EnableIn is set
Postscan
Function Block
Action
No action taken.
No action taken.
No action taken.
EnableOut is cleared.
The instruction executes.
EnableOut is set.
No action taken.
544
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Trigonometric Instructions (SIN, COS, TAN, ASN, ASIN, ACS, ACOS, ATN, ATAN)
Chapter 14
Example:
Calculate the arc tangent of
value and place the result in result.
Relay Ladder
Structured Text
result := ATAN(value);
Function Block
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
545
Chapter 14
Trigonometric Instructions (SIN, COS, TAN, ASN, ASIN, ACS, ACOS, ATN, ATAN)
Notes:
546
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Chapter
15
Advanced Math Instructions
(LN, LOG, XPY)
Topic
Page
If you want to
Take the natural log of a value
Take the log base 10 of a value
Raise a value to the power of another value
The advanced math instructions include these instructions.
Use this instruction
LN
LOG
XPY
Available in these languages
Relay ladder
Structured text
Function block
Relay ladder
Structured text
Function block
Relay ladder
Structured text
(1)
Function block
(1) There is no equivalent structured text instruction. Use the operator in an expression.
Page
You can mix data types, but loss of accuracy and rounding error might occur and the instruction takes more time to execute. Check the S:V bit to see whether the result was truncated.
For relay ladder instructions, bold data types indicate optimal data types. An instruction executes faster and requires less memory if all the operands of the instruction use the same optimal data type, typically DINT or REAL.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
547
Chapter 15
Advanced Math Instructions (LN, LOG, XPY)
Natural Log (LN)
Operands:
The LN instruction takes the natural log of the Source and stores the result in the
Destination.
Relay Ladder
Operand
Source
Destination
Type
SINT
INT
DINT
REAL
SINT
INT
DINT
REAL
Format
Immediate
Tag
Description
Find the natural log of this value
Tag Tag to store the result dest := LN(source);
Input Parameter
EnableIn
Source
Output Parameter
EnableOut
Structured Text
Use LN as a function. This function computes the natural log of source and stores the result in
dest.
See
Structured Text Programming for information on the syntax of expressions
within structured text.
Function Block
Operand
LN tag
Type
FBD_MATH_ADVANCED
Format
Structure
Description
LN structure
FBD_MATH_ADVANCED Structure
Data Type
BOOL
REAL
Data Type
BOOL
Description
Enable input. If cleared, the instruction does not execute and outputs are not updated.
Default is set.
Input to math instruction.
Valid = any float
Description
The instruction produced a valid result.
Description:
The Source must be greater than zero, otherwise the overflow status bit (S:V) is set. The resulting Destination is greater than or equal to -87.33655 and less than or equal to 88.72284.
548
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Advanced Math Instructions (LN, LOG, XPY)
Chapter 15
Arithmetic Status Flags:
Arithmetic status flags are affected.
Fault Conditions:
None
Execution:
Condition
Prescan
Rung-condition-in is false
Rung-condition-in is true
Postscan
Relay Ladder
Action
The rung-condition-out is set to false.
The rung-condition-out is set to false.
The controller calculates the natural log of the Source and places the result in the Destination.
The rung-condition-out is set to true.
The rung-condition-out is set to false.
Condition
Prescan
Instruction first scan
Instruction first run
EnableIn is cleared
EnableIn is set
Postscan
Function Block
Action
No action taken.
No action taken.
No action taken.
EnableOut is cleared.
The instruction executes.
EnableOut is set.
No action taken.
Example:
Calculate the natural log of
value and place the result in result.
Relay Ladder Example
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
549
Chapter 15
Advanced Math Instructions (LN, LOG, XPY)
Structured Text
result := LN(value);
Function Block
550
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Advanced Math Instructions (LN, LOG, XPY)
Chapter 15
Log Base 10 (LOG)
Operands:
The LOG instruction takes the log base 10 of the Source and stores the result in the Destination.
Relay Ladder
Operand
Source
Destination
Type
SINT
INT
DINT
REAL
SINT
INT
DINT
REAL
Format
Immediate
Tag
Description
Find the log of this value
Tag Tag to store the result dest := LOG(source);
Input Parameter
EnableIn
Source
Output Parameter
EnableOut
Dest
Structured Text
Use LOG as a function. This function computes the log of source and stores the result in
dest.
See Structured Text Programming
for information on the syntax of expressions within structured text.
Function Block
Operand
LOG tag
Type
FBD_MATH_ADVANCED
Format
Structure
Description
LOG structure
FBD_MATH_ADVANCED Structure
Data Type
BOOL
REAL
Data Type
BOOL
REAL
Description
Enable input. If cleared, the instruction does not execute and outputs are not updated.
Default is set.
Input to math instruction.
Valid = any float
Description
The instruction produced a valid result.
Result of the math instruction. Arithmetic status flags are set for this output.
Description:
The Source must be greater than zero, otherwise the overflow status bit (S:V) is set. The resulting Destination is greater than or equal to -37.92978 and less than or equal to 38.53184.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
551
Chapter 15
Advanced Math Instructions (LN, LOG, XPY)
Arithmetic Status Flags:
Arithmetic status flags are affected.
Fault Conditions:
None
Execution:
Condition
Prescan
Rung-condition-in is false
Rung-condition-in is true
Postscan
Relay Ladder
Action
The rung-condition-out is set to false.
The rung-condition-out is set to false.
The controller calculates the log of the Source and places the result in the Destination.
The rung-condition-out is set to true.
The rung-condition-out is set to false.
Condition
Prescan
Instruction first scan
Instruction first run
EnableIn is cleared
EnableIn is set
Postscan
Function Block
Action
No action taken.
No action taken.
No action taken.
EnableOut is cleared.
The instruction executes.
EnableOut is set.
No action taken.
Example:
Calculate the log of
value and place the result in result.
Relay Ladder
552
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Structured Text
result := LOG(value);
Function Block
Advanced Math Instructions (LN, LOG, XPY)
Chapter 15
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
553
Chapter 15
Advanced Math Instructions (LN, LOG, XPY)
X to the Power of Y (XPY)
Operands:
The XPY instruction takes Source A (X) to the power of Source B (Y) and stores the result in the Destination.
Relay Ladder
Operand
Source X
Source Y
Destination
SINT
INT
DINT
REAL
SINT
INT
DINT
REAL
Type
SINT
INT
DINT
REAL
Format
Immediate
Tag
Description
Base value
Immediate
Tag
Exponent
Tag Tag to store the result dest := sourceX ** sourceY;
Structured Text
Use two, adjacent multiply signs ‘’ as an operator within an expression. This expression takes sourceX to the power of sourceY and stores the result in
dest.
See
Structured Text Programming for information on the syntax of expressions
within structured text.
Function Block
Operand
XPY tag
Type
FBD_MATH
Format
Structure
Description
XPY structure
554
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Advanced Math Instructions (LN, LOG, XPY)
Chapter 15
Input Parameter
EnableIn
Source X
Source Y
Output Parameter
EnableOut
Dest
Data Type
BOOL
REAL
REAL
Data Type
BOOL
REAL
FBD_MATH Structure
Description
Enable input. If cleared, the instruction does not execute and outputs are not updated.
Default is set.
Base value.
Valid = any float
Exponent.
Valid = any float
Description
The instruction produced a valid result.
Result of the math instruction. Arithmetic status flags are set for this output.
Description:
If Source X is negative, SourceY must be an integer value or a minor fault will occur.
The XPY instruction uses this algorithm: Destination = X**Y
The controller evaluates x
0
=1 and 0 x
=0.
Arithmetic Status Flags:
Arithmetic status flags are affected.
Fault Conditions:
A Minor Fault Will Occur If
Source X is negative and Source Y is not an integer value
Fault Type
4
Fault Code
4
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
555
Chapter 15
Advanced Math Instructions (LN, LOG, XPY)
Execution:
Condition
Prescan
Rung-condition-in is false
Rung-condition-in is true
Postscan
Condition
Prescan
Instruction first scan
Instruction first run
EnableIn is cleared
EnableIn is set
Postscan
Relay Ladder
Action
The rung-condition-out is set to false.
The rung-condition-out is set to false.
The controller takes Source X to the power of Source Y and places the result in the Destination.
The rung-condition-out is set to true.
The rung-condition-out is set to false.
Function Block
Action
No action taken.
No action taken.
No action taken.
EnableOut is cleared.
The instruction executes.
EnableOut is set.
No action taken.
Example:
The XPY instruction takes
value_1 to the power of value_2 and places the result in result.
Relay Ladder
556
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Structured Text
result := (value_1 value_2);
Function Block
Advanced Math Instructions (LN, LOG, XPY)
Chapter 15
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
557
Chapter 15
Advanced Math Instructions (LN, LOG, XPY)
Notes:
558
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
If you want to
Convert radians to degrees
Convert degrees to radians
Convert an integer value to a BCD value
Convert a BCD value to an integer value
Remove the fractional part of a value
(1) Structured text only.
Chapter
16
Math Conversion Instructions
(DEG, RAD, TOD, FRD, TRN, TRUNC)
Topic
Page
The math conversion instructions convert values.
Use this instruction
DEG
RAD
TOD
FRD
TRN
TRUNC
(1)
Available in these languages
Relay ladder
Structured text
Function block
Relay ladder
Structured text
Function block
Relay ladder
Function block
Relay ladder
Function block
Relay ladder
Structured text
Function block
Page
You can mix data types, but loss of accuracy and rounding error might occur and the instruction takes more time to execute. Check the S:V bit to see whether the result was truncated.
For relay ladder instructions, bold data types indicate optimal data types. An instruction executes faster and requires less memory if all the operands of the instruction use the same optimal data type, typically DINT or REAL.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
559
Chapter 16
Math Conversion Instructions (DEG, RAD, TOD, FRD, TRN, TRUNC)
Degrees (DEG)
Operands:
The DEG instruction converts the Source (in radians) to degrees and stores the result in the Destination.
Relay Ladder
Operand
Source
Destination
Type
SINT
INT
DINT
REAL
SINT
INT
DINT
REAL
Format
Immediate
Tag
Description
Value to convert to degrees
Tag Tag to store the result dest := DEG(source);
Structured Text
Use DEG as a function. This function converts source to degrees and stores the result in
dest.
See
Structured Text Programming for information on the syntax of expressions
within structured text.
Function Block
Operand
DEG tag
Type
FBD_MATH_ADVANCED
Format
Structure
Description
DEG structure
560
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Math Conversion Instructions (DEG, RAD, TOD, FRD, TRN, TRUNC)
Chapter 16
FBD_MATH_ADVANCED Structure
Input Parameter
EnableIn
Source
Output Parameter
EnableOut
Dest
Data Type
BOOL
REAL
Data Type
BOOL
REAL
Description
Enable input. If cleared, the instruction does not execute and outputs are not updated.
Default is set.
Input to the conversion instruction.
Valid = any float
Description
The instruction produced a valid result.
Result of the conversion instruction. Arithmetic status flags are set for this output.
Description:
The DEG instruction uses this algorithm:
Source*180/(where = 3.141593)
Arithmetic Status Flags:
Arithmetic status flags are affected.
Fault Conditions:
None
Execution:
Condition
Prescan
Rung-condition-in is false
Rung-condition-in is true
Postscan
Relay Ladder
Action
The rung-condition-out is set to false.
The rung-condition-out is set to false.
The controller converts the Source to degrees and places the result in the Destination.
The rung-condition-out is set to true.
The rung-condition-out is set to false.
Condition
Prescan
Instruction first scan
Instruction first run
EnableIn is cleared
EnableIn is set
Postscan
Function Block
Action
No action taken.
No action taken.
No action taken.
EnableOut is cleared.
The instruction executes.
EnableOut is set.
No action taken.
Example:
Convert value to degrees and place the result in result.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
561
Chapter 16
Math Conversion Instructions (DEG, RAD, TOD, FRD, TRN, TRUNC)
Relay Ladder
Structured Text
result := DEG(value);
Function Block
562
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Radians (RAD)
dest := RAD(source);
Math Conversion Instructions (DEG, RAD, TOD, FRD, TRN, TRUNC)
Chapter 16
Operands:
The RAD instruction converts the Source (in degrees) to radians and stores the result in the Destination.
Relay Ladder
Operand
Source
Destination
Type
SINT
INT
DINT
REAL
SINT
INT
DINT
REAL
Format
Immediate
Tag
Description
Value to convert to radians
Tag Tag to store the result
Structured Text
Use RAD as a function. This function converts source to radians and stores the result in
dest.
See Structured Text Programming
for information on the syntax of expressions within structured text.
Function Block
Operand
RAD tag
Type
FBD_MATH_ADVANCED
Format
structure
Description
RAD structure
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
563
Chapter 16
Math Conversion Instructions (DEG, RAD, TOD, FRD, TRN, TRUNC)
FBD_MATH_ADVANCED Structure
Input Parameter
EnableIn
Source
Output Parameter
EnableOut
Dest
Data Type
BOOL
REAL
Data Type
BOOL
REAL
Description
Enable input. If cleared, the instruction does not execute and outputs are not updated.
Default is set.
Input to the conversion instruction.
Valid = any float
Description
The instruction produced a valid result.
Result of the conversion instruction. Arithmetic status flags are set for this output.
Description:
The RAD instruction uses this algorithm:
Source*/180 (where = 3.141593)
Arithmetic Status Flags:
Arithmetic status flags are affected.
Fault Conditions:
None
Execution:
Condition
Prescan
Rung-condition-in is false
Rung-condition-in is true
Postscan
Relay Ladder
Action
The rung-condition-out is set to false.
The rung-condition-out is set to false.
The controller converts the Source to radians and places the result in the Destination.
The rung-condition-out is set to true.
The rung-condition-out is set to false.
Condition
Prescan
Instruction first scan
Instruction first run
EnableIn is cleared
EnableIn is set
Postscan
Function Block
Action
No action taken.
No action taken.
No action taken.
EnableOut is cleared.
The instruction executes.
EnableOut is set.
No action taken.
Example
Convert value to radians and place the result in result.
564
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Relay Ladder
Math Conversion Instructions (DEG, RAD, TOD, FRD, TRN, TRUNC)
Chapter 16
Structured Text
result := RAD(value);
Function Block
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
565
Chapter 16
Math Conversion Instructions (DEG, RAD, TOD, FRD, TRN, TRUNC)
Convert to BCD (TOD)
Operands:
The TOD instruction converts a decimal value
(0
Source 99,999,999)
to a BCD value and stores the result in the Destination.
Relay Ladder
Operand
Source
Destination
Type
SINT
INT
DINT
Format
Immediate
Tag
Description
Value to convert to decimal
A SINT or INT tag converts to a DINT value by zero-fill.
SINT
INT
DINT
Tag Stores the result
Input Parameter
EnableIn
Source
Output Parameter
EnableOut
Dest
Function Block
Operand
TOD tag
Type
FBD_CONVERT
Format
Structure
Description
TOD structure
Data Type
BOOL
DINT
Data Type
BOOL
DINT
FBD_CONVERT Structure
Description
Enable input. If cleared, the instruction does not execute and outputs are not updated.
Default is set.
Input to the conversion instruction.
Valid = any integer
Description
The instruction produced a valid result.
Result of the conversion instruction. Arithmetic status flags are set for this output.
Description:
BCD is the Binary Coded Decimal number system that expresses individual decimal digits (0…9) in a 4-bit binary notation.
If you enter a negative Source, the instruction generates a minor fault and clears the Destination.
566
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Math Conversion Instructions (DEG, RAD, TOD, FRD, TRN, TRUNC)
Chapter 16
Arithmetic Status Flags:
Arithmetic status flags are affected.
Fault Conditions:
A minor fault will occur if
Source < 0
Fault Type
4
Execution:
Fault Code
4
Condition
Prescan
Rung-condition-in is false
Rung-condition-in is true.
Relay Ladder
Action
The rung-condition-out is set to false.
The rung-condition-out is set to false.
Source < 0
S:V is set to 1.
Yes
No
Source > 99,999,999
No
Convert source to BCD.
Yes
Rung-condition-in is true
Postscan
Rung-condition-out is set to true.
End
The controller converts the Source to BCD and places the result in the Destination.
The rung-condition-out is set to true.
The rung-condition-out is set to false.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
567
Chapter 16
Math Conversion Instructions (DEG, RAD, TOD, FRD, TRN, TRUNC)
Condition
Prescan
Instruction first scan
Instruction first run
EnableIn is cleared
EnableIn is set
Postscan
Function Block
Action
No action taken.
No action taken.
No action taken.
EnableOut is cleared.
The instruction executes.
EnableOut is set.
No action taken.
Example:
The TOD instruction converts
value_1 to a BCD value and places the result in
result_a.
Relay Ladder
Function Block
568
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Math Conversion Instructions (DEG, RAD, TOD, FRD, TRN, TRUNC)
Chapter 16
Convert to Integer (FRD)
Operands:
The FRD instruction converts a BCD value (Source) to a decimal value and stores the result in the Destination.
Relay Ladder
Operand
Source
Destination
Type
SINT
INT
DINT
Format
Immediate
Tag
Description
Value to convert to decimal
A SINT or INT tag converts to a DINT value by zero-fill.
SINT
INT
DINT
Tag Stores the result
Function Block
Operand
FRD tag
Type
FBD_CONVERT
Format:
Structure
Description
FRD structure
Input Parameter
EnableIn
Source
Output Parameter
EnableOut
Dest
Data Type
BOOL
DINT
Data Type
BOOL
DINT
FBD_CONVERT Structure
Description
Enable input. If cleared, the instruction does not execute and outputs are not updated.
Default is set.
Input to the conversion instruction.
Valid = any integer
Description
The instruction produced a valid result.
Result of the conversion instruction. Arithmetic status flags are set for this output.
Description:
The FRD instruction converts a BCD value (Source) to a decimal value and stores the result in the Destination.
Arithmetic Status Flags:
Arithmetic status flags are affected.
Fault Conditions:
None
Execution:
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
569
Chapter 16
Math Conversion Instructions (DEG, RAD, TOD, FRD, TRN, TRUNC)
Condition
Prescan
Rung-condition-in is false
Rung-condition-in is true
Postscan
Relay Ladder
Action
The rung-condition-out is set to false.
The rung-condition-out is set to false.
The controller converts the Source to a decimal value and places the result in the Destination.
The rung-condition-out is set to true.
The rung-condition-out is set to false.
Condition
Prescan
Instruction first scan
Instruction first run
EnableIn is cleared
EnableIn is set
Postscan
Function Block
Action
No action taken.
No action taken.
No action taken.
EnableOut is cleared.
The instruction executes.
EnableOut is set.
No action taken.
Example:
The FRD instruction converts value_a to a decimal value and places the result in
result_1.
Relay Ladder
Function Block
570
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Truncate (TRN)
dest := TRUNC(source);
Input Parameter
EnableIn
Source
Output Parameter
EnableOut
Dest
Data Type
BOOL
REAL
Data Type
BOOL
DINT
Math Conversion Instructions (DEG, RAD, TOD, FRD, TRN, TRUNC)
Chapter 16
Operands:
The TRN instruction removes (truncates) the fractional part of the Source and stores the result in the Destination.
Relay Ladder
Operand
Source
Type
REAL
Destination SINT
INT
DINT
REAL
Format
Immediate
Tag
Tag
Description
Value to truncate
Tag to store the result
Structured Text
Use TRUNC as a function. This function truncates source and stores the result in
dest.
See Structured Text Programming
for information on the syntax of expressions within structured text.
Function Block
Operand
TRN tag
Type
FBD_TRUNCATE
Format
Structure
Description
TRN structure
FBD_TRUNCATE Structure
Description
Enable input. If cleared, the instruction does not execute and outputs are not updated.
Default is set.
Input to the conversion instruction.
Valid = any float
Description
The instruction produced a valid result.
Result of the conversion instruction. Arithmetic status flags are set for this output.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
571
Chapter 16
Math Conversion Instructions (DEG, RAD, TOD, FRD, TRN, TRUNC)
Description:
Truncating does not round the value; rather, the non-fractional part remains the same regardless of the value of the fractional part.
Arithmetic Status Flags:
Arithmetic status flags are affected.
Fault Conditions:
None
Execution:
Condition
Prescan
Rung-condition-in is false
Rung-condition-in is true
Postscan
Relay Ladder
Action
The rung-condition-out is set to false.
The rung-condition-out is set to false.
The controller removes the fractional part of the Source and places the result in the Destination.
The rung-condition-out is set to true.
The rung-condition-out is set to false.
Condition
Prescan
Instruction first scan
Instruction first run
EnableIn is cleared
EnableIn is set
Postscan
Function Block
Action
No action taken.
No action taken.
No action taken.
EnableOut is cleared.
The instruction executes.
EnableOut is set.
No action taken.
572
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Math Conversion Instructions (DEG, RAD, TOD, FRD, TRN, TRUNC)
Chapter 16
Example:
Remove the fractional part of
float_value_1, leaving the non-fractional part the same, and place the result in float_value_1_truncated.
Relay Ladder
Structured Text
float_value_1_truncated := TRUNC(float_value_1);
Function Block
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
573
Chapter 16
Math Conversion Instructions (DEG, RAD, TOD, FRD, TRN, TRUNC)
Notes:
574
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Chapter
17
ASCII Serial Port Instructions
(ABL, ACB, ACL, AHL, ARD, ARL, AWA, AWT)
Topic
ASCII Test For Buffer Line (ABL)
Page
Use the ASCII serial port instructions to read and write ASCII characters
.
IMPORTANT
To use the ASCII serial port instructions, you must configure the serial port of the controller. For procedures, see the Logix5000 Controllers Common
Procedures Programming Manual, publication 1756-PM001 .
The 1756-L7x controllers do not have a serial port and do not use the ASCII
Read/Write instructions. In addition, you cannot redirect an ASCII Read/
Write instruction to the USB port.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
575
Chapter 17
ASCII Serial Port Instructions (ABL, ACB, ACL, AHL, ARD, ARL, AWA, AWT)
If you want to For example
Determine when the buffer contains termination characters
Count the characters in the buffer
Check for data that contains termination characters
Check for the required number of characters before reading the buffer
Clear the buffer
Clear out ASCII Serial Port instructions that are currently executing or are in the queue
• Remove old data from the buffer at start-up.
• Synchronize the buffer with a device.
Obtain the status of the serial port control lines Cause a modem to hang up
Turn on or off the DTR signal
Turn on or off the RTS signal
Read a fixed number of characters Read data from a device that sends the same number of characters each transmission
Read a varying number of characters, up to and including the first set of termination characters
Send characters and automatically append one or two additional characters to mark the end of the data
Send characters
Read data from a device that sends a varying number of characters each transmission
Send messages that always use the same termination character(s)
Send messages that use a variety of termination characters
Use this instruction Available in these languages
ABL Relay ladder
Structured text
ACB
ACL
Relay ladder
Structured text
Relay ladder
Structured text
AHL
ARD
ARL
AWA
AWT
Relay ladder
Structured text
Relay ladder
Structured text
Relay ladder
Structured text
Relay ladder
Structured text
Relay ladder
Structured text
Page
Instruction Execution
ASCII serial port instructions execute asynchronous to the scan of the logic.
Logic
Rung-condition-in of instruction transitions from false to true.
Instruction enters the ASCII queue.
ASCII Queue
Instruction 1
Instruction 2
Instruction 3
Instruction 4
ASCII Task
Instruction at the top of the queue executes.
Data flows between task and buffer.
Data flows between buffer and serial port.
Serial Port
Buffer
Each ASCII serial port instruction (except ACL) uses a
SERIAL_PORT_CONTROL structure to perform these functions:
• Control the execution of the instruction
• Provide status information about the instruction
576
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
ASCII Serial Port Instructions (ABL, ACB, ACL, AHL, ARD, ARL, AWA, AWT)
Chapter 17
The following timing diagram depicts the changes in the status bits as an ABL instruction tests the buffer for termination characters.
Scan Scan Scan Scan
Rung-condition-in false
.EN
.EU
off off
.FD
.EM
.RN
.DN or .ER
off off off off true on on
Enters Queue
Executes
In this example, finds termination characters.
on off on on false off true on off off off on off on on on
When scanned and .DN or
.ER are set, sets the .EM bit.
Resets status bits.
on false off
The ASCII queue holds up to 16 instructions. When the queue is full, an instruction tries to enter the queue on each subsequent scan of the instruction, as depicted below.
Scan Scan Scan Scan false Rung-condition-in false
.EN
.EU
off off true on on
Attempts to enter queue but queue is full
Enters queue
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
577
This hex code
16#2
16#3
16#4
16#A
16#C
16#D
16#E
16#F
16#51
16#54
16#55
Chapter 17
ASCII Serial Port Instructions (ABL, ACB, ACL, AHL, ARD, ARL, AWA, AWT)
ASCII Error Codes
If an ASCII serial port instruction fails to execute, the ERROR member of its
SERIAL_PORT_CONTROL structure will contain one of the following hexadecimal error codes.
Indicates that the
Modem went offline.
CTS signal was lost during communication.
Serial port was in system mode.
Before the instruction executed, the .UL bit was set. This prevents the execution of the instruction.
The controller changed from Run mode to Program mode. This stops the execution of an ASCII serial port instruction and clears the queue.
In the Controller Properties dialog box, User Protocol tab, the buffer size or echo mode parameters were changed and applied. This stops the execution of an
ASCII serial port instruction and clears the queue.
ACL instruction executed.
Serial port configuration changed from User mode to System mode. This stops the execution of an ASCII serial port instruction and clears the ASCII serial port instruction queue.
The LEN value of the string tag is either negative or greater than the DATA size of the string tag.
The Serial Port Control Length is greater than the size of the buffer.
The Serial Port Control Length is either negative or greater than the size of the Source or Destination.
String Data Types
You store ASCII characters in tags that use a string data type.
• You can use the default STRING data type. It stores up to 82 characters.
• You can create a new string data type that stores less or more characters.
To create a new string data type, see the Logix5000 Controllers Common
Procedures Programming Manual, publication 1756-PM001 .
Name
LEN
Data Type
DINT
DATA SINT array
Each string data type contains the following members.
Description
Number of characters in the string
Notes
The LEN automatically updates to the new count of characters whenever you:
• See the String Browser dialog box to enter characters.
• See instructions that read, convert, or manipulate a string.
The LEN shows the length of the current string. The DATA member may contain additional, old characters, which are not included in the LEN count.
ASCII characters of the string • To access the characters of the string, address the name of the tag.
For example, to access the characters of the string_1 tag, enter string_1.
• Each element of the DATA array contains one character.
• You can create new string data types that store less or more characters.
578
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
ASCII Serial Port Instructions (ABL, ACB, ACL, AHL, ARD, ARL, AWA, AWT)
Chapter 17
ASCII Test For Buffer Line
(ABL)
Operands:
The ABL instruction counts the characters in the buffer up to and including the first termination character.
ABL
ASCII Test For Buffer Line
Channel
SerialPort Control
Character Count
?
?
?
EN
DN
ER
Relay Ladder
Operand
Channel
Type
DINT
Serial Port
Control
SERIAL_PORT_
CONTROL
Character Count DINT
Format
Immediate
Tag
Tag
Immediate
Description
0
Tag that controls the operation
0
During execution, displays the number of characters in the buffer, including the first set of termination characters.
.RN
.EM
.ER
.FD
.POS
Mnemonic
.EN
.EU
.DN
.ERROR
ABL(Channel
SerialPortControl);
Structured Text
The operands are the same as those for the relay ladder ABL instruction. You access the Character Count value via the .POS member of the
SERIAL_PORT_CONTROL structure.
SERIAL_PORT_CONTROL Structure
BOOL
BOOL
BOOL
BOOL
DINT
Data Type
BOOL
BOOL
BOOL
DINT
Description
The enable bit indicates that the instruction is enabled.
The queue bit indicates that the instruction entered the ASCII queue.
The done bit indicates when the instruction is done, but it is asynchronous to the logic scan.
The run bit indicates that the instruction is executing.
The empty bit indicates that the instruction is done, but it is synchronous to the logic scan.
The error bit indicates when the instruction fails (errors).
The found bit indicates that the instruction found the termination character or characters.
The position determines the number of characters in the buffer, up to and including the first set of termination characters.
The instruction only returns this number after it finds the termination character or characters.
The error contains a hexadecimal value that identifies the cause of an error.
Description
The ABL instruction searches the buffer for the first set of termination characters. If the instruction finds the termination characters, it does the following:
• Sets the .FD bit.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
579
Chapter 17
ASCII Serial Port Instructions (ABL, ACB, ACL, AHL, ARD, ARL, AWA, AWT)
Condition
Prescan
Rung-condition-in is false
Rung-condition-in is true
EnableIn is set
• Counts the characters in the buffer up to and including the first set of termination characters.
The Controller Properties dialog box, User Protocol tab, defines the ASCII characters that the instruction considers as the termination characters.
Follow these guidelines to program the ABL instruction.
1. Configure the serial port of the controller for user mode and define the characters that serve as the termination characters.
2. This is a transitional instruction.
• In relay ladder, toggle the rung-condition-in from cleared to set each time the instruction should execute.
• In structured text, condition the instruction so that it executes only on a transition.
Arithmetic Status Flags:
Not affected
Fault Conditions:
None
Execution:
Relay Ladder Action
The rung-condition-out is set to false.
The rung-condition-out is set to false.
The instruction executes when rung-condition-in toggles from cleared to set.
The rung-condition-out is set to true.
N/A
Structured Text Action
No action taken.
N/A
N/A
EnableIn is always set.
The instruction executes.
Instruction execution
Postscan
The instruction counts the characters in the buffer.
The .EN bit is set.
The remaining status bits, except .UL, are cleared.
The instruction attempts to enter the ASCII queue.
The rung-condition-out is set to false.
No action taken.
Example:
Continuously test the buffer for the termination characters.
Relay Ladder
MV_line.EN
/
ABL
ASCII Test For Buffer Line
Channel
SerialPort Control
Character Count
0
MV_line
0
EN
DN
ER
580
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Structured Text
ABL(0,MV_line);
ASCII Serial Port Instructions (ABL, ACB, ACL, AHL, ARD, ARL, AWA, AWT)
Chapter 17
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
581
ACB(Channel
SerialPortControl);
.RN
.EM
.ER
.FD
Mnemonic
.EN
.EU
.DN
.POS
.ERROR
Chapter 17
ASCII Serial Port Instructions (ABL, ACB, ACL, AHL, ARD, ARL, AWA, AWT)
ASCII Chars in Buffer (ACB)
The ACB instruction counts the characters in the buffer.
Operands:
ACB
ASCII Chars in Buffer
Channel
SerialPort Control
Character Count
?
?
?
EN
DN
ER
Relay Ladder
Operand
Channel
Type
DINT
Serial Port
Control
SERIAL_PORT_
CONTROL
Character Count DINT
Format
Immediate
Tag
Tag
Immediate
Enter
0
Tag that controls the operation
0
During execution, displays the number of characters in the buffer.
BOOL
BOOL
BOOL
BOOL
Data Type
BOOL
BOOL
BOOL
DINT
DINT
Structured Text
The operands are the same as those for the relay ladder ACB instruction.
However, you specify the Character Count value by accessing the .POS member of the SERIAL_PORT_CONTROL structure, rather than by including the value in the operand list.
SERIAL_PORT_CONTROL Structure
Description
The enable bit indicates that the instruction is enabled.
The queue bit indicates that the instruction entered the ASCII queue.
The done bit indicates when the instruction is done, but it is asynchronous to the logic scan.
The run bit indicates that the instruction is executing.
The empty bit indicates that the instruction is done, but it is synchronous to the logic scan.
The error bit indicates when the instruction fails (errors).
The found bit indicates that the instruction found a character.
The position determines the number of characters in the buffer, up to and including the first set of termination characters.
The error contains a hexadecimal value that identifies the cause of an error.
582
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
ASCII Serial Port Instructions (ABL, ACB, ACL, AHL, ARD, ARL, AWA, AWT)
Chapter 17
Description:
The ACB instruction counts the characters in the buffer.
Follow these guidelines to program the ACB instruction.
1. Configure the serial port of the controller for user mode.
2. This is a transitional instruction.
• In relay ladder, toggle the rung-condition-in from cleared to set each time the instruction should execute.
• In structured text, condition the instruction so that it executes only on a transition.
Arithmetic Status Flags:
Not affected
Fault Conditions:
None
Execution:
Condition
Prescan
Rung-condition-in is false
Rung-condition-in is true
EnableIn is set
Instruction execution
Postscan
Relay Ladder Action
The rung-condition-out is set to false.
The rung-condition-out is set to false.
The instruction executes when rung-condition-in toggles from cleared to set.
The rung-condition-out is set to true.
N/A
The instruction counts the characters in the buffer.
The .EN bit is set.
The remaining status bits, except .UL, are cleared.
The instruction attempts to enter the ASCII queue.
The rung-condition-out is set to false.
Structured Text Action
No action taken.
N/A
N/A
EnableIn is always set.
The instruction executes.
No action taken.
Example:
Continuously count the characters in the buffer.
Relay Ladder
bar_code_count.EN
/
ACB
ASCII Chars in Buffer
Channel
SerialPort Control
Character Count
0 bar_code_count
0
EN
DN
ER
Structured Text
ACB(0,bar_code_count);
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
583
Chapter 17
ASCII Serial Port Instructions (ABL, ACB, ACL, AHL, ARD, ARL, AWA, AWT)
ASCII Clear Buffer (ACL)
Operands:
The ACL instruction immediately clears the buffer and ASCII queue.
ACL
ASCII Clear Buffer
Channel
Clear Serial Port Read
Clear Serial Port Write
?
?
?
Relay Ladder
Operand
Channel
Type
DINT
Clear Serial Port
Read
Clear Serial Port
Write
BOOL
BOOL
Format
Immediate
Tag
Immediate
Tag
Immediate
Tag
Enter
0
To empty the buffer and remove ARD and ARL instructions from the queue, enter Yes.
To remove AWA and AWT instructions from the queue, enter Yes.
ACL(Channel,
ClearSerialPortRead,
ClearSerialPortWrite);
Structured Text
The operands are the same as those for the relay ladder ACL instruction.
Description:
The ACL instruction immediately performs one or both of the following actions:
• Clears the buffer of characters and clears the ASCII queue of read instructions
• Clears the ASCII queue of write instructions
Follow these guidelines to program the ACL instruction.
1. Configure the serial port of the controller:
If Your Application
Uses ARD or ARL instructions
Does not use ARD or ARL instructions
Then
Select User mode
Select either System or User mode
2. To determine if an instruction was removed from the queue or aborted, examine the following of the appropriate instruction.
• .ER bit is set.
• .ERROR member is 16#E.
Arithmetic Status Flags:
Not affected
Fault Conditions:
None
584
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Condition
Prescan
Rung-condition-in is false
Rung-condition-in is true
EnableIn is set
Instruction execution
Postscan
S:FS
ASCII Serial Port Instructions (ABL, ACB, ACL, AHL, ARD, ARL, AWA, AWT)
Chapter 17
Execution:
Relay Ladder Action
The rung-condition-out is set to false.
The rung-condition-out is set to false.
The instruction executes.
The rung-condition-out is set to true.
N/A
Structured Text Action
No action taken.
N/A
N/A
EnableIn is always set.
The instruction executes.
The instruction clears the specified instructions and buffer(s).
The rung-condition-out is set to false.
No action taken.
Example:
When the controller enters Run mode, clear the buffer and the ASCII queue.
Relay Ladder
ACL
ASCII Clear Buffer
Channel
Clear Serial Port Read
Clear Serial Port Write
0
1
1
Structured Text
osri_1.InputBit := S:FS;
OSRI(osri_1);
IF (osri_1.OutputBit) THEN
ACL(0,0,1);
END_IF;
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
585
Chapter 17
ASCII Serial Port Instructions (ABL, ACB, ACL, AHL, ARD, ARL, AWA, AWT)
ASCII Handshake Lines (AHL)
The AHL instruction obtains the status of control lines and turns on or off the
DTR and RTS signals.
Operands:
Relay Ladder
AHL
ASCII Handshake Lines
Channel
AND Mask
OR Mask
SerialPort Control
Channel Status(Decimal)
??
?
?
?
??
?
?
EN
DN
ER
Operand
Channel
ANDMask
ORMask
Serial Port Control
Channel Status (Decimal)
Type
DINT
DINT
DINT
SERIAL_PORT_CONTROL
DINT
Format
Immediate
Tag
Immediate
Tag
Immediate
Tag
Tag
Immediate
Enter
0
Refer to the description.
Tag that controls the operation
0
During execution, displays the status of the control lines.
For the Status Of This Control Line Examine This Bit:
CTS
RTS
0
1
DSR
DCD
DTR
Received the XOFF character
2
3
4
5
Structured Text
AHL(Channel,ANDMask,ORMask,
SerialPortControl);
The operands are the same as those for the relay ladder AHL instruction.
However, you specify the Channel Status value by accessing the .POS member of the SERIAL_PORT_CONTROL structure, rather than by including the value in the operand list.
586
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
.RN
.EM
.ER
.FD
Mnemonic
.EN
.EU
.DN
.POS
.ERROR
ASCII Serial Port Instructions (ABL, ACB, ACL, AHL, ARD, ARL, AWA, AWT)
Chapter 17
SERIAL_PORT_CONTROL Structure
BOOL
BOOL
BOOL
BOOL
Data Type
BOOL
BOOL
BOOL
DINT
DINT
Description
The enable bit indicates that the instruction is enabled.
The queue bit indicates that the instruction entered the ASCII queue.
The done bit indicates when the instruction is done, but it is asynchronous to the logic scan.
The run bit indicates that the instruction is executing.
The empty bit indicates that the instruction is done, but it is synchronous to the logic scan.
The error bit indicates when the instruction fails (errors).
The found bit does not apply to this instruction.
The position stores the status of the control lines.
The error contains a hexadecimal value that identifies the cause of an error.
Description:
The AHL instruction can do the following:
• Obtain the status of the control lines of the serial port
• Turn on or off the data terminal ready (DTR) signal
• Turn on or off the request to send signal (RTS)
Follow these guidelines to program the AHL instruction.
1. Configure the serial port of the controller.
If your application
Uses ARD or ARL instructions
Does not use ARD or ARL instructions
Then
Select User mode
Select either System or User mode
2. Use the following table to select the correct values for the ANDMask and
ORMask operands.
To turn DTR And turn RTS
Off
On
Unchanged
Off
On
Unchanged
Off
Off
On
On
Unchanged
Unchanged
2
0
0
0
0
1
2
3
1
Enter this ANDMask value
0
2
0
3
1
0
1
0
2
And enter this ORMask value
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
587
Chapter 17
ASCII Serial Port Instructions (ABL, ACB, ACL, AHL, ARD, ARL, AWA, AWT)
3. This is a transitional instruction.
• In relay ladder, toggle the rung-condition-in from cleared to set each time the instruction should execute.
• In structured text, condition the instruction so that it executes only on a transition.
Arithmetic Status Flags:
Not affected
Fault Conditions:
Type
4
Code
57
Condition
Prescan
Rung-condition-in is false
Rung-condition-in is true
EnableIn is set
Instruction execution
Postscan
Cause
The AHL instruction failed to execute because the serial port is set to no handshaking.
Recovery Method
Either:
• Change the Control Line setting of the serial port.
• Delete the AHL instruction.
Execution:
Relay Ladder Action
The rung-condition-out is set to false.
Structured Text Action
No action taken.
The rung-condition-out is set to false.
The instruction executes when rung-condition-in toggles from cleared to set.
The rung-condition-out is set to true.
N/A
N/A
N/A
EnableIn is always set.
The instruction executes.
The instruction obtains the control line status and turns on or off DTR and RTS signals.
The .EN bit is set.
The remaining status bits, except .UL, are cleared.
The instruction attempts to enter the ASCII queue.
The rung-condition-out is set to false.
No action taken.
Example:
When
get_control_line_status becomes set, obtain the status of the control lines of the serial port and store the status in the Channel Status operand. To view the status of a specific control line, monitor the SerialPortControl tag and expand the POS member.
Relay Ladder
get_control_line_status AHL
ASCII Handshake Lines
Channel
AND Mask
OR Mask
SerialPort Control
Channel Status(Decimal)
0 serial_port
29
0
0
EN
DN
ER
588
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
ASCII Serial Port Instructions (ABL, ACB, ACL, AHL, ARD, ARL, AWA, AWT)
Chapter 17
Structured Text
osri_1.InputBit := get_control_line_status;
OSRI(osri_1);
IF (osri_1.OutputBit) THEN
AHL(0,0,0,serial_port);
END_IF;
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
589
Chapter 17
ASCII Serial Port Instructions (ABL, ACB, ACL, AHL, ARD, ARL, AWA, AWT)
ASCII Read (ARD)
Operands:
The ARD instruction removes characters from the buffer and stores them in the
Destination.
Relay Ladder
ARD
ASCII Read
Channel ?
Destination ?
??
SerialPort Control ?
SerialPort Control Length
Characters Read
?
?
EN
DN
ER
Operand
Channel
Destination
Serial Port
Control
Serial Port
Control Length
Characters Read
Type
DINT
String
SINT
INT
DINT
SERIAL_PORT_
CONTROL
DINT
DINT
Format
Immediate
Tag
Tag
Tag
Immediate
Immediate
Enter
0
Notes
Tag into which the characters are moved (read):
• For a string data type, enter the name of the tag.
• For a SINT, INT, or DINT array, enter the first element of the array.
Tag that controls the operation
• If you want to compare, convert, or manipulate the characters, use a string data type.
• String data types are:
– default STRING data type
– any new string data type that you create
Number of characters to move to the destination (read)
0
• The Serial Port Control Length must be less than or equal to the size of the Destination.
• If you want to set the Serial Port Control Length equal to the size of the Destination, enter 0.
During execution, displays the number of characters that were read.
ARD(Channel,Destination,
SerialPortControl);
Structured Text
The operands are the same as those for the relay ladder ARD instruction.
However, you specify the Serial Port Control Length and the Characters Read values by accessing the .LEN and .POS members of the
SERIAL_PORT_CONTROL structure, rather than by including the values in the operand list.
590
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
ASCII Serial Port Instructions (ABL, ACB, ACL, AHL, ARD, ARL, AWA, AWT)
Chapter 17
SERIAL_PORT_CONTROL Structure
.RN
.EM
.ER
.FD
Mnemonic
.EN
.EU
.DN
.LEN
.POS
.ERROR
BOOL
BOOL
BOOL
BOOL
Data Type
BOOL
BOOL
BOOL
DINT
DINT
DINT
Description
The enable bit indicates that the instruction is enabled.
The queue bit indicates that the instruction entered the ASCII queue.
The done bit indicates when the instruction is done, but it is asynchronous to the logic scan.
The run bit indicates that the instruction is executing.
The empty bit indicates that the instruction is done, but it is synchronous to the logic scan.
The error bit indicates when the instruction fails (errors).
The found bit does not apply to this instruction.
The length indicates the number of characters to move to the destination (read).
The position displays the number of characters that were read.
The error contains a hexadecimal value that identifies the cause of an error.
Description:
The ARD instruction removes the specified number of characters from the buffer and stores them in the Destination.
• The ARD instruction continues to execute until it removes the specified number of characters (Serial Port Control Length).
• While the ARD instruction is executing, no other ASCII Serial Port instruction executes.
Follow these guidelines to program the ARD instruction.
1. Configure the serial port of the controller for user mode.
2. Use the results of an ACB instruction to trigger the ARD instruction. This prevents the ARD instruction from holding up the ASCII queue while it waits for the required number of characters.
3. This is a transitional instruction.
• In relay ladder, toggle the rung-condition-in from cleared to set each time the instruction should execute.
• In structured text, condition the instruction so that it executes only on a transition.
4. To trigger a subsequent action when the instruction is done, examine the
EM bit.
Arithmetic Status Flags:
Not affected
Fault Conditions:
None
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
591
Chapter 17
ASCII Serial Port Instructions (ABL, ACB, ACL, AHL, ARD, ARL, AWA, AWT)
Condition
Prescan
Rung-condition-in is false
Rung-condition-in is true
EnableIn is set
Instruction execution
Postscan
Execution:
Relay Ladder Action
The rung-condition-out is set to false.
Structured Text Action
No action taken.
The rung-condition-out is set to false.
The instruction executes when rung-condition-in toggles from cleared to set.
The rung-condition-out is set to true.
N/A
N/A
N/A
EnableIn is always set.
The instruction executes.
The instruction removes characters from the buffer and stores them in the destination.
The .EN bit is set.
The remaining status bits, except .UL, are cleared.
The instruction attempts to enter the ASCII queue.
The rung-condition-out is set to false.
No action taken.
Example:
A bar code reader sends bar codes to the serial port (channel 0) of the controller.
Each bar code contains 24 characters. To determine when the controller receives a bar code, the ACB instruction continuously counts the characters in the buffer.
When the buffer contains at least 24 characters, the controller has received a bar code. The ARD instruction moves the bar code to the DATA member of the
bag_bar_code tag, which is a string.
Relay Ladder
bar_code_count.EN
/
ACB
ASCII Chars in Buffer
Channel
SerialPort Control
Character Count
0 bar_code_count
0
EN
DN
ER
GEQ
Grtr Than or Eql (A>=B)
Source A bar_code_count.pos
Source B
0
24
ARD
ASCII Read
Channel 0
Destination bag_bar_code
''
SerialPort Control
SerialPort Control Length bar_code_read
24
Characters Read 0
EN
DN
ER
592
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
ASCII Serial Port Instructions (ABL, ACB, ACL, AHL, ARD, ARL, AWA, AWT)
Chapter 17
Structured Text
ACB(0,bar_code_count);
IF bar_code_count.POS >= 24 THEN bar_code_read.LEN := 24;
ARD(0,bag_bar_code,bar_code_read);
END_IF;
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
593
Chapter 17
ASCII Serial Port Instructions (ABL, ACB, ACL, AHL, ARD, ARL, AWA, AWT)
ASCII Read Line (ARL)
Operands:
The ARL instruction removes specified characters from the buffer and stores them in the Destination.
Relay Ladder
ASCII Read Line
Channel
Destination
ARL
SerialPort Control
SerialPort Control Length
Characters Read
??
?
?
?
?
?
EN
DN
ER
Operand
Channel
Destination
Type
DINT
String
SINT
INT
DINT
Format
Immediate
Tag
Tag
Serial Port
Control
Serial Port Control
Length
SERIAL_PORT_
CONTROL
DINT
Characters Read DINT
Tag
Immediate immediate
Enter
0
Notes
Tag into which the characters are moved (read):
• For a string data type, enter the name of the tag.
• For a SINT, INT, or DINT array, enter the first element of the array.
Tag that controls the operation
• If you want to compare, convert, or manipulate the characters, use a string data type.
• String data types are:
– Default STRING data type
– Any new string data type that you create
Maximum number of characters to read if no termination characters are found
0
• Enter the maximum number of characters that any message will contain (that is, when to stop reading if no termination characters are found).
For example, if messages range from 3 to 6 characters in length, enter 6.
• The Serial Port Control Length must be less than or equal to the size of the Destination.
• If you want to set the Serial Port Control Length equal to the size of the Destination, enter 0.
During execution, displays the number of characters that were read.
594
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
.RN
.EM
.ER
.FD
.LEN
Mnemonic
.EN
.EU
.DN
.POS
.ERROR
ARL(Channel,Destination,
SerialPortControl);
ASCII Serial Port Instructions (ABL, ACB, ACL, AHL, ARD, ARL, AWA, AWT)
Chapter 17
Structured Text
The operands are the same as those for the relay ladder ARL instruction.
However, you specify the Serial Port Control Length and the Characters Read values by accessing the .LEN and .POS members of the
SERIAL_PORT_CONTROL structure, rather than by including the values in the operand list.
SERIAL_PORT_CONTROL Structure
BOOL
BOOL
BOOL
BOOL
DINT
Data Type
BOOL
BOOL
BOOL
DINT
DINT
Description
The enable bit indicates that the instruction is enabled.
The queue bit indicates that the instruction entered the ASCII queue.
The done bit indicates when the instruction is done, but it is asynchronous to the logic scan.
The run bit indicates that the instruction is executing.
The empty bit indicates that the instruction is done, but it is synchronous to the logic scan.
The error bit indicates when the instruction fails (errors).
The found bit does not apply to this instruction.
The length indicates the maximum number of characters to move to the destination (that is, when to stop reading if no termination characters are found).
The position displays the number of characters that were read.
The error contains a hexadecimal value that identifies the cause of an error.
Description:
The ARL instruction removes characters from the buffer and stores them in the
Destination.
• The ARL instruction continues to execute until it removes either the:
– first set of termination characters
– specified number of characters (Serial Port Control Length)
• While the ARL instruction is executing, no other ASCII serial port instruction executes.
Follow these guidelines to program the ARL instruction.
1. Configure the serial port of the controller.
a. Select User mode.
b. Define the characters that serve as the termination characters.
2. Use the results of an ABL instruction to trigger the ARL instruction. This prevents the ARL instruction from holding up the ASCII queue while it waits for the termination characters.
3. This is a transitional instruction.
• In relay ladder, toggle the rung-condition-in from cleared to set each time the instruction should execute.
• In structured text, condition the instruction so that it executes only on a transition.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
595
Chapter 17
ASCII Serial Port Instructions (ABL, ACB, ACL, AHL, ARD, ARL, AWA, AWT)
Condition
Prescan
Rung-condition-in is false
Rung-condition-in is true
EnableIn is set
Postscan
Arithmetic Status Flags:
Not affected
Fault Conditions:
None
Execution:
4. To trigger a subsequent action when the instruction is done, examine the
EM bit.
Instruction execution
Relay Ladder Action
The rung-condition-out is set to false.
Structured Text Action
No action taken.
The rung-condition-out is set to false.
The instruction executes when rung-condition-in toggles from cleared to set.
The rung-condition-out is set to true.
N/A
N/A
N/A
EnableIn is always set.
The instruction executes.
The instruction removes the specified characters from the buffer and stores them in the destination.
The .EN bit is set.
The remaining status bits, except .UL, are cleared.
The instruction attempts to enter the ASCII queue.
The rung-condition-out is set to false.
No action taken.
Example:
Continuously test the buffer for a message from a MessageView terminal. Since each message ends in a carriage return ($r), the carriage return is configured as the termination character in the Controller Properties dialog box, User Protocol tab. When the ABL finds a carriage return, its sets the
FD bit.
When the ABL instruction finds the carriage return ( MV_line.FD is set), the controller has received a complete message. The ARL instruction removes the characters from the buffer, up to and including the carriage return, and places them in the DATA member of the
MV_msg tag, which is a string.
Relay Ladder
MV_line.EN
/
ABL
ASCII Test For Buffer Line
Channel
SerialPort Control
0
MV_line
Character Count 0
EN
DN
ER
596
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
MV_line.FD
ASCII Serial Port Instructions (ABL, ACB, ACL, AHL, ARD, ARL, AWA, AWT)
Chapter 17
ASCII Read Line
Channel
Destination
ARL
SerialPort Control
SerialPort Control Length
Characters Read
0
MV_msg
''
MV_read
12
0
EN
DN
ER
Structured Text
ABL(0,MV_line); osri_1.InputBit := MVLine.FD;
OSRI(osri_1);
IF (osri_1.OutputBit) THEN mv_read.LEN := 12;
ARL(0,MV_msg,MV_read);
END_IF;
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
597
Chapter 17
ASCII Serial Port Instructions (ABL, ACB, ACL, AHL, ARD, ARL, AWA, AWT)
ASCII Write Append (AWA)
The AWA instruction sends a specified number of characters of the Source tag to a serial device and appends either one or two predefined characters.
Operands:
Relay Ladder
Operand
Channel
Source
AWA
ASCII Write Append
Channel ?
Source ?
??
SerialPort Control ?
SerialPort Control Length
Characters Sent
?
?
EN
DN
ER
Type
DINT
string
SINT
INT
DINT
Format
Immediate
Tag
Tag
Serial Port
Control
Serial Port Control
Length
SERIAL_PORT_
CONTROL
DINT
Characters Sent DINT
Tag
Immediate
Immediate
Enter
0
Notes
Tag that contains the characters to send:
• For a string data type, enter the name of the tag.
• For a SINT, INT, or DINT array, enter the first element of the array.
Tag that controls the operation
• If you want to compare, convert, or manipulate the characters, use a string data type.
• String data types are:
– Default STRING data type
– Any new string data type that you create
Number of characters to send
0
• The Serial Port Control Length must be less than or equal to the size of the Source.
• If you want to set the Serial Port Control Length equal to the number of characters in the Source, enter 0.
During execution, displays the number of characters that were sent.
AWA(Channel,Source,
SerialPortControl);
Structured Text
The operands are the same as those for the relay ladder AWA instruction.
However, you specify the Serial Port Control Length and the Characters Sent values by accessing the .LEN and .POS members of the
SERIAL_PORT_CONTROL structure, rather than by including the values in the operand list.
598
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
ASCII Serial Port Instructions (ABL, ACB, ACL, AHL, ARD, ARL, AWA, AWT)
Chapter 17
.RN
.EM
.ER
.FD
Mnemonic
.EN
.EU
.DN
.LEN
.POS
.ERROR
SERIAL_PORT_CONTROL Structure
BOOL
BOOL
BOOL
BOOL
Data Type
BOOL
BOOL
BOOL
DINT
DINT
DINT
Description
The enable bit indicates that the instruction is enabled.
The queue bit indicates that the instruction entered the ASCII queue.
The done bit indicates when the instruction is done, but it is asynchronous to the logic scan.
The run bit indicates that the instruction is executing.
The empty bit indicates that the instruction is done, but it is synchronous to the logic scan.
The error bit indicates when the instruction fails (errors).
The found bit does not apply to this instruction.
The length indicates the number of characters to send.
The position displays the number of characters that were sent.
The error contains a hexadecimal value that identifies the cause of an error.
Description:
The AWA instruction does the following:
• Sends the specified number of characters (Serial Port Control Length) of the Source tag to the device that is connected to the serial port of the controller
• Adds to the end of the characters (appends) either one or two characters that are defined in the Controller Properties dialog box, User Protocol tab
Follow these guidelines to program the AWA instruction.
1. Configure the serial port of the controller.
a. Does your application also include ARD or ARL instructions?
If
Yes
No
Then
Select User mode
Select either System or User mode b. Define the characters to append to the data.
2. This is a transitional instruction.
• In relay ladder, toggle the rung-condition-in from cleared to set each time the instruction should execute.
• In structured text, condition the instruction so that it executes only on a transition.
3. Each time the instruction executes, do you always send the same number of characters?
If
Yes
No
Then
In the Serial Port Control Length, enter the number of characters to send.
Before the instruction executes, set the LEN member of the Source tag to the LEN member of the Serial Port Control tag.
Arithmetic Status Flags:
Not affected
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
599
Chapter 17
ASCII Serial Port Instructions (ABL, ACB, ACL, AHL, ARD, ARL, AWA, AWT)
Condition
Prescan
Rung-condition-in is false
Rung-condition-in is true
EnableIn is set
Instruction execution
Postscan
Fault Conditions:
None
Execution:
Relay Ladder Action
The rung-condition-out is set to false.
Structured Text Action
No action taken.
The rung-condition-out is set to false.
The instruction executes when rung-condition-in toggles from cleared to set.
The rung-condition-out is set to true.
N/A
N/A
N/A
EnableIn is always set.
The instruction executes.
The instruction sends a specified number of characters and appends either one or two predefined characters.
The .EN bit is set.
The remaining status bits, except .UL, are cleared.
The instruction attempts to enter the ASCII queue.
The rung-condition-out is set to false.
No action taken.
Example 1:
When the temperature exceeds the high limit ( temp_high is set), the AWA instruction sends a message to a MessageView terminal that is connected to the serial port of the controller. The message contains five characters from the DATA member of the
string[1] tag, which is a string. (The $14 counts as one character.
It is the hex code for the Ctrl-T character.) The instruction also sends (appends) the characters defined in the controller properties. In this example, the AWA instruction sends a carriage return ($0D), which marks the end of the message.
Relay Ladder
temp_high
ASCII Write Append
Channel
Source
AWA
0 string[1]
'$1425\1'
SerialPort Control temp_high_write
SerialPort Control Length 5
Characters Sent 6
EN
DN
ER
Structured Text
IF temp_high THEN temp_high_write.LEN := 5;
AWA(0,string[1],temp_high_write); temp_high := 0;
END_IF;
600
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
alarm
ASCII Serial Port Instructions (ABL, ACB, ACL, AHL, ARD, ARL, AWA, AWT)
Chapter 17
Example 2:
When
alarm is set, the AWA instruction sends the specified number of characters in alarm_msg and appends a termination character (s). Because the number of characters in
alarm_msg varies, the rung first moves the length of the string
( alarm_msg.LEN) to the Serial Port Control Length of the AWA instruction
(
alarm_write.LEN). In alarm_msg, the $14 counts as one character. It is the hex code for the Ctrl-T character.
Relay Ladder
MOV
Move
Source alarm_msg.LEN
5
Dest alarm_write.LEN
5
AWA
ASCII Write Append
Channel
Source
SerialPort Control
SerialPort Control Length
Characters Sent
0 alarm_msg
'$1425\1' alarm_write
5
6
EN
DN
ER
Structured Text
osri_1.InputBit := alarm;
OSRI(osri_1);
IF (osri_1.OutputBit) THEN alarm_write.LEN := alarm_msg.LEN;
AWA(0,alarm_msg,alarm_write);
END_IF;
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
601
Chapter 17
ASCII Serial Port Instructions (ABL, ACB, ACL, AHL, ARD, ARL, AWA, AWT)
ASCII Write (AWT)
Operands:
The AWT instruction sends a specified number of characters of the Source tag to a serial device.
Relay Ladder
AWT
ASCII Write
Channel
Source
SerialPort Control
SerialPort Control Length
Characters Sent
??
?
?
?
?
?
EN
DN
ER
Operand
Channel
Source
Type
DINT
String
SINT
INT
DINT
Serial Port
Control
Serial Port Control
Length
SERIAL_PORT_
CONTROL
DINT
Characters Sent DINT
Format
Immediate
Tag
Tag
Tag
Immediate
Immediate
Enter
0
Notes
Tag that contains the characters to send:
• For a string data type, enter the name of the tag.
• For a SINT, INT, or DINT array, enter the first element of the array.
Tag that controls the operation
• If you want to compare, convert, or manipulate the characters, use a string data type.
• String data types are:
– Default STRING data type
– Any new string data type that you create
Number of characters to send
0
• The Serial Port Control Length must be less than or equal to the size of the Source.
• If you want to set the Serial Port Control Length equal to the number of characters in the Source, enter 0.
During execution, displays the number of characters that were sent.
AWT(Channel,Source,
SerialPortControl);
Structured Text
The operands are the same as those for the relay ladder AWT instruction.
However, you specify the Serial Port Control Length and the Characters Sent values by accessing the .LEN and .POS members of the
SERIAL_PORT_CONTROL structure, rather than by including the values in the operand list.
602
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
ASCII Serial Port Instructions (ABL, ACB, ACL, AHL, ARD, ARL, AWA, AWT)
Chapter 17
.RN
.EM
.ER
.FD
Mnemonic
.EN
.EU
.DN
.LEN
.POS
.ERROR
SERIAL_PORT_CONTROL Structure
BOOL
BOOL
BOOL
BOOL
Data Type
BOOL
BOOL
BOOL
DINT
DINT
DINT
Description
The enable bit indicates that the instruction is enabled.
The queue bit indicates that the instruction entered the ASCII queue.
The done bit indicates when the instruction is done, but it is asynchronous to the logic scan.
The run bit indicates that the instruction is executing.
The empty bit indicates that the instruction is done, but it is synchronous to the logic scan.
The error bit indicates when the instruction fails (errors).
The found bit does not apply to this instruction.
The length indicates the number of characters to send.
The position displays the number of characters that were sent.
The error contains a hexadecimal value that identifies the cause of an error.
Description:
The AWT instruction sends the specified number of characters (Serial Port
Control Length) of the Source tag to the device that is connected to the serial port of the controller.
Follow these guidelines to program the AWT instruction.
1. Configure the serial port of the controller.
If your application
Uses ARD or ARL instructions
Does not use ARD or ARL instructions
Then
Select User mode
Select either System or User mode
2. This is a transitional instruction.
• In relay ladder, toggle the rung-condition-in from cleared to set each time the instruction should execute.
• In structured text, condition the instruction so that it executes only on a transition.
3. Each time the instruction executes, do you always send the same number of characters?
If
Yes
No
Then
In the Serial Port Control Length, enter the number of characters to send.
Before the instruction executes, move the LEN member of the Source tag to the LEN member of the Serial Port Control tag.
Arithmetic Status Flags:
Not affected
Fault Conditions:
None
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
603
Chapter 17
ASCII Serial Port Instructions (ABL, ACB, ACL, AHL, ARD, ARL, AWA, AWT)
Condition
Prescan
Rung-condition-in is false
Rung-condition-in is true
EnableIn is set
Instruction execution
Postscan
Execution:
Relay Ladder Action
The rung-condition-out is set to false.
The rung-condition-out is set to false.
The instruction executes when rung-condition-in toggles from cleared to set.
The rung-condition-out is set to true.
N/A
Structured Text Action
No action taken.
N/A
N/A
EnableIn is always set.
The instruction executes.
The instruction sends a specified number of characters.
The .EN bit is set.
The remaining status bits, except .UL, are cleared.
The instruction attempts to enter the ASCII queue.
The rung-condition-out is set to false.
No action taken.
Example 1:
When the temperature reaches the low limit ( temp_low is set), the AWT instruction sends a message to the MessageView terminal that is connected to the serial port of the controller. The message contains nine characters from the
DATA member of the
string[2] tag, which is a string. (The $14 counts as one character. It is the hex code for the Ctrl-T character.) The last character is a carriage return ($r), which marks the end of the message.
Relay Ladder
temp_low AWT
ASCII Write
Channel
Source
0 string[2]
'$142224\01$r' temp_low_write SerialPort Control
SerialPort Control Length
Characters Sent
9
9
EN
DN
ER
Structured Text
osri_1.InputBit := temp_low;
OSRI(osri_1);
IF (osri_1.OutputBit) THEN temp_low_write.LEN := 9;
AWT(0,string[2],temp_low_write);
END_IF;
604
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
MV_update
ASCII Serial Port Instructions (ABL, ACB, ACL, AHL, ARD, ARL, AWA, AWT)
Chapter 17
Example 2:
When
MV_update is set, the AWT instruction sends the characters in MV_msg.
Because the number of characters in MV_msg varies, the rung first moves the length of the string (
MV_msg.LEN) to the Serial Port Control Length of the
AWT instruction ( MV_write.LEN). In MV_msg, the $16 counts as one character. It is the hex code for the Ctrl-V character.
Relay Ladder
MOV
Move
Source MV_msg.LEN
Dest
10
MV_write.LEN
10
AWT
ASCII Write
Channel 0
Source MV_msg
'$161365\8\1$r'
SerialPort Control
SerialPort Control Length
MV_write
10
Characters Sent 10
EN
DN
ER
Structured Text
osri_1.InputBit := MV_update;
OSRI(osri_1);
IF (osri_1.OutputBit) THEN
MV_write.LEN := Mv_msg.LEN;
AWT(0,MV_msg,MV_write);
END_IF;
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
605
Chapter 17
ASCII Serial Port Instructions (ABL, ACB, ACL, AHL, ARD, ARL, AWA, AWT)
Notes:
606
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Chapter
18
ASCII String Instructions
(CONCAT, DELETE, FIND, INSERT, MID)
Topic
Page
Use the ASCII string instructions to modify and create strings of
ASCII characters.
If you want to
Add characters to the end of a string
Delete characters from a string
Determine the starting character of a sub-string
Insert characters into a string
For example
Add termination characters or delimiters to a string
Use this instruction Available in these languages
CONCAT Relay ladder
Structured text
Remove header or control characters from a string DELETE
Locate a group of characters within a string
Create a string that uses variables
FIND
INSERT
Relay ladder
Structured text
Relay ladder
Structured text
Relay ladder
Structured text
Extract characters from a string Extract information from a bar code MID Relay ladder
Structured text
Page
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
607
Chapter 18
ASCII String Instructions (CONCAT, DELETE, FIND, INSERT, MID)
You can also use the following instructions to compare or convert
ASCII characters.
If you want to
Compare a string to another string
See if the characters are equal to specific characters
See if the characters are not equal to specific characters
See if the characters are equal to or greater than specific characters
See if the characters are greater than specific characters
See if the characters are equal to or less than specific characters
See if the characters are less than specific characters
Rearrange the bytes of a INT, DINT, or REAL tag
Find a string in an array of strings
Convert characters to a SINT, INT, DINT, or REAL value
Convert characters to a REAL value
Convert a SINT, INT, DINT, or REAL value to a string of ASCII characters
Convert REAL value to a string of ASCII characters
SWPB
FSC
STOD
STOR
DTOS
RTOS
GEQ
GRT
LEQ
LES
Use this instruction
CMP
EQU
NEQ
Page
608
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
ASCII String Instructions (CONCAT, DELETE, FIND, INSERT, MID)
Chapter 18
String Data Types
You store ASCII characters in tags that use a string data type.
• You can use the default STRING data type. It stores up to 82 characters.
• You can create a new string data type that stores less or more characters.
To create a new string data type, see the Logix5000 Controllers Common
Procedures Programming Manual, publication 1756-PM001 .
Name
LEN
Data Type
DINT
DATA SINT array
Each string data type contains the following members.
Description
Number of characters in the string
ASCII characters of the string
Notes
The LEN automatically updates to the new count of characters whenever you:
·Use the String Browser dialog box to enter characters.
·Use instructions that read, convert, or manipulate a string.
The LEN shows the length of the current string. The DATA member may contain additional, old characters, which are not included in the LEN count.
·To access the characters of the string, address the name of the tag.
For example, to access the characters of the string_1 tag, enter string_1.
·Each element of the DATA array contains one character.
·You can create new string data types that store less or more characters.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
609
Chapter 18
ASCII String Instructions (CONCAT, DELETE, FIND, INSERT, MID)
String Concatenate (CONCAT)
The CONCAT instruction adds ASCII characters to the end of a string.
Operands:
Relay Ladder
CONCAT
String Concatenate
Source A
Source B
?
??
?
Dest
??
?
??
Operand
Source A
Source B
Destination
Type
String
String
String
Format
Tag
Tag
Tag
Enter
Tag that contains the initial characters
Tag that contains the end characters
Tag to store the result
Notes
String data types are:
·default STRING data type.
·any new string data type that you create.
Structured Text
CONCAT(SourceA,SourceB,
Dest);
The operands are the same as those for the relay ladder CONCAT instruction.
Description:
The CONCAT instruction combines the characters in Source A with the characters in Source B and places the result in the Destination.
• The characters from Source A are first, followed by the characters from
Source B.
• Unless Source A and the Destination are the same tag, Source A remains unchanged.
Arithmetic Status Flags:
Not affected
Fault Conditions:
Type
4
Code
51
Cause
The LEN value of the string tag is greater than the DATA size of the string tag.
Recovery Method
1. Check that no instruction is writing to the LEN member of the string tag.
2. In the LEN value, enter the number of characters that the string contains.
610
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Condition
Prescan
Rung-condition-in is false
Rung-condition-in is true
EnableIn is set
Instruction execution
Postscan add_node
ASCII String Instructions (CONCAT, DELETE, FIND, INSERT, MID)
Chapter 18
Execution:
Relay Ladder Action
The rung-condition-out is set to false.
The rung-condition-out is set to false.
The instruction executes.
The rung-condition-out is set to true.
N/A
Structured Text Action
No action taken.
N/A
N/A
EnableIn is always set.
The instruction executes.
The instruction concatenates the strings.
The rung-condition-out is set to false.
No action taken.
Example:
To trigger a message in a MessageView terminal, the controller must send an
ASCII string that contains a message number and node number.
String_1 contains the message number. When add_node is set, the CONCAT instruction adds the characters in
node_num_ascii (node number) to the end of the characters in string_1 and then stores the result in msg.
Relay Ladder
CONCAT
String Concatenate
Source A string_1
'$1423\'
Source B node_num_ascii
Dest
'1' msg
'$1423\1'
Structured Text
IF add_node THEN
CONCAT(string_1,node_num_ascii,msg); add_node := 0;
END_IF;
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
611
Chapter 18
ASCII String Instructions (CONCAT, DELETE, FIND, INSERT, MID)
String Delete (DELETE)
Operands:
The DELETE instruction does not automatically remove all ASCII characters from a string. An algorithm determines which characters in the string are removed depending on the starting position, quantity, and size of the Source.
DELETE
String Delete
Source
Qty
Start
Dest
?
??
?
??
?
??
?
??
Relay Ladder
The DELETE instruction does the following:
• Copies the string from the Source to the Destination, ignoring deleted characters and updating the Destination string with the number of characters copied
• Updates the length of the Destination string by the position of characters in the Source string and the number of characters being deleted
• Leaves the Source unchanged unless the Source and the Destination are the same tag
Operand
Source
Quantity
Start
Destination
Type
string
SINT
INT
DINT
SINT
INT
DINT
string
Format
Tag
Immediate
Tag
Immediate
Tag
Tag
Enter
Tag that contains the string from which you want to delete characters
Number of characters to delete
Notes
String data types are:
·Default STRING data type
·Any new string data type that you create
The Start plus the Quantity must be less than or equal to the
DATA size of the Source.
Enter a number between 1 and the DATA size of the Source.
Position of the first character to delete
Tag to store the result
4
Structured Text
DELETE(Source,Qty,Start,
The operands are the same as those for the relay ladder DELETE instruction.
Arithmetic Status Flags:
Not affected
Type
4
Code
51
56
Fault Conditions:
Cause
The LEN value of the string tag is greater than the DATA size of the string tag.
The Start or Quantity value is invalid.
Recovery Method
1. Check that no instruction is writing to the LEN member of the string tag.
2. In the LEN value, enter the number of characters that the string contains.
1. Check that the Start value is between 1 and the DATA size of the Source.
2. Check that the Start value plus the Quantity value is less than or equal to the DATA size of the
Source.
612
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Condition
Prescan
Rung-condition-in is false
Rung-condition-in is true
EnableIn is set
Instruction execution
Postscan term_read.EM
ASCII String Instructions (CONCAT, DELETE, FIND, INSERT, MID)
Chapter 18
Execution:
Relay Ladder Action
The rung-condition-out is set to false.
The rung-condition-out is set to false.
The instruction executes.
The rung-condition-out is set to true.
N/A
Structured Text Action
No action taken
N/A
N/A
EnableIn is always set.
The instruction executes.
The instruction deletes the specified characters.
The rung-condition-out is set to false.
No action taken.
Example:
ASCII information from a terminal contains a header character. After the controller reads the data (
term_read.EM is set) the DELETE instruction removes the header character.
Relay Ladder
DELETE
String Delete
Source term_input
Qty
'$0655'
1
Start
Dest
1 term_text
'55'
Structured Text
IF term_read.EM THEN
DELETE(term_input,1,1,term_text); term_read.EM := 0;
END_IF;
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
613
Chapter 18
ASCII String Instructions (CONCAT, DELETE, FIND, INSERT, MID)
Find String (FIND)
Operands:
The FIND instruction locates the starting position of a specified string within another string.
Relay Ladder
FIND
Find String
Source
Search
Start
Result
?
??
?
??
?
??
?
??
Operand
Source
Search
Start
Result
Type
String
String
SINT
INT
DINT
SINT
INT
DINT
Format
Tag
Tag
Immediate
Tag
Tag
Enter
String to search in
String to find
Notes
String data types are:
·Default STRING data type
·Any new string data type that you create
Position in Source to start the search Enter a number between 1 and the DATA size of the Source.
Tag that stores the starting position of the string to find
Structured Text
4
FIND(Source,Search,Start,
Type
4
Description:
The FIND instruction searches the Source string for the Search string. If the instruction finds the Search string, the Result shows the starting position of the
Search string within the Source string.
Arithmetic Status Flags:
Not affected
Code
51
56
The operands are the same as those for the relay ladder FIND instruction described above.
Fault Conditions:
Cause
The LEN value of the string tag is greater than the DATA size of the string tag.
The Start value is invalid.
Recovery Method
1. Check that no instruction is writing to the LEN member of the string tag.
2. In the LEN value, enter the number of characters that the string contains.
Check that the Start value is between 1 and the DATA size of the Source.
614
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Condition
Prescan
Rung-condition-in is false
Rung-condition-in is true
EnableIn is set
Instruction execution
Postscan
MV_read.EM
ASCII String Instructions (CONCAT, DELETE, FIND, INSERT, MID)
Chapter 18
Execution:
Relay Ladder Action
The rung-condition-out is set to false.
The rung-condition-out is set to false.
The instruction executes.
The rung-condition-out is set to true.
N/A
Structured Text Action
No action taken.
N/A
N/A
EnableIn is always set.
The instruction executes.
The instruction searches for the specified characters.
The rung-condition-out is set to false.
No action taken.
Example:
A message from a MessageView terminal contains several pieces of information.
The backslash character [ \ ] separates each piece of information. To locate a piece of information, the FIND instruction searches for the backslash character and records its position in
find_pos.
Relay Ladder
FIND
Find String
Source MV_msg
'$06324\12\1\$r'
Search
Start find
'\'
1
Result find_pos
5
Structured Text
IF MV_read.EM THEN
FIND(MV_msg,find,1,find_pos);
MV_read.EM := 0;
END_IF;
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
615
Chapter 18
ASCII String Instructions (CONCAT, DELETE, FIND, INSERT, MID)
Insert String (INSERT)
Operands:
The INSERT instruction adds ASCII characters to a specified location within a string.
Relay Ladder
Operand
Source A
Source B
Start
Result
INSERT
Insert String
Source A
Source B
Start
Dest
?
??
?
??
?
??
?
??
Type
String
String
SINT
INT
DINT
String
Format
Tag
Tag
Immediate
Tag
Tag
Enter
String to add the characters to
String containing the characters to add
Position in Source A to add the characters
Notes
String data types are:
·Default STRING data type
·Any new string data type that you create
Enter a number between 1 and the DATA size of the Source.
String to store the result
Type
4
4
Structured Text
INSERT(SourceA,SourceB,
The operands are the same as those for the relay ladder INSERT instruction.
Description:
The INSERT instruction adds the characters in Source B to a designated position within Source A and places the result in the Destination.
• Start defines where in Source A that Source B is added.
• Unless Source A and the Destination are the same tag, Source A remains unchanged.
Arithmetic Status Flags:
Not affected
Fault Conditions:
Code
51
56
Cause
The LEN value of the string tag is greater than the DATA size of the string tag.
The Start value is invalid.
Recovery Method
1. Check that no instruction is writing to the LEN member of the string tag.
2. In the LEN value, enter the number of characters that the string contains.
Check that the Start value is between 1 and the DATA size of the Source.
616
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Condition
Prescan
Rung-condition-in is false
Rung-condition-in is true
EnableIn is set
Instruction execution
Postscan temp_high
ASCII String Instructions (CONCAT, DELETE, FIND, INSERT, MID)
Chapter 18
Execution:
Relay Ladder Action
The rung-condition-out is set to false.
The rung-condition-out is set to false.
The instruction executes.
The rung-condition-out is set to true.
N/A
Structured Text Action
No action taken.
N/A
N/A
EnableIn is always set.
The instruction executes.
The instruction inserts the specified characters.
The rung-condition-out is set to false.
No action taken.
Example:
When temp_high is set, the INSERT instruction adds the characters in string_2 to position 2 within
string_1 and places the result in string_3:
Relay Ladder
INSERT
Insert String
Source A string_1
'AD'
Source B string_2
'BC'
Start 2
Dest string_3
'ABCD'
Structured Text
IF temp_high THEN
INSERT(string_1,string_2,2,string_3); temp_high := 0;
END_IF;
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
617
Chapter 18
ASCII String Instructions (CONCAT, DELETE, FIND, INSERT, MID)
Middle String (MID)
Operands:
The MID instruction copies a specified number of ASCII characters from a string and stores them in another string.
Relay Ladder
Operand
Source
Quantity
Start
Destination
MID
Middle String
Source
Qty
Start
Dest
?
??
?
??
?
??
?
??
Type
String
SINT
INT
DINT
SINT
INT
DINT
String
Format
Tag
Immediate
Tag
Immediate
Tag
Tag
Enter
String to copy characters from
Number of characters to copy
Notes
String data types are:
·Default STRING data type
·Any new string data type that you create
The Start plus the Quantity must be less than or equal to the
DATA size of the Source.
Position of the first character to copy Enter a number between 1 and the DATA size of the Source.
String to copy the characters to
Type
4
4
Structured Text
MID(Source,Qty,Start,
The operands are the same as those for the relay ladder MID instruction.
Description:
The MID instruction copies a group of characters from the Source and places the result in the Destination.
• The Start position and Quantity define the characters to copy.
• Unless the Source and Destination are the same tag, the Source remains unchanged.
Arithmetic Status Flags:
Not affected
Code
51
56
Fault Conditions:
Cause
The LEN value of the string tag is greater than the DATA size of the string tag.
The Start or Quantity value is invalid.
Recovery Method
1. Check that no instruction is writing to the LEN member of the string tag.
2. In the LEN value, enter the number of characters that the string contains.
1. Check that the Start value is between 1 and the DATA size of the Source.
2. Check that the Start value plus the Quantity value is less than or equal to the DATA size of the
Source.
618
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Condition
Prescan
Rung-condition-in is false
Rung-condition-in is true
EnableIn is set
Instruction execution
Postscan bag_read.EM
ASCII String Instructions (CONCAT, DELETE, FIND, INSERT, MID)
Chapter 18
Execution:
Relay Ladder Action
The rung-condition-out is set to false.
The rung-condition-out is set to false.
The instruction executes.
The rung-condition-out is set to true.
N/A
Structured Text Action
No action taken.
N/A
N/A
EnableIn is always set.
The instruction executes.
The instruction copies the specified characters from a string and stores them in another string.
The rung-condition-out is set to false.
No action taken.
Example:
In a baggage handling conveyor of an airport, each bag gets a bar code. Characters
9…17 of the bar code are the flight number and destination airport of the bag.
After the bar code is read ( bag_read.EM is set) the MID instruction copies the flight number and destination airport to the
bag_flt_and_dest string.
Relay Ladder
MID
Middle String
Source bag_barcode
'NWA HOP 5058 AMS 01'
Qty 9
Start 9
Dest bag_flt_and_dest
'5058 AMS '
Structured Text
IF bag_read.EM THEN
MID(bar_barcode,9,9,bag_flt_and_dest); bag_read.EM := 0;
END_IF;
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
619
Chapter 18
ASCII String Instructions (CONCAT, DELETE, FIND, INSERT, MID)
Notes:
620
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Chapter
19
ASCII Conversion Instructions
(STOD, STOR, DTOS, RTOS, UPPER, LOWER)
Topic
Page
If you want to
Convert the ASCII representation of an integer value to a SINT, INT, DINT, or REAL value
Convert the ASCII representation of a floatingpoint value to a REAL value
Convert a SINT, INT, DINT, or REAL value to a string of ASCII characters
Convert a REAL value to a string of ASCII characters
Convert the letters in a string of ASCII characters to upper case
Convert the letters in a string of ASCII characters to lower case
Use the ASCII conversion instructions to alter the format of data.
For example
Convert a value from a weight scale or other ASCII device to an integer so you can use it in your logic
Convert a value from a weight scale or other ASCII device to a REAL value so you can use it in your logic
Convert a variable to an ASCII string so you can send it to a MessageView terminal
Use this instruction Available in these languages
STOD
STOR
Relay ladder
Structured text
Relay ladder
Structured text
DTOS
Convert a variable to an ASCII string so you can send it to a MessageView terminal
Convert an entry made by an operator to all upper case so you can search for it in an array
Convert an entry made by an operator to all lower case so you can search for it in an array
RTOS
UPPER
LOWER
Relay ladder
Structured text
Relay ladder
Structured text
Relay ladder
Structured text
Relay ladder
Structured text
Page
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
621
Chapter 19
ASCII Conversion Instructions (STOD, STOR, DTOS, RTOS, UPPER, LOWER)
You can also use the following instructions to compare or manipulate
ASCII characters.
If you want to
Add characters to the end of a string
Delete characters from a string
Determine the starting character of a sub-string
Insert characters into a string
Extract characters from a string
Rearrange the bytes of a INT, DINT, or REAL tag
Compare a string to another string
See if the characters are equal to specific characters
See if the characters are not equal to specific characters
See if the characters are equal to or greater than specific characters
See if the characters are greater than specific characters
See if the characters are equal to or less than specific characters
See if the characters are less than specific characters
Find a string in an array of strings
LEQ
LES
FSC
EQU
NEQ
GEQ
GRT
Use this instruction
CONCAT
DELETE
FIND
INSERT
MID
SWPB
CMP
Page
String Data Types
You store ASCII characters in tags that use a string data type.
• You can use the default STRING data type. It stores up to 82 characters.
• You can create a new string data type that stores less or more characters.
To create a new string data type, see the Logix5000 Controllers Common
Procedures Programming Manual, publication 1756-PM001 .
Each string data type contains the following members.
Name
LEN
Data Type
DINT
DATA
622
SINT array
Description
Number of characters in the string
Notes
The LEN automatically updates to the new count of characters whenever you do the following:
• Use the String Browser dialog box to enter characters.
• Use instructions that read, convert, or manipulate a string.
The LEN shows the length of the current string. The DATA member may contain additional, old characters, which are not included in the LEN count.
ASCII characters of the string • To access the characters of the string, address the name of the tag.
For example, to access the characters of the string_1 tag, enter string_1.
·Each element of the DATA array contains one character.
·You can create new string data types that store less or more characters.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
ASCII Conversion Instructions (STOD, STOR, DTOS, RTOS, UPPER, LOWER)
Chapter 19
String To DINT (STOD)
Operands:
The STOD instruction converts the ASCII representation of an integer to an integer or REAL value.
Relay Ladder
STOD
String To DINT
Source
Dest
?
??
?
??
Operand
Source
Destination
Type
String
SINT
INT
DINT
REAL
Format
Tag
Tag
Enter
Tag to store the integer value
Notes
Tag that contains the value in ASCII String data types are:
• default STRING data type.
• any new string data type that you create.
If the Source value is a floating-point number, the instruction converts only the non-fractional part of the number
(regardless of the destination data type).
STOD(Source,Dest);
Structured Text
The operands are the same as those for the relay ladder STOD instruction.
Description:
The STOD converts the Source to an integer and places the result in the
Destination.
• The instruction converts positive and negative numbers.
• If the Source string contains non-numeric characters, the STOD converts the first set of contiguous numbers:
– The instruction skips any initial control or non-numeric characters
(except the minus sign in front of a number).
– If the string contains multiple groups of numbers that are separated by delimiters (for example, / ), the instruction converts only the first group of numbers.
Arithmetic Status Flags:
Arithmetic status flags are affected.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
623
Chapter 19
ASCII Conversion Instructions (STOD, STOR, DTOS, RTOS, UPPER, LOWER)
Type
4
4
Postscan
Code
51
53
Condition
Prescan
Rung-condition-in is false
Rung-condition-in is true
EnableIn is set
Instruction execution
Fault Conditions
Cause
The LEN value of the string tag is greater than the DATA size of the string tag.
The output number is beyond the limits of the destination data type.
Recovery Method
1. Check that no instruction is writing to the LEN member of the string tag.
2. In the LEN value, enter the number of characters that the string contains.
Either:
• Reduce the size of the ASCII value.
• Use a larger data type for the destination.
Execution:
Relay Ladder Action
The rung-condition-out is set to false.
The rung-condition-out is set to false.
The instruction executes.
The rung-condition-out is set to true.
N/A
Structured Text Action
No action taken.
N/A
N/A
EnableIn is always set.
The instruction executes.
SC is set.
Destination is cleared.
The instruction converts the Source.
If the result is zero, then S:Z is set
The rung-condition-out is set to false.
No action taken.
Example:
When
MV_read.EM is set, the STOD instruction converts the first set of numeric characters in MV_msg to an integer value. The instruction skips the initial control character ($06) and stops at the delimiter ( \ ).
Relay Ladder
MV_read.EM
STOD
String To DINT
Source MV_msg
'$06324\12\1\$r'
Dest MV_msg_nmbr
324
Structured Text
IF MV_read.EM THEN
STOD(MV_msg,MV_msg_nmbr);
MV_read.EM := 0;
END_IF;
624
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
ASCII Conversion Instructions (STOD, STOR, DTOS, RTOS, UPPER, LOWER)
Chapter 19
String To REAL (STOR)
Operands:
The STOR instruction converts the ASCII representation of a floating-point value to a REAL value.
Operand
Source
Destination
STOR
String to Real
Source
Dest
?
??
?
??
Type
String
REAL
Format
Tag
Tag
Relay Ladder Operands
Enter Notes
Tag that contains the value in ASCII String data types are:
• Default STRING data type
• Any new string data type that you create
Tag to store the REAL value
4
Type
4
STOR(Source,Dest);
Structured Text
The operands are the same as those for the relay ladder STOR instruction.
Description:
The STOR converts the Source to a REAL value and places the result in the
Destination.
• The instruction converts positive and negative numbers.
• If the Source string contains non-numeric characters, the STOR converts the first set of contiguous numbers, including the decimal point [ . ]:
– The instruction skips any initial control or non-numeric characters
(except the minus sign in front of a number).
– If the string contains multiple groups of numbers that are separated by delimiters (for example, / ), the instruction converts only the first group of numbers.
Arithmetic Status Flags:
Arithmetic status flags are affected.
Code
51
53
Fault Conditions:
Cause
The LEN value of the string tag is greater than the DATA size of the string tag.
The output number is beyond the limits of the destination data type.
Recovery Method
1. Check that no instruction is writing to the LEN member of the string tag.
2. In the LEN value, enter the number of characters that the string contains.
Either:
• Reduce the size of the ASCII value.
• Use a larger data type for the destination.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
625
Chapter 19
ASCII Conversion Instructions (STOD, STOR, DTOS, RTOS, UPPER, LOWER)
Condition
Prescan
Rung-condition-in is false
Rung-condition-in is true
EnableIn is set
Instruction execution
Postscan
Execution:
Relay Ladder Action
The rung-condition-out is set to false.
The rung-condition-out is set to false.
The instruction executes.
The rung-condition-out is set to true.
N/A
S:C is set.
Destination is cleared.
The instruction converts the Source.
If the result is zero, then S:Z is set
The rung-condition-out is set to false.
Structured Text Action
No action taken.
N/A
N/A
EnableIn is always set.
The instruction executes.
No action taken.
Example:
After reading the weight from a scale (
weight_read.EM is set) the STOR instruction converts the numeric characters in weight_ascii to a REAL value.
You may see a slight difference between the fractional parts of the Source and
Destination.
Relay Ladder
weight_read.EM
STOR
String to Real
Source weight_ascii
Dest
'428.259' weight
428.259
Structured Text
IF weight_read.EM THEN
STOR(weight_ascii,weight); weight_read.EM := 0;
END_IF;
626
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
ASCII Conversion Instructions (STOD, STOR, DTOS, RTOS, UPPER, LOWER)
Chapter 19
DINT to String (DTOS)
Operands:
The DTOS instruction produces the ASCII representation of a value.
Relay Ladder
Operand
Source
Destination
DTOS
DINT to String
Source
Dest
?
??
?
??
Type
SINT
INT
DINT
REAL
String
Format
Tag
Tag
Enter
Tag that contains the value
Tag to store the ASCII value
Notes
If the Source is a REAL, the instruction converts it to a DINT value. .
String data types are:
• default STRING data type.
• any new string data type that you create.
Type
4
DTOS(Source,Dest);
Structured Text
The operands are the same as those for the relay ladder DTOS instruction.
Description:
The DTOS converts the Source to a string of ASCII characters and places the result in the Destination.
Arithmetic Status Flags:
Not affected
Fault Conditions:
Code
52
Cause
The output string is larger than the destination.
Recovery Method
Create a new string data type that is large enough for the output string.
Use the new string data type as the data type for the destination.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
627
Chapter 19
ASCII Conversion Instructions (STOD, STOR, DTOS, RTOS, UPPER, LOWER)
Condition
Prescan
Rung-condition-in is false
Rung-condition-in is true
EnableIn is set
Instruction execution
Postscan
Execution:
Relay Ladder Action
The rung-condition-out is set to false.
The rung-condition-out is set to false.
The instruction executes.
The rung-condition-out is set to true.
N/A
Structured Text Action
No action taken.
N/A
N/A
EnableIn is always set.
The instruction executes.
The instruction converts the source.
The rung-condition-out is set to false.
No action taken.
Example:
When temp_high is set, the DTOS instruction converts the value in msg_num to a string of ASCII characters and places the result in
msg_num_ascii. Subsequent rungs insert or concatenate msg_num_ascii with other strings to produce a complete message for a display terminal.
Relay Ladder
temp_high DTOS
DINT to String
Source msg_num
23
Dest msg_num_ascii
'23'
Structured Text
IF temp_high THEN
DTOS(msg_num,msg_num_ascii); temp_high := 0;
END_IF;
628
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
ASCII Conversion Instructions (STOD, STOR, DTOS, RTOS, UPPER, LOWER)
Chapter 19
REAL to String (RTOS)
Operands:
The RTOS instruction produces the ASCII representation of a REAL value.
Operand
Source
Destination
RTOS
Real to String
Source
Dest
?
??
?
??
Type
REAL
String
Format
Tag
Tag
Relay Ladder
Enter
Tag that contains the REAL value
Tag to store the ASCII value
Notes
String data types are:
• Default STRING data type
• Any new string data type that you create
Type
4
RTOS(Source,Dest);
Structured Text
The operands are the same as those for the relay ladder RTOS instruction.
Description:
The RTOS converts the Source to a string of ASCII characters and places the result in the Destination.
Arithmetic Status Flags:
Not affected
Fault Conditions:
Code
52
Cause
The output string is larger than the destination.
Recovery Method
Create a new string data type that is large enough for the output string.
Use the new string data type as the data type for the destination.
Condition
Prescan
Rung-condition-in is false
Rung-condition-in is true
EnableIn is set
Instruction execution
Postscan
Execution:
Relay Ladder Action
The rung-condition-out is set to false.
The rung-condition-out is set to false.
The instruction executes.
The rung-condition-out is set to true.
N/A
The instruction converts the source.
The rung-condition-out is set to false.
Structured Text Action
No action taken.
N/A
N/A
EnableIn is always set.
The instruction executes.
No action taken.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
629
Chapter 19
ASCII Conversion Instructions (STOD, STOR, DTOS, RTOS, UPPER, LOWER) send_data
Example:
When
send_data is set, the RTOS instruction converts the value in data_1 to a string of ASCII characters and places the result in data_1_ascii. Subsequent rungs insert or concatenate
data_1_ascii with other strings to produce a complete message for a display terminal.
You may see a slight difference between the fractional parts of the Source and
Destination.
Relay Ladder
RTOS
Real to String
Source data_1
15.3001
Dest data_1_ascii
'15.3001003'
Structured Text
IF send_data THEN
RTOS(data_1,data_1_ascii); send_data := 0;
END_IF;
630
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
ASCII Conversion Instructions (STOD, STOR, DTOS, RTOS, UPPER, LOWER)
Chapter 19
Upper Case (UPPER)
Operands:
The UPPER instruction converts the alphabetical characters in a string to upper case characters.
Relay Ladder
Operand
Source
Destination
Type
String
String
Format
Tag
Tag
Description
Tag that contains the characters that you want to convert to upper case
Tag to store the characters in upper case
UPPER(Source,Dest);
Structured Text
The operands are the same as those for the relay ladder UPPER instruction.
Description:
The UPPER instruction converts to upper case all the letters in the Source and places the result in the Destination.
• ASCII characters are case sensitive. Upper case ‘A’ ($41) is not equal to lower case ‘a’ ($61).
• If operators directly enter ASCII characters, convert the characters to all upper case or all lower case before you compare them.
Any characters in the Source string that are not letters remain unchanged.
Arithmetic Status Flags:
Not affected
Fault Conditions:
None
Execution:
Condition
Prescan
Rung-condition-in is false
Rung-condition-in is true
EnableIn is set
Relay Ladder Action
The rung-condition-out is set to false.
The rung-condition-out is set to false.
The instruction executes.
The rung-condition-out is set to true.
N/A
Structured Text Action
No action taken.
N/A
N/A
EnableIn is always set.
The instruction executes.
Instruction execution
Postscan
The instruction converts the Source to upper case.
The rung-condition-out is set to false.
No action taken.
Example:
To find information about a specific item, an operator enters the catalog number of the item into an ASCII terminal. After the controller reads the input from a
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
631
Chapter 19
ASCII Conversion Instructions (STOD, STOR, DTOS, RTOS, UPPER, LOWER) terminal (
terminal_read.EM is set), the UPPER instruction converts the characters in catalog_number to all upper case characters and stores the result in
catalog_number_upper_case. A subsequent rung then searches an array for characters that match those in catalog_number_upper_case.
Relay Ladder
Structured Text
IF terminal_read.EM THEN
UPPER(catalog_number,catalog_number_upper_case); terminal_read.EM := 0;
END_IF;
632
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
ASCII Conversion Instructions (STOD, STOR, DTOS, RTOS, UPPER, LOWER)
Chapter 19
Lower Case (LOWER)
Operands:
The LOWER instruction converts the alphabetical characters in a string to lower case characters.
Relay Ladder
Operand
Source
Destination
Type
String
String
Format
Tag
Tag
Description
Tag that contains the characters that you want to convert to lower case
Tag to store the characters in lower case
LOWER(Source,Dest);
Structured Text
The operands are the same as those for the relay ladder LOWER instruction.
Description:
The LOWER instruction converts to lower case all the letters in the Source and places the result in the Destination.
• ASCII characters are case sensitive. Upper case ‘A’ ($41) is not equal to lower case ‘a’ ($61).
• If operators directly enter ASCII characters, convert the characters to all upper case or all lower case before you compare them.
Any characters in the Source string that are not letters remain unchanged.
Arithmetic Status Flags:
Not affected
Fault Conditions:
None
Execution:
Condition
Prescan
Rung-condition-in is false
Rung-condition-in is true
EnableIn is set
Relay Ladder Action
The rung-condition-out is set to false.
The rung-condition-out is set to false.
The instruction executes.
The rung-condition-out is set to true.
N/A
Structured Text Action
No action taken.
N/A
N/A
EnableIn is always set.
The instruction executes.
Instruction execution
Postscan
The instruction converts the Source to lower case.
The rung-condition-out is set to false.
No action taken.
Example:
To find information about a specific item, an operator enters the item number into an ASCII terminal. After the controller reads the input from a terminal
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
633
Chapter 19
ASCII Conversion Instructions (STOD, STOR, DTOS, RTOS, UPPER, LOWER)
(
terminal_read.EM is set), the LOWER instruction converts the characters in
item_number to all lower case characters and stores the result in
item_number_lower_case. A subsequent rung then searches an array for characters that match those in item_number_lower_case.
Relay Ladder
Structured Text
IF terminal_read.EM THEN
LOWER(item_number,item_number_lower_case); terminal_read.EM := 0;
END_IF;
634
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Chapter
20
Debug Instructions
(BPT, TPT)
If you want to
Stop program emulation when a rung is true
Log data you select when a rung is true
Topic
Page
Use the debug instructions to monitor the state of your logic when it is in conditions that you determine. These instructions are compatible only with
RSLogix Emulate 5000 software, with which you can emulate a
Logix5000 controller on your personal computer.
Use this instruction
BPT
TPT
Available in these languages
Relay ladder
Relay ladder
Page
Breakpoints (BPT)
Operands:
Breakpoints stop program emulation when a rung is true.
Relay Ladder
Operand
Format
Trace This
Type
String
BOOL, SINT, INT, DINT,
REAL
Format Description
Tag A string that sets the formatting for the text that appears in the trace window for the breakpoint.
Tag The tag that has a value you want to display in the trace window.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
635
Chapter 20
Debug Instructions (BPT, TPT)
Description:
Breakpoints are programmed with the Breakpoint output instruction (BPT).
When the inputs on a rung containing a BPT instruction are true, the
BPT instruction stops program execution. The software displays a window indicating that the breakpoint triggered and the values that triggered it.
636
When a breakpoint triggers, the emulator displays a window informing you that a breakpoint occurred. The title bar of the window shows the slot containing the emulator that encountered the breakpoint.
When you click OK, the emulator resumes program execution. If the conditions that triggered the breakpoint persist, the breakpoint will recur.
In addition, the emulator opens a trace window for the breakpoint. The trace window displays information about the breakpoint and the values.
IMPORTANT
ATTENTION: When a breakpoint triggers, you will not be able to edit your project until you permit the execution to continue. You can go online with the emulator to observe the state of your project, but you will not be able to edit it. If you try to accept a rung edit while a breakpoint is triggered, you will see a dialog box saying the controller is not in the correct mode.
String Format
With the Format string in the tracepoint and breakpoint instructions, you can control how the traced tags appear in the traces or breakpoint windows. The format of the string is: heading:(text)%(type) where heading is a text string identifying the tracepoint or breakpoint, text is a string describing the tag (or any other text you choose), and %(
type) indicates the format of the tag. You need one type indicator for each tag you are tracing with the tracepoint or breakpoint instruction.
For example, you could format a tracepoint string as shown.
My tracepoint:Tag 1 = %e and Tag 2 = %d
The %e formats the first traced tag as double-precision float with an exponent, and %d formats the second traced tag as a signed decimal integer.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Debug Instructions (BPT, TPT)
Chapter 20
In this case, you would have a tracepoint instruction that has two Trace This operands (one for a REAL and one for an INT, although the value of any tag can be formatted with any flag).
The resulting tracepoint window that would appear when the tracepoint is triggered would look like the example.
The heading (the text preceding the colon in the format string) appears here.
The slot number indicates the slot containing the emulator module that has the tracepoint or breakpoint being traced in the trace window.
The text for the REAL (represented in the format string as %e) appears here.
The text for the INT (represented in the format string as %d) appears here.
Postscan
Arithmetic Status Flags:
Not affected
Fault Conditions:
None
Execution:
Condition
Prescan
Rung-condition-in is false
Rung-condition-in is true
Relay Ladder Action
The rung-condition-out is set to false.
The rung-condition-out is set to false.
The rung-condition-out is set to true.
Execution jumps to the rung that contains the LBL instruction with the referenced label name.
The rung-condition-out is set to false.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
637
Chapter 20
Debug Instructions (BPT, TPT)
Example:
You can display many tag values with the BPT instruction. However, the formatting string can contain only 82 characters. Because the formatting string requires two characters for each tag you want in the breakpoint, you cannot trace more than 41 tags with a single BPT instruction. However, to separate tag data in your traces, you will need to include spaces and other formatting, thus reducing the number of tag values that one BPT instruction can effectively display to far fewer than 41.
This rung shows a breakpoint that stops program execution when an analog value is greater than 3.02 or less than 2.01.
You want to display the breakpoint information in the Format string (myformat).
In this case, the format string contains the following text:
Breakpoint:The input value is %f
When the breakpoint triggers, the breakpoint trace window shows the characters before the colon (‘Breakpoint’) in the title bar of the trace window. The other characters make up the traces. In this example, %f represents the first (and in this case, the only) tag to be traced (‘analogvalue’).
The resulting traces appear as shown here.
638
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Tracepoints (TPT)
Operands:
Debug Instructions (BPT, TPT)
Chapter 20
Trace points log data you select when a rung is true.
Relay Ladder
Operand
Format
Type
String
Format
Tag
Description
A string that sets the formatting for the trace reports (both on-screen and logged to disk).
The tag you want to trace.
Trace This BOOL, SINT, INT,
DINT,
REAL
Tag
Description:
Tracepoints are programmed with the tracepoint output instruction (TPT).
When the inputs on a rung containing a TPT instruction are true, the
TPT instruction writes a trace entry to a trace display or log file.
You can trace many tags with the TPT instruction. However, the formatting string can contain only 82 characters. Because the formatting string requires two characters for each tag you want to trace, you cannot trace more than 41 tags with a single TPT instruction. However, to separate tag data in your traces, you will need to include spaces and other formatting, thus reducing the number of tags that one TPT instruction can effectively trace to far fewer than 41.
String Format
With the Format string in the tracepoint and breakpoint instructions, you can control how the traced tags appear in the traces or breakpoint windows. The format of the string is as shown here: heading:(text)%(type) where heading is a text string identifying the tracepoint or breakpoint, text is a string describing the tag (or any other text you choose), and %(
type) indicates the format of the tag. You need one type indicator for each tag you are tracing with the tracepoint or breakpoint instruction.
For example, you could format a tracepoint string as shown.
My tracepoint:Tag 1 = %e and Tag 2 = %d
The %e formats the first traced tag as double-precision float with an exponent, and %d formats the second traced tag as a signed decimal integer.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
639
Chapter 20
Debug Instructions (BPT, TPT)
In this case, you would have a tracepoint instruction that has two Trace This operands (one for a REAL and one for an INT, although the value of any tag can be formatted with any flag).
The resulting tracepoint window that would appear when the tracepoint is triggered would look like the example.
The heading (the text preceding the colon in the format string) appears here.
The slot number indicates the slot containing the emulator module that has the tracepoint or breakpoint being traced in the trace window.
The text for the REAL (represented in the format string as %e) appears here.
The text for the INT (represented in the format string as %d) appears here.
Postscan
.
Arithmetic Status Flags:
Not affected
Fault Conditions:
None
Execution:
Condition:
Prescan
Rung-condition-in is false
Rung-condition-in is true
Relay Ladder Action
The rung-condition-out is set to false.
The rung-condition-out is set to false.
The rung-condition-out is set to true.
Execution jumps to the rung that contains the LBL instruction with the referenced label name.
The rung-condition-out is set to false.
640
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Debug Instructions (BPT, TPT)
Chapter 20
Example:
This rung triggers a trace of three analog values when any one of them exceeds a given value (30.01).
You want to display the tracepoint information in the Format string (myformat).
In this case, the format string contains this text:
Analog inputs trace:Analog inputs = %f, %f, and %f
When the tracepoint triggers, the characters before the colon (‘Analog inputs trace’) appear in the title bar of the trace window. The other characters make up the traces. In this example, %f represents the tags to be traced (‘analogvalue1,’
‘analogvalue2,’ and ‘analogvalue3’).
The resulting traces appear as shown here.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
641
Chapter 20
Debug Instructions (BPT, TPT)
When this trace is logged to disk, the characters before the colon appear in the traces.
This indicates which tracepoint caused which trace entry. This is an example of a trace entry. ‘Analog inputs trace:’ is the heading text from the tracepoint's format string.
Analog inputs trace: Analog inputs = 31.00201, 30.282000, and 30.110001.
642
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Introduction
Status Flags
Appendix
A
Common Attributes
This appendix describes attributes that are common to the Logix instructions.
For Information About
See Page
To access controller configuration and status in your logic, use the Get System
Value (GSV) and Set System Value (SSV) instructions. There is a also a set of status Status Flags that you can access directly with relay and structured text instructions. These flags are not tags and you cannot create aliases for them.
Status Flag
S:FS
S:N
Description
First scan flag
The first scan flag is set by the controller on the first scan of routines in a program. This flag can be used with only the XIC and XIO relay instructions or in structured text like a Boolean variable. You can use this flag to initialize data for use in later scans.
Sometimes called the ‘first pass’ bit.
Negative flag
The controller sets the negative flag when the result of an arithmetic or logical operation is a negative value. This flag can be used only with XIC, XIO, OTE, OTL and OTU relay instructions or in structured text like a Boolean variable.
You can use this flag as a quick test for a negative value.
Using S:N is more efficient than using the CMP instruction.
This math status flag is cleared at the start of executing an instruction capable of setting this flag.
Sometimes called the ‘sign’ bit.
If a computation results in a NAN value, the sign bit is irrelevant and could be positive or negative. In this situation, the software displays 1#.NAN with no sign.
An integer divide returns the numerator when the denominator is 0, but does not set this flag.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
643
Appendix A
Common Attributes
644
Status Flag
S:Z
S:V
S:C
S:MINOR
Description
Zero flag
The zero flag is set by the controller when the result of an arithmetic or logical operation is zero. This flag can be used with only the XIC, XIO, OTE, OTL and OTU relay instructions or in structured text like a Boolean variable.
You can use this flag as a quick test for a zero value. Using
S:Z is more efficient than using the CMP instruction.
The math status flag is cleared at the start of executing an instruction capable of setting this flag.
An integer divide returns the numerator when the denominator is 0, but does not set this flag.
Overflow flag
The controller sets the overflow flag when the result of an arithmetic operation resulted in an overflow. This flag can be used with only the XIC, XIO, OTE, OTL and OTU relay instructions or in structured text like a Boolean variable.
You can use this flag to check that the result of an operation is still in range. For example, adding 1 to a SINT generates an overflow when the value goes from
127…128.
The overlow flag generates a minor fault when it transitions from false to true.
This math status flag is cleared at the start of executing an instruction capable of setting this flag.
Sometimes called the ‘overflow’ bit.
The MOD instruction does not capture an overflow that may have occurred during the calculation. If an overflow occurs, a minor fault will be generated, but the S:V bit will not be set.
Carry flag
The controller sets the carry flag when the result of an arithmetic operation resulted in the generation of a carry out of the most significant bit. This flag can be used with only the XIC, XIO, OTE, OTU and OTL relay instructions or in structured text like a Boolean variable.
This math status flag is cleared at the start of executing an instruction capable of setting this flag.
Sometimes called the ‘carry’ bit.
Minor fault flag
The controller sets the minor fault flag when there is at least one minor program fault. This flag can be used with only the XIC, XIO, OTE, OTL and OTU relay instructions or in structured text like a Boolean variable. You could use this flag to test that a minor fault has occurred and take appropriate action. This bit is triggered only by programming faults (like overflow). It will not be triggered by a battery fault. The bit is cleared on every scan. An OTL can be used to explicitly program a minor fault occurrence.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Common Attributes
Appendix A
Expressions in Array Subscripts
Expressions set status flags based on the results of arithmetic operations. If you have an array subscript as an expression, both the expression and the instruction could generate minor faults.
Under certain circumstances, the S:Z status flag may be set if the expression of an array element evaluates to zero. In this example, Array[Element*3], 0 if
Element=0 the subscript [Element*3] evaluates to 0 and the S:Z bit will be set.
Immediate Values
When you enter an immediate value (constant) in decimal format
(for example, -2, 3) the controller stores the value by using 32 bits. If you enter a value in a radix other than decimal, such as binary or hexadecimal, and do not specify all 32 bits, the controller places a zero in the bits that you do not specify
(zero-fill).
IMPORTANT
If you enter
-1
16#ffff (-1)
8#1234 (668)
2#1010 (10)
Zero-filling of immediate values
The controller stores
16#ffff ffff (-1)
16#0000 ffff (65535)
16#0000 029c (668)
16#0000 000a (10)
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
645
Appendix A
Common Attributes
Floating Point Values
Logix controllers handle floating point values according to the IEEE 754 standard for binary floating-point arithmetic. This standard defines how floating point numbers are stored and calculated. The IEEE 754 standard for floating point math was designed to provide speed and the ability to handle very large numbers in a reasonable amount of storage space.
Not all decimal values can be represented in binary format to the exact value, which results in a loss of precision. This standard is widely used throughout industry, including in computer operating systems. As a result, there is no way to control the number of digits to the right of the decimal point in logic in a
Logix5000 controller.
For example, in most cases, if you subtract 10 from 10.1, you expect the result to be 0.1. In a Logix controller, the result could very well be 0.10000038. In this example, the difference between 0.1 and 0.10000038 is .000038%, or practically zero. For most operations, this small inaccuracy is insignificant. To put things in perspective, if you were sending a floating point value to an analog output module, there would be no difference in the output voltage for a value being sent to the module that differs by .000038%. Again, this applies to most cases, but not necessarily every time.
Guidelines for Floating-point Math Operations
Follow these guidelines:
• When performing certain floating-point math operations, there may be a loss of precision and you may receive unexpected results. In general, floating-point numbers are quite accurate, but floating-point processors have their own internal precision that can impact resultant values.
• Do not use floating point math for money values or for totalizer functions.
Use INT or DINT values, scale the values up, and keep track of the decimal place (or use one INT or DINT value for dollars, and a second
INT or DINT value for cents).
• Do not compare floating-point numbers. Instead, check for values within a range. The LIM instruction is provided specifically for this purpose.
646
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Common Attributes
Appendix A
Totalizer Examples
The IEEE 754 standard affects totalization applications such that errors occur when adding very small numbers to very large numbers. The standard requires exponents in the two operands to be the same. Since the fractional component is only 23 bits, as the exponent gets larger, the fractional component approaches zero.
This can be seen when adding 1 to a number over a period of time. When the sum is in the 16 million range, the number 1 becomes 0 because the exponent is so large, a 1 is insignificant, and gets shifted out of the equation. The result is that a
0 is added instead of a 1.
To work around this, do math on small numbers until the results get large. Then, transfer them to another location for additional large-number math. For example: x is the small incremented variable.
y is the large incremented variable.
z is the total current count that can be used anywhere.
x-x+1; if x = 100,000;
{ y = y + 100,000; x = 0;
} z = y + x;
Or another example: x+ x + some_tiny_number; if (x >= 100)
{
} z += 100; x -= 100; // there might be a tiny remainder …
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
647
Appendix A
Common Attributes
Data Conversions
Data conversions occur when you mix data types in your programming.
When programming
Relay Ladder Logic
Function Block
Conversions can occur when you
Mix data types for the parameters within one instruction
Wire two parameters that have different data types
If
Yes
No
Instructions execute faster and require less memory if all the operands of the instruction use:
• The same data type.
• An optimal data type:
– In the ‘Operands’ section of each instruction in this manual, a bold data type indicates an optimal data type.
– The DINT and REAL data types are typically the optimal data types.
– Most function block instruction support only one data type (the optimal data type) for its operands.
If you mix data types and use tags that are not the optimal data type, the controller converts the data according to these rules.
• Are any of the operands a REAL value?
Then input operands (for example, source, tag in an expression, limit) convert to
REALs
DINTs
• After instruction execution, the result (a DINT or REAL value) converts
To the destination data type, if necessary
You cannot specify a BOOL tag in an instruction that operates on integer or
REAL data types.
Because the conversion of data takes additional time and memory, you can increase the efficiency of your programs by doing the following:
• Using the same data type throughout the instruction.
• Minimizing the use of the SINT or INT data types.
In other words, use all DINT tags or all REAL tags, along with immediate values, in your instructions.
The following sections explain how the data is converted when you use SINT or
INT tags or when you mix data types.
648
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Data Types
Common Attributes
Appendix A
LINT Data Type Considerations
When using LINT data types, many limitations apply. A LINT data type cannot be used in most instructions. Limitations are as follows:
• The LINT data type is not supported in Machine Edition. The LINT data type is a 64-bit word; ME uses only 32-bit words.
• The LINT data type is not supported by HMIs.
• The LINT data type is not supported in most instructions.
TIP
LINTs can only be used with Move and Copy instructions. They are used with the CST/WallClock Time attribute, time synchronization and Add-On
Instructions.You cannot Add, Subtract, Multiply, or Divide this tag type.
When using LINT data types, consider the following descriptions when these issues occur.
How to Description
Move/copy two double-integer DINT values into one LINT Create a double integer array of two elements, total of 64 bits (that is, DINT[2], which can then be copied into one long integer.
Correct Date/Time Display error When a tag has a negative value, it cannot be displayed as
Date/Time. In the tag editor, check whether the value is negative by changing the style of the tag from Date/Time to Binary. When the most significant bit (leftmost one) is
1, the value is negative and therefore cannot be displayed as a Date or Time.
SINT or INT to DINT
For those instructions that convert SINT or INT values to DINT values, the
‘Operands’ sections in this manual identify the conversion method.
This conversion method
Sign-extension
Zero-fill
Converts data by placing
The value of the leftmost bit (the sign of the value) into each bit position to the left of the existing bits until there are 32 bits.
Zeroes to the left of the existing bits until there are 32 bits.
The following example shows the results of converting a value using signextension and zero-fill.
This value
Converts to this value by sign-extension
Converts to this value by zero-fill
2#1111_1111_1111_1111
2#1111_1111_1111_1111_1111_1111_1111_1111
2#0000_0000_0000_0000_1111_1111_1111_1111
(-1)
(-1)
(65535)
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
649
Appendix A
Common Attributes
Because immediate values are always zero-filled, the conversion of a SINT or
INT value may produce unexpected results. In the following example, the comparison is false because Source A, an INT, converts by sign-extension; while
Source B, an immediate value, is zero-filled.
adder Logic Listing - Total number of rungs: 3
EQU
Equal
Source A remote_rack_1:I.Data[0]
2#1111_1111_1111_1111
42093
If you use a SINT or INT tag and an immediate value in an instruction that converts data by sign-extension, use one of these methods to handle immediate values.
• Specify any immediate value in the decimal radix.
• If you are entering the value in a radix other than decimal, specify all
32 bits of the immediate value. To do so, enter the value of the leftmost bit into each bit position to its left until there are 32 bits.
• Create a tag for each operand and use the same data type throughout the instruction. To assign a constant value, either:
– Enter it into one of the tags.
– Add a MOV instruction that moves the value into one of the tags.
• Use a MEQ instruction to check only the required bits.
The following examples show two ways to mix an immediate value with an INT tag. Both examples check the bits of a 1771 I/O module to determine if all the bits are on. Since the input data word of a 1771 I/O module is an INT tag, it is easiest to use a 16-bit constant value.
IMPORTANT
Mixing an INT tag with an immediate value
ATTENTION: Since remote_rack_1:I.Data[0] is an INT tag, the value to check it against is also entered as an INT tag.
EQU
Equal
2#1111_1111_1111_1111
Source B int_0
2#1111_1111_1111_1111
42093
650
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Common Attributes
Appendix A
IMPORTANT
Mixing an INT tag with an immediate value
Since remote_rack_1:I.Data[0] is an INT tag, the value to check it against first moves into int_0, also an INT tag. The EQU instruction then compares both tags.
2#1111_1111_1111_1111
MOV
Move
Dest int_0
2#1111_1111_1111_1111
EQU
Equal
2#1111_1111_1111_1111
Source B int_0
2#1111_1111_1111_1111
42093
Integer to REAL
The controller stores REAL values in IEEE single-precision, floating-point number format. It uses one bit for the sign of the value, 23 bits for the base value, and eight bits for the exponent (32 bits total). If you mix an integer tag (SINT,
INT, or DINT) and a REAL tag as inputs in the same instruction, the controller converts the integer value to a REAL value before the instruction executes.
• A SINT or INT value always converts to the same REAL value.
• A DINT value may not convert to the same REAL value:
– A REAL value uses up to 24 bits for the base value (23 stored bits plus a
‘hidden’ bit).
– A DINT value uses up to 32 bits for the value (one for the sign and 31 for the value).
– If the DINT value requires more than 24 significant bits, it
may not convert to the same REAL value. If it will not, the controller rounds to the nearest REAL value by using 24 significant bits.
DINT to SINT or INT
To convert a DINT value to a SINT or INT value, the controller truncates the upper portion of the DINT and sets the overflow status flag, if necessary. The following example shows the result of a DINT to SINT or INT conversion.
IMPORTANT
Conversion of a DINT to an INT and a SINT
This DINT value
16#0001_0081 (65,665)
Converts to this smaller value
INT: 16#0081 (129)
SINT: 16#81 (-127)
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
651
Appendix A
Common Attributes
REAL to an Integer
To convert a REAL value to an integer value, the controller rounds the fractional part and truncates the upper portion of the non-fractional part. If data is lost, the controller sets the overflow status flag. Numbers round as in the following examples.
• Numbers other than x.5 round to the nearest whole number.
•
X.5 rounds to the nearest even number.
The following example shows the result of converting REAL values to DINT values.
IMPORTANT
Conversion of REAL values to DINT values
-1.4
1.4
1.5
1.6
2.5
This REAL value
-2.5
-1.6
-1.5
2
2
-1
1
2
-2
-2
Converts to this DINT value
-2
IMPORTANT
The arithmetic status flags are set based on the value being stored.
Instructions that normally do not affect arithmetic status keywords might appear to do so if type conversion occurs because of mixed data types for the instruction parameters. The type conversion process sets the arithmetic status keywords.
652
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Appendix
B
Function Block Attributes
Introduction
This appendix describes issues that are unique with function block instructions.
Review the information in this appendix to make sure you understand how your function block routines will operate.
IMPORTANT
When programming in function block, restrict the range of engineering units to +/-10
+/-15
because internal floating point calculations are done by using single precision floating point.
Engineering units outside of this range may result in a loss of accuracy if results approach the limitations of single precision floating point
(+/-10
+/-38
).
Function Block Elements
Input Reference (IREF) Function Block
To control a device, use these elements.
Output Reference (OREF)
Output Wire
Connector (OCON)
Input Wire
Connector (ICON)
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
653
Appendix B
Function Block Attributes
Use the table to choose your function block elements.
If you want to
Supply a value from an input device or tag
Send a value to an output device or tag
Perform an operation on an input value or values and produce an output value or values
Transfer data between function blocks when they are:
·Far apart on the same sheet
·On different sheets within the same routine
Disperse data to several points in the routine
Use a
Input reference (IREF)
Output reference (OREF)
Function block
Output wire connector (OCON) and an input wire connector (ICON)
Single output wire connector (OCON) and multiple input wire connectors (ICON)
Latching Data
If you use an IREF to specify input data for a function block instruction, the data in that IREF is latched for the scan of the function block routine. The IREF latches data from program-scoped and controller-scoped tags. The controller updates all IREF data at the beginning of each scan.
IREF
In this example, the value of tagA is stored at the beginning of the routine’s execution. The stored value is used when Block_01 executes. The same stored value is also used when Blcock_02 executes. If the value of tagA changes during execution of the routine, the stored value of tagA in the IREF does not change until the next execution of the routine.
Block_01 tagA
Block_02
654
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Function Block Attributes
Appendix B
This example is the same as the one above. The value of tagA is stored only once at the beginning of the routine’s execution. The routine uses this stored value throughout the routine.
Block_01 tagA
Block_02 tagA
Starting with RSLogix 5000 software, version 11, you can use the same tag in multiple IREFs and an OREF in the same routine. Because the values of tags in
IREFs are latched every scan through the routine, all IREFs will use the same value, even if an OREF obtains a different tag value during execution of the routine.
In this example, if tagA has a value of 25.4 when the routine starts executing this scan, and Block_01 changes the value of tagA to 50.9, the second IREF wired into Block_02 will still use a value of 25.4 when Block_02 executes this scan. The new tagA value of 50.9 will not be used by any IREFs in this routine until the start of the next scan.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
655
Appendix B
Function Block Attributes
Order of Execution
The Logix Designer application automatically determines the order of execution for the function blocks in a routine when you do the following:
• Verify a function block routine.
• Verify a project that contains a function block routine.
• Download a project that contains a function block routine.
You define execution order by wiring function blocks together and indicating the data flow of any feedback wires, if necessary.
If function blocks are not wired together, it does not matter which block executes first. There is no data flow between the blocks.
656
If you wire the blocks sequentially, the execution order moves from input to output. The inputs of a block require data to be available before the controller can execute that block. For example, block 2 has to execute before block 3 because the outputs of block 2 feed the inputs of block 3.
1 2 3
Execution order is relative only to the blocks that are wired together. The following example is fine because the two groups of blocks are not wired together.
The blocks within a specific group execute in the appropriate order in relation to the blocks in that group.
1 3 5
2 4 6
Resolve a Loop
To create a feedback loop around a block, wire an output pin of the block to an input pin of the same block. The following example is okay. The loop contains only a single block, so execution order does not matter.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Function Block Attributes
Appendix B
This input pin uses an output that the block produced on the previous scan.
If a group of blocks are in a loop, the controller cannot determine which block to execute first. In other words, it cannot resolve the loop.
?
?
?
To identify which block to execute first, mark the input wire that creates the loop
(the feedback wire) with the Assume Data Available indicator. In the following example, block 1 uses the output from block 3 that was produced in the previous execution of the routine.
1 2 3
This input pin uses the output that block 3 produced on the previous scan.
1
This is okay
Assume Data Available indicator
The
Assume Data Available indicator defines the data flow within the loop. The arrow indicates that the data serves as input to the first block in the loop.
Do not mark all the wires of a loop with the Assume Data Available indicator.
This is NOT okay
2
?
?
Assume Data Available indicator
The controller cannot resolve the loop because all the wires use the Assume Data
Available indicator.
The Assume Data Available indicator defines the data flow within the loop.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
657
Appendix B
Function Block Attributes
This is okay
Resolve Data Flow between Two Blocks
If you use two or more wires to connect two blocks, use the same data flow indicators for all of the wires between the two blocks.
This is not okay
Neither wire uses the Assume Data Available indicator.
One wire uses the Assume Data Available indicator while the other wire does not.
Assume Data Available
Indicator
Both wires use the Assume Data Available indicator.
Create a One Scan Delay
To produce a one scan delay between blocks, use the Assume Data Available indicator. In the following example, block 1 executes first. It uses the output from block 2 that was produced in the previous scan of the routine.
2 1
Assume Data Available Indicator
658
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Function Block Attributes
Appendix B
Summary
A function block routine executes in this order.
1. The controller latches all data values in IREFs.
2. The controller executes the other function blocks in the order determined by how they are wired.
3. The controller writes outputs in OREFs.
ALMNTCH
DEDTPMUL
DERVPOSP
ESELRLIM
FGENRMPS
HPFSCRV
LDL2SEL
LDLGSNEG
LPFSRTP
MAVESSUM
MAXCTOT
MINCUPDN
MSTD
MUX
Function Block Responses to
Overflow Conditions
In general, the function block instructions that maintain history do not update history with ±NAN, or ±INF values when an overflow occurs. Each instruction has one of these responses to an overflow condition.
Response 1
Blocks execute their algorithm and check the result for
±
NAN or
NAN or
±
INF. If
INF.
±
NAN or
±
INF, the block outputs
HLL
INTG
PI
PIDE
SCL
SOC
Response 2
Blocks with output limiting execute their algorithm and check the result for defined by the HighLimit and LowLimit input parameters.
If
±
±
NAN or
±
INF. The output limits are
INF, the block outputs a limited result. If
±
NAN, the output limits are not used and the block outputs
±
NAN.
Response 3
The overflow condition does not apply. These instructions typically have a boolean output.
BANDOSRI
BNOTRESD
BORRTOR
BXORSETD
CUTDTOFR
D2SDTONR
D3SD
DFF
JKFF
OSFI
Timing Modes
These process control and drives instructions support different timing modes.
DEDT
DERV
HPF
INTG
LDL2
LDLG
LPF
NTCH
PI
PIDE
RLIM
SCRV
SOC
TOT
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
659
Appendix B
Function Block Attributes
Timing Mode
Periodic
Oversample
Real time sampling
There are three different timing modes.
Description
Periodic mode is the default mode and is suitable for most control applications. We recommend that you place the instructions that use this mode in a routine that executes in a periodic task. The delta time (DeltaT) for the instruction is determined as follows:
If the instruction executes in a
Then DeltaT equals
Periodic task
Event or continuous task
Period of the task
Elapsed time since the previous execution
The controller truncates the elapsed time to whole milliseconds (ms). For example, if the elapsed time = 10.5 ms, the controller sets DeltaT = 10 ms.
The update of the process input needs to be synchronized with the execution of the task or sampled 5-10 times faster than the task executes in order to minimize the sampling error between the input and the instruction.
In oversample mode, the delta time (DeltaT) used by the instruction is the value written into the OversampleDT parameter of the instruction. If the process input has a time stamp value, use the real time sampling mode instead.
Add logic to your program to control when the instruction executes. For example, you can use a timer set to the OversampleDeltaT value to control the execution by using the EnableIn input of the instruction.
The process input needs to be sampled 5-10 times faster than the instruction is executed in order to minimize the sampling error between the input and the instruction.
In the real time sampling mode, the delta time (DeltaT) used by the instruction is the difference between two time stamp values that correspond to the updates of the process input. Use this mode when the process input has a time stamp associated with its updates and you need precise coordination.
The time stamp value is read from the tag name entered for the RTSTimeStamp parameter of the instruction. Normally this tag name is a parameter on the input module associated with the process input.
The instruction compares the configured RTSTime value (expected update period) against the calculated DeltaT to determine if every update of the process input is being read by the instruction. If DeltaT is not within 1 millisecond of the configuration time, the instruction sets the RTSMissed status bit to indicate that a problem exists reading updates for the input on the module.
Time-based instructions require a constant value for DeltaT in order for the control algorithm to properly calculate the process output. If DeltaT varies, a discontinuity occurs in the process output. The severity of the discontinuity depends on the instruction and range over which DeltaT varies.
A discontinuity occurs if the following happens:
• Instruction is not executed during a scan.
• Instruction is executed multiple times during a task.
• Task is running and the task scan rate or the sample time of the process input changes.
• User changes the time-base mode while the task is running.
• Order parameter is changed on a filter block while the task is running.
Changing the Order parameter selects a different control algorithm within the instruction.
Common Instruction Parameters for Timing Modes
The instructions that support time-base modes have these input and output parameters.
660
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Input Parameter
TimingMode
Data Type
DINT
OversampleDT
RTSTime
RTSTimeStamp
REAL
DINT
DINT
Function Block Attributes
Appendix B
Input Parameters
Description
0
1
Selects timing execution mode.
Value: Description:
2
Valid = 0…2
Periodic mode
Oversample mode
Real time sampling mode
Default = 0
When TimingMode = 0 and task is periodic, periodic timing is enabled and DeltaT is set to the task scan rate. When
TimingMode = 0 and task is event or continuous, periodic timing is enabled and DeltaT is set equal to the elapsed time span since the last time the instruction was executed.
When TimingMode = 1, oversample timing is enabled and DeltaT is set to the value of the OversampleDT parameter.
When TimingMode = 2, real time sampling timing is enabled and DeltaT is the difference between the current and previous time stamp values read from the module associated with the input.
If TimingMode invalid, the instruction sets the appropriate bit in Status.
Execution time for oversample timing. The value used for DeltaT is in seconds. If TimingMode = 1, then OversampleDT =
0.0 disables the execution of the control algorithm. If invalid, the instruction sets DeltaT = 0.0 and sets the appropriate bit in Status.
Valid = 0…4194.303 seconds
Default = 0.0
Module update period for real time sampling timing. The expected DeltaT update period is in milliseconds. The update period is normally the value that was used to configure the module’s update time. If invalid, the instruction sets the appropriate bit in Status and disables RTSMissed checking.
Valid = 1…32,767ms
Default = 1
Module time stamp value for real time sampling timing. The time stamp value that corresponds to the last update of the input signal. This value is used to calculate DeltaT. If invalid, the instruction sets the appropriate bit in Status, disables execution of the control algorithm, and disables RTSMissed checking.
Valid =1…32,767ms (wraps from 32767 to 0)
1 count = 1 millisecond
Default = 0
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
661
Appendix B
Function Block Attributes
Output Parameter
DeltaT
Data Type
REAL
Status DINT
TimingModeInv (Status.27) BOOL
RTSMissed (Status.28)
RTSTimeInv (Status.29)
BOOL
BOOL
RTSTimeStampInv (Status.30) BOOL
DeltaTInv (Status.31) BOOL
Output Parameters
Description
Elapsed time between updates. This is the elapsed time in seconds used by the control algorithm to calculate the process output.
Periodic: DeltaT = task scan rate if task is Periodic task, DeltaT = elapsed time since previous instruction execution if task is
Event or Continuous task
Oversample: DeltaT = OversampleDT
Real Time Sampling: DeltaT = (RTSTimeStamp n
- RTSTimeStamp n-1
)
Status of the function block.
Invalid TimingMode value.
Only used in real time sampling mode. Set when ABS | DeltaT - RTSTime | > 1 (.001 second).
Invalid RTSTime value.
Invalid RTSTimeStamp value.
Invalid DeltaT value.
662
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
TimingMode = 0
Periodic Timing
Function Block Attributes
Appendix B
Overview of Timing Modes
The following diagram shows how an instruction determines the appropriate timing mode.
Determine Time-base Mode
TimingMode = 1 TimingMode = 2
Oversample Timing
DeltaT = OversampleDT
If DeltaT < 0 or DeltaT > 4194.303 s the instruction sets DeltaT = 0.0 and sets the appropriate bit in Status.
If DeltaT > 0, the instruction executes.
Real Time Timing
DeltaT = RTSTimeStamp n
If DeltaT > 0, the instruction executes.
If |RTSTIME - DeltaT| > 1, the instruction sets RTSMissed bit in
Status.
- RTSTimeStamp n-1
Determine Task Type
Periodic Task
DeltaT = Task scan time
If DeltaT > 0, the instruction executes.
Event or Continuous Task
DeltaT = Elapsed time since last execution
If DeltaT > 0, the instruction executes.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
663
Appendix B
Function Block Attributes
Program/Operator Control
Several instructions support the concept of Program/Operator control. These instructions include the following:
• Enhanced Select (ESEL)
• Totalizer (TOT)
• Enhanced PID (PIDE)
• Ramp/Soak (RMPS)
• Discrete 2-State Device (D2SD)
• Discrete 3-State Device (D3SD)
Program/Operator control lets you control these instructions simultaneously from both your user program and from an operator interface device. When in
Program control, the instruction is controlled by the Program inputs to the instruction; when in Operator control, the instruction is controlled by the
Operator inputs to the instruction.
Program or Operator control is determined by using these inputs.
Input
.ProgProgReq
.ProgOperReq
.OperProgReq
.OperOperReq
Description
A program request to go to Program control.
A program request to go to Operator control.
An operator request to go to Program control.
An operator request to go to Operator control.
To determine whether an instruction is in Program or Control control, examine the ProgOper output. If ProgOper is set, the instruction is in Program control; if
ProgOper is cleared, the instruction is in Operator control.
Operator control takes precedence over Program control if both input request bits are set. For example, if ProgProgReq and ProgOperReq are both set, the instruction goes to Operator control.
The Program request inputs take precedence over the Operator request inputs.
This provides the capability to use the ProgProgReq and ProgOperReq inputs to
‘lock’ an instruction in a desired control.
664
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Wiring a ‘1’ into ProgOperReq means the user program always wants the TOT to be in
Operator control
Function Block Attributes
Appendix B
For example, let’s assume that a Totalizer instruction will always be used in
Operator control, and your user program will never control the running or stopping of the Totalizer. In this case, you could wire a literal value of 1 into the
ProgOperReq. This would prevent the operator from ever putting the Totalizer into Program control by setting the OperProgReq from an operator interface device.
Because the ProgOperReq input is always set, pressing the “Program” button on the faceplate (which sets the OperProgReg input) has no effect. Normally, setting
OperProgReq puts the TOT in Program control.
Likewise, constantly setting the ProgProgReq can ‘lock’ the instruction into
Program control. This is useful for automatic startup sequences when you want the program to control the action of the instruction without worrying about an operator inadvertently taking control of the instruction.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
665
Appendix B
Function Block Attributes
In this example, you have the program set the ProgProgReq input during the startup, and then clear the ProgProgReq input once the startup was complete.
Once the ProgProgReq input is cleared, the instruction remains in Program control until it receives a request to change. For example, the operator could set the OperOperReq input from a faceplate to take over control of that instruction.
The following example shows how to lock an instruction into Program control.
666
When StartupSequenceActive is set, the PIDE instruction is placed in
Program control and Manual mode.
The StartupCV value is used as the loop output.
Operator request inputs to an instruction are always cleared by the instruction when it executes. This allows operator interfaces to work with these instructions by merely setting the desired mode request bit. You don’t have to program the operator interface to reset the request bits. For example, if an operator interface sets the OperAutoReq input to a PIDE instruction, when the PIDE instruction executes, it determines what the appropriate response should be and clears the
OperAutoReq.
Program request inputs are not normally cleared by the instruction because these are normally wired as inputs into the instruction. If the instruction clears these inputs, the input would just get set again by the wired input. There might be situations where you want to use other logic to set the Program requests in such a manner that you want the Program requests to be cleared by the instruction. In this case, you can set the ProgValueReset input and the instruction will always clear the Program mode request inputs when it executes.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Function Block Attributes
Appendix B
In this example, a rung of ladder logic in another routine is used to one-shot latch a ProgAutoReq to a PIDE instruction when a push button is pushed. Because the
PIDE instruction automatically clears the Program mode requests, you don’t have to write any ladder logic to clear the ProgAutoReq after the routine executes, and the PIDE instruction will receive only one request to go to Auto every time the push button is pressed.
When the TIC101AutoReq push button is pressed, one-shot latch ProgAutoReq for the PIDE instruction TIC101. TIC101 has been configured with the ProgValueReset input set, so when the PIDE instruction executes, it automatically clears ProgAutoReq.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
667
Appendix B
Function Block Attributes
Notes:
668
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Appendix
C
Structured Text Programming
Introduction
This appendix describes issues that are unique with structured text programming.
Review the information in this appendix to make sure you understand how your structured text programming executes.
Topic
Page
Structured Text Syntax
Term
Assignment
Expression
Structured text is a textual programming language that uses statements to define what to execute.
• Structured text is not case sensitive.
• Use tabs and carriage returns (separate lines) to make your structured text easier to read. They have no effect on the execution of the structured text.
Structured text is not case sensitive. Structured text can contain these components.
Definition
Use an assignment statement to assign values to tags.
The operator is the assignment operator.
Terminate the assignment with a semi colon ‘;.’
An expression is part of a complete assignment or construct statement. An expression evaluates to a number (numerical expression) or to a true or false state (BOOL expression).
An expression contains:
Tags
Immediate
Operators
A named area of the memory where data is stored (BOOL,
SINT,INT,DINT, REAL, string).
A constant value.
A symbol or mnemonic that specifies an operation within an expression.
Functions When executed, a function yields one value. Use parentheses to contain the operand of a function.
Even though their syntax is similar, functions differ from instructions in that functions can be used only in expressions. Instructions cannot be used in expressions.
Examples
tag := expression; value1
4 tag1 + tag2 tag1 >= value1 function(tag1)
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
669
Appendix C
Structured Text Programming
Term
Instruction
)
Construct
(see
Comment
)
)
Definition
An instruction is a standalone statement.
An instruction uses parenthesis to contain its operands.
Depending on the instruction, there can be zero, one, or multiple operands.
When executed, an instruction yields one or more values that are part of a data structure.
Terminate the instruction with a semi colon(;).
Even though their syntax is similar, instructions differ from functions in that instructions cannot be used in expressions. Functions can be used only in expressions.
A conditional statement used to trigger structured text code (that is, other statements).
Terminate the construct with a semi colon (;).
Text that explains or clarifies what a section of structured text does.
• Use comments to make it easier to interpret the structured text.
• Comments do not affect the execution of the structured text.
• Comments can appear anywhere in structured text.
Examples
instruction(); instruction(operand); instruction(operand1, operand2,operand3);
IF...THEN
CASE
FOR...DO
WHILE...DO
REPEAT...UNTIL
EXIT
//comment
(*start of comment . . . end of comment*)
/*start of comment . . . end of comment*/
Assignments
Use an assignment to change the value stored within a tag. An assignment has this syntax: tag := expression ; where:
;
Component
Tag
:=
Expression
Description
Represents the tag that is getting the new value
The tag must be a BOOL, SINT, INT, DINT, or REAL
Is the assignment symbol
Represents the new value to assign to the tag
If tag is this data type
BOOL
Use this type of expression
BOOL expression
SINT
INT
DINT
REAL
Ends the assignment
Numeric expression
The tag retains the assigned value until another assignment changes the value.
The expression can be simple, such as an immediate value or another tag name, or the expression can be complex and include several operators and/or functions.
See
.
670
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Structured Text Programming
Appendix C
Specify a Non-retentive Assignment
The non-retentive assignment is different from the regular assignment described above in that the tag in a non-retentive assignment is reset to zero each time the controller does the following:
• Enters the RUN mode.
• Leaves the step of an SFC if you configure the SFC for
Automatic reset.
(This applies only if you embed the assignment in the action of the step or use the action to call a structured text routine via a JSR instruction.)
A non-retentive assignment has this syntax: tag
[:=] expression ; where:
;
Component
Tag
[:=]
Expression
Description
Represents the tag that is getting the new value
The tag must be a BOOL, SINT, INT, DINT, or REAL
Is the non-retentive assignment symbol
Represents the new value to assign to the tag
If tag is this data type
BOOL
Use this type of expression
BOOL expression
SINT
INT
DINT
REAL
Ends the assignment
Numeric expression
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
671
Appendix C
Structured Text Programming
Assign an ASCII Character to a String
Use the assignment operator to assign an ASCII character to an element of the
DATA member of a string tag. To assign a character, specify the value of the character or specify the tag name, DATA member, and element of the character.
The table shows some examples.
This Is Okay
string1.DATA[0]:= 65; string1.DATA[0]:= string2.DATA[0];
This Is Not Okay
string1.DATA[0] := A; string1 := string2;
To add or insert a string of characters to a string tag, use either of these ASCII string instructions.
To
Add characters to the end of a string
Insert characters into a string
Use this instruction
CONCAT
INSERT
672
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Expressions
Structured Text Programming
Appendix C
An expression is a tag name, equation, or comparison. To write an expression, use any of the following:
• Tag name that stores the value (variable)
• Number that you enter directly into the expression (immediate value)
• Functions, such as: ABS, TRUNC
• Operators, such as: +, -, <, >, And, Or
As you write expressions, follow these general rules:
• Use any combination of upper-case and lower-case letter. For example, these three variations of ‘AND’ are acceptable: AND, And, and.
• For more complex requirements, use parentheses to group expressions within expressions. This makes the whole expression easier to read and ensures that the expression executes in the desired sequence. See
Determine the Order of Execution
on
.
In structured text, you use two types of expressions.
BOOL expression: An expression that produces either the BOOL value of
1 (true) or 0 (false).
• A bool expression uses bool tags, relational operators, and logical operators to compare values or check if conditions are true or false.
For example, tag1>65.
• A simple bool expression can be a single BOOL tag.
• Typically, you use bool expressions to condition the execution of other logic.
Numeric expression: An expression that calculates an integer or floating-point value.
• A numeric expression uses arithmetic operators, arithmetic functions, and bitwise operators. For example, tag1+5.
• Often, you nest a numeric expression within a bool expression. For example, (tag1+5)>65.
Use the table to choose operators for your expressions.
If you want to
Calculate an arithmetic value
Compare two values or strings
Check if conditions are true or false
Compare the bits within values
Then
Use Arithmetic Operators and Functions
on
.
on
.
Use Logical Operators on page 677
.
on
.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
673
Appendix C
Structured Text Programming
Use this format
value1 operator value2 operator value1 function(numeric_expression) value1 operator (function((value2+value3)/2)
674
Use Arithmetic Operators and Functions
You can combine multiple operators and functions in arithmetic expressions.
Arithmetic operators calculate new values.
To
Add
Subtract/negate
Multiply
Exponent (x to the power of y)
Divide
Modulo-divide
-
*
Use this operator
+
/
**
MOD
Optimal data type
DINT, REAL
DINT, REAL
DINT, REAL
DINT, REAL
DINT, REAL
DINT, REAL
Arithmetic functions perform math operations. Specify a constant, a nonboolean tag, or an expression for the function.
For
Absolute value
Arc cosine
Arc sine
Arc tangent
Cosine
Radians to degrees
Natural log
Log base 10
Degrees to radians
Sine
Square root
Tangent
Truncate
Use this function
ABS (numeric_expression)
ACOS (numeric_expression)
ASIN (numeric_expression)
ATAN (numeric_expression)
COS (numeric_expression)
DEG (numeric_expression)
LN (numeric_expression)
LOG (numeric_expression)
RAD (numeric_expression)
SIN (numeric_expression)
SQRT (numeric_expression)
TAN (numeric_expression)
TRUNC (numeric_expression)
Optimal data type
DINT, REAL
REAL
REAL
REAL
REAL
DINT, REAL
REAL
REAL
DINT, REAL
REAL
DINT, REAL
REAL
DINT, REAL
The table shows some examples.
Example
For this situation
If gain_4 and gain_4_adj are DINT tags and your specification says:
‘Add 15 to gain_4 and store the result in gain_4_adj’"
If alarm and high_alarm are DINT tags and your specification says:
‘Negate high_alarm and store the result in alarm.’
If overtravel and overtravel_POS are DINT tags and your specification says: ‘Calculate the absolute value of overtravel and store the result in overtravel_POS.’
If adjustment and position are DINT tags and sensor1 and sensor2 are REAL tags and your specification says: ‘Find the absolute value of the average of sensor1 and sensor2, add the adjustment, and store the result in position.’
Write
gain_4_adj := gain_4+15; alarm:= -high_alarm; overtravel_POS := ABS(overtravel); position := adjustment + ABS((sensor1 + sensor2)/2);
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Structured Text Programming
Appendix C
Use Relational Operators
Relational operators compare two values or strings to provide a true or false result. The result of a relational operation is a BOOL value.
If the comparison is
True
False
The result is
1
0
Use these relational operators.
For this comparison
Equal
Less than
Less than or equal
Greater than
Greater than or equal
Not equal
>
>=
<>
Use this operator
=
<
<=
The table shows some examples.
Use this format
value1 operator value2 stringtag1 operator stringtag2
Example
For this situation
If temp is a DINT tag and your specification says: ‘If temp is less than 100 then…’
If bar_code and dest are string tags and your specification says: ‘If bar_code equals dest then…’
If bar_code is a string tag and your specification says: ‘If bar_code.DATA[0] equals ’A’ then…’
Write
IF temp<100 THEN...
IF bar_code=dest THEN...
IF bar_code.DATA[0]=65 THEN...
char1 operator char2
To enter an ASCII character directly into the expression, enter the decimal value of the character.
bool_tag := bool_expressions If count and length are DINT tags, done is a BOOL tag, and your specification says: ‘If count is greater than or equal to length, you are done counting.’
Done := (count >= length);
Optimal data type
DINT, REAL, string
DINT, REAL, string
DINT, REAL, string
DINT, REAL, string
DINT, REAL, string
DINT, REAL, string
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
675
Appendix C
Structured Text Programming
How Strings Are Evaluated
The hexadecimal values of the ASCII characters determine if one string is less than or greater than another string.
• When the two strings are sorted as in a telephone directory, the order of the strings determines which one is greater. se r
L es at er
Gr e
AB
B a
1b
A
ASCII Characters
1ab ab
Hex Codes
$31$61$62
$31$62
$41
$41$42
$42
$61
$61$62
AB < B a > B
• Strings are equal if their characters match.
• Characters are case sensitive. Uppercase ‘A’ ($41) is not equal to lowercase
‘a’ ($61).
676
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Use this format
BOOLtag
NOT BOOLtag
expression1 & expression2
expression1 OR expression2
expression1 XOR expression2
BOOLtag := expression1 & expression2
Structured Text Programming
Appendix C
Use Logical Operators
Logical operators let you check if multiple conditions are true or false. The result of a logical operation is a BOOL value.
If the comparison is
True
False
The result is
1
0
Use these logical operators.
For
Logical AND
Logical OR
Logical exclusive OR
Logical complement
Use this operator
&, AND
OR
XOR
NOT
Data type
BOOL
BOOL
BOOL
BOOL
The table shows some examples.
Example
For this situation
If photoeye is a BOOL tag and your specification says: ‘If photoeye is on then…’
If photoeye is a BOOL tag and your specification says: ‘If photoeye is off then…’
If photoeye is a BOOL tag, temp is a DINT tag, and your specification says: ‘If photoeye is on and temp is less than 100 then…’
If photoeye is a BOOL tag, temp is a DINT tag, and your specification says: ‘If photoeye is on or temp is less than 100 then…’
If photoeye1 and photoeye2 are BOOL tags and your specification says: ‘If:
• photoeye1 is on while photoeye 2 is off
• photoeye1 is off while photoeye 2 is on then…’
If photoeye1 and photoeye2 are BOOL tags, open is a BOOL tag, and your specification says: ‘If photoeye1 and photoeye2 are both on, set open to true’.
Write
IF photoeye THEN...
IF NOT photoeye THEN...
IF photoeye & (temp<100) THEN...
IF photoeye OR (temp<100) THEN...
IF photoeye1 XOR photoeye2 THEN...
Open := photoeye1 & photoeye2;
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
677
Appendix C
Structured Text Programming
Use this format
value1 operator value2
6.
7.
4.
5.
2.
3.
Order
1.
8.
9.
10.
11.
12.
Use Bitwise
Operators
Bitwise operators manipulate the bits within a value based on two values.
For
Bitwise AND
Bitwise OR
Bitwise exclusive OR
Bitwise complement
Use this operator
&, AND
OR
XOR
NOT
Optimal data type
DINT
DINT
DINT
DINT
This is an example.
Example
For this situation
If input1, input2, and result1 are DINT tags and your specification says:
‘Calculate the bitwise result of input1 and input2. Store the result in result1.’
Write
result1 := input1 AND input2;
Determine the Order of Execution
The operations you write into an expression are performed in a prescribed order, not necessarily from left to right.
• Operations of equal order are performed from left to right.
• If an expression contains multiple operators or functions, group the conditions in parenthesis ( ) . This ensures the correct order of execution and makes it easier to read the expression.
Operation
( ) function (…)
**
(negate)
NOT
*, /, MOD
+, - (subtract)
<, <=, >, >=
=, <>
&, AND
XOR
OR
678
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Instructions
Structured Text Programming
Appendix C
Structured text statements can also be instructions. See the Locator Table
for a list of the instructions available in structured text. A structured text instruction executes each time it is scanned. A structured text instruction within a construct executes every time the conditions of the construct are true. If the conditions of the construct are false, the statements within the construct are not scanned. There is no rung-condition or state transition that triggers execution.
This differs from function block instructions that use EnableIn to trigger execution. Structured text instructions execute as if EnableIn is always set.
This also differs from relay ladder instructions that use rung-condition-in to trigger execution. Some relay ladder instructions only execute when rungcondition-in toggles from false to true. These are transitional relay ladder instructions. In structured text, instructions will execute each time they are scanned unless you pre-condition the execution of the structured text instruction.
For example, the ABL instruction is a transitional instruction in relay ladder. In this example, the ABL instruction only executes on a scan when tag_xic transitions from cleared to set. The ABL instruction does not execute when
tag_xic stays set or when tag_xic is cleared.
In structured text, if you write this example as:
IF tag_xic THEN ABL(0,serial_control);
END_IF;
The ABL instruction will execute every scan that
tag_xic is set, not just when
tag_xic transitions from cleared to set.
If you want the ABL instruction to execute only when tag_xic transitions from cleared to set, you have to condition the structured text instruction. Use a one shot to trigger execution.
osri_1.InputBit := tag_xic;
OSRI(osri_1);
IF (osri_1.OutputBit) THEN
ABL(0,serial_control);
END_IF;
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
679
Appendix C
Structured Text Programming
Constructs
Constructs can be programmed alone or nested within other constructs.
If you want to
Do something if or when specific conditions occur
Select what to do based on a numerical value
Do something a specific number of times before doing anything else
Use this construct
IF...THEN
CASE...OF
FOR...DO
Keep doing something as long as certain conditions are true WHILE...DO
Keep doing something until a condition is true REPEAT...UNTIL
Available in these languages
Structured text
Structured text
Structured text
Structured text
Structured text
Page
Some Key Words are Reserved
These constructs are not available:
• GOTO
• REPEAT
Logix Designer application will not let you use them as tag names or constructs.
680
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
IF...THEN
Operands:
Structured Text Programming
Appendix C
Use IF…THEN to do something if or when specific conditions occur.
Structured Text
IF bool_expression THEN
<statement>
;
Operand
Bool_ expression
Type
BOOL
Format
Tag expression
Description:
The syntax is described in the table.
optional optional
Enter
BOOL tag or expression that evaluates to a BOOL value
(BOOL expression)
IF bool_expression1 THEN
.
.
.
<statement >;
ELSIF bool_expression2 THEN
.
.
.
<statement>;
ELSE
.
.
.
<statement>;
END_IF;
Statements to execute when
bool_expression1 is true
Statements to execute when
bool_expression2 is true
Statements to execute when both expressions are false
To use ELSIF or ELSE, follow these guidelines.
1. To select from several possible groups of statements, add one or more
ELSIF statements.
• Each ELSIF represents an alternative path.
• Specify as many ELSIF paths as you need.
• The controller executes the first true IF or ELSIF and skips the rest of the ELSIFs and the ELSE.
2. To do something when all of the IF or ELSIF conditions are false, add an
ELSE statement.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
681
Appendix C
Structured Text Programming
The table summarizes different combinations of IF, THEN, ELSIF, and ELSE.
If you want to
Do something if or when conditions are true
Choose from alternative statements (or groups of statements) based on input conditions
And
Do nothing if conditions are false
Do something else if conditions are false
Do nothing if conditions are false
Use this construct
IF…THEN
IF…THEN…ELSE
IF…THEN…ELSIF
Assign default statements if all conditions are false IF…THEN…ELSIF…ELSE
Arithmetic Status Flags
Not affected
Fault Conditions:
None
Example 1:
IF…THEN
If you want this
IF rejects > 3 then conveyor = off (0) alarm = on (1)
Enter this structured text
IF rejects > 3 THEN
END_IF; conveyor := 0; alarm := 1;
Example 2:
IF…THEN…ELSE
If you want this
If conveyor direction contact = forward (1) then light = off
Otherwise light = on
Enter this structured text
IF conveyor_direction THEN light := 0;
ELSE
END_IF; light [:=] 1;
682
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Structured Text Programming
Appendix C
The [:=] tells the controller to clear
light whenever the controller does the following:
• Enters the RUN mode.
• Leaves the step of an SFC if you configure the SFC for
Automatic reset.
(This applies only if you embed the assignment in the action of the step or use the action to call a structured text routine via a JSR instruction.)
Example 3:
IF…THEN…ELSIF
If you want this
If sugar low limit switch = low (on) and sugar high limit switch = not high
(on) then inlet valve = open (on)
Until sugar high limit switch = high (off)
Enter this structured text
IF Sugar.Low & Sugar.High THEN
Sugar.Inlet [:=] 1;
ELSIF NOT(Sugar.High) THEN
END_IF;
Sugar.Inlet := 0;
The [:=] tells the controller to clear Sugar.Inlet whenever the controller does the following:
• Enters the RUN mode.
• Leaves the step of an SFC if you configure the SFC for
Automatic reset.
(This applies only if you embed the assignment in the action of the step or use the action to call a structured text routine via a JSR instruction.)
If you want this
If tank temperature > 100 then pump = slow
If tank temperature > 200 then pump = fast
Otherwise pump = off
Example 4:
IF…THEN…ELSIF…ELSE
Enter this structured text
IF tank.temp > 200 THEN pump.fast :=1; pump.slow :=0; pump.off :=0;
ELSIF tank.temp > 100 THEN pump.fast :=0; pump.slow :=1; pump.off :=0;
ELSE
END_IF; pump.fast :=0; pump.slow :=0; pump.off :=1;
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
683
Appendix C
Structured Text Programming
CASE...OF
Operands:
Use CASE to select what to do based on a numerical value.
CASE
numeric_expression OF
selector1: statement;
selectorN: statement;
ELSE
Structured Text
Operand
Numeric_ expression
Selector
Type
SINT
INT
DINT
REAL
SINT
INT
DINT
REAL
Format
Tag expression
Immediate
Enter
Tag or expression that evaluates to a number
(numeric expression)
Same type as numeric_expression
IMPORTANT
If you use REAL values, use a range of values for a selector because a REAL value is more likely to be within a range of values than an exact match of one, specific value.
optional
Description:
The syntax is described in the table.
Specify as many alternative selector values (paths) as you need.
CASE
numeric_expression OF
selector1
: <statement>;
.
.
.
selector2
: <statement>;
.
.
.
selector3
: <statement>;
.
.
.
ELSE
.
.
.
<statement>;
END_CASE;
for valid selector values.
Statements to execute when
numeric_expression = selector1
Statements to execute when
numeric_expression = selector2
Statements to execute when
numeric_expression = selector3
Statements to execute when
numeric_expression any selector
684
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Structured Text Programming
Appendix C
These are the syntax for entering the selector values.
When selector is
One value
Multiple, distinct values
Enter
value: statement
value1, value2, valueN : <statement>
A range of values
Use a comma (,) to separate each value.
value1..valueN : <statement>
Use two periods (..) to identify the range.
Distinct values plus a range of values valuea, valueb, value1..valueN : <statement>
The CASE construct is similar to a switch statement in the C or C++ programming languages. However, with the CASE construct the controller executes only the statements that are associated with the first matching selector value. Execution always breaks after the statements of that selector and goes to the END_CASE statement.
Arithmetic Status Flags:
Not affected
Fault Conditions:
None
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
685
Appendix C
Structured Text Programming
Example
If you want this
If recipe number = 1 then
Ingredient A outlet 1 = open (1)
Ingredient B outlet 4 = open (1)
If recipe number = 2 or 3 then
Ingredient A outlet 4 = open (1)
Ingredient B outlet 2 = open (1)
If recipe number = 4, 5, 6, or 7 then
Ingredient A outlet 4 = open (1)
Ingredient B outlet 2 = open (1)
If recipe number = 8, 11, 12, or 13 then
Ingredient A outlet 1 = open (1)
Ingredient B outlet 4 = open (1)
Otherwise all outlets = closed (0)
Enter this structured text
CASE recipe_number OF
1:
Ingredient_A.Outlet_1 :=1;
Ingredient_B.Outlet_4 :=1;
2,3:
Ingredient_A.Outlet_4 :=1;
Ingredient_B.Outlet_2 :=1;
4…7:
Ingredient_A.Outlet_4 :=1;
Ingredient_B.Outlet_2 :=1;
8,11…13
Ingredient_A.Outlet_1 :=1;
Ingredient_B.Outlet_4 :=1;
ELSE
Ingredient_A.Outlet_1 [:=]0;
Ingredient_A.Outlet_4 [:=]0;
Ingredient_B.Outlet_2 [:=]0;
Ingredient_B.Outlet_4 [:=]0;
END_CASE;
The [:=] tells the controller to also clear the outlet tags whenever the controller does the following:
• Enters the RUN mode.
• Leaves the step of an SFC if you configure the SFC for
Automatic reset.
(This applies only if you embed the assignment in the action of the step or use the action to call a structured text routine via a JSR instruction.)
686
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
FOR…DO
FOR
count:= initial_value TO
final_value BY increment DO
< statement>;
END_FOR;
Structured Text Programming
Appendix C
Operands:
Use the FOR…DO loop to do something a specific number of times before doing anything else.
Structured Text
Operand
count initial_ value final_ value increment
SINT
INT
DINT
SINT
INT
DINT
Type
SINT
INT
DINT
SINT
INT
DINT
Format
Tag
Description
Tag to store count position as the FOR…DO executes
Tag expression
Immediate
Tag expression
Immediate
Tag expression
Immediate
Must evaluate to a number
Specifies initial value for count
Specifies final value for count, which determines when to exit the loop
(Optional) amount to increment count each time through the loop
If you don’t specify an increment, the count increments by 1.
Optional
Optional
IMPORTANT
Make sure that you do not iterate within the loop too many times in a single scan.
• The controller does not execute any other statements in the routine until it completes the loop.
• If the time that it takes to complete the loop is greater than the watchdog timer for the task, a major fault occurs.
• Consider using a different construct, such as
IF...THEN.
Description:
The syntax is described in the table.
{
FOR count := initial_value
TO final_value
BY increment
DO
<statement>;
IF bool_expression THEN
EXIT;
END_IF;
END_FOR;
If you don’t specify an increment, the loop increments by
1.
If there are conditions when you want to exit the loop early, use other statements, such as an IF...THEN construct, to condition an EXIT statement.
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
687
Appendix C
Structured Text Programming
Done x Number Of
Times?
No
Statement 1
Statement2
Statement 3
Statement 4
…
Yes
The following diagrams show how a FOR...DO loop executes and how an EXIT statement leaves the loop early.
Done x Number Of
Times?
Yes
No
Rest Of The Routine
The FOR…DO loop executes a specific number of times.
Statement 1
Statement 2
Statement 3
Statement 4
…
Exit ?
No
Yes
Rest Of The Routine
To stop the loop before the count reaches the last value, use an EXIT statement.
Arithmetic Status Flags:
Not affected
Fault Conditions:
A major fault will occur if
The construct loops too long.
Example 1:
If you want this
Clear bits 0…31 in an array of BOOLs:
1. Initialize the subscript tag to 0.
2. Clear array[ subscript ] . For example, when
subscript = 5, clear array[5].
3. Add 1 to subscript.
4. If subscript is to 31, repeat
.
Otherwise, stop.
Enter this structured text
For subscript:=0 to 31 by 1 do array[subscript] := 0;
End_for;
Fault type
6
Fault code
1
688
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Structured Text Programming
Appendix C
Example 2:
If you want this
A user-defined data type (structure) stores the following information about an item in your inventory:
• Barcode ID of the item (string data type)
• Quantity in stock of the item (DINT data type)
An array of the above structure contains an element for each different item in your inventory. You want to search the array for a specific product (use its bar code) and determine the quantity that is in stock.
1. Get the size (number of items) of the Inventory array and store the result in
Inventory_Items (DINT tag).
2. Initialize the position tag to 0.
3. If Barcode matches the ID of an item in the array, then: a. Set the Quantity tag = Inventory[position].Qty. This produces the quantity in stock of the item.
b. Stop.
Barcode is a string tag that stores the bar code of the item for which you are searching. For example, when position = 5, compare Barcode to Inventory[5].ID.
4. Add 1 to position.
5. If position is to (Inventory_Items -1), repeat 3 and 4
. Since element numbers start at 0, the last element is 1 less than the number of elements in the array.
Otherwise, stop.
Enter this structured text
SIZE(Inventory,0,Inventory_Items);
For position:=0 to Inventory_Items - 1 do
If Barcode = Inventory[position].ID then
End_for;
End_if;
Quantity := Inventory[position].Qty;
Exit;
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
689
Appendix C
Structured Text Programming
WHILE…DO
Operands:
Use the WHILE…DO loop to keep doing something as long as certain conditions are true.
WHILE
bool_expression DO
<
statement>;
Structured Text
Operand
Bool_ expression
Type
BOOL
Format
Tag expression
Enter
BOOL tag or expression that evaluates to a BOOL value
Optional
IMPORTANT
Description:
The syntax is described in the table.
WHILE bool_expression1 DO
<statement>;
IF bool_expression2 THEN
EXIT;
END_IF;
Make sure that you do not iterate within the loop too many times in a single scan.
• The controller does not execute any other statements in the routine until it completes the loop.
• If the time that it takes to complete the loop is greater than the watchdog timer for the task, a major fault occurs.
• Consider using a different construct, such as IF...THEN.
Statements to execute while bool_expression1 is true
If there are conditions when you want to exit the loop early, use other statements, such as an IF...THEN construct, to condition an EXIT statement.
END_WHILE;
690
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Structured Text Programming
Appendix C
BOOL expression
True
Statement 1
Statement 2
Statement 3
Statement 4
…
False
The following diagrams show how a WHILE...DO loop executes and how an
EXIT statement leaves the loop early.
False
BOOL expression
True
Rest Of The Routine
While the bool_expression is true, the controller executes only the statements within the WHILE…DO loop.
Statement 1
Statement 2
Statement 3
Statement 4
…
Exit ?
No
Yes
Rest Of The Routine
To stop the loop before the conditions are true, use an EXIT statement.
Arithmetic Status Flags:
Not affected
Fault Conditions:
A major fault will occur if
The construct loops too long
Fault type
6
Example 1:
If you want this
The WHILE...DO loop evaluates its conditions first. If the conditions are true, the controller then executes the statements within the loop.
This differs from the REPEAT...UNTIL loop because the REPEAT...UNTIL loop executes the statements in the construct and then determines if the conditions are true before executing the statements again. The statements in a REPEAT...UNTIL loop are always executed at least once. The statements in a WHILE...DO loop might never be executed.
Enter this structured text
pos := 0;
While ((pos <= 100) & structarray[pos].value <> targetvalue)) do pos := pos + 2;
String_tag.DATA[pos] := SINT_array[pos]; end_while;
1
Fault code
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
691
Appendix C
Structured Text Programming
Example 2:
If you want this
Move ASCII characters from a SINT array into a string tag. (In a SINT array, each element holds one character.) Stop when you reach the carriage return.
1. Initialize Element_number to 0.
2. Count the number of elements in SINT_array (array that contains the ASCII characters) and store the result in SINT_array_size (DINT tag).
3. If the character at SINT_array[element_number] = 13 (decimal value of the carriage return), then stop.
4. Set String_tag[element_number] = the character at
SINT_array[element_number].
5. Add 1 to element_number. This lets the controller check the next character in
SINT_array.
6. Set the Length member of String_tag = element_number. (This records the number of characters in String_tag so far.)
7. If element_number = SINT_array_size, then stop. (You are at the end of the array and it does not contain a carriage return.)
.
Enter this structured text
element_number := 0;
SIZE(SINT_array, 0, SINT_array_size);
While SINT_array[element_number] <> 13 do
String_tag.DATA[element_number] := SINT_array[element_number]; element_number := element_number + 1;
String_tag.LEN := element_number;
If element_number = SINT_array_size then exit; end_if; end_while;
692
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Structured Text Programming
Appendix C
REPEAT…UNTIL
Operands:
Use the REPEAT…UNTIL loop to keep doing something until conditions are true.
REPEAT
<
statement>;
Optional
Structured Text
Operand
bool_ expression
Type
BOOL
Format
Tag expression
Enter
BOOL tag or expression that evaluates to a BOOL value
(BOOL expression)
IMPORTANT
Make sure that you do not iterate within the loop too many times in a single scan.
• The controller does not execute any other statements in the routine until it completes the loop.
• If the time that it takes to complete the loop is greater than the watchdog timer for the task, a major fault occurs.
• Consider using a different construct, such as IF...THEN.
Description:
The syntax is described in the table.
REPEAT
<statement>;
IF bool_expression2 THEN
EXIT;
END_IF;
statements to execute while bool_expression1 is false
If there are conditions when you want to exit the loop early, use other statements, such as an IF...THEN construct, to condition an EXIT statement.
UNTIL bool_expression1
END_REPEAT;
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
693
Appendix C
Structured Text Programming
Statement 1
Statement 2
Statement 3
Statement 4
…
BOOL expression
False
True
The following diagrams show how a REPEAT...UNTIL loop executes and how an EXIT statement leaves the loop early.
Statement 1
Statement 2
Statement 3 statement 4
…
Exit ?
Yes
No
True
Rest Of The Routine
BOOL expression
False
While the bool_expression is false, the controller executes only the statements within the REPEAT…UNTIL loop.
Rest Of The Routine
To stop the loop before the conditions are false, use an EXIT statement.
Arithmetic Status Flags:
Not affected
Fault Conditions:
A major fault will occur if
The construct loops too long
Fault type
6
Example 1:
If you want this
The REPEAT...UNTIL loop executes the statements in the construct and then determines if the conditions are true before executing the statements again.
This differs from the WHILE...DO loop because the WHILE...DO The WHILE...DO loop evaluates its conditions first. If the conditions are true, the controller then executes the statements within the loop. The statements in a REPEAT...UNTIL loop are always executed at least once. The statements in a WHILE...DO loop might never be executed.
Enter this structured text
pos := -1;
REPEAT pos := pos + 2;
UNTIL ((pos = 101) OR (structarray[pos].value = targetvalue)) end_repeat;
Fault code
1
694
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Structured Text Programming
Appendix C
Example 2:
If you want this
Move ASCII characters from a SINT array into a string tag. (In a SINT array, each element holds one character.) Stop when you reach the carriage return.
1. Initialize Element_number to 0.
2. Count the number of elements in SINT_array (array that contains the ASCII characters) and store the result in SINT_array_size (DINT tag).
3. Set String_tag[element_number] = the character at
SINT_array[element_number].
4. Add 1 to element_number. This lets the controller check the next character in
SINT_array.
5. Set the Length member of String_tag = element_number. (This records the number of characters in String_tag so far.)
6. If element_number = SINT_array_size, then stop. (You are at the end of the array and it does not contain a carriage return.)
7. If the character at SINT_array[element_number] = 13 (decimal value of the carriage return), then stop.
Otherwise, go to
Enter this structured text
element_number := 0;
SIZE(SINT_array, 0, SINT_array_size);
Repeat
String_tag.DATA[element_number] := SINT_array[element_number]; element_number := element_number + 1;
String_tag.LEN := element_number;
If element_number = SINT_array_size then exit; end_if;
Until SINT_array[element_number] = 13 end_repeat;
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
695
Appendix C
Structured Text Programming
Comments
Format
//comment
(*comment*)
/*comment*/
To make your structured text easier to interpret, add comments to it.
• Comments let you use plain language to describe how your structured text works.
• Comments do not affect the execution of the structured text.
The table describes how to add comments to your structured text.
To add a comment
On a single line
At the end of a line of structured text
Within a line of structured text
That spans more than one line
Use one of these formats
//comment
(*comment*)
/*comment*/
(*comment*)
/*comment*/
(*start of comment . . . end of
comment*)
/*start of comment . . . end of
comment*/
The table shows some examples.
Example
At the beginning of a line
//Check conveyor belt direction
IF conveyor_direction THEN...
At the end of a line
ELSE //If conveyor isn’t moving, set alarm light light := 1;
END_IF;
Sugar.Inlet[:=]1;(*open the inlet*)
IF Sugar.Low (*low level LS*)& Sugar.High (*high level LS*)THEN...
(*Controls the speed of the recirculation pump. The speed depends on the temperature in the tank.*)
IF tank.temp > 200 THEN...
Sugar.Inlet:=0;/*close the inlet*/
IF bar_code=65 /*A*/ THEN...
/*Gets the number of elements in the Inventory array and stores the value in the Inventory_Items tag*/
SIZE(Inventory,0,Inventory_Items);
696
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Index
A
ABL instruction
ABS instruction
absolute value
ACB instruction
ACL instruction
ACS instruction
ADD instruction
addition
addressing
bit
advanced math instructions
introduction
LN
log
XPY
AFI instruction
AHL instruction
alarms
and events instructions alarm status
ALMA, analog alarm
buffer alarms
configuration
message text
programmatically access
suppress or disable alarms
all mode
ALMA instruction
ALMD
digital alarm
instruction alarms and events instructions
always false instruction
AND instruction
arc
cosine
sine
tangent
ARD instruction
arithmetic
operators structured text
status flags overflow
ARL instruction
array instructions
AVE
BSL
,
COP
DDT
FAL
,
file/misc.
FLL
,
LFL
,
mode of operation
RES
sequencer
,
SQI
,
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
array subscript
expressions
ASCII
chars in buffer
handshake lines
instructions
ABL
,
CONCAT
delete
DTOS
find
insert
lower case
MID
RTOS
STOD
upper case
read
structured text assignment
test for buffer line
write
,
ASN instruction
assignment
ASCII character
non-retentive
retentive
assume data available
ATN instruction
attributes
converting data types
immediate values
AVE instruction
average
AWA instruction
AWT instruction
B
BAND
bit
addressing
field distribute
,
instructions introduction
ONS
,
,
,
XIO
shift left
,
bitwise
AND
exclusive OR
NOT
operators structured text
OR
BNOT
BOOL expression
structured text
697
Index
698
Boolean
AND
Exclusive OR
NOT
OR
BOR
break
BRK instruction
BSL instruction
BSR instruction
BTD instruction
BTDT instruction
buffer alarms
BXOR
C cache
connection
CASE
CIP
large connection option
clear
CLR instruction
CMP instruction
comments
structured text
common attributes
converting data types
immediate values
compare
instructions
CMP
EQU
expression format
,
GEQ
introduction
LEQ
,
MEQ
NEQ
order of operation
valid operators
structure
compute
instructions
ABS
CPT
DIV
expression format
,
introduction
MOD
NEG
order of operation
SQR
valid operators
CONCAT instruction
configuring
MSG instruction
PID instruction
connection
cache
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
D data transitional
data type
LINT
DDT instruction
operands
search mode
deadband
debug instructions
DEG instruction
degree
delete instruction
description
structured text
diagnostic detect
DINT to String
disable flag
status
DIV instruction
division
document
structured text
DTOS instruction
DTR instruction
connector
function block diagram
construct
structured text
control structure
,
,
,
conversion instructions
,
DEG
FRD
introduction
RAD
TOD
,
convert
data types
to BCD
,
COP instruction
copy
COS instruction
cosine
count
down
up
counter instructions
CTD
,
introduction
RES
counter structure
CPS instruction
CPT instruction
CTD instruction
CTU instruction
CTUD instruction
E elements
size instruction
end of transition instruction
EOT instruction
EQU instruction
equal to
error codes
ASCII
event
MSG instruction
instruction
task trigger via consumed tag
,
examine if open
execution order
exponential
expression
array subscript
BOOL expression structured text
format
,
numeric expression structured text
order of execution structured text
,
structured text arithmetic operators
bitwise operators
functions
logical operators
overview
relational operators
valid operators
,
F
FAL instruction
mode of operation
operands
FBC instruction
operands
search mode
FBD_BIT_FIELD_DISTRIBUTE structure
FBD_BOOLEAN_AND structure
FBD_BOOLEAN_NOT structure
FBD_BOOLEAN_OR structure
FBD_BOOLEAN_XOR structure
FBD_COMPARE structure
,
,
FBD_CONVERT structure
,
FBD_COUNTER structure
FBD_LIMIT structure
FBD_LOGICAL structure
,
FBD_MASK_EQUAL structure
FBD_MASKED_MOVE structure
FBD_MATH structure
,
,
Index
FBD_MATH_ADVANCED structure
,
,
FBD_ONESHOT structure
FBD_TIMER structure
FBD_TRUNCATE structure
feedback loop
function block diagram
feedforward
FFL instruction
FFU instruction
FIFO load
FIFO unload
file
arithmetic and logic
bit comparison
fill
instructions. See array instructions
search and compare
find instruction
find string
FLL instruction
floating point value
FOR instruction
FOR…DO
for/break instructions
BRK
FOR
introduction
RET
FRD instruction
FSC instruction
mode of operation
operands
function block diagram
choose elements
resolve a loop
,
functions
structured text
G
GEQ instruction
get system value
greater
than
,
GRT instruction
GSV instruction
objects
I icon
if...then
immediate
output instruction
immediate values
incremental mode
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
699
Index
700 input
reference
wire connector
input/output instructions
GSV
introduction
IOT
MSG
insert
SSV
instruction
string
instructions
ASCII conversion
bit
compare
,
debug
for/break
input/output
logical
math conversion
program control
sequencer
,
,
timer
IOT instruction
IREF
J
JMP instruction
JSR instruction
jump
,
to subroutine
JXR instruction
control structure
L label
,
large connection option
CIP
latching data
LBL instruction
,
LEQ instruction
LES instruction
less
than
LFL instruction
LFU instruction
LIFO load
LIFO unload
LIM instruction
limit
LINT
data type
LN instruction
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
log
base 10
instruction
natural
logical
instructions
AND
introduction
NOT
OR
XOR
operators structured text
lower case
instruction
M masked
equal to
move
,
masks
master control reset
math
conversion instructions
DEG
FRD
introduction
RAD
TOD
,
operators structured text
MCR instruction
MEQ instruction
message
cach connections
programming guidelines
structure
MID instruction
middle string
mixing data types
MOD instruction
mode of operation
modulo division
MOV instruction
move
instructions
BTD
CLR
move/logical instructions
BAND
,
,
MSG
introduction
MOV
,
instruction
cache connection
error codes
operands
programming guidelines
structure
MUL instruction
multiplication
Index
MVM instruction
MVMT instruction
N natural log
NEG instruction
negate
NEQ instruction
no operation
NOP instruction
not equal to
NOT instruction
numeric expression
numerical mode
O objects
GSV/SSV instruction
OCON
one shot
falling
rising
,
ONS instruction
operators
,
order of execution structured text
OR instruction
order of execution
structured text expression
order of operation
,
OREF
OSF instruction
OSFI instruction
OSR instruction
OSRI instruction
OTE instruction
OTL instruction
OTU instruction
output
biasing
energize
latch
reference
unlatch
,
wire connector
overflow conditions
P pause SFC instruction
PID
instruction alarms
configuring
deadband
feedforward
operands
,
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012 scaling
tuning
structure
postscan
structured text
program
control instructions
AFI
EOT
event
introduction
JMP
,
LBL
,
MCR
NOP
RET
SBR
TND
UID
operator control overview
proportional, integral, and derivative
R
RAD instruction
radians
REAL to String
relational operators
structured text
REPEAT…UNTIL
RES instruction
reset
result
SFC instruction
structure
,
RET instruction
,
retentive
timer on
,
return
,
RTO instruction
RTOR instruction
RTOS instruction
S
SBR instruction
scaling
scan delay
function block diagram
search
mode
,
string
sequencer
input
SQI
load
nstructions introduction
output
701
Index
702 serial port
control structure
instructions
,
ABL
introduction
set system value
SFP instruction
SFR instruction
shift instructions
BSL
,
FFL
introduction
LFL
SIN instruction
sine
size
instruction
size in elements
sort
special instructions
DDT
,
FBC
introduction
PID
SFP
SQI instruction
SQL instruction
SQO instruction
SQR instruction
square root
SRT instruction
SSV instruction
objects
,
standard deviation
status
disable flag
status flags
STD instructions
STOD instruction
STOR instruction
string
concatenate
DTOS
introduction
lower case
RTOS
STOD
,
upper case
data type
,
evaluation in structured text
manipulation instructions
CONCAT
delete
find
insert
MID
structure
,
to DINT
,
structure
message
structured text
arithmetic operators
,
bitwise operators
CASE
comments
,
evaluation of strings
FOR…DO
functions
if...then
logical operators
non-retentive assignment
relational operators
REPEAT…UNTIL
while…do
structures
compare
,
,
,
,
,
FBD_BIT_FIELD_DISTRIBUTE
,
,
,
,
,
,
,
,
,
,
,
,
,
message
PID
RES instruction
result
serial port control
,
timer
SUB instruction
subroutine
subtraction
swap byte
SWPB instruction
synchronous copy
T
TAN instruction
tangent
task
trigger event task
temporary end
timer
instructions introduction
RES
,
TOF
,
off delay
,
structure
timing modes
TND instruction
TOD instruction
TOF instruction
TOFR instruction
TON instruction
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
TONR instruction
trigger
event task
trigonometric instructions
ACS
,
COS
introduction
SIN
TAN
TRN instruction
truncate
tuning
U
UID instruction
UIE instruction
unresolved loop
function block diagram
update output
upper case
instruction
user
interrupt disable
W while…do
X
X to the power of Y
XIO instruction
XOR instruction
XPY instruction
Index
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
703
Index
Notes:
704
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Notes:
Index
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
705
Index
Notes:
706
Rockwell Automation Publication 1756-RM003O-EN-P - November 2012
Rockwell Automation Support
Rockwell Automation provides technical information on the Web to assist you in using its products.
At http://www.rockwellautomation.com/support , you can find technical manuals, technical and application notes, sample code and links to software service packs, and a MySupport feature that you can customize to make the best use of these tools. You can also visit our Knowledgebase at http://www.rockwellautomation.com/knowledgebase for FAQs, technical information, support chat and forums, software updates, and to sign up for product notification updates.
For an additional level of technical phone support for installation, configuration, and troubleshooting, we offer
TechConnect
SM
support programs. For more information, contact your local distributor or Rockwell Automation representative, or visit http://www.rockwellautomation.com/support/ .
Installation Assistance
If you experience a problem within the first 24 hours of installation, review the information that is contained in this manual. You can contact Customer Support for initial help in getting your product up and running.
United States or Canada 1.440.646.3434
Outside United States or Canada Use the Worldwide Locator at http://www.rockwellautomation.com/support/americas/phone_en.html
, or contact your local Rockwell
Automation representative.
New Product Satisfaction Return
Rockwell Automation tests all of its products to ensure that they are fully operational when shipped from the manufacturing facility. However, if your product is not functioning and needs to be returned, follow these procedures.
United States
Outside United States
Contact your distributor. You must provide a Customer Support case number (call the phone number above to obtain one) to your distributor to complete the return process.
Please contact your local Rockwell Automation representative for the return procedure.
Documentation Feedback
Your comments will help us serve your documentation needs better. If you have any suggestions on how to improve this document, complete this form, publication RA-DU002 , available at http://www.rockwellautomation.com/literature/ .
Rockwell Otomasyon Ticaret A.Ş., Kar Plaza İş Merkezi E Blok Kat:6 34752 İçerenköy, İstanbul, Tel: +90 (216) 5698400
Publication 1756-RM003O-EN-P - November 2012
Supersedes Publication 1756-RM003N-EN-P - October 2011 Copyright © 2012 Rockwell Automation, Inc. All rights reserved. Printed in the U.S.A.
Download
Advertisement
Key features
Scalable and flexible
Multiple programming languages
Integrated communication protocols
Robust and reliable operation
Easy to configure and use
Wide range of I/O options
Frequently asked questions
The Logix5000 controller family includes ControlLogix, CompactLogix, SoftLogix, FlexLogix, and PowerFlex 700S. Each type of controller has different features and capabilities that make it suitable for specific applications.
Logix5000 controllers support multiple programming languages including Relay Ladder Logic, Function Block Diagram, Structured Text, Sequential Function Chart, and Ladder Diagram.
Logix5000 controllers support a wide range of communication protocols, including Ethernet/IP, ControlNet, DeviceNet, DH+, DH-485, and RS-232.