280 likes | 366 Views
Concept V2.5. Lesson 17 Objectives: After completing this lesson, the learner will be able to: Program logic using the ST Editor. Demonstrate an Understanding of ST Language. Concept V2.5. Overview ST is a high level language, similar to PASCAL or BASIC.
E N D
Concept V2.5 • Lesson 17 Objectives: • After completing this lesson, the learner will be able to: • Program logic using the ST Editor. • Demonstrate an Understanding of ST Language.
Concept V2.5 • Overview • ST is a high level language, similar to PASCAL or BASIC. • ST is a distinct language that has been specifically developed for industrial control applications. • ST has a comprehensive range of constructs for assigning values to variables, calling FFBs, creating expressions, for conditional evaluation of selected statements, or for iteration, i.e. repeating selected section of code.
Concept V2.5 • Advantages • Fairly straight forward and easy to learn and to use. • Compact formulation of a complex programming task. • Clear program construction by instruction blocks. • Powerful constructs for controlling the instruction flow. • Useful for complex mathematic solutions. • Simple solutions for difficult problems in FBD, LD or IL.
Concept V2.5 • Executed operations • Logical, arithmetic, compare operations and allocations. • Complex instructions and instruction groupsunconditioned / conditioned. • Declaration of functions and function blocks. • Execute functions and function blocksunconditioned / conditioned.
Concept V2.5 • Invocation of Function Blocks • Each FFB instance must be invoked once • Multiple invocation (instantiation) is allowed • FFB-call: with a list of input parameters
Concept V2.5 • Statements, Expressions and Operators • A structured text program contains: • statements. • A statement contains: • Expressions • Keywords • An expression contains one or more: • Operators with Operands • Admissible Operands • Literals, all variables, elements of multi-element variables, FFB outputs or direct addresses
Concept V2.5 • Statements must close with semicolons (;) One line may contain several statements, separated by (;) • The following statements are available: • VAR ... END_VAR Declaration of FFB's • Function Block Calls Invoking of FFBs • IF ... THEN ... END_IF Conditioned execution of statements • ELSIF ... THEN Conditioned execution of statements, if the preceded expression is not fulfilled (false). • ELSE ... Execution of statements, if expressions of preceded statements are not fulfilled (false). NOTE: ( ... means condition/expression)
Concept V2.5 • CASE ... OF ... END_CASE A list of statements with given labels. Execution, if the label is true. • FOR ... TO ... BY ... DO ... END_FOR Repeated execution of statements up to a given number. • WHILE...DO...END_WHILE Repeated execution of statements up to preceded condition = 0. • REPEAT ... UNTIL ... END_REPEAT Repeated execution of statements up to succeeded condition = 0. • EXIT To terminate repeat statements (FOR, WHILE, REPEAT) before the end condition is true. NOTE: ( ... means condition/expression)
Concept V2.5 • Keywords That Can Not Be used • TYPE...END_TYP • VAR_INPUT...END_VAR • VAR_OUTPUT...END_VAR • VAR_IN_OUT...END_VAR • VAR_EXTERNAL...END_VAR • FUNCTION...END_FUNCTION • FUNCTION_BLOCK...END_FUNCTION_BLOCK • PROGRAM...END_PROGRAM • STEP...END_STEP • TRANSITION...END_TRANSITION • ACTION...END_ACTION • SEGMENT_SCHEDULER • RETURN
Concept V2.5 • Operators • Operators are generic, i.e. they automatically adjust to the data type of the operand. • The evaluation of an expression consists of applying the operators to the operands in the order defined by the rule of precedence of the operators. • The operator with the highest rule of precedence in an expression will be executed first. • Operators with the same precedence are executed from left to right, as described in the expression. • This order can be changed through bracketing.
Concept V2.5 Operator Operand Significance Precedence ( ) Expression Bracketing 1 (highest) FUNCNAME ANY Function editing (call) 2 * * REAL, ANY_NUM Raising to a power 3 ANY_NUM Negation 4 NOT ANY_BIT Complement 4 * ANY_NUM or TIME Multiplication 5 / ANY_NUM Division 5 MOD ANY_NUM Modulo 5 All operands also: Expression, literal, variable, direct address
Concept V2.5 + ANY_NUM or TIME Addition 6 ANY_NUM or TIME Subtraction 6 < ANY_ELEM Less than 7 > ANY_ELEM Greater than 7 < = ANY_ELEM Less or equal 7 > = ANY_ELEM Greater or equal 7 = ANY_ELEM Equality 8 < > ANY_ELEM Inequality 8 &, AND ANY_BIT Logic AND 9 XOR ANY_BIT Logic exclusive OR 10 OR ANY_BIT Logic OR 11 All operands also: Expression, literal, variable, direct address Operator Operand Significance precedence
Concept V2.5 Input Output Default Data Type Possible Data Types %IX, %QX BOOL BOOL%I %Q %IB %QB BYTE BYTE %IW %QW INT INT, UINT, WORD %ID %QD REAL REAL, DINT, UDINT, TIME Example: %IX1 means address 100001 (input bit 1) %QW1 means address 400001 (output word 1)
Concept V2.5 • Keywords, Separators and Comments • When entering keywords, separators and comments, there is an immediate spell check • If a keyword, a separator or a comment is detected, it is identified with a color shading. • If unauthorized keywords (instructions or operators) are entered, this will be identified through color shading as well. • Spaces and tabs have no effect on syntax, they can be used anywhere.
Concept V2.5 • The Objects Menu
Concept V2.5 • Example: Entering a direct function call • No declaration is required!
Concept V2.5 • Example: Entering a function block IN, PT, Q, and ETare the labels of thepins on a TON timer
Concept V2.5 • Handling, general • Create or open ST Section • Type or select statement, operator etc.: Objects... • Type or select operand: Edit Lookup variables • Type or select FFB: Objects Insert FFB or click on • Insert FFB see next slide
Concept V2.5 • Insert FFB • Browse and select FFB • Declaration • Invocation • Assignment
Concept V2.5 • Use Expand statement to complete e.g.,VAR ... END_VAR • Use Go to counterpart to find e.g.,second bracket ( ) • Enter comments, consider Options, Preferences! • Syntax check: Project Analyze Section. • Any errors found are displayed in the message window. • Double click on the first line means:go to the line with the first error in ST.
This area used for Upload function Concept V2.5 • Before closing the ST section, go to Project Code generation options creates additional information forprocess diagnosis during code generation generates a runtimeoptimized code Tests loops within ST (and IL) sections • Code generation together with the syntax check will be performed when the section is closed.
Concept Programming in ST ST Example • Comment • FFB-Declaration • AND-Function with Allocation • FFB call with Allocation • AND-Function with Allocation • FFB call with Allocation
Concept V2.5 Watch Selected Inspect Selected
Concept V2.5 • Select variable with double click • Animation Selected mode or • Go to Online Watch Selected • Repeat for next variable • Remains open until it is closed or the animation is terminated • A dialog box can be opened for each section
Concept V2.5 • Select variable with double click • go to menu Online Inspect Selected • set cursor to any position on section • click left mouse button • Set cursor into cyan field • depress right mouse button • select operation mode: • Move field to another position • Delete field or • Options... see next slide
Concept V2.5 • Select operation mode options... • Enter Minimum/Maximum • Notice the color change Yellow Magenta
Structured Text Demonstration and Lab