Rockwell Automation Logix5000 Controllers User Manual

Logix5000 Controllers Structured Text

Catalog Numbers SoftLogix, 1794 FlexLogix, PowerFlex 700S with DriveLogix
Programming Manual
1756 ControlLogix, 1769 CompactLogix, 1789
Important User Information
WARNING
IMPORTANT
ATTENTION
SHOCK HAZARD
BURN HAZARD
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 Automation sales office or online at http://www.rockwellautomation.com/literature/ 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.
) describes some important differences
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.
Identifies information that is critical for successful application and understanding of the product.
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
Labels may be on or inside the equipment, for example, a drive or motor, to alert people that dangerous voltage may be present.
Labels may be on or inside the equipment, for example, a drive or motor, to alert people that surfaces may reach dangerous temperatures.
Allen-Bradley, Rockwell Automation, and TechConnect are trademarks of Rockwell Automation, Inc.
Trademarks not belonging to Rockwell Automation are property of their respective companies.

Summary of Changes

IMPORTANT
This manual contains new and updated information.
RSLogix 5000 programming software is now known as Studio 5000™ Logix Designer application, a component of Studio 5000 Engineering and Design Environment.
Changes throughout this revision are marked by change bars, as shown in the margin of this page.
3Publication 1756-PM007D-EN-P - November 2012 3
Summary of Changes
Notes:
4 Publication 1756-PM007D-EN-P - November 2012

Table of Contents

Preface
Program Structured Text
Studio 5000 Engineering and Design Environment and
Logix Designer Application. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
In This Manual . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
How to Use this Manual . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Chapter 1
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Assignments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Specify a Non-retentive Assignment. . . . . . . . . . . . . . . . . . . . . . . . 12
Assign an ASCII Character to a String . . . . . . . . . . . . . . . . . . . . . . 13
Expressions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Use Arithmetic Operators and Functions . . . . . . . . . . . . . . . . . . . 15
Use Relational Operators. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
Use Logical Operators. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
Use Bitwise Operators. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
Determine the Order of Execution . . . . . . . . . . . . . . . . . . . . . . . . 19
Instructions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
Constructs. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
Some Key Words Are Reserved for Future Use . . . . . . . . . . . . . . 21
IF...THEN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
CASE...OF . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
FOR…DO . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
WHILE…DO . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
REPEAT…UNTIL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
5Publication 1756-PM007D-EN-P - November 2012 5
Table of Contents
6 Publication 1756-PM007D-EN-P - November 2012

Preface

Studio 5000 Engineering and Design Environment and Logix Designer Application

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.
The Studio 5000 environment is the foundation for the future of Rockwell Automation
place for design engineers to develop all the elements of their control system.
®
engineering design tools and capabilities. It is the one

In This Manual

This manual shows how to program Logix5000 controllers with the structured text programming language. This manual is one of a set of related manuals that show common procedures for programming and operating Logix5000 controllers. For a complete list of common procedures manuals, see the Logix 5000 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
SoftLogix5800 controllers
7Publication 1756-PM007D-EN-P - November 2012 7
Preface

How to Use this Manual

Text that is Identifies For example Means
Italic the actual name of an item that you
see on your screen or in an example
courier information that you must supply
based on your application (a variable)
enclosed in brackets a keyboard key Press [Enter]. Press the Enter key.
Some text is formatted differently from the rest of the text.
Right-click User-Defined Right-click the item that is named
User-Defined.
Right-click name_of_program
You must identify the specific program in your application. Typically, it is a name or variable that you have defined.
8 Publication 1756-PM007D-EN-P - November 2012
Program Structured Text
Chapter
1

Introduction

Term Definition Examples
Assignment
(see page 11)
Expression
(see page 13)
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 A named area of the memory where data is stored
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:
tag := expression;
value1
(BOOL, SINT,INT,DINT, REAL, string). Immediates A constant value. 4 Operators 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 only be used
in expressions. Instructions cannot be used in
expressions.
Publication 1756-PM007D-EN-P - November 2012 9
tag1 + tag2
tag1 >= value1 function(tag1)
Chapter 1 Program Structured Text
IMPORTANT
Term Definition Examples
Instruction
(see page 20)
Construct
(see page 21)
Comment
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 only be used in expressions.
A conditional statement used to trigger structured text code (i.e, other statements).
Terminate the construct with a semi colon “;”.
Text that explains or clarifies what a section of structured text does.
instruction();
instruction(operand);
instruction(operand1, operand2,operand3);
IF...THEN
CASE
FOR...DO
WHILE...DO
REPEAT...UNTIL
EXIT //comment
(see page page 37)
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.
Use caution when copying and pasting components between different versions of the Logix Designer application. The application only supports pasting to the same version or newer version. Pasting to a prior version of the application is not supported. When pasting to a prior version, the paste action may succeed but the results may not be as intended.
(*start of comment . . . end of comment*)
/*start of comment . . . end of comment*/
10 Publication 1756-PM007D-EN-P - November 2012
Program Structured Text Chapter 1
TIP

Assignments

Use an assignment to change the value stored within a tag. An assignment has this syntax:
tag := expression ;
where:
Component Description
tag Represents the tag that is getting the new value.
The tag must be a BOOL, SINT, INT, DINT, or REAL. := Is the assignment symbol. expression Represents the new value to assign to the tag.
If tag is this data type Use this type of expression
BOOL BOOL expression
SINT
INT
DINT
REAL
Numeric expression
; Ends the assignment.
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.
I/O module data updates asynchronously to the execution of logic. If you reference an input multiple times in your logic, the input could change state between separate references. If you need the input to have the same state for each reference, buffer the input value and reference that buffer tag.
Publication 1756-PM007D-EN-P - November 2012 11
Chapter 1 Program Structured Text
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:
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 Description
tag 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 expression Represents the new value to assign to the tag.
If tag is this data type Use this type of expression
BOOL BOOL expression
SINT
INT
DINT
REAL ; Ends the assignment.
Numeric expression
12 Publication 1756-PM007D-EN-P - November 2012
Loading...
+ 28 hidden pages