pl7 - structured text language

8
``````````````````````````````````````````````````````````````````````````` æ —fi»›»²‹¿‹•–² –” ˝‹fi«‰‹«fi»… »¤‹ ·¿²„«¿„» —fi•²‰•·» ˝‹fi«‰‹«fi»… »¤‹ ·¿²„«¿„» •› «›»… ‹– ‰fi»¿‹» fi–„fi¿‡› § 'fi•‹•²„ fi–„fi¿‡‡•²„ ·•²»› ‡¿…» « –” ¿·‚¿²«‡»fi•‰ ‰‚¿fi¿‰‹»fi› ‚•› ·¿²„«¿„» ‰¿² –²·§ » «›»… § —Ø «²•–fi ›–”‹'¿fi» –² ˝¨ ºØ —› ‚» ˝ ›‹¿‹»‡»²‹ ‰–²›‹•‹«‹»› ‹‚» ¿›•‰ «²•‹ –” ˝‹fi«‰‹«fi»… »¤‹ ·¿²„«¿„» ¿²… ¿ ›»fi•»› –” ›‹¿‹»‡»²‹› •› «›»… ‹– …»”•²» ¿ fi–„fi¿‡ ‚» ‡¿•² •²›‹fi«‰‹•–²› •² ˝‹fi«‰‹«fi»… »¤‹ ·¿²„«¿„» ¿fi» ¿› ”–··–'› { •‹ •²›‹fi«‰‹•–²› { ¿fi•‹‚‡»‹•‰ ¿²… ·–„•‰ •²›‹fi«‰‹•–²› –² '–fi…› ¿²… …–«·» '–fi…› { ¿fi•‹‚‡»‹•‰ •²›‹fi«‰‹•–²› –² ”·–¿‹•²„ –•²‹› { ²«‡»fi•‰¿· ‰–‡¿fi•›–²› –² '–fi…› …–«·» '–fi…› ¿²… ”·–¿‹•²„ –•²‹› { ²«‡»fi•‰¿· ‰–²“»fi›•–²› { •²›‹fi«‰‹•–²› –² •‹ '–fi… …–«·» '–fi… ¿²… ”·–¿‹•²„ –•²‹ ‹¿·»› { ‰‚¿fi¿‰‹»fi ›‹fi•²„ •²›‹fi«‰‹•–²› { ¿·‚¿²«‡»fi•‰¿· ‰–‡¿fi•›–²› { ‹•‡» ‡¿²¿„»‡»²‹ •²›‹fi«‰‹•–²› { fi–„fi¿‡ •²›‹fi«‰‹•–²› { ‰–²‹fi–· •²›‹fi«‰‹•–²› { ›‹¿²…¿fi… ”«²‰‹•–² ·–‰ •²›‹fi«‰‹•–²› { »¤·•‰•‹ »¤‰‚¿²„» •²›‹fi«‰‹•–²› { ¿·•‰¿‹•–²›»‰•”•‰ •²›‹fi«‰‹•–²› l‰–‡‡«²•‰¿‹•–² — ‰–²‹fi–· »‹‰ ¤¿‡·» ˝»‰‹•–² æ ``````````````````````````````````````````````````````````````````````````` ²›‹fi«‰‹•–²› •‹ •²›‹fi«‰‹•–²› »›‰fi•‹•–² «²‰‹•–² ª •‹ ¿››•„²‡»²‹ ˛ ––·»¿² ˛ ––·»¿² ¨˛ ¤‰·«›•“» ––·»¿² ˛ ²“»fi›•–² ˛ ˛•›•²„ »…„» ¿··•²„ »…„» ˝ ˝»‹ ‹– ˛˝ ˛»›»‹ ‹– «‡»fi•‰¿· ‰–‡¿fi•›–²› –² '–fi…› …–«·» '–fi…› ¿²… ”·–¿‹•²„ –•²‹› »›‰fi•‹•–² «²‰‹•–² ˝‹fi•‰‹·§ ·»›› ‹‚¿² ˝‹fi•‰‹·§ „fi»¿‹»fi ‹‚¿² ª »›› ‹‚¿² –fi »fl«¿· ‹– ª fi»¿‹»fi ‹‚¿² –fi »fl«¿· ‹– ª fl«¿· ‹– •””»fi»²‹ ”fi–‡ •‹ ‹¿·»› »›‰fi•‹•–² «²‰‹•–² ¿·» ª ¿·» ››•„²‡»²‹ »‹'»»² ‹'– ‹¿·»› ¿·» ª –fi… ››•„²‡»²‹ –” ¿ '–fi… ‹– ¿ ‹¿·» –fi… ª ¿·» ››•„²‡»²‹ –” ¿ ‹¿·» ‹– ¿ '–fi… ¿·» ª –«·» '–fi… ››•„²‡»²‹ –” ¿ …–«·» '–fi… ‹– ¿ ‹¿·» –«·» '–fi… ª ¿·» ››•„²‡»²‹ –” ¿ ‹¿·» ‹– ¿ …–«·» '–fi… —˙` –§ ¿ •‹ ‹¿·» ‹– ¿ •‹ ‹¿·» `˛¨ »‹'»»² ‹'– ‹¿·»› ˛`˛¨ ˛ »‹'»»² ‹'– ‹¿·»› ¨˛`˛¨ ¤‰·«›•“» ˛ »‹'»»² ‹'– ‹¿·»› `˛¨ »„¿‹•–² –² ¿ ‹¿·» ` –§ ¿ •‹ ‹¿·» ‹– ¿ '–fi… ‹¿·» ` –§ ¿ •‹ ‹¿·» ‹– ¿ …–«·» '–fi… ‹¿·» ` –§ ¿ '–fi… ‹¿·» ‹– ¿ •‹ ‹¿·» ` –§ ¿ …–«·» '–fi… ‹¿·» ‹– ¿ •‹ ‹¿·»

