Logix5000 Controllers Structured Text Catalog Numbers 1756 ControlLogix, 1769 CompactLogix, 1789 SoftLogix, 1794 FlexLogix, PowerFlex 700S with DriveLogix Programming Manual
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.
Summary of Changes This manual contains new and updated information. IMPORTANT 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.
Summary of Changes Notes: 4 Publication 1756-PM007D-EN-P - November 2012
Table of Contents Preface Studio 5000 Engineering and Design Environment and Logix Designer Application. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 In This Manual . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 How to Use this Manual . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 Chapter 1 Program Structured Text 5Publication 1756-PM007D-EN-P - November 2012 Introduction . . . . . . . . . . . . . . . . .
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.
Preface How to Use this Manual Text that is Identifies Italic the actual name of an item that you Right-click User-Defined … see on your screen or in an example Right-click the item that is named User-Defined. courier information that you must supply based on your application (a variable) 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. Press [Enter]. Press the Enter key.
Chapter 1 Program Structured Text 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.
Chapter 1 Program Structured Text Term Definition Examples Instruction An instruction is a standalone statement. instruction(); (see page 20) 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. instruction(operand); instruction(operand1, operand2,operand3); Terminate the instruction with a semi colon “;”.
Program Structured Text Assignments Chapter 1 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.
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.
Program Structured Text Chapter 1 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. This is OK This is not OK string1.DATA[0]:= 65; string1.DATA[0] := A; string1.DATA[0]:= string2.
Chapter 1 Program Structured Text 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.
Program Structured Text Chapter 1 Use Arithmetic Operators and Functions You can combine multiple operators and functions in arithmetic expressions. Arithmetic operators calculate new values. To Use this operator Optimal data type Add + DINT, REAL Subtract/negate - DINT, REAL Multiply * DINT, REAL Exponent (x to the power of y) ** DINT, REAL Divide / DINT, REAL Modulo-divide MOD DINT, REAL Arithmetic functions perform math operations.
Chapter 1 Program Structured Text For example: Use this format Example For this situation You’d write value1 operator value2 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." gain_4_adj := gain_4+15; operator value1 If alarm and high_alarm are DINT tags and your specification says: “Negate high_alarm and store the result in alarm.
Program Structured Text Chapter 1 For example: Use this format Example For this situation You’d write value1 operator value2 If temp is a DINT tag and your specification says: “If temp is less than 100⋅ then…” IF temp<100 THEN... stringtag1 operator stringtag2 If bar_code and dest are string tags and your specification says: “If bar_code equals dest then…” IF bar_code=dest THEN... char1 operator char2 If bar_code is a string tag and your specification says: “If bar_code.
Chapter 1 Program Structured Text Use Logical Operators Logical operators let you check if multiple conditions are true or false.
Program Structured Text Chapter 1 Use Bitwise Operators Bitwise operators manipulate the bits within a value based on two values. For Use this operator Optimal Data Type Bitwise AND &, AND DINT Bitwise OR OR DINT Bitwise exclusive OR XOR DINT Bitwise complement NOT DINT For example: Use this format value1 operator value2 Example For this situation You’d write If input1, input2, and result1 are DINT tags and your specification says: “Calculate the bitwise result of input1 and input2.
Chapter 1 Program Structured Text Instructions Structured text statements can also be instructions. 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.
Program Structured Text Constructs Chapter 1 Constructs can be programmed singly or nested within other constructs. If you want to Use this construct Do something if or when specific conditions occur IF...THEN Select what to do based on a numerical value CASE...OF Do something a specific number of times before doing anything else FOR...DO Keep doing something as long as certain conditions are true WHILE...DO Keep doing something until a condition is true REPEAT...
Chapter 1 Program Structured Text Use IF…THEN to do something if or when specific conditions occur. IF...THEN Operands: Structured Text IF bool_expression THEN ; END_IF; Operand Type Format Enter bool_ expression BOOL Tag BOOL tag or expression that evaluates to a BOOL value (BOOL expression) Expression Description: The syntax is: IF bool_expression1 THEN ; Statements to execute when bool_expression1 is true . . .
Program Structured Text Chapter 1 This table summarizes combinations of IF, THEN, ELSIF, and ELSE.
Chapter 1 Program Structured Text Example 3: IF…THEN…ELSIF If you want this Enter this structured text If sugar low limit switch = low (on) and sugar high limit switch = not high (on) then IF Sugar.Low & Sugar.High THEN inlet valve = open (on) Sugar.Inlet [:=] 1; Until sugar high limit switch = high (off) ELSIF NOT(Sugar.High) THEN Sugar.Inlet := 0; END_IF; The [:=] tells the controller to clear Sugar.Inlet whenever the controller: • enters the Run mode.
Program Structured Text Chapter 1 Use CASE to select what to do based on a numerical value. CASE...
Chapter 1 Program Structured Text ELSE ; optional Statements to execute when numeric_expression ¼ any selector . . . END_CASE; The syntax for entering the selector values is: When selector is Enter One value value: statement Multiple, distinct values value1, value2, valueN : Use a comma (,) to separate each value. A range of values value1...valueN : Use two periods (..) to identify the range. Distinct values plus a range valuea, valueb, value1...
Program Structured Text Chapter 1 Example If you want this Enter this structured text If recipe number = 1 then CASE recipe_number OF 1: Ingredient A outlet 1 = open (1) Ingredient B outlet 4 = open (1) Ingredient_A.Outlet_1 :=1; Ingredient_B.Outlet_4 :=1; If recipe number = 2 or 3 then 2,3: Ingredient A outlet 4 = open (1) Ingredient_A.Outlet_4 :=1; Ingredient_B.Outlet_2 :=1; Ingredient B outlet 2 = open (1) If recipe number = 4, 5, 6, or 7 then 4..
Chapter 1 Program Structured Text Use the FOR…DO loop to do something a specific number of times before doing anything else.
Program Structured Text Chapter 1 Description: The syntax is: FOR count := initial_value TO final_value BY increment Optional { If you don’t specify an increment, the loop increments by 1. DO ; IF bool_expression THEN EXIT; Optional 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_IF; END_FOR; These diagrams show how a FOR...
Chapter 1 Program Structured Text Example 1: If you want this Enter this structured text Clear bits 0 - 31 in an array of BOOLs: For subscript:=0 to 31 by 1 do array[subscript] := 0; 1. Initialize the subscript tag to 0. End_for; 2. Clear array[ subscript ] . For example, when subscript = 5, clear array[5]. 3. Add 1 to subscript. 4. If subscript is £ to 31, repeat 2 and 3. Otherwise, stop.
Program Structured Text Chapter 1 Use the WHILE…DO loop to keep doing something as long as certain conditions are true. WHILE…DO Operands: Structured Text WHILE bool_expression DO ; END_WHILE; Operand Type Format Enter bool_ expression BOOL Tag BOOL tag or expression that evaluates to a BOOL value Expression IMPORTANT Make sure that you do not iterate within the loop too many times in a single scan.
Chapter 1 Program Structured Text These diagrams show how a WHILE...DO loop executes and how an EXIT statement leaves the loop early. BOOL expression False False BOOL expression True True Statement 1 Statement 1 Statement 2 Statement 2 Statement 3 Statement 3 Rest of the routine Yes No Rest of the routine While the bool_expression is true, the controller executes only the statements within the WHILE…DO loop. To stop the loop before the conditions are true, use an EXIT statement.
Program Structured Text Chapter 1 Example 2: If you want this Enter this structured text 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. element_number := 0; SIZE(SINT_array, 0, SINT_array_size); While SINT_array[element_number] <> 13 do 1. Initialize Element_number to 0. 2.
Chapter 1 Program Structured Text Use the REPEAT…UNTIL loop to keep doing something until conditions are true. REPEAT…UNTIL Operands: Structured Text REPEAT ; UNTIL bool_expression END_REPEAT; Operand Type Format Enter bool_ expression BOOL Tag BOOL tag or expression that evaluates to a BOOL value (BOOL expression) Expression Make sure that you do not iterate within the loop too many times in a single scan.
Program Structured Text Chapter 1 These diagrams show how a REPEAT...UNTIL loop executes and how an EXIT statement leaves the loop early. Statement 1 Statement 1 Statement 2 Statement 2 Statement 3 BOOL expression Statement 3 True Yes No False BOOL expression True Rest of the routine False Rest of the routine While the bool_expression is false, the controller executes only the statements within the REPEAT…UNTIL loop. To stop the loop before the conditions are false, use an EXIT statement.
Chapter 1 Program Structured Text Example 2: If you want this Enter this structured text 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. element_number := 0; SIZE(SINT_array, 0, SINT_array_size); Repeat 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). String_tag.
Program Structured Text Comments Chapter 1 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. Structured text comments are downloaded into controller memory and are available for upload.
Chapter 1 Program Structured Text For example: Format Example //comment 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; (*comment*) 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...
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, a knowledge base of FAQs, 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.