Upload: rathnampm

Post on 19-Aug-2015

233 views

Category:

Documents


11 download

DESCRIPTION

ST

TRANSCRIPT

4___________________________________________________________________________4/1A4.1 Presentation of Structured Text Ianguage4.1-1 PrincipIeStructured Text language is used to create programs by writing programming lines madeup of alphanumeric characters. This language can only be used by PL7 Junior softwareon TSX 57 PLCs.The ST statement constitutes the basic unit of Structured Text language, and a seriesof statements is used to define a program.The main instructions in Structured Text language are as follows : bit instructions, arithmetic and logic instructions on words and double words, arithmetic instructions on floating points, numerical comparisons on words, double words and floating points, numerical conversions, instructions on bit, word, double word and floating point tables, character string instructions, alphanumerical comparisons, time management instructions, program instructions, control instructions, standard function block instructions, explicit exchange instructions, application-specific instructions (communication, PD control, etc).Example :Section 44/2___________________________________________________________________________A4.1-2 InstructionsBit instructionsDescription Function:= Bit assignmentOR Boolean ORAND Boolean ANDXOR Exclusive Boolean ORNOT nversionRE Rising edgeFE Falling edgeSET Set to 1RESET Reset to 0NumericaI comparisons on words, doubIe words and fIoating pointsDescription Function< Strictly less than> Strictly greater than= Greater than or equal to= Equal to Different fromBit tabIesDescription FunctionTable := Table Assignment between two tablesTable := Word Assignment of a word to a tableWord := Table Assignment of a table to a wordTable := Double word Assignment of a double word to a tableDouble word := Table Assignment of a table to a double wordCOPY_BT Copy a bit table to a bit tableAND_ARX AND between two tablesOR_ARX OR between two tablesXOR_ARX Exclusive OR between two tablesNOT_ARX Negation on a tableBT_W Copy a bit table to a word tableBT_D Copy a bit table to a double word tableW_BT Copy a word table to a bit tableD_BT Copy a double word table to a bit table4___________________________________________________________________________4/3AInteger arithmetic on words and doubIe wordsDescription Function+ Addition- Subtraction* Multiplication/ nteger divisionREM Remainder of the integer divisionSQRT nteger square rootABS Absolute valueNC ncrementationDEC DecrementationArithmetic on fIoating pointsDescription Function+ Addition- Subtraction* Multiplication/ DivisionSQRT Square rootABS Absolute valueLogic instructions on words and doubIe wordsDescription FunctionAND Logic ANDOR Logic ORXOR Exclusive logic ORNOT Logic complementSHL Logic shift to leftSHR Logic shift to rightROL Logic rotate to leftROR Logic rotate to rightNumericaI conversion instructionsDescription FunctionBCD_TO_NT BCDK Binary conversionNT_TO_BCD BinaryK BCD conversionGRAY_TO_NT GrayK Binary conversionNT_TO_REALDNT_TO_REALREAL_TO_NTREAL_TO_DNTDBCD_TO_DNT Conversion of 32-bit BCD number into 32-bit integerDNT_TO_DBCD Conversion of 32-bit integer into 32-bit BCD numberDBCD_TO_NT Conversion of 32-bit BCD number into 16-bit integerNT_TO_DBCD Conversion of 16-bit integer into 32-bit BCD numberFloating point K nteger conversionnteger K Floating point conversion4/4___________________________________________________________________________AInstructions on word and doubIe word tabIesDescription FunctionTable := Table Assignment between two tablesTable := Word nitialize a table+, -, *, /, REM Arithmetic operations between tables+, -, *, /, REM Arithmetic operations between expressions and tablesSUM Sum of the elements of a tableEQUAL Comparison of two tablesNOT Logic complement of a tableAND, OR, XOR Logic operations between two tablesAND, OR, XOR Logic operations between expressions and tablesFND_EQW, FND_EQD Find first element equal to a valueFND_GTW, FND_GTD Find first element greater than a valueFND_LTW, FND_LTD Find first element less than a valueMAX_ARW, MAX_ARD Find maximum value in a tableMN_ARW, MN_ARD Find minimum value in a tableOCCUR_ARW, OCCUR_ARD Number of occurrences of a value in a tableSORT_ARW, SORT_ARD Sort a table in ascending or descending orderROL_ARW, ROL_ARD Rotate a table to the leftROR_ARW, ROR_ARD Rotate a table to the rightInstructions on fIoating point tabIesDescription FunctionTable := Table Assignment between two tablesTable := Floating point nitialize a tableInstruction on character stringDescription FunctionSTRNG_TO_NTSTRNG_TO_DNTNT_TO_STRNGDNT_TO_STRNGSTRNG_TO_REAL ASCK Floating point conversionREAL_TO_STRNG Floating pointK ASC conversion, =, =, Alphanumeric comparisonFND Position of a substringEQUAL_STR Position of first different characterLEN Length of a character stringMD Extract a substringNSERT nsert a substringDELETE Delete a substringCONCAT Concatenate two stringsREPLACE Replace a stringLEFT Start of stringRGHT End of stringASC K Binary conversionBinary K ASC conversion4___________________________________________________________________________4/5ATime management instructionsDescription FunctionRRTC Read system dateWRTC Update system datePTC Read date and stop codeADD_TOD Add a time period to a time of dayADD_DT Add a time period to a date and timeDELTA_TOD Measure deviation between times of dayDELTA_D Measure deviation between dates (without time)DELTA_DT Measure deviation between dates (with time)SUB_TOD Subtract a time period from a time of daySUB_DT Subtract a time period from a date and timeDAY_OF_WEEK Read current day of weekTRANS_TME Convert duration to dateDATE_TO_STRNG Convert date to character stringTOD_TO_STRNG Convert time to character stringDT_TO_STRNG Convert complete date to character stringTME_TO_STRNG Convert duration to character string"Orphee" instructionsDescription FunctionWSHL_RBT, DSHL_RBT Shift word to left, with retrieval of shifted bitsWSHR_RBT, DSHR_RBT Shift word to right with sign extension and retrieval ofshifted bitsWSHRZ_C, DSHRZ_C Shift word to right, replacing with 0, with retrieval of shiftedbitsSCOUNT Up/down counting with indication of under/overflowProgram instructionsDescription FunctionHALT Stop program executionJUMP Jump to a labelSRi Call subroutineRETURN Return from subroutineMASKEVT Mask events in the PLCUNMASKEVT Unmask events in the PLCAll these functions and instructions are described in part B of this reference manual, aswell as instructions relating to standard function blocks.nstructions and functions relating to explicit exchanges and the various applications aredescribed in the "Application-specific functions installation manual".The control structures are described in section 4.2.-5 of this part.4/6___________________________________________________________________________A4.2 Program structure4.2-1 GeneraIA Structured Text program is organized into statements. Each ST statement consists ofthe following elements : label, comments, instructions.Eachof theseelements isoptional, ie. itis possibleto have an emptystatement,astatement consisting only of comments or consisting only of a label. Each statementbegins with an exclamation mark (which is generated automatically).Example :! %L2 : (* Here is a statement with a label, comments *)SET %M0; %MW4 := %MW2 + %MW9;(* and several instructions *)%MF12 := SQRT (%MF14);4.2-2 CommentA comment is enclosed at either end by the characters (* and *), it can be placed at anypointinastatementandthereisnorestrictiononthenumberofcommentsperstatement. ts role is to facilitate the interpretation of the statement to which it is assigned,but it is not compulsory. Any characters can be used in a comment. The number of characters is restricted to 256 per comment. Nested comments are not permitted. A comment may be several lines in length.Comments are stored in the PLC and can be accessed at any moment by the user.Because of this, they consume program memory.4___________________________________________________________________________4/7A4.2-3 LabeIA label is used to reference a statement in a program entity (main program, subroutine,etc) but is not compulsory.This label has the following syntax : %Li where i is between 0 and 999 and is located atthebeginningofthestatement.Alabelreferencecanonlybeassignedtoasinglestatement within the same program entity (SR, Main, Program module).On the other hand, a statement must be refenced in order to allow connection after aprogram jump.The label references can be in any order; it is the order in which the statements areentered which is taken into account by the system during the scan.4.2-4 InstructionsTheprogramismadeupofinstructions.AnSTstatementcancontainseveralinstructions. Each instruction must end with the character ';'.4/8___________________________________________________________________________A4.2-5 ControI structuresThere are four control structures : the conditional action F, the conditional iterative actions WHLE and REPEAT, the repetitive action FOR.Each control structure is enclosed between key words, and it begins and ends in thesame statement. t is possible to nest control structures one inside the other, regardlessof their type. Control structures can be preceded or followed by any other languageinstruction.The conditionaI action IF ... END_IF;Simple form (the instruction performs an action if a condition is true).Example :Syntax OperationIF condition THENactions ;END_IF;CONDTONACTONSstart of Fend of Fcheckednot checked4___________________________________________________________________________4/9AGeneraI formExample : Conditions can be multiple. Each action represents a list of instructions. Several "F" control structures can be nested. There is no restriction on the number of ELSF instructions. There is a maximum of one ELSE part.Syntax OperationIF condition 1 THENaction1;ELSIF condition 2 THENaction2;ELSEaction3;END_IF;CONDTON 2CONDTON 1ACTON 3start of Fend of Fnot checkednot checkedcheckedcheckedACTON 2ACTON 14/10___________________________________________________________________________AThe conditionaI iterative action WHILE ... END_WHILE;The instruction performs a repetitive action as long as a condition is checked.Example :Syntax Mode of operationWHILE condition DOaction;END_WHILE;CONDTONACTONend of WHLEstart of WHLEcheckednot checked The condition can be multiple. The action represents a list of instructions. Theconditionistestedbeforeexecutingtheaction.f,whentheconditionisfirstevaluated, its value is false, the action is not executed. Several WHLE control structures can be nested.4___________________________________________________________________________4/11AThe conditionaI iterative action REPEAT ... END_REPEAT;The instruction performs a repetitive action until a condition is checked.Example : The condition can be multiple. The action represents a list of instructions. The condition is tested once the action has been executed. f, when the condition isfirst evaluated, its value is false, the action is executed once again. Several REPEAT control structures can be nested.Syntax Mode of operationREPEATaction;UNTIL condition END_REPEAT;CONDTONACTONend of REPEATstart of REPEATcheckednot checked4/12___________________________________________________________________________AThe repetitive action FOR ... END_FOR;The instruction performs a processing operation a certain number of times, incrementingan index by 1 on each loop.Example : When the index is strictly greater than the final value, execution is continued at theinstruction following the END_FOR key word. The index is incremented automatically and is therefore not the responsibility of theuser. The action represents a list of instructions. The initial value and the final value must be word-type numerical expressions. The index must be a word-type object which is accessible in read mode. Several FOR control structures can be nested.Syntax OperationFOR index := initial value TO final value DOaction;END_FOR;NDEX >FNAL VALUEACTONNDEX + 1 r NDEXNTAL VALUE r NDEXendof FORstart of FORtruefalsecontinue4___________________________________________________________________________4/13ALoop exit instruction EXIT The EXT key word is used to stop execution of the loop and continue at the instructionfollowing the key word at the end of the loop. t can be used only in the actions of one of the three WHLE, REPEAT or FOR loops. t is assigned to the closest enclosing loop, ie. it does not stop the execution of all theloops which surround it.Example :n this example, the EXT key word is used to stop the REPEAT loop but not the WHLEloop.4/ 14___________________________________________________________________________A4.3 RuIes for executing a Structured Text programA Structured Text program is executed sequentially, instruction by instruction, whilerespecting the control structures.n the case of arithmetic or Boolean expressions consisting of several operators, rulesof priority have been defined between the various operators.Operator priority ruIesThe table below gives the priority for evaluating a higher or lower priority expression.Operator Symbol PriorityParentheses (expression) HighestLogic complement NOTnversion NOT- on an operand -+ on an operand +Multiplication *Division /Modulo REMAddition +Subtraction -Comparisons , =Comparison of equality =Comparison of inequality Logic AND ANDBoolean AND ANDLogic exclusive OR XORBoolean exclusive OR XORLogic OR OR LowestBoolean OR ORExample :NOT %MW3 * 25 AND %MW10 + %MW12n this example, the NOT is performed on %MW3, then the result is multiplied by 25. Thesum of %MW10 and %MW12 is calculated, then a logic AND is performed between theresult of the multiplication and the addition.4___________________________________________________________________________4/ 15AWhen there is conflict between two operators of the same priority, the first operator willtake precedence (evaluation is performed from left to right).Example :%MW34 * 2 REM 6n this example, %MW34 is first multiplied by 2, then the result is used toperform the modulo.Use of parenthesesParentheses are used to modify the order in which operators are evaluated, for exampleto give an addition higher priority than a multiplication.Example :(%MW10 + %MW11) * %MW12n this example, the addition will be performed before the multiplication.Parentheses can be nested; there is no limit to the levels of nesting.Parentheses can also be used to avoid incorrect interpretation of the program.Example :NOT %MW2 %MW4 + %MW6By using operator priority rules, the following interpretation is obtained :((NOT %MW2) (%MW4 + %MW6))The user might well try to perform the following operation :NOT (%MW2 (%MW4 + %MW6))This example shows that parentheses can be used to clarify the program.4/ 16___________________________________________________________________________AImpIicit conversionsmplicit conversions relate to words and double words. The operators which are usedin arithmetic expressions and comparisons and the assignment operator perform theseimplicit conversions (which are therefore not the responsibility of the user).Foraninstructionoftheform:,thepossibleconversions are as follows :Operand 1 Operand 2 Conversion Conversion Operationof type : of type : Operand 1 Operand 2 of type :Word Word No No WordWord Double word Double word No Double wordDouble word Word No Double word Double wordDouble word Double word No No Double wordForanassignmentoftheform:=,theleftoperandimposes the type of operand which is expected in order to perform the operation, whichmeans that the right operand must be converted if necessary, according to the table :Left operand Right operand Right operandtype type conversionWord Word NoWord Double word WordDouble word Word Double wordDouble word Double word NoNote :Any operation between two immediately adjacent values is performed in double length.