Home
W447-E1-14 - Products
Contents
1. SYSMAC CS CJ Series W394 Describes programming and other methods to use the func CS1G H CPUL IL EV1 C81G H CPUL TH tions of the CS CJ series and NSJ series PLCs CS1D CPULIL H CS1D CPULLIS The following information is included CJ1G CPUL JL CJ1G H CPULIL H Programming CJ1H CPULILOH R CJ1G CPUL ILJP Tasks CJ1M CPULIL J NSJCT B G5D File memory NSJLI B M3D Other functions Programmable Controllers Use this manual together with the W339 or W393 Programming Manual SYSMAC CS CJ Series W340 Describes the ladder diagram programming instructions sup CS1G H CPULILI EV1 CS1G H CPULJLIH ported by CS CJ series and NSJ series PLCs CS1D CPULILH CS1D CPULLIS When programming use this manual together with the Oper CJ1G CPUL IL CJ1G H CPULILIH ation Manual CS1 W339 or CJ1 W393 and Programming CJ1H CPULILOH R CJ1G CPUL IL P Manual W394 CJ1M CPULI NSJL B G5D NSJLI B M3D Programmable Controllers Instructions Reference Manual CS1G H CPULILI EV1 CS1G H CPULJLIH W342 Describes the communications commands that can be CS1D CPULIL H CS1D CPULILS addressed to CS CJ series CPU Units
2. Example 0 0 ADD INT DINT 10 0 Algorithm Body EN ee Q POP SIGN IN16 tmi D100 a P N16 Gree p d Doo iNse M f L IN32 tmp OUT32 Variable tabe A Usage Name Data type OUT32 is a DINT variable so Internal imp DINT the variable s value is passed input EN BOOL nput IN16 INT to D1000 and D1001 apt m DINT utput ENO BOOL Output ouTs2 DINT Initial Value Retained Comment FALSE Indicates successful execution of the Fun FALSE Internals Inputs Outputs Like internal variables the values of output variables are retained until the next time the instance is executed i e when EN turns OFF the value of the output variable is retained Example In the following example the value of output variable CV will be retained until the next time the instance is executed Product A counter CTD cD Q LD PV cy 2150 1 The same name cannot be assigned to an input variable and output vari able If it is necessary to receive a value from an external variable change the variable inside the function block and then return the result to the ex ternal variable use an input output variable 2 When the instance is executed output variables are passed to the corre sponding parameters after the algorithm is processed Consequently val ues cannot be written from output variables to
3. Variable name Data type Description Source string STRING Specifies the text string in which to replace characters Replace string STRING Specifies the replace text string Number of characters INT UINT Specifies the number of characters to be replaced Position INT UINT Specifies the position from which to replace characters The first character is position 1 e g position 1 is A in mes sage 1 in the following illustration Return value STRING Returns the text string with the characters replaced Example TR Message 1 4 Blc BlElrilaln Message 2 y ylz STRING Message1 STRING Message2 Result REPLACE Message1 Message2 2 3 STRING Result ABXYEFGH is stored in the Result variable Result A B X E F GfH FIND Find Characters e Function Finds the first occurrence of the specified text string in another text string and returns the position If the text string is not found O is returned Application Return value FIND Source string Find string Arguments and Return Values Variable name Source string STRING Data type Description Specifies the text string to search Find string STRING Specifies the text string to find Return value 200 INT Returns the position of the first occurrence of the find text string The first character is position 1 e g position 1 is A in message 1 in
4. dad Name Data Type AT initial v Ret Comment E Tie NewProject af Hew CEST one A symbole G7 10 Table S settings 4 Memory ES Programs NewProgrami 00 A gi Symos ST input area Sectiont Fa END fF Function Blocks FunctionBlockt F FunctionBlock2 J Variable table Internals Inputs Outputs Externals As shown a function block definition consists of a variable table that serves as an interface and a ladder program or structured text that serves as an algo rithm Variable Table as an Interface At this point the variable table is empty because there are no variables allo cated for I O memory addresses in the PLC Ladder Program or Structure Text as an Algorithm With some exceptions the ladder program for the function block can con tain any of the instructions used in the normal program Refer to 2 4 Pro gramming Restrictions for restrictions on the instructions that can be used Structured text can be input according to the ST language defined in IEC61131 3 Using OMRON FB Library Double click the inserted function block library or right click and select Open Files from the pop up menu to display the variable table that has finished being created at the top right window and the ladder program that has finished being created in the bottom right window Both windows are displayed in gray and cannot be edited 86 Procedures Se
5. EIP 2 048 max per CPU Unit Instance names 15 000 characters max Storing function blocks as files Project files The project file cxp cxt Includes function block definitions and instances Program files The file memory program file obj includes function block definitions and instances Function block library files Each function block definition can be stored as a single file cxf for reuse in other projects Introducing the Function Blocks Section 1 1 Note The structured text ST language conforms to the IEC 61131 3 standard but CX Programmer Ver 5 0 supports only assignment statements selection statements CASE and IF statements iteration statements FOR WHILE REPEAT and EXIT statements RETURN statements arithmetic operators logical operators comparison functions numeric functions standard string functions numeric string functions OMRON expansion functions and com ments For details refer to SECTION 5 Structured Text ST Language Speci fications in Part 2 Structured Text ST 1 1 3 Files Created with CX Programmer Ver 6 0 or Later Project Files cxp and File Memory Program Files obj Function Block Library Files cxf Note Project Text Files Containing Function Blocks cxt Projects created using CX Programmer that contain function
6. Describes the ladder diagram programming instructions sup ported by CS CJ series or NSJ series PLCs When programming use this manual together with the Oper ation Manual or Hardware User s Manual CS1 W339 CJ1 W393 or CJ2 W472 and Programming Manual or Software User s Manual CS1 CJ1 W394 or CJ2 W473 SYSMAC CS Series CS1G H CPUL IL H Programmable Controllers Operation Manual Provides an outline of and describes the design installation maintenance and other basic operations for the CS series PLCs The following information is included An overview and features The system configuration Installation and wiring I O memory allocation Troubleshooting Use this manual together with the W394 SYSMAC Cu Series CJ1G CPUL TL CJ1G H CPU CJ1H CPULTLH R CJ1G CPU CJ1M CPU Programmable Controllers Operation Manual xii Provides an outline of and describes the design installation maintenance and other basic operations for the CJ series PLCs The following information is included An overview and features The system configuration Installation and wiring I O memory allocation Troubleshooting Use this manual together with the W394 Contents
7. External variables Version Upgrade Information Section 1 6 Improvements on TIMER For the CJ2 CPU Units the available range of TIMER COUNTER type vari COUNTER Type Variables ables is expanded The TIMER COUNTER type variables are made available in ST pro grams You can use the timer counter completion flags and the timer counter present values in ST programs n the ST program you can start and stop the timers counters You can register and use TIMER COUNTER type variables as an external variable of FB Support of TIMER COUNTER Type Variables Comparison with Previous Versions Version 9 1 or earlier Version 9 2 or higher Global symbol table Ladder program Local symbol table Section view ST program Local symbol table ST editor SFC program Local symbol table SFC chart view Sub chart view Sub chart symbol table Action ladder view Action ST view Transition ladder view Transition ST view FB ladder Variables Internal variables Input variables Output variables Input Output variables External variables Variables Internal variables Input variables Output variables Input Output variables External variables Version 9 0 to 9 1 Upgrade Information The new CPU Unit models of CJ2M CPU supporting function blocks and structured text are now supported When the PLC model is set to the CJ2M FB Program Area usage can be
8. NewPLC1 0 errors 1 warning The programs have been checked with the program check option set to Unit Ver 4 0 LSTSTA TEN Compile A Find Report Transfer 7 6 1 6 Downloading Uploading Programs to the Actual CPU Unit After a program containing the ST programs has been created the CX Pro grammer can be connected online to the actual PLC and the program down loaded to the actual PLC Conversely the program can be uploaded from an actual PLC Program tasks cannot be downloaded or uploaded individually in task units 6 1 7 Comparing ST Programs It is possible to compare the edited ST program with an ST program block in the actual PLC or another project file to check whether the two ST programs are identical For details on comparing programs refer to the CX Programmer Operation Manual W446 184 Procedures Section 6 1 6 1 8 Monitoring and Debugging the ST Program Monitoring the ST Program s Variables Note The ST program can be monitored The ST program is displayed in the left side of the window called the ST pro gram monitor window The values of variables used in the ST program are displayed in the right side of the window called the ST variable monitor window At this point it is possible to monitor variable values change PVs force set or force reset bits and copy paste variables in the Watch Window These oper ations are described below n Monitoring Variables Variabl
9. P EM banks 7 toE EM banks 11 to 18 CS CJ series CPU Units Ver 3 0 or Later and NSJ Controllers Function block instance area Non retained Initial value of start address Initial value of size Allowed data areas CIO WR HR DM EM Retained HR DM EM Timer TIM Counter FQM1 Flexible Motion Controllers FB Instance Area Non Retain Default value Start address End address CNT Applicable memory areas CIO WR DM Retain Timers TIM Counters CNT 57 Function Block Applications Guidelines Note CP series CPU Units Function block instance area Non retained Initial value of start address Initial value of size Section 2 5 Allowed data areas CIO WR HR DM See note Retained HR DM See note Timer TIM Counter DM area of CP1L L Address CP1L L D0000 to D9999 Provided D10000 to D31999 Not Provided D32000 to D32767 Provided CNT If there is an instruction in the user program that accesses an address in an FB instance area the CX Programmer will output an error in the following cases e When a program check is performed by the user by selecting Program Compile from the Program Menu or Compile All Programs from the PLC Menu e When attempting to write the program through online editing writing is not possible
10. jb xaa S HS Te p aman cS i S 9 E El xs NewProject zx E E NewPLCI CJ1G H Monitor Mode 3 Symbols WW 10 Table and Unit Setup Settings Memory card EB Error log PLC Clock lt r Memory B 3 Programs 3 Work piece Measurement 00 Ri 3 Symbols Default Setting Measurement END E ER NewProgram1 01 Running 3 Symbols E S Result Display 02 Running 5 Symbols LED Display END F Function Blocks 4 gt Project x PLC Name Name Addy Data T NewPLC1 NewProgra REAL NewPLCI C NewProgra D2 REAL NewPLC1 Right click in the Watch Window and select Paste 4 4 gt i gt i i m OGG GEL lale i 4n x tz t2 We B s T Rz 29 2515 9r 3c 25 e i OE er o Em m m m m AE average thickness1 thickness2 thickness3 3 0 average 0 0000000 Float fhickness 0 000000 Float thicknes jement IF flag 3 THEN IF average criterion margin THEN red lamp TRUE ELSIF average criterion margin THEN red lamp TRUE ELSE green lamp TRUE END IF END IF flag 0 Select the variable in the average 0 pA60000 Float ST variable monitor red lampe aversef 0 0000000 Float window right click aha lt and select Copy green lamp 0 4 aah n FB Usage Value Value B Comment 0 000 0 000 Measur 0 00
11. For information on calculating the number of program steps used for the function block object code refer to 2 9 Number of Function Block Program Steps and Instance Execution Time 3 2 12 Compiling Function Block Definitions Checking Program A function block definition can be compiled to perform a program check on it Use the following procedure 1 2 3 Select the function block definition right click and select Compile from the pop up menu Alternately press the Ctrl F7 Keys The function block will be compiled and the results of the program check will be automatically displayed on the Compile Table Page of the Output Window F NewProject Ei E NewPLCILCJIG H Offline 3 Symbols OOL lr BOOL 810 WORD Bo0L 200 00 Iconstant m a 2x0 300 00 4 1 H 2 sample02 FunctionBlock2 BOOL BOOL N ENO Comment lock Instance This can be rer 1 FunctionBlock2 Results of program check displayed The programs have been checked with the program check option set to Unit Ver 3 0 Nan Compile Find Report Transfer 3 2 13 Printing Function Block Definition Use the following procedure to print function block definitions 1 2 3 1 Double click the function block definition to be printed and with the vari able table and algorithm displayed select Print from the File Menu The following Target Print Rung Dia
12. Output variable 1 0 is turned OFF but internal variable a retains its previous value Program If the programming were entered directly into the program instead of in a function block definition both bit 1 0 and variable a would be turned OFF P Off P On Internal variable a A Caution An instance will not be executed while its EN input variable is OFF so Differ entiation and Timer instructions will not be initialized while EN is OFF If you use Differentiation or Timer instructions inside a function block use the Always ON Flag P On for the EN input condition Also make sure that the Always ON Flag is not made ineffective by interlock instructions jump instruc tions or subroutine instructions Nesting With CX Programmer Ver 6 0 and later versions a function block can be called from another function block i e nesting is supported Function blocks can be nested up to 8 levels including the function block called from the pro gram The calling function block and called function block can be either ST lan guage ladder language or either combination of the two Program FBO Ladder diagram FB1 Ladder diagram FB7 Ladder diagram FB8 Ladder diagram INSTANCE FBO INSTANCE FB1 LN INSTANCE FB2 INSTANCE FB8 Tubo Be x ot HF4A ret KII 2na f PH4 rg H ne 14 res Tw FBO ST 7 f a FB1 ST E FB7 ST FB8 ST Example UE Example et Example dd E
13. P Section Name Section1 800 BooL 4 00 Moves to here RightDirinput ActuatorRight o On 0 DVD ThickSelectControl 0 01 BOOL BOOL 401 DETTE PAA TOR rbput Actuation 0 00 BOOL BOOL 0 n 0 E EN ENO 3 00 BOOL LINT D10 7 100 BOOL BOOL 2 00 0 pe iiaia oL Sw Cyinae Right i 0 n o 30 BOOL 1 01 BOOL BOOL 2 01 o eae Ser d cyindeteno 0 n 0 GS eee vo lean fi Measure1 0 0000000 i D2 REAL Measure2 0 0000000 D4 REAL Measure3 0 0000000 1 2 StageA_ BoxSelect 2 WorkMoveControl_LSONcount Example Step In from ST Program to Internal Ladder Program With an ST program an arrow is displayed to the left Click the Step In Icon to Stopped here of the stopped position start Step In execution Z LSneg LSpos ActuatorPosOut 1 L 4 Actuator output for pos ifr v4 i Limit switch fo Limit switch fo p P Reset TRUE THEN Reset 0 PrevCycleLS FALSE r DF ENE Actuator oulp 1 NegDirinput LSpos LSneg ActuatorNegOut 4 H 1 H VW j Actustor output for neg Input for negat Limit switch fo Limit switch fo WorkMove RightDirinput LeftDirinput LSright LSleft ActuatorRightOn ActustorLe RightDirinput D LeftDirinput 0 LSright 0 LSleft 0 ActuatorF ActuatorNegOut IF PrevCycleLS FALSE and LSright TRUE THEN PrevCycleLS 0 LSright 0 Actuator outp LS_ONnumber LS_ONnumbers1 LS_ONnumber 0L LS_ONnumber 0 2 F
14. 0 ec cee eee 71 2 8 2 Operation of Timer Instructions esee TI 2 9 Number of Function Block Program Steps and Instance Execution Time 78 2 9 1 Number of Function Block Program Steps 78 2 9 2 Function Block Instance Execution Time 79 31 Function Block Specifications Section 2 1 2 1 Function Block Specifications 2 1 1 Function Block Specifications Item Description Number of function CJ2H CPU Units block definitions e CJ2H CPU6LI EIP 2 048 max per CPU Unit CJ2M CPU Units e CJ2M CPULT1 LI2 L18 256 max per CPU Unit e CJ2M CPUL1AL 15 2 048 max per CPU Unit CS1 H CJ1 H CPU Units e Suffix CPU44H 45H 64H 65H 66H 67H 64H R 65H R 66H R 67H R 1 024 max per CPU Unit Suffix CPUA2H A3H 63H 128 max per CPU Unit CJ1M CPU Units e CJ1M CPU11 12 13 21 22 23 128 max per CPU Unit CP1H CPU Units CP1H XA X Y 128 max per CPU Unit CP1L CPU Units CP1L M L 128 max per CPU Unit NSJ Controllers All models 1 024 max per Controller FQM1 Flexible Motion Controllers e FQM1 CM002 MMA22 MMP22 128 max per Controller Number of instances CJ2H CPU Units e CJ2H CPUGL I EIP 2 048 max per CPU Unit CJ2M CPU Units e CJ2M CPUL11 _12 _13 256 max per CPU Unit e CJ2M CPUL 44 15 2 048 max per CPU Unit CS1 H CJ1 H CPU Units e Suffix CPU44H 45H 64H 65H 66H 67H 64H R 65H R 66H R 67H R 2 048 max per CPU Unit Suffix CPU42H
15. CJ2M CJ2M CPU1 1 12 13 1 4 15 31 32 33 34 35 CS1G H with unit version 4 0 CS1G CPU45H 44H 43H 42H CS1H H with unit version 4 0 CS1H CPU67H 66H 65H 64H 63H CJ1G H with unit version 4 0 CJ1G CPU45H 44H 43H 42H CJ1H H with unit version 4 0 CJ1H CPU67H 66H 65H 67H R 66H R 65H R 64H R CJ1M with unit version 4 0 4 2 2 Specifications Item Specification CJ1M CPU23 22 21 13 12 11 Program languages that can be allocated to tasks SFC ladder or ST These programs can be combined freely ST program units Task units Up to 288 tasks 32 cyclic tasks and 256 extra cyclic tasks Tasks to which ST programs can be allocated Cyclic tasks and extra cyclic tasks Online editing ST chart editing Note The user can select standard mode ST source code included in transfer or quick mode ST source code not included in transfer Array variables Array variables can be used in SFC ladder and ST programs 135 CX Programmer Specifications Section 4 2 136 SECTION 5 Structured Text ST Language Specifications This section provides specifications for reference when using structured text programming as well as programming examples and restrictions 5 1 Structured Text Language Specifications 00 00 0008 138 5 1 1 Overview of the Structured Text Language 138 5 2 Data Types Used in ST Programs 0 0 0 e ee
16. Program index files Kbytes Variable tables Kbytes 2 8 2 Operation of Timer Instructions Selecting the Option Not Selecting the Option Default There is an option called Apply the same spec as T0 2047 to T2048 4095 in the PLC properties This setting affects the operation of timers as described in this section If this option is selected all timers will operate the same regardless of timer number as shown in the following table Timer Operation for Timer Numbers T0000 to T4095 Refresh Description When instruction is The PV is refreshed each time the instruction is executed executed If the PV is 0 the Completion Flag is turned ON If it is not 0 the Completion Flag is turned OFF When execution of all All PV are refreshed once each cycle tasks is completed Every 80 ms If the cycle time exceeds 80 ms all PV are refreshed once every 80 ms If this option is not selected the refreshing of timer instructions with timer numbers T0000 to T2047 will be different from those with timer numbers T2048 to T4095 as given below This behavior is the same for CPU Units that do not support function blocks Refer to the descriptions of individual instruc tion in the CS CJ Series Instruction Reference for details 77 Section 2 9 Number of Function Block Program Steps and Instance Execution Time Timer Operation for Timer Numbers T0000 to T2047 Refresh Description The PV is refres
17. SYSMAC CX Programmer Ver 9 CXONE ALLI_IC V4 ALLILID V4 OPERATION MANUAL Function Blocks Structured Text OMRON NOTE All rights reserved No part of this publication may be reproduced stored in a retrieval system or transmitted in any form or by any means mechanical electronic photocopying recording or otherwise without the prior written permission of OMRON No patent liability is assumed with respect to the use of the information contained herein Moreover because OMRON is constantly striving to improve its high quality products the information contained in this manual is subject to change without notice Every precaution has been taken in the preparation of this manual Neverthe less OMRON assumes no responsibility for errors or omissions Neither is any liability assumed for damages resulting from the use of the information contained in this publication Trademarks Microsoft Windows are either registered trademarks or trademarks of Microsoft Corporation in the United States and other countries Other company names and product names in this document are the trademarks or registered trademarks of their respective companies Copyrights Microsoft product screen shots reprinted with permission from Microsoft Corporation SYSMAC CX Programmer Ver 9 CXONE ALOOC V4 ALOOD V4 Operation Manual Function Blocks Structured Text Revised October 2015 Notic
18. When the Retain Option is not selected the value of the variable will not be held when the power is interrupted or operation starts Even variables not set to be retained however can be held at the start of operation by turning ON the IOM Hold Bit A50012 and can be held during power interruptions by set ting the PLC Setup as shown in the following table IOM Hold Bit A50012 setting ON IOM Hold Bit Status at Startup PLC Setup selected IOM Hold Bit Status at Startup PLC Setup not selected Variables not set to Retain Start of operation Not retained Retained Retained Power ON Not retained Retained Not retained Note 38 The IOM Hold Bit A50012 is supported for compatibility with previous mod els To hold the values of variables in function blocks however use the Retain Option and not the IOM Hold Bit Initial Value An initial value can be set for an internal variable that is not being retained i e when the Retain Option not selected An initial value cannot be set for an internal variable if the Retain Option is selected Internal variables that are not being retained will be initialized to O The initial value will not be written to the internal variable if the IOM Hold Bit A50012 is ON Auxiliary Area control bit Initial value IOM Hold Bit A50012 ON OFF The initial value will not be set The initial value will be set Function Block
19. 2 Click the OK Button A contact will be entered with the function block inter nal variable aaa as the operand variable type internal Untitled CX Programmer NewPLC1 FunctionBlock1 FB Ladder 5 x F5 Fie Edit View Insert PLC Program Tools Window Help laj xl DSA SA sOO Qo mEBl Cr A5E LU B AR RSPR DTPT wea x a AQ JES Ramie OB REEL amp Cea DPA 88 2h E E 29 39 36 ilz f Name Data Type Ar Initial Value Retai Comment E NewProject EN BOOL FALSE Controls execution of the Function Block B I NewPLC1 CJ1G H Offline wi aaa BOOL FALSE Symbols QT 10 Table S settings s Memory amp SB Programs Externals E G NewProgramt 00 a 53 Symbols Sectiont Q END S fF Function Blocks FunctionBlockt Contact entered with function block internal variable aaa as operand The rest of the ladder program is input in exactly the same way as for stan dard programs with CX Programmer Note Addresses cannot be directly input for instruction operands within function blocks Only Index Registers IR and Data Registers DR can be input directly as follows not as variables Addresses DRO to DR5 direct specifica tions IRO to IR15 and indirect specifications IRO to IR15 Using Structured Text An ST language program see note can either be input directly into the ST input area or a program input into a general purpose text
20. Cannot be set Must be set Initial Value Can be set Cannot be set See note 1 Can be set Cannot be set Retained Can be set Cannot be set See note 1 Can be set Cannot be set Size Can be set See note 2 Cannot be set Cannot be set 1 The value of the input parameter will be given 2 Valid only for STRING variables Cannot be set Variables Section 1 3 1 3 5 Internal Allocation of Variable Addresses When an instance is created from a function block definition the CX Program mer internally allocates addresses to the variables Addresses are allocated to all of the variables registered in the function block definition except for vari ables that have been assigned actual addresses with the AT Settings prop erty FB instance areas Program Non retained area Instance of function block definition A Starting address 15 0 g CIO H W ta Input 0 00 a b Output 2 00 HHD ore Area 4 Size words t Output 5 00 Retained area Note Variable c is an internal Starting address 15 o variable so it is not displayed HDorE 4 Ar zor 1 Size words Usage Inputs rea j Properties m Name Type AT initial Value Retained Timer area a BOOL e tarting address Size Completion Usage Outputs d T Area Flags Properties
21. Output one line of numeric data to file WRITE_TEXT CsvLineStr FileName n 0 END_IF Related Auxiliary Address Description Area Flag File Memory Opera A343 13 ON when any of the following conditions exists tion Flag CMND instruction sending a FINS command to the local CPU Unit File Memory Instruction being executed Program replacement using the control bit in the Auxiliary Area Easy backup operation Memory Card A343 15 ON when a Memory Card has been detected Detected Flag For further information and precautions on related Auxiliary Area flags refer to the section on the FWRIT File Memory Instruction in the CS CJ series Instruction Reference Manual Communications Functions TXD CPU Send String via CPU Unit RS 232C Port Function Sends a text string from the RS 232C port on the CPU Unit Application TXD CPU Send string Conditions The serial communications mode of the RS 232C port must be set to no protocol communications Arguments and Return Values STRING Specifies the text string to send 209 Function Descriptions Appendix C Example CPU Unit Get Scene Number command READ RS 232C port Barcode Reader Variables BOOL DoSendData Variable to control send function INT iProcess Process number STRING Message Send message i BOOL SendEnableCPUPort Send Ready Flag AT A392 05 Send data when
22. CASE variable OF 1 expression 1 2 expression 2 3 expression 3 ELSE expression 4 END CASE FOR TO BY DO Repeatedly evaluates an expression FOR identifier initial value TO END FOR according to the initial value final final value BY increment DO value and increment expression END FOR WHILE DO END WHILE Repeatedly evaluates an expression WHILE condition DO as long as a condition is true expression END WHILE REPEAT UNTIL Repeatedly evaluates an expression REPEAT END REPEAT until a condition is true expression UNTIL condition END REPEAT EXIT Stops repeated processing EXIT RETURN ST program RETURN Ends the ST task that is being exe cuted and executes the next task ST used in SFC Ends the SFC action program that is being executed and executes the next action program ST used in a function block Returns from the called program to the point in the calling program where the call occurred Function block instance call Calls a function block definition When used in a function block Variable name with FUNCTION BLOCK data type called function block definition s input variable name calling function block definition s variable name or constant called function block definition s output vari able name or constant gt calling func tion block definition s output variable name ST Language Configuration Se
23. ELSIF average criterion margin THEN red lamp TRUE 9i ELSE green lamp TRUE END_IF Project For Help press F1 NewPLC1 Offline Ln 1 Col 1 If the symbol table with the registered variables is displayed while inputting the ST program it is easy to reference the variable names for program ming Note 1 Tabs or spaces can be input to create indents They will not affect the al gorithm 2 When an ST language program is input or pasted into the ST input area syntax keywords reserved words will be automatically displayed in blue comments in green text strings in brown errors in red and everything else in black 181 Procedures Section 6 1 3 To change the font size or colors select Options from the Tools Menu and then click the ST Font Button on the Appearance Tab Page The font names font size default is 8 point and color can be changed 4 For details on ST language specifications refer to SECTION 5 Structured Text ST Language Specifications in Part 2 Structured Text ST in this manual Registering Variables When using structured text a dialog box will not be displayed to register the While Using variable whenever a variable name that has not been registered is input Be Structured Text sure to always register variables used in standard text programming in the variable table either as you need them or after completing the program Entering Functions and Variables 1 2
24. P_Off Interlocked Interlock will not affect instructions in the function block definition An instance will not be executed while its EN input variable is OFF so the fol lowing precautions are essential when using a Differentiation Instruction in a function block definition Differentiation Instructions include DIFU DIFD and any instruction with an or prefix As long as the instance s EN input variable is OFF the execution condition will retain its previous status the last status when the EN input variable was ON and the Differentiation Instruction will not operate 53 Programming Restrictions Timer Instructions in Function Block Definitions 54 Section 2 4 When the instance s EN input variable goes ON the present execution condition status will not be compared to the last cycle s status The present execution condition will be compared to the last condition when the EN input variable was ON so the Differentiation Instruction will not operate properly If the EN input variable remains ON the Differentiation Instruction will operate properly when the next rising edge or falling edge occurs Example 0 0 i FB1 I EN ENO A A TIDEN TORINI IN1 OUTi SET OUTI These Differentiation Instructions do not operate when input condition 0 00 goes from OFF to ON the first time The instructions do not operate while input conditio
25. Restriction on Specifying Data Structures as Parameters When Nesting Function Blocks Restriction on the Address Incremental Copy Function When calling another function block from within a function block i e when nesting function blocks you cannot specify individual members of the data structure as parameters for the nested function block You must specify the entire data structure When a function block is used in the selected section the Address Incremen tal Copy function cannot be used 2 5 Function Block Applications Guidelines This section provides guidelines for using function blocks with the CX Pro 2 5 1 Integer Data Types 1 2 or 4 word Data 58 Note grammer Deciding on Variable Data Types Use the following data types when handling single numbers in 1 2 or 4 word units INT and UINT DINT and DINT LINT and ULINT Use signed integers if the numbers being used will fit in the range Function Block Applications Guidelines Section 2 5 Word Data Types 1 2 or 4 word Data Text String Data Use the following data types when handling groups of data non numeric data in 1 2 or 4 word units WORD DWORD L WORD Use the following data type for text string data STRING 2 5 2 Determining Variable Types Inputs Outputs In Out Externals and Internals Using Input Variable to Change Passed Values To paste a function block into the program and then cha
26. amp 10 OFF TIME Pulse 4sON 1sOFF P On CLOCK PULSE El ENO ON TIME amp 10 OFF TIME 37 Function Block Specifications Variables Condition Section 2 1 Name Retained Comment tmp Data Type AT Initial Value DINT 0 Internals Inputs Outputs Externals Algorithm Body EN D100 i Li inte ours2 __ 91000 IN32 Variable table 10 0 0 0 ADD_INT_DINT EN ENO SIGN IN16 tmp L IN32 tmp OUT32 Internal variable tmp Name Type is not displayed Internal tmp DINT Input EN BOOL Input _ N16 INT Input IN32 DINT Output ENO BOOL Output ouTs2 DINT Retain Data through Power Interruptions and Start of Operation Internal variables retain the value from the last time that the instance was called In addition the Retain Option can be selected so that an internal vari able will also retains its value when the power is interrupted or operation starts the mode is switched from PROGRAM to RUN or MONITOR mode When the Retain Option is selected the value of the variable is retained when the power is interrupted or operation starts unless the CPU Unit does not have a backup battery If the CPU Unit does not have a good battery the value will be unstable Variables Condition Saus Retained Retained Variables set to Retain Start of operation Power ON
27. Cancel Enter the function block instance name and click the OK Button An in stance of the function block definition will be inserted below the original program circuits as shown below sample01 CX Programmer NewPLC1 NewProgram1 Section1 Diagram 5 xj P Fle Edt yew Inset PLC Program Took Window Help 13 x pnzum jen smecj ass evllases sn s2R ese mmomT w a a QQ ESEE iE mR 4r ur 1 O C E E EL IX amp m niu ep 4 IProsrom Name Newrogrant 4 Fi B tsection Name Section e Start Lmt Eror Setting d H Vt Vt l m aq seting 4 4 un Madri T movo Move s amp S Sectiont v Gata Source word ew 5 4E Function Blocks a AE FunctionBlockt BE Dio Destination E Sel Complete EL E Set_Complete Temp serm Run 7 VA 5 sempe FunctionBlockt oou 8000 EN NO oou E001 Stet Run a conation insertot shit nit i 5 IET J Project ad sd Name Address or Value Comment X PLCName Browse IE T T DPN Conoie A Find Report Transfer 7 ram gag Goo S EB 22 39 26 e we For Help press F1 NewPLCI Net 0 Node 0 Offline Fung3 9 0 100 MM 9 Enterthe input conditions and parameters for the instance that was insert ed The function block definition generation function is convenient for converting existing ladder programming that has been pr
28. FB Instance Default value Applicable memory Area Start address End address arcas Non Retain CIO WR DM See note Retain Timers Counters Note Bit data can be accessed even if the DM Area is specified for the non retained area CP series CPU Units FB Instance Default value Applicable memory Area Start address End address areas Non Retain CIO WR HR DM See note Retain HR DM See note Timers TIM Counters CNT 105 Procedures Section 3 2 Note DM area of CP1L L Address CP1L L D0000 to D9999 Provided D10000 to D31999 Not Provided D32000 to D32767 Provided 3 2 7 Checking internal Address Allocations for Variables The following procedure can be used to check the I O memory addresses 1 2 3 106 internally allocated to variables 1 Select View Symbols Global 2 Select the instance in the global symbol table right click and select Func tion Block SFC Memory Address from the pop up menu Alternately select Memory Allocation Function Block SFC Memory Function Block SFC Memory Address from the PLC Menu Example Instance name displayed in global variable table automatically registered Edit PUF P_Step P_Output_ 4A Validate Symbols Insert Symbol PAT ss Letons Plow Bal Cut PJE Ba cop o P IO Verif E PH PST P Reusable File gt
29. Function block program mem ory Kbytes 256 Comment files Kbytes Program index files Kbytes Variable tables Kbytes NSJ series NSJ Controllers Max number of I O points NSJ5 TQO G5D NSJ5 SQ0 NSJ8 TVO G5D NSJ10 TVO NSJ12 TSO0 G5D 1 280 NSJ5 TQO NSJ8 TVO M3D NSJ5 SQO M3D Program capacity steps 60K Data memory 32K words Extended data memory 32K words X 3 banks EO 00000 to E2 32767 Function blocks Maximum num ber of definitions 1 024 Maximum num ber of instances 2 048 Inside comment memory 76 Function block program mem ory Kbytes 1 024 Comment files Kbytes 64 Program index files Kbytes 64 Variable tables Kbytes CPU Unit Function Block Specifications Section 2 8 FQM1 Flexible Motion Controllers Model Coordinator Module Motion Control Modules FQM1 CM002 FQM1 MMA22 FQM1 MMP22 Max number of I O points 344 points 24 built in 20 built in points points 320 points on Basic I O Units Program capacity steps 10K Data memory 32K words Function blocks Maximum num ber of definitions 128 Maximum num ber of instances 256 Inside comment Function block memory program mem ory Kbytes 256 Comment files Kbytes
30. P_First_Cy P Fist Cy Rename PER P EQ EST Properties Delete Data Type _Address value Rack Location usage Comment Work WR Area Parameter Work Underflow UF Flag Work Step Flag Work Output OFF Bit Work Always ON Flag Work Always OFF Flag Work Overflow OF Flag Work Not Equals NE Flag Right click on the instance name and select Function Block Instance Address Work Less Than LT Flag Work Low Battery Flag Work Less Than or Equals LE Flag Work _ T O Verification Error Flag Work HR Area Parameter Work Greater Than GT Flag Work Greater Than or Equals GE Fl Work First Task Execution Flag Work First Cycle Flag Work Instruction Execution Error ER Work Equals EQ Flag 3 The FB Interface Memory Dialog Box will be displayed Check the I O memory addresses internally allocated to variables here Example Addresses used internally for the input variables FB Instance Memory InstanceD1 Internals Inputs outputs Close Procedures Section 3 2 Method Used for Checking Addresses Internally Allocated to Variables Program Instance of function block definition A instance name sample a b c Right click and select Function Instance registered in global Block Memory Address symbol table under instance name FM Instance Memory Dialog Box Name Type P cerees ERE Type
31. a ASIN b arc sine of variable b stored in variable a Arc cosine COS argu ACOS b l ment arc cosine of variable b stored in variable a ASIN argument REAL LREAL REAL LREAL Arc sine SIN argument ACOS argument REAL LREAL REAL LREAL 146 ST Language Configuration Function ATAN argument Argument data type REAL LREAL Return value data type REAL LREAL Description Arc tangent TAN argu ment Section 5 4 Example a ATAN b arc tangent of variable b stored in variable a EXPT base expo Base nent REAL LREAL REAL LREAL Exponential Base Ponent a EXPT b c Exponent INT DINT LINT UINT UDINT ULINT REAL LREAL Exponential with variable b as the base and variable c as the exponent is stored in variable a MOD dividend data divisor data Dividend INT UINT UDINT ULINT DINT LINT INT UINT UDINT ULINT DINT LINT Note Text String Functions Divisor INT UINT UDINT ULINT DINT LINT Remainder a MOD b c Remainder found by divid ing variable b by variable c is stored in variable a The data type returned for numerical functions is the same as that used in the argument Therefore variables substituted for function return values must be the same data type as the argument Funct
32. nternal variables FREAD omitted omitted omitted read data O A two element array can be used to store the result from a ladder program s SIGNED BINARY DIVIDE instruction The result from the instruction is D quotient and D 1 remainder This method can be used to obtain the remain der from a division operation in ladder programming When ST language is used it isn t necessary to use an array to receive the result of a division operation Also the remainder can t be calculated directly in ST language The remainder must be calculated as follows Remainder Dividend Divisor x Quotient 2 5 5 Specifying Addresses Allocated to Special I O Units Note 1 2 3 Use Index Registers IRO to IR15 indirectly specified constant offset to spec ify addresses allocated to Special I O Units based on the value passed for the unit number as an input parameter within the function block definition as shown in the following examples For details on using Index Registers in function blocks refer to 2 5 6 Using Index Registers Examples Example 1 Specifying the ClO Area within a Function Block Same for DM Area Special I O Units Variables Use the unit number as an input variable and specifying the first allocation address as an internal variable with the AT set to CIO 2000 Programs Use the following procedure 1 Multiply the unit number input variable by amp 10 and create the unit num ber offset internal
33. required when the function block is executed Type usage of the variable Name of the variable Data type of the variable Initial value of the variable Enter the programming logic in ladder or structured text Enter the programming logic using variables Input constants directly without registering in variables Function blocks can have comments Function Block Each function block definition has a name The names can be up to 64 char Definition Name acters long and there are no prohibited characters The default function block name is FunctionBlock_ where LI is a number assigned in order Function block definition name CLOCK PULSE EN ENO BOOL BOOL ON TIME INT OFF TIME INT Language Select either ladder programming language or structured text ST language Note 1 For details on ST language refer to SECTION 5 Structured Text ST Language Specifications in Part 2 Structured Text ST 2 When nesting function blocks using ST language and ladder language can be combined freely version 6 0 and higher only Variable Definitions Define the operands and variables used in the function block definition Variable Names Variable names can be up to 30 000 characters long Variables name cannot contain spaces or any of the following characters 1 9206 amp 2 V Qo 0 1 5 7 Variable names cannot start with
34. s icon will change to indicate that it is protected The icon also indicates the protection level as shown below Prohibit writing and display same for ladder and ST AF Prohibit writing ladder F Prohibit writing ST Protecting Multiple __ Use the following procedure to set the password protection for two or more Function Block Definitions function block definitions at the same time 1 2 3 1 Select Function Blocks in the project workspace right click and select Function Block Protection Set from the pop up menu 2 The Function Block Protection Collective Setting Dialog Box will be dis played Select the names of the function blocks that you want to protect select the Protection Type protection level input the password and click the Set Button Function Block Protection Colle X Input the password after selecting Function Blocks Function Block Name FunctionBlock1 O FunctionBlock2 FunctionBlock3 O FunctionBlock4 FunctionBlock5 O FunctionBlock6 FunctionBlock LI FunctionBlock8 FunctionBlock8 Password 0 7 3 The selected function block definitions will be password protected 113 Procedures Section 3 2 Clearing Password Protection This operation can be performed offline only Password protection can be cleared from an individual function block defini tion or multiple function block definitions together Clearing Password Use the following procedure to clear the password p
35. 186 177 Procedures Section 6 1 6 1 Procedures This section explains how to create ST programs For details on creating a function block with ST language refer to SECTION 3 Creating Function Blocks in Part 1 Function Blocks of this manual 6 1 1 Creating a Project 1 2 3 1 Start the CX Programmer and select File New 2 Inthe Change PLC Dialog Box select a PLC model that supports ST pro grams from the Device Type list Refer to 4 2 1 PLC Models Compatible with ST Programs ST Tasks for a table of the PLC models that support ST programs 3 Click the Settings Button and select the CPU Type For details on other settings refer to the CX Programmer Operation Manual W446 6 1 2 Creating a New ST Program Use the following procedure to create an ST program in a project 1 2 3 1 Right click the Programs Item in the project workspace to display the pop up menu 2 Select Insert Program ST from the pop up menu n T axl o Pa Name NewProgram1 z NewProject E E NewPLC1 CJ1G H Offline 3 Symbols QF 10 Table and Unit Setup E RN EEN ENE E Settings 4 GF Memory m Section Name Section 8 Ladder Insert Program em Structured Text X s Ba Co tp src F Fun e Paste v allow Docking Hide Float In Main Window Properties An ST program will be inserted in the project workspace and the ST Editor will be displayed on the right side of the workspace Note 1 Lad
36. 2 22507385850720 x 10308 0 2 22507385850720 x 107908 to 1 79769313486232 x 10308 WORD 16 bit data 16 0000 to FFFF or amp 0 to 65 535 DWORD 32 bit data 32 00000000 to FFFFFFFF or amp 0 to 4 294 967 295 LWORD 64 bit data 64 0000000000000000 to FFFFFFFFFFFFFFFF or amp 0 to 18 446 744 073 709 551 615 STRING See note 3 Text string Variable FUNCTION BLOCK Function block instance CHANNEL Word See note 1 NUMBER Constant or number See note 2 TIMER Timer Comple tion flag 1 Present value 16 Timer No 0 to 4095 Timer completion flag O 1 Timer PV 0 to 9999 BCD 0 to 65535 Binary Counter Note Comple tion flag 1 Present value 6 Counter No 0 to 4095 Counter completion flag 0 1 Counter PV 0 to 9999 BCD 0 to 65535 Binary 1 In ST programs these data types are recognized as the following data types UNIT BCD is recognized as WORD UDINT BCD is recognized as DWORD e ULINT BCD is recognized as L WORD CHANNEL is recognized as WORD 2 This data type cannot be used in an ST program A program error will oc cur if this data type is specified 8 Refer to the Section 5 3 Inputting ST Programs for the input method 139 Inputting ST Programs Section 5 3 5 2 2 Derivative Data Types 5 3 5 3 1 Statement Delimiters Syntax Rules Comments Spaces Carriage Returns
37. Array index out of range An array index larger than the array size was specified Array 100 10 Array is an array variable with an array size of 100 Conversion cannot convert from 96s to s A numeric equation in which the data type of the operation result does not match the vari able at the substitution desti nation and a variable that is different from the data type was substituted Y ABS X X is an INT type variable Y is a UINT type variable Division by Zero The numeric expression con tains division by 0 End of comment not found The comment does not have a closing parenthesis and aster isk corresponding to the opening parenthesis and asterisk of the comment comment Invalid Literal Format s The numeric format is illegal X 123_ There is no numeral after underscore X 1 23 The underscore is followed immediately by another underscore X 2 301 Y 8 90 A numeral that cannot be used with binary or octal values has been used Note The underscore can be inserted between numerals to make them easier to read Placing 2 8 and 164 at the beginning of the numeral expresses the numerals as binary octal and hexadecimal values respectively Invalid Literal Value The numeric value is illegal X 1e2 an index was used for a numeric value that was not a REAL data type Note e indicates an exponent of 10 Invalid arra
38. DINT LINT WORD DWORD LWORD REAL LREAL Input data BOOL INT UINT UDINT Specifies the input data ULINT DINT LINT WORD DWORD LWORD REAL LREAL Upper limit data BOOL INT UINT UDINT Specifies the upper limit ULINT DINT LINT WORD DWORD LWORD REAL LREAL Return value BOOL INT UINT UDINT Returns the output data ULINT DINT LINT WORD DWORD LWORD REAL LREAL 203 Function Descriptions Appendix C Note When the input data is smaller than the lower limit data the value of the lower limit data is returned as the result When the input data is bigger than the upper limit data the value of the upper limit data is returned as the result When the input data is a value between the upper limit data and lower limit data the value of the input data is returned as the result The same data type must be set for the arguments and the return value Result Upper limit MX F 77777 Data1 7 7 Lower limit MN Example Variables INT MN MN 123 Data1 456 MX 789 INT Data1 INT MX Result LIMIT MN Data1 MX INT Result 456 is stored in the Result variable Data Selection Functions SEL Data Selection Function Selects one of two data according to the selection condition Application Heturn value SEL Selection condition Selection target data1 Selection target data2 Arguments and Return Values Variable name Data type Description Sele
39. Monitor FB Instance When monitoring the program online monitors ST variable status as well as I O bit and word status I O bit monitor of the ladder diagram in the instance Supported by CX Programmer Ver 6 1 and later only Register in Watch Window Displays the FB variables registration Dialog Box in order to register a variable from the selected instance to the Watch Window Function Block Definition Shortcut Keys F Key Pasting Function Block Definitions in Program Enter Key Inputting Parameters Displays the selected instance s function block definition on the right side of the window Move the cursor to the position at which to create the copied function block instance in the Ladder Section Window and press the F Key This operation is the same as selecting nsert Function Block Invocation Position the cursor at the left of the input variable or input output variable or at the right of the output variable and press the Enter Key This operation is the same as selecting nsert Function Block Parameter 1 2 Function Blocks 1 2 1 Outline A function block is a basic program element containing a standard processing function that has been defined in advance Once the function block has been defined the user just has to insert the function block in the program and set the I O in order to use the function As a standard processing function a function block does not contain actual addresses
40. OUT2 FB OUT3 OUT3 ENO gt B EN and ENO not entered Instance FB FB IN1 IN1 FB IN2 IN2 FB IN3 IN3 FB_OUT1 gt OUT1 FB_OUT2 gt OUT2 FB_OUT3 gt OUT3 ENO not entered Instance_FB EN A FB_IN1 IN1 FB_IN2 IN2 FB_IN3 IN3 FB_OUT1 gt OUT1 FB_OUT2 gt OUT2 FB_OUT3 gt OUTS3 FB_OUT2 data not required Instance_FB EN A FB_IN1 IN1 FB_IN2 IN2 FB_IN3 IN3 FB_OUT1 gt OUT1 FB_OUT3 gt OUT3 ENO gt B 171 Statement Descriptions Section 5 5 Instance_FB FB_IN1 IN1 FB_IN2 IN2 FB_IN3 IN3 FB_OUT1 gt OUT1 FB_OUT3 gt OUT3 Different order of entry Instance FB EN A FB IN1 IN1 FB OUT1 OUT1 FB IN2 IN2 FB_OUT2 gt OUT2 FB_IN3 IN3 FB_OUT3 gt OUT3 ENO gt B B Example of Entry Method 2 In this example only parameter variables including constants of a new instance are entered Instance FB IN1 IN2 IN3 OUT1 OUT2 OUT3 Instance FB IN1 IN2 IN3 OUT1 The arguments and return values must be listed in a fixed order Input variable 1 Input variable 2 Output variable 1 Output variable 2 The input variables arguments must be at the beginning of the list or just after the EN variable if the EN variable is listed An output variable can be omitted if the data is not actually being used and the output variable is not in the middle of the list of output variables Example Instance FB IN1 IN2 INS OUT1 OUTS In this case the OUT3 at the end of the list would return the value f
41. Save the contents of Index Regis ter IRO by storing it in Save A O internal variable data type DINT 1 array element Using Index Registers Example The real I O memory address for 1 Setting the value in the Index Register Stores the real I O memory the first word of CIO 1500 unit number X address for first CIO Area word n 25 allocated in the CPU Bus Unit allocation area based on the CPU Bus Unit s unit number amp 0 to amp 15 passed from the func tion block is stored in IRO Calculate offset address from unit number Procedure Enn tne Assumes that unit numbers amp 0 to amp 15 have 825 Mutipicanal wora already been input from outside the func tion block in UnitNo input variables INT data type Poet mesut wora 1 Multiple UnitNo by amp 25 and store in Off Unt Notas set internal variable DINT data type MOVR 680 Move To Register 2 Store the real I O memory address for SCPU ev Source wordt SCPU Relay internal variable WORD umen fl iaten traes regten data type if required specify the array as 400 elements see note AT setting 1500 in Index Register IRO L 401 Double Signed Binary Add Without Carry RU Frst augend word Note Specifying an array for SCPU relay such as SCPU relay 2 for example 1 enables the address CIO 1500 JR Rete wd UnitNo X amp 25 2 to be specified i This also applies in example 2 below 3 Increment the real I O memory address in Index
42. Tabs 140 Data type Content Array 1 dimensional array 32 000 elements max Structure User defined data type Inputting ST Programs Statements assignment and control statements must always end in a semicolon The statement cannot be completed by simply using a car riage return Do not use a semicolon as a delimiter within a statement such as fol lowing reserved words values or equations Inserting a semicolon within a statement except at the end of a statement will result in a syntax error e Comments are enclosed in parentheses and asterisks i e comment Any characters except parentheses and asterisks can be used within a comment Nesting within comments is not supported Notation Example comment this is the comment Note Nesting in comments is not possible i e this type of nesting is not supported e Any number of spaces carriage returns and tabs or combinations of these can be used anywhere within statements Therefore use spaces carriage returns and tabs between reserved words and equations to make them easier to read Spaces carriage returns and tabs cannot be used between the following tokens the smallest meaningful unit for compiling in which case they are referred to as token separators Tokens Reserved words variable names special characters constants numerical values Reserved words upper or lower case AND CASE DO ELSE
43. and C are INT data types A B C is possible If however A and B are INT data types but C is a REAL data type or LINT data type a syn tax error will occur for A B C n the structured text the following cannot be used P CY P EQ P ER P N P GE P GT P LE P LT P NE P OF and P UF E Monitor Restrictions 174 There are following restrictions on monitoring timer functions When you use a TIMER type variable in a TENTH MS TIMER or HUN DREDTH MS TIMER the present value of the TIMER type variable of the timer function is not displayed on the ST monitor view In this case is displayed for the present value When the present value of the TIMER type variable is used in another place on the ST editor or assigned to a different variable their present val ues are undependable Restrictions Section 5 7 There are following restrictions on using 2 byte characters in variable names When you use any 2 byte characters in a variable name insert a single byte space between the variable and the operator Without the space the present value of the variable may not be monitored correctly 5 7 2 Commonly Asked Questions Q How is a hexadecimal value expressed A Add 16 before the value e g 16 123F The prefixes 8 and 2 can also be added to express octal numbers and binary numbers respectively Numbers without these prefixes will be inter preted as decimal numbers Q How many times can FOR be u
44. and equals sign B Statement Syntax Variable Equation variable or constant B Usage Use assignment statements for inputting values in variables This is a basic statement for use before or within control statements This statement can be used for setting initial values storing calculation results and incrementing or decrementing variables B Description Substitutes stores an equation variable or constant for the variable Examples Example 1 Substitute variable A with the result of the equation X 1 A X41 Example 2 Substitute variable A with the value of variable B A zB Example 3 Substitute variable A with the constant 10 A z10 E Precautions The data type of the equation variable or constant to be assigned must be the same as the data type of the variable to be substituted Otherwise a syn tax error will occur 5 5 2 Control Statements IF Statement Single Condition BH Summary This statement is used to execute an expression when a specified condition is met If the condition is not met a different expression is executed B Reserved Words IF THEN ELSE END IF Note ELSE can be omitted B Statement Syntax IF condition THEN expression 1 ELSE expression 2 END IF 155 Statement Descriptions Section 5 5 B Process Flow Diagram E Usage Use the IF statement to perform a different operation depending on whether a single condition condition e
45. condition equation is met B Description Condition 1 If true execute expression 1 Condition 1 If false Condition 2 f true execute expression 2 Condition 2 f false Condition 3 If true execute expression 3 etc Condition n If true execute expression n If none of these conditions are met condition m is executed B Precautions IF must be used together with END IF e Condition contains the true or false result of the equation e g IF A gt 10 A boolean BOOL data type variable only can also be specified as the condition rather than an equation For boolean conditions the result is true when the variable value is 1 ON and false when it is 0 OFF Statements that can be used in expression are assignment state ments IF CASE FOR WHILE or REPEAT 158 Statement Descriptions Section 5 5 e Multiple statements can be executed in expression Be sure to use a semicolon delimiter between multiple statements in an expression The ELSE statement can be omitted When ELSE is omitted no opera tion is executed if the result of any condition equation is false B Examples Example 1 If variable A gt 0 is true variable X will be substituted with numerical value 10 If A gt 0 is false but variable B 1 variable X will be substituted with numerical value 1 If A gt 0 is false but variable B 2 variable X will be substituted with numerical value 2 If either
46. e Name Type AT initial Value Retained Counter area b BOOL ws I Startin Size Completion t TIMER Automatic allocation of aa C Area Pegs P addresses by system Usage Internals E Example Properties gt E IName Type AT Initial Value Retained c IBOOL 2000 00 Manual allocation of address to variable in FB by AT Settings option Setting Internal Allocation The user sets the function block instance areas in which addresses are allo Areas for Variables cated internally by the system The variables are allocated automatically by the system to the appropriate instance area set by the user Setting Procedure Select Function Block SFC Memory Function Block SFC Memory Allo cation from the PLC Menu Set the areas in the Function Block SFC Memory Allocation Dialog Box 21 Variables Section 1 3 Function Block Instance Areas CJ2 series CPU Units FB Instance Default value Applicable memory Area Start address End address argas Non Retain CIO WR HR DM EM See note Retain HR DM EM See note Timers TIM Counters CNT Note Force setting resetting is enabled when the following EM banks are specified CJ2H CPU64 EIP CPU65 EIP EM bank 3 CJ2H CPU66 EIP EM banks 6 to 9 CJ2H CPU67 EIP EM banks 7 to E CJ2H CPU68 EIP EM banks 11 to 18 CS CJ series CPU Units Ver 3 0 or Later and NSJ Controllers FB Instance Default value App
47. previous version Revision code February 2005 Revised content Original production November 2005 Added Ver 6 1 upgrade information such as information on the Simulation functions and ST program variable monitoring July 2006 Added Ver 7 0 upgrade information January 2007 Pages 17 and 18 Changed can to cannot in table two locations and changed note Page 29 Changed text in inputs cell for the status of value at next execution Page 213 Changed illustration Pages 214 216 to 218 and 202 Changed illustration and changed code Pages 215 and 219 Changed text in bottom right cell July 2007 Added upgrade information from Ver 7 0 to Ver 7 2 June 2008 Added upgrade information from Ver 7 2 to Ver 8 0 February 2009 Added upgrade information from Ver 8 0 to Ver 8 1 December 2009 Added upgrade information from Ver 8 3 to Ver 9 0 February 2010 Added upgrade information from Ver 9 0 to Ver 9 1 October 2010 Added upgrade information from Ver 9 1 to Ver 9 2 January 2011 Added upgrade information from Ver 9 2 to Ver 9 3 August 2012 Page xi Changed catalog number from W445 to W464 Pages xii and xiii Changed manual names for W339 W394 W340 and W342 Page xiii and xiv Added model numbers for W452 and W463 Page xxiv Modified the description of the third paragraph from the top Page 52 Modified the description of the
48. refer to 1 6 Version e CJ1G H CJ1G CPU42H 43H 44H 45H Upgrade Information CJ1H H CJ1H CPU65H 66H 67H 64H R 65H R 66H R 67H R CJ1M CJ1M CPU1 1 12 13 21 22 23 The following CP series CPU Units are compatible CP1H CP1H X XA Y CP1L CP1L M L Note If a user program containing function blocks created on the CX Program mer Ver 5 0 or later is downloaded to a CPU Unit that does not support function blocks CS CJ series CPU Units with unit version 2 0 or earlier all instances will be treated as illegal commands and it will not be possi ble to edit or execute the user program G5D Used for the NSJ5 TQOL J G5D NSJ5 SQO0L1 G5D NSJ8 TVOLI G5D NSJ10 TVOLI G5D and NSJ12 TSOLJ G5D M3D Used for the NSJ5 TQOLI M3D NSJ5 SQOL M3D and NSJ8 TVOLI M3D FOM1 CM FQM1 CM002 FQM1 MMA FQM 1 MMA22 FQM1 MMP FQM1 MMP22 CS CJ CP Series Function Restrictions Instructions Not Supported in Function Block Definitions Block Program Instructions BPRG and BEND Subroutine Instructions SBS GSBS RET MCRO and SBN Jump Instructions JMP CJP and CJPN Step Ladder Instructions STEP and SNXT Immediate Refresh Instructions VO REFRESH IORF ONE MS TIMER TMHH and TMHHX These tim ers can be used with CJ1 H R CPU Units Note For details and other restrictions refer to 2 4 Pro
49. subroutine number Maximum value of 1 024 256 1 024 256 jump number in JMP instruction Internal inputs 10 points e 4 interrupt inputs pulse catch e 2 high speed counter inputs 50 kHz phase dif ference or 100 kHz single phase Internal outputs 6 points 6 points e 2 pulse outputs 100 kHz 2 pulse out e 2 PWM outputs puts 100 kHz 1 PWM out put Function Maxi 128 blocks mum number of definitions Maxi 256 mum number of instances Com Total for 704 ment all files Memory Kbytes Unit ver 4 0 or later Inside Function 256 com block pro ment gram memory memory ver 3 0 Kbytes or later Com 64 ment files Kbytes Program 64 index files Kbytes Variable 64 tables Kbytes CP1H CPU Units 74 CPU Unit Function Block Specifications Section 2 8 Item X models XA models Y models Model CP1H X40DR A CP1H XA40DR A CP1H X40DT D CP1H XA40DT D CP1H X40DT1 D CP1H XA40DT1 D CP1H Y20DT D Max number of I O points 320 points 40 built in points 40 points Expansion Rack x 7 Racks 300 points 20 built in points 40 points Expan sion Rack x 7 Racks Program capacity steps 20K Data memory 32K words Number of connectable Expan sion Units and Expansion I O Units 7 Units CP series Expansion Units and Expansion I O Units Function blocks Maximum num ber of definitions 128 Maximu
50. 2 1N N T 9 D 0 E E E P Dll DL L lt E gt M E e The numbers O to 9 cannot be used as the first character of variable names An underscore cannot be followed immediately by another underscore in variable names Spaces cannot be used in variable names An error message will occur if any of these characters are used in this way Operator Priority Consider the operator priority in the structured text syntax or enclose operations requiring priority in parentheses Example AND takes priority over OR Therefore in the example X OR Y AND Z priority will be given to Y AND Z STRING Data Type The following text strings are supported Strings with up to 255 alphanumeric characters The text strings are not case sensitive Text strings defined in the ST language are stored in PLC memory as fol lows Data for the Text String 123456 n n 1 n 2 The null code 00 is stored nas at the end of the text string Place text strings inside signal quotation marks Indicates the text string A ASCII 41 Indicates a text string containing a single space ASCII 20 Indicates an empty text string 141 Inputting ST Programs Section 5 3 Two hexadecimal digits following a dollar sign are interpreted as hexa decimal values Notation Description The hexadecimal number 02 start code 03 The hexadecimal number 03 end code Certain alph
51. 7 Restrictions 5 7 1 Restrictions Section 5 7 ENO true ELSE ENO false RETURN END_IF Num BCD INT TO BCD WORD Input Num For example if Num is 100 1650064 it is converted to BCD 0100 Output String WORD TO STRING Num BCD Convert BCD 0100 to text string B Nesting There is no restriction on the number of nests that can be used in IF CASE FOR WHILE or REPEAT statements B Data Type Restrictions Integers can only be allocated to variables with data types WORD DWORD INT DINT UINT UDINT or ULINT For example if A is an INT data type A 1 it possible If the value is not an integer data type a syn tax error will occur For example if A is an INT data type a syntax error will occur for A 2 5 f a real number floating point decimal data can only be allocated to vari ables with data types REAL and UREAL For example if A is a REAL data type A 1 5 is possible If the value is not an real data type a syntax error will occur For example if A is a REAL data type a syntax error will occur for A 2 Use A 2 0 Bits TRUE FALSE can only be allocated to variables with the BOOL data type For example if A is a BOOL data type A FALSE is possible If a BOOL data type is not used a syntax error will occur For example if A is an INT data type a syntax error will occur for A ZFALSE Data types must all be consistent within the structured text For example if A B
52. Address sample FB FunctionBlocki N A Auto a__ BOOL W400 00 Outputs Name Type Address Instance name e BOOL W401 02 Addresses used for function block internal variables Checking the Status of The following procedure can be used to check the number of addresses allo Addresses Internally r cated to variables and the number still available for allocation in the function Allocated to Variables block instance areas 1 2 3 1 Select the instance in the Ladder Section Window right click and select Memory Allocation Function Block SFC Memory Function Block SFC Memory Statistics from the PLC Menu 2 The Function Block SFC Memory Statistics Dialog Box will be displayed as shown below Check address usage here Function Block SFC Memory Statist x Memory Area Available FB Non Retained 896 27 869 FB Retained 128 0 128 FB Timer 1024 0 1024 FB Counter 1024 0 1024 SFC Bit Share with F Share with E The total number The number of of words in each The number words still available interface area of words already used Optimizing Function When a variable is added or deleted addresses are automatically re allocated Memory in the variables instance area Consecutive addresses are required for each instance so all of the variables will be allocated to a different block of addresses if the original block of addresses cannot accommodate the change in variables This will result in an unus
53. Block Connections Downloading in Task Units Programming Console Displays Online Editing Restrictions 56 Branches are not allowed on the left side of the instance Branches are allowed on the right side Incorrect Correct FB O FB 2 Instruction Instruction A program rung cannot have more than one instance Incorrect FB Q FB A function block s input cannot be connected to another function block s out put In this case a variable must be registered to transfer the execution status from the first function block s output to the second function blocks input 0 0 0 0 FB1 FB1 EN FB2 EN XOUT XIN1 xour 23000 eh 0 0 D100 XIN2 FB2 Temporary variables EN transfer the value from FB1 to FB2 D3000 JLXIN1 D100 x n2 Tasks including function blocks cannot be downloaded in task units but uploading is possible When a user program created with the CX Programmer is downloaded to the CPU Unit and read by a Programming Console the instances will all be dis played as question marks The instance names will not be displayed The following online editing operations cannot be performed on the user pro gram in the CPU Unit Changing or deleting function block definitions variable table or algo rithm Inserting
54. Blocks 00005 43 2 2 1 Basic Data Types cuta epu RR a 43 2 2 2 Derivative Data Types 00 0 0 eee eee 43 2 3 Instance Specifications 0 0 0 cee eee ee 44 2 3 1 Composition of an Instance 0 000 002 e eee 44 2 3 2 Parameter Specifications 0 0 0 2 ee eee eee eee 49 2 3 3 Operating Specifications 0 0 0 0 eee ee eee 51 2 4 Programming Restrictions lleleleeeeee eee 53 2 4 1 Ladder Programming Restrictions 000 53 2 4 2 ST Programming Restrictions 0 00 00 00008 55 2 4 3 Programming Restrictions 0 00 0 eee eee eee 56 2 5 Function Block Applications Guidelines 0 00008 58 2 5 1 Deciding on Variable Data Types llle eese 58 2 5 2 Determining Variable Types Inputs Outputs In Out Externals and Internals 59 2 5 3 AT Settings for Internal Variables 0004 61 2 5 4 Array Settings for Input Output Variables and Internal Variables 61 2 5 5 Specifying Addresses Allocated to Special I O Units 63 2 5 6 Using Index Registers eee eee eee 64 2 6 Precautions for Instructions with Operands Specifying the First or Last of Multiple Words 22 0 0 l l 67 2 7 Instruction Support and Operand Restrictions 004 70 2 8 CPU Unit Function Block Specifications 0 00004 71 2 8 1 Specifications
55. CASO AYLSE Example CLOCK PULSE 1 Algorithm tim b Algorithm TIMX tim a OFF TIME d tim_a ariable definitions TIMX tim b ON TIME ENO 2 Variable Definitions Usage Name Type Internal tim a TIMER Internal tim b TIMER Input ON TIME INT Input OFF TIME INT 1 Algorithm Standardized programming is written with variable names rather than real I O memory addresses In the CX Programmer algorithms can be written in either ladder programming or structured text 2 Variable Definitions The variable table lists each variable s usage input output input output or internal and properties data type etc For details refer to 1 3 Variables The maximum number of function block definitions that can be created for one CPU Unit is either 128 or 1 024 depending on the CPU Unit model 13 Function Blocks Section 1 2 Instances Number of Instances 14 Note To use an actual function block definition in a program create a copy of the function block diagram and insert it in the program Each function block defini tion that is inserted in the program is called an instance or function block instance Each instance is assigned an identifier called an instance name By generating instances a single function block definition can be used to pro cess different I O data with the same function Not y
56. Conditions Flags Appendix A System defined external variables supported in function blocks Greater Than or Equals GE Flag External variable in CX Programmer P GE Data type BOOL Address CF00 Not Equals NE Flag P_NE BOOL CF001 Less Than or Equals LE Flag P_LE BOOL CF002 Instruction Execution Error ER Flag P_ER BOOL CF003 Carry CY Flag P_CY BOOL CF004 Greater Than GT Flag P_GT BOOL CF005 Equals EQ Flag P_EQ BOOL CF006 Less Than LT Flag P_LT BOOL CF007 Negative N Flag P_N BOOL CF008 Overflow OF Flag P_OF BOOL CF009 Underflow UF Flag P_UF BOOL CF010 Access Error Flag P_AER BOOL CF011 Always OFF Flag P_Off BOOL CF114 Always ON Flag P_On BOOL CF113 Clock Pulses 0 02 second clock pulse bit P_0_02s BOOL CF103 0 1 second clock pulse bit P_0_1s BOOL CF100 0 2 second clock pulse bit P_0_2s BOOL CF101 1 minute clock pulse bit P 1mim BOOL CF104 1 0 second clock pulse bit P 1s BOOL CF102 Auxiliary Area Flags Bits First Cycle Flag P First Cycle BOOL A200 11 Step Flag P Step BOOL A200 12 First Task Execution Flag P First Cycle Task BOOL A200 15 Maximum Cycle Time P Max Cycle Time UDINT A262 Present Scan
57. Data type Content Array 1 dimensional array 32 000 elements max Structure User defined data type 43 Instance Specifications Section 2 3 2 3 Instance Specifications 2 3 1 Composition of an Instance The following table lists the items that the user must set when registering an instance Item Description Instance name Name of the instance Language The programming and variables are the same as in Variable definitions the function block definition Function block instance areas The ranges of addresses used by the variables Comments A comment can be entered for each instance Instance Name This is the name of the instance Instance names can be up to 30 000 characters long Instance names cannot contain spaces or any of the following characters 1I 9 6 amp 2 V Q9 1 5 7 Instance names cannot start with a number 0 to 9 There are no other restrictions The instance name is displayed above the instance in the diagram Instance name Pulse 250N 2sOFF CLOCK PULSE EN I ENO amp 20 ON TIME LANE OFF TIME Function Block To use a function block the system requires memory to store the instance s Instance Areas internal variables input variables output variables and input output variables These areas are known as the function block instance areas and the user must specify the first addresses and sizes of these areas The first addresses and area sizes ca
58. Description 1 The following instance is registered in the internal or global variables in the variable table Internal variable element Content Example Name Any instance name Calcu execute Data type FUNCTION BLOCK FUNCTION BLOCK FB definition Selects the called func Calculation tion block definition 168 Statement Descriptions Section 5 5 2 The values that will be passed between variables are specified within pa rentheses after the instance name registered in step 1 Calcu_execute in this example and a semi colon marks the end of the statement as shown in the following example Calcu execute A B C gt D The value of B is passed to A and at the same time the value of C is re ceived at D A Called function block definition s input variable name B One of the following values depending on the ST program being used Calling function block s input variable or a constant when ST is being used in the function block s instance Global variable or local variable name when ST is being used in an ST task or SFC action program C Called function block definition s output variable name or constant D One of the following values depending on the ST program being used Calling function block s output variable or constant when ST is being used in the function block s instance Global variable or local variable name when ST is being used in an ST task or SFC action program B Examples Sho
59. DoSendData is ON and iProcess is 0 IF DoSendData TRUE AND iProcess 0 THEN iProcess 1 DoSendData FALSE END_IF Execute send processing according to process number CASE iProcess OF 1 Create send text data Message READ iProcess 2 2 Execute send function if sending is enabled IF SendEnableCPUPort TRUE THEN TXD_CPU Message iProcess 3 END_IF 3 Sending is finished if Send Ready Flag is ON IF SendEnableCPUPort TRUE THEN iProcess 0 END_IF END_CASE Related Auxiliary Address Description Area Flag RS 232C Port Send A392 05 ON when sending is enabled in no protocol mode Ready Flag For further information and precautions on related Auxiliary Area flags refer to the section on TXD Serial Com munications Instruction in the CS CJ series Instruction Reference Manual TXD_SCB Send String via Serial Port on Serial Communications Board e Function Sends a text string from a serial port on a Serial Communications Board SCB Application TXD SCB Send string Serial port Conditions The serial communications mode of the serial port must be set to no protocol communications Arguments and Return Values TET Send string STRING Specifies the text string to send Serial port INT UINT WORD Specifies the number of the serial port 1 Serial port 1 2 Serial port 2 210 Function Descriptions Appendix C Example Serial Commu
60. FOR IT NOT OF OR REPEAT THEN TO UNTIL WHILE XOR TRUE FALSE ELSIF BY EXIT RETURN Any text that is not a reserved word will be recognized as a variable name Variable names Special characters Constants numerical values 2 2 2 amp e Numerical value only for decimal numbers 16 followed by numerical value for hexadecimal numbers e 2 followed by numerical value for binary numbers e 8 followed by numerical value for octal numbers Inputting ST Programs Section 5 3 If a space carriage return or tab is used between any of the above tokens the parts of the token on either side will be treated as separate tokens Therefore make sure that spaces carriage returns or tabs are not used within a single token Always use a space carriage return tab or other token separator between reserved words and variable names Using token separators between other token combinations is optional In the following example the box LJ indicates where a space carriage return tab or other token separator is required IFLJIA gt 0THEN ELSE 0 Upper and Lower Case Reserved words and variable names do not distinguish between upper and lower case either can be used Prohibited Characters for The following characters enclosed in square brackets cannot be used in Variable Names variable names e 1 I 8 7e 8 D E D GL
61. GT 10 Table and Unit Setup eb ES Settings 2 lt q Memory 2 E F Programs 22000100101000000107 4 E NewProgram1 00 2 Symbols ge Section Leno Function Blocks will appear under the PLC 2 Function block definitions are created by inserting function block defini tions after the Function Blocks icon Creating Function Block Function blocks can be defined by the user using either ladder programming Definitions or structured text 84 Procedures Section 3 2 Creating Inserting Function Block Definitions with Ladders 1 Select Function Blocks in the project workspace right click and select Insert Function Blocks Ladder from the pop up menu Or select Func tion Block Ladder from the Insert Menu Creating Inserting Function Block Definitions with Structured Text 1 Select Function Blocks in the project workspace right click and select Insert Function Blocks Structured Text from the pop up menu Or se lect Function Block Structured Text from the Insert Menu E NewProject NewPLC1 C31G H Offline Symbols 8 10 Table and Unit Setup S Settings zx 0 Program Name NewProgram1 Section Name Section1 lt j Memory A Programs a NewProgram1 00 7 Symbols Section1 END AE 2 FunctionBlock1 is displayed as the F Icon under the Function Blocks Icon F I 2 A function block called FunctionBlock1 will be automatically inserted either after the for ladder p
62. MS TIMER instruction Therefore is displayed for the present value on the ST monitor view 2 When you use the present value of the TIMER type variable argument of the TENTH MS TIMER or HUNDREDTH MS TIMER instruction in any item other than timer instructions the present value cannot be displayed correctly i e the value is undependable When the present value is as signed to a different variable its present value is also undependable Changing PVs To change a PV select the desired variable in the ST variable monitor window displayed in reverse video when selected right click and select Set Value from the pop up menu Select the variable Input 2 304856e 041 Float Inp Sopy UpLimit 0 0000000 Float Avge Result The Set New Value Dialog Box will be displayed Input the new value in the Value field Force setting and Force resetting Bits To force set force reset or clear the forced status select the desired variable in the ST variable monitor window displayed in reverse video when selected right click and select Force On Force Off Force Cancel or Force Cancel All Forces from the pop up menu 118 Procedures Section 3 2 Copying and Pasting in the Watch Window 1 2 3 1 To copy a variable to the Watch Window select the desired variable in the ST variable monitor window displayed in reverse video when selected right click and select Copy from the pop up menu 2 Right
63. NewPLC1 i H522 02 BOOL On Off Conta Output 0 OK or NewPLC1 internal EO ODD ee DOO REAL Floating Point Right click in the Watch Window and select Paste Te IRA sheet A For Help press F1 119 Procedures Checking Programs within Function Block Definitions 1 2 3 Monitoring Instance Variables in the Watch Window 1 2 3 120 Section 3 2 Use the following procedure to check the program in the function block defini tion for an instance during monitoring Right click the instance and select To Lower Layer from the pop up menu The function block definition will be displayed Use the following procedure to monitor instance variables 1 Select View Window Watch A Watch Window will be displayed 2 Useanyone ofthe three following methods to display the FB variables reg istration Dialog Box a Right click the instance and select Register in Watch Windows from the pop up menu Copy the instance and paste it in the Watch Window c Right click an empty row in the Watch Window and select Register in Watch Windows from the pop up menu PLC NewPLCI F FB Instance sample01 Usage iten v Data Type All M Comment 4 PIER BOOL Error Bit Ok_Bit BOOL Range Che NG_Bit BOOL Range Che AddressOk_Bit BOOL Addrss Rai Control Data WORD CMND cor Tmp_Data WORD For interna Phase WORD Process or Command Data WORD CMND cor Response Data
64. Sends a text string to a serial port on a Serial Communications Unit TXD_SCU a b c d text string a is sent from the serial port specified by variable c on the Serial Communications Unit speci fied by variable b using the internal logic port specified by variable d The variable d indicates the internal logic port number RXD CPU Storage location Number of characters Argument data type Return value data type Send string STRING Send string STRING Serial port INT UINT WORD Send string STRING SCU unit INT number UINT WORD Serial port INT pas UINT WORD Internal_logic INT _port UINT WORD Storage_ STRING location Number of INT characters UINT WORD 152 Receives a text string from the RS 232C port on the CPU Unit RXD_CPU a b number of characters specified by variable b are received from the RS 232C port on the CPU Unit and stored in variable a ST Language Configuration Section 5 4 Function Argument data type Return Description Example value data type RXD_SCB lt Storage_ Storage_ STRING Receives a text string RXD_SCB a b c location gt lt Number_of_ location from the serial port on number of characters characters gt lt Serial_port gt Number of INT a Serial Communica specified by variable b are characters UINT tions Board received from the seria
65. Target data1 S1 BOOL INT UINT UDINT Specifies the target data ULINT DINT LINT WORD DWORD LWORD REAL LREAL Target data2 S2 BOOL INT UINT UDINT Specifies the target data ULINT DINT LINT WORD DWORD LWORD REAL LREAL Target data3 S3 BOOL INT UINT UDINT Specifies the target data ULINT DINT LINT WORD DWORD LWORD REAL LREAL Target data31 S31 BOOL INT UINT UDINT Specifies the target data ULINT DINT LINT WORD DWORD LWORD REAL LREAL Return value BOOL INT UINT UDINT Returns the output data ULINT DINT LINT WORD DWORD LWORD REAL LREAL Note Heturn value MAX Target_data1 Target data2 Target dataG Target data31 The same data type must be set for all arguments and the return value Example Variables INT Data1 Data1 123 Data2 456 Data3 789 INT Data2 INT Data3 INT Result 123 456 789 Result Result MAX Data1 Data2 Data3 789 is stored in the Result variable MIN Minimum Value Function Selects the minimum value from the target data Up to 31 data can be specified as target data Application Return value MIN Target data1 Target data2 Target data3 Target data31 206 Function Descriptions Appendix C Arguments and Return Values Variable name Data type Description Target data1 S1 BOOL INT UINT UDINT Specifies the target data ULINT DINT LINT WORD DWORD LWORD R
66. Type BOOL for contacts and WORD for channel word Initial Value The default for the data type Retain Not selected 3 Make any required changes and click the OK Button 4 As shown below the variable that was registered will be displayed in the variable table above the program 7 Untitled CX Programmer NewPLCI FunctionBlock1 FB Ladder LT Edt View Insert PLC Program Tools Window Help n a E rR amp 3 X n ce a 522 e l8 amp GA T je a Se belles 4c e w 1 o DEE SAE 3 e g 2 x t ii E E Fs Jo rs m E ERIS d 5 E 19 39 16 amp m z9 y oe mos zled Name Data Type AT Initial V Ret Comment E ie Newer aaa BOOL FALSE EE nes ence H Offline bbb OOL ALSE Internals Inputs utputs Externals NE a 5 dT Fun I Instruction input Function block internal variable registered If the type or properties of a variable that was input are not correct double click the variable in the variable table and make the required corrections n Reference Information AT Settings Specified Address AT settings can be made in the variable properties to specify allocation addresses for Basic I O Units Special I O Units or CPU Bus Units or Auxil iary Area addresses not registered using the CX Programmer A variable name is required to achieve this Use the following procedure to specify an address Afte
67. a number 0 to 9 Variable names cannot contain two underscore characters in a row e The following characters cannot be used to indicate addresses in I O memory A W H or HR D or DM E or EM T or TIM C or CNT followed by the numeric value word address 33 Function Block Specifications Variable Notation Variable Type Usage Item See note 3 Definition re Variable table ENO Usage Name Type BOOL BOOL Internal tim a TIMER ON TIME Internal tim b TIMER ND Input ON TIME INT OFF_TIME Input OFF_TIME INT INT qe E Output variables Input variables TIMX tim a OFF TIME TIMX tim b OFF TIME Internal variables Variable type Section 2 1 Operands to the instance Outputs Return values from the instance In Out Variables used to pass data to and from instances using addresses Internals Variables used only within instance Externals See note 1 Global symbols reg istered as variables beforehand with the CX Programmer or user defined global symbols Status of value at next execu tion The value of the input parameter will be given The value is passed on to the next execution The value of the external parameter The value is passed on to the next execution The value of the variable registered externally Display Displ
68. and select Properties from the pop up menu Alternately select Proper ties from the View Menu 2 The Function Block Properties Dialog Box will be displayed Click the Pro tection Tab and click the Set Button Function Block Properties al General Protection Comments Memory Protection Status 3 The Function Block Protect Setting Dialog Box will be displayed Select the protection level in the Protection Type Field Function Block Protection Settin x Input a password after selecting a protection type Protection Type Prohibit writing and display Prohibit writing only Password ni Password confirmation rev Cancel Procedures Section 3 2 The following table shows the functions restricted in each protection level Function Protect Type Prohibit writing and Prohibit writing display Displaying function block contents Prohibited Allowed Printing function block contents Editing function block contents Prohibited Saving loading to function block Allowed Allowed library files 4 Input the password in the Password Field of the Function Block Protect Setting Dialog Box Input the same password again in the confirmation field to verify the password and click the Set Button The password can be up to 8 characters long and only alphanumeric char acters can be used 5 When a function block definition has been password protected the func tion block definition
69. arrow in an ST program indicates whether an operation has been paused in the Simulation Function Window as well as which operation has been paused Debug Color default Program execution Details operation status Step Run or Simulator paused Paused by Step Run Continuous status operation or the Pause Step Run Button Regular color Not executed due to Step is not being exe interlock or other cuted because of an function instruction such as IL MILR MILH JMPO or FOR BREAK Break point Simulator instruction Paused break status by break a break point Note 1 When Tools Simulation Always Display Current Execution Point has been selected the Simulator automatically scrolls the display to show the paused point in the instance when performing Step Run or Continu ous Step Run operation 2 The color of the cursor or arrow in an ST program which indicates when an operation has been paused in the Simulation Function Window can be changed from its default color To change the color select Tools Options and click the Appearance Tab Select Pause Simulator Simulator Instruction Break or Simulator IO Break and change the color for that condition Break Point Operation in an Instance Execution can be paused automatically at the preset break point in the instance In this case the Step In operation cannot be used Note When a break point is set for an instance the break point is valid for th
70. be backed up if power is turned OFF To display the status of writing to flash memory on the CX Programmer select Display dialog to show PLC Memory Backup Status in the PLC properties and then select Windows PLC Memory Backup Status from the View Menu Programs including function blocks ladder programming language or structured text ST language can be downloaded or uploaded in the same way as standard programs that do not contain function blocks Tasks including function blocks however cannot be downloaded in task units uploading is possible If a user program containing function blocks created on the CX Program mer Ver 5 0 or later is downloaded to a CPU Unit that does not support function blocks CS CJ series CPU Units with unit version 2 0 or earlier all instances will be treated as illegal commands and it will not be possible to edit or execute the user program If the input variable data is not in boolean format and numerical values only e g 20 are input in the parameters the actual value in the CIO Area address e g 0020 will be passed Therefore be sure to include an amp or prefix before inputting the numerical value Addresses can be set in input parameters but an address itself cannot be passed as an input variable Even if an address is set as an input param eter the value passed to the function block will be that for the size of data of the input variable Therefore an input variable cannot be u
71. block definitions and projects with instances are saved in the same standard project files cxp and file memory program files obj The following diagram shows the contents of a project The function block def initions are created at the same directory level as the program within the rele vant PLC directory Project file cxp PLC1 Global symbol table I O table PLC Setup PLC memory table r Program with rung comments Local symbol table Section 1 with instances 4 i i Section 2 with instances lt i END section with instances 1 i i Function block definitions 7 i 1 i FunctionBlock1 Each function block can be cushy E E EEE EEEE stored in a separate FunctionBlock2 definition file cxf Instances created in program sections PLC2 A function block definition created in a project with CX Programmer Ver 6 0 can be saved as a file 1 definition 1 file enabling definitions to be loaded into other programs and reused When function blocks are nested all of the nested destination function block definitions are included in this function block library file cxf Data equivalent to that in project files created with CX Programmer Ver 6 0 cxp can be saved as CXT text files cxt 1 1 4 Function Block Menus in CX Programmer Ver 5 0 and later Versions The following
72. clear the area without retaining the values when starting opera tion 1 4 Converting Function Block Definitions to Library Files A function block definition created using the CX Programmer can be stored as a single file known as a function block definition file with filename extension cxf These files can be reused in other projects PLCs Project Project Function block definition Function block definition Example CLOCK_PULSE Example CLOCK PULSE 1 Algorithm T t TIMX tim a OFF TIME SN amp ITIMK tim a OFF TIME TiYX tim b ON TIME TIMX tim b ON TIME Name Type Uma TIMER ti TIMER ON_TIME INT OFF TIME INT TIME OFF TIME INT Function block definition file cxf 1 5 Usage Procedures Once a function block definition has been created and an instance of the algo rithm has been created the instance is used by calling it when it is time to execute it Also the function block definition that was created can be saved in a file so that it can be reused in other projects PLCs 1 5 1 Creating Function Blocks and Executing Instances The following procedure outlines the steps required to create and execute a function block 1 2 3 1 First create the function block definition including the algorithm and vari able definitions in ladder progra
73. click in the Watch Window and select Paste from the pop up menu EEUU CX Programmer NewPLC1 StageA_D DThickSelect D DThickJudge Avagy h lol x File Edit View Insert PLC Program Tools Window Help l xl D c m rR S I eB ess N As 6 hs n n e cR eR EDS ER ER o e n s amp frs ient e 3e unm 1 o GS GEL amp ER e es tn tm tz to a Rs Jr m E E 1 es 5 9 09 EE E 38 28 36 ees o amp gt m m iu a xix Agarage value calculation and check of threshould for three values 5 NewProject T S D NewPLCI CJ1G H Stop Program avave Input Input2 Input3 3 0 T Di ide al AvgValue 0 0000000 Flo Gre 2 2 304856e 041 Float Inp e amp vgValue lt UpLimit AND AvgValue LowLimit THEN Com AvgValue 0 0000000 Flos UpLimit 0 0000000 Float amp vgve 53 Symbols Result TRUE Result 0 i 10 Table and Unit Setup ELSE Select the variable in the ST Settings Result FALSE Result 0 variable monitor window Tgll Memory card BEE right click and select Copy E35 Error log PLC Clock lt q Memory E A Programs cg OvK B p fit 00 Stor 3 Symbols Sectiont END AF Function Blocks IF ActuatorControl BF AvgValue ThresholdChec EF DVD ThickSelectControl EF WorkMoveControl LSONc gt f vil gt l x PLC Name Mame Address Data Type Format FB Usage Value Value B Comment d
74. delayed by one cycle depending on the access timing CNTX COUNTER Function Operates a decrementing counter Equivalent to the CNTX 546 ladder instruction The counter present value is decremented by one every time the count input is turned ON The counter completion flag is turned ON when the present value reaches 0 When the reset input is ON the counter will be reset and the present value will become equal to the counter set value Also the counter completion flag is turned OFF and the count input is made invalid Application CNTX Count input Reset input Counter address Counter set value Arguments Variable name Data type Description Count input BOOL The counter present value is decremented every time the count input is turned ON Reset input BOOL When the reset input is ON the counter s PV and completion flag are reset Counter address COUNTER Specifies the counter address CO to C4095 variable to use Counter set value UINT Specifies the default value from which the counter value is decremented amp 0 to amp 65535 0 to amp FFFF CNTRX REVERSIBLE COUNTER e Function Operates an incrementing decrementing counter Equivalent to the CNTRX 548 ladder instruction 221 Function Descriptions Appendix C When the increment input is turned ON the value is incremented When the decrement input is turned ON the value is decremented When incrementing the counter c
75. elements for both array variable a and b Using a WORD data type with 10 elements for both variables a and b To transfer 20 words be sure to specify 20 elements for both array variables a and b Internally allocated address Example H700 10 words Example H710 Example H719 a 10 words Internally allocated address Array variable Array variable 10 d words 20 words a 10 words Example H810 20 words will be n transferred regard The variables allocated in this area less of the size of ar H810 to H819 in this example are ray variables a and b overwritten The data is variable length data so the CX Programmer Example H819 will not output a compile error 69 Instruction Support and Operand Restrictions Section 2 7 Other Operand Specifying Size Variable Even if the number of array elements does not match the size i e size to be processed by the instruction specified in another operand variable the CX Programmer will not output an error when compiling The instruction will be executed according to the size specified by the operand regardless of the number of elements in the array variable Particularly if the number of elements in the array is less than the size i e size to be processed by the instruction specified by another operand vari able other variables will be affected and unexpected operation may occur 2 7 Instruction Support and Operand Restriction
76. from a single function block The same instance must be called from multiple locations Instance Specifications Section 2 3 _ Program 1 automatic operation Program 2 manual operation i Product A counter Product B counter CTD CTD CD Q CD Q LD LD PV cv 2100 pv cv D150 Product B counter Reading the same product s counter value at different locations CTD cD Q Reading different products counter values LD Algorithm calculating counter value is the same PV cv L D200 Program 1 im Instance A nstance I O variables FB a a Internal variables FB definition 4 n i Body j Variable nstance n definitions FB A Body Instance B I O variables Internal f P 2 variables Program Yi j A Ty Instance A VN Body re ME N Use the same internal variables Use different internal variables 2 3 2 Parameter Specifications The data that can be set by the user in the input parameters and output parameters is as follows Item Applicable data Input parameters Values See note 1 addresses and program symbols glo bal symbols and local symbols See note 2 Note The data that is passed to the input variable from the parameter is the actual value of the size of the input variable data An address itself will not
77. handling is eas ier for many applications Note The IEC 61131 standard was defined by the International Electro technical Commission IEC as an international programmable log ic controller PLC standard The standard is divided into 7 parts Specifications related to PLC programming are defined in Part 3 Textual Languages IEC 61131 3 A function block ladder programming language or structured text ST language can be called from another function block ladder programming language or structured text ST language Function blocks can be nested up to 8 levels and ladder ST language function blocks can be com bined freely Introducing the Function Blocks Section 1 1 1 1 2 Function Block Specifications For specifications that are not listed in the following table refer to the CX Pro grammer Operation Manual W446 Item Specifications Model number CXONE ALUILIC V4 ALLILID V4 Setup disk CXONE ALL IL IC V4 CD ROM CXONE ALLILID V4 DVD ROM Compatible CPU Units PLC models CS CJ series CS1 H CJ1 H and CJ1M CPU Units with unit version 3 0 or later Note The function block and structured 2 compatible text functions supported by CS Device Type CPU Type CJ series CPU Units with unit ver e CJ2H CJ2H CPU68 67 66 65 64 68 EIP 67 EIP 66 EIP 65 EIP sion 4 0 or later can not be used 64 EIP d Me ee cen CJ2M CPU11 12 13 14 15 31 32 33 34 35 series PLCs NSJ series PLCs or CS1G H CS1G CPU42H 43H 44H 45H For details
78. in transfer 10 words from the address EON DATA_1 is 1 word the value beginning with DATA_1 to the address D00100 or the word D00100 is beginning with DATA 2 i j passed ws00 S f the size of the data type in XFER DATA 2 is 2 words the value or the 2 words W500 and DATA 1 W501 is passed DATA 2 The address can be specified but the address itself is not passed Values are passed in a batch from the input parameters to the input vari ables before algorithm execution not at the same time as the instruction in the algorithm is executed Therefore to pass the value from a parame ter to an input variable when the instruction in the function block algorithm is executed use an internal variable or external variable instead of an input variable 59 Function Block Applications Guidelines Section 2 5 Passing Values from or Monitoring Output Variables Input Output Variables to Return FB Processing Results from Values Passed from Input Parameters to Output Parameters Input Output Array Variables to Pass Large Amounts of Data 60 To paste into the program and then pass values outside the program from the function block for each instance or monitor values use output variables Program Instance for function block definition A The actual value is passed OK_Flag NG Flag X WO 01 rus Variable for passing a value outside or monitoring Use an output variable The f
79. instance Supported by CX Pro grammer Ver 6 0 and later only To Upper Layer Returns to the calling instance ladder diagram or ST Supported by CX Programmer Ver 6 0 and later only Window FB Instance Viewer Displays the FB Instance Viewer When nesting the dis play shows details such as the relationship between instance nesting levels and allocated variable addresses in the instances Function Block Invocation Creates an instance in the program section at the present cursor location Function Block Parameter When the cursor is located to the left of an input variable or the right of an output variable sets the variable s input or output parameter Memory Alloca tion Block SFC Function Function Block SFC Memory Allocation Sets the range of addresses function block instance areas internally allocated to the selected instance s variables Memory Function Block SFC Memory Statistics Checks the status of the addresses internally allocated to the selected instance s variables Function Block Instance Address Checks the addresses internally allocated to each variable in the selected instance Optimize Func tion Block SFC Memory Optimizes the allocation of addresses internally allocated to variables Program Online Edit Begin Starts online editing of a function block Send Change Transfers changes made during on
80. is used ladder programs created with non CX Programmer Ver 4 0 or earlier can be reused by copying and past ing When ST language is used it is easy to program mathematical pro cesses that would be difficult to enter with ladder programming Note The ST language is an advanced language for industrial control primarily Programmable Logic Controllers that is described in IEC 61131 3 The ST language supported by CX Programmer con forms to the IEC 61131 3 standard Function blocks can be created easily because variables do not have to be declared in text They are registered in variable tables A variable can be registered automatically when it is entered in a ladder or ST program Registered variables can also be entered in ladder programs after they have been registered in the variable table A single function block can be converted to a library function as a single file making it easy to reuse function blocks for standard processing A program check can be performed on a single function block to easily confirm the function block s reliability as a library function Programs containing function blocks ladder programming language or structured text ST language can be downloaded or uploaded in the same way as standard programs that do not contain function blocks Tasks containing function blocks however cannot be downloaded in task units uploading is possible One dimensional array variables are supported so data
81. name must be 8 characters or less The file name extension is always TXT For example the following file name creates a file named LINE A TXT in the root directory LINE_A Delimiter STRING Empty character Comma L or I Line feed ASCII 0A N or n Carriage return line feed ASCII OD 0A P or p New page ASCII OC R or r Carriage return ASCII OD T or t Tab ASCII 09 Parameter INT UINT WORD 0 Append 1 Create new file 208 Function Descriptions Appendix C Variables I 1 BOOL P MemcCardBusyFlag File Memory Operation Flag AT A343 13 1 BOOL P MemCardAskFlag Memory Card Detected Flag AT A343 15 STRING FileName File name i INT LogData1 2 3 Log number STRING FiledStrl1 2 3 Log number text string L STRING CsvLineStr CSV format log 1 line text string FileName LOGFILE LogData1 12 LogData2 345 LogData3 6789 ee p Contents of output file Output data to text file if Memory Card write conditions are met IF P MemCardAckFlag AND NOT P MemCardBusyFlag THEN LOGFILE TXT Convert from number to text string FieldStr1 INT TO STRING LogDatat1 12 345 6789 FieldStr2 INT TO STRING LogData2 FieldStr3 INT TO STRING LogData3 Create 1 row CSV format numeric value text string CsvLineStr FieldStr1 FieldStr2 FieldStr3
82. of the manual to help you locate different types of information Note Indicates information of particular interest for efficient and convenient opera tion of the product 1 2 3 1 Indicates lists of one sort or another such as procedures checklists etc Part 1 Function Block SECTION 1 Introduction to Function Blocks SECTION 2 Function Block Specifications SECTION 3 Creating Function Blocks Part 2 Structured Text SECTION 4 Introduction to Structured Text SECTION 5 Structured Text ST Language Specifica tions SECTION 6 Creating ST Programs Appendices TABLE OF CONTENTS PRECAUTIONS 3459 0 towssdtt eid I even dersms SIN 1 Intended Audience i2 tt LR RARE EROR E MERI EROR EL o eee XX 2 General Precautions enaa pep dr eR RARE ER RUN PRA oa eae XX 3 Safety Precautions se cesse S esti DER ee a ple pfe EUIS EPOR XX 4 Application Precautions cisi eei e eR edge Saves CAE a he ACHAIA RC Rm n xxi Part 1 Function Blocks SECTION 1 Introduction to Function Blocks 3 1 1 Introducing the Function Blocks sslseeeeeeeeee III 4 1 2 Function Blocks scr e RR REY ener GS Cae one AE Y ee 11 1 3 Variables e obe ites a a Hae eis de DAW aL EM 18 1 4 Converting Function Block Definitions to Library Files 000 0 23 1 5 Usage Procedures sse ere bee Se ihe ee ee Ree ete dal iter 23 1 6 Version Upgrade Information 0 0 00 eee eee ee
83. on the CP series CP1H PLCs CP1H XA CP1H CPU Unit e Overview Features CP1H Y Operation Manual System configuration Mounting and wiring O memory allocation Troubleshooting Use this manual together with the CP1H CP1L Programmable Controllers Programming Manual W451 SYSMAC CP Series Provides the following information on the CP series CP1L PLCs CP1L CPU Unit Oper e Overview Features ation Manual System configuration Mounting and wiring O memory allocation Troubleshooting Use this manual together with the CP1H Programmable Control lers Programming Manual W451 SYSMAC CP Series Provides the following information on the CP series CP1H and CP1H CP1L CPU CP1L PLCs Unit Programming Programming instructions Manual Programming methods Tasks Use this manual together with the CP1H CP1L Programmable Controllers Operation Manual W450 Installation from CX One For details on procedures for installing the CX Programmer from CX One FA Integrated Tool Package refer to the CX One Ver 3 0 Setup Manual provided with CX One Model Manual name Contents CXONE ALLILIC V4 _ CX One Setup Manual Installation and overview of CX One FA D V4 CXONE Inte
84. operation man uals for the CS CJ Series and CP Series for other specifications 2 8 1 Specifications CJ2H CPU Units Section 2 8 Item Specification Model CJ2H CPU68 CJ2H CPU67 CJ2H CPU66 CJ2H CPU65 CJ2H CPU64 EIP EIP EIP EIP EIP I O points 2 560 Program capacity steps 400K 250K 150K 100K 50K Data memory 32K words The D M and EM areas can be accessed in bit units Extended Data Memory 32K words X 25 banks 32K words X 15 banks 32K words X 10 banks 32K words X 4 banks 32K words X 4 banks EO 00000 to EO 00000 to EO 00000 to EO 00000 to EO 00000 to E18 32767 EE 32767 E9 32767 E3_ 32767 E3_32767 Force set EM 11 to EM 18 EM7to EME EM 6 to EM9 EM3 EM3 reset enabled area Function Maximum 1 024 blocks number of def initions Maximum 2 048 number of instances Source Symboltables 3 5MB See note Com comments ment program areas indexes Note CJ2M CPU Units Item Specification Model The total capacity of source and comment areas is 3 5 MB 31 CJ2M CPU1 1 CJ2M CPU12 32 CJ2M CPU13 33 CJ2M CPU14 34 There is no restriction on the memory capacity by the stored data CJ2M CPU15 35 I O points 2 560 Program capacity steps 5K 10K 20K 30K 60 K 32K words Data memory Extended Data Memory 32K words X 4 banks EO 00000 to E3_ 32767 2 048 32K words
85. page 187 3 After the transfer is completed the ST program will return to its previous status in which the ST program cannot be edited If further editing is nec essary resume the online editing procedure from the beginning of the pro cedure Starting Online Editing To discard the changes made to the ST program select Program Online Edit Cancel The edited ST program will not be sent to the PLC and the ST program will revert to the original status before online editing was started In Standard Mode both the ST program s source code and object code are transferred to the CPU Unit Some time may be required for Standard Mode transfers because of the quantity of data that must be sent Other editing or transfer operations cannot be performed until the transfer has been com pleted In Quick Mode only the ST program s object code is transferred to the CPU Unit The ST source code is not transferred making Quick Mode faster than Normal Mode After transferring the object code in Quick Mode either 1 select Program Transfer SFC ST Source to PLC to transfer the source code or 2 transfer the source code according to instructions displayed in a dialog box when you go offline After transferring the object code a yellow mark will be displayed at the bot tom of the window until offline status is entered to indicate that the source code has not yet been transferred This yellow mark will disappear when the source code is transfer
86. parameters within the algorithm If itis necessary to write a value within the execution cycle of the algorithm do not write the value to a parameter Assign the value to an in ternal variable and use an AT setting specified addresses Initial Value An initial value can be set for an output variable that is not being retained i e when the Retain Option is not selected An initial value cannot be set for an output variable if the Retain Option is selected The initial value will not be written to the output variable if the IOM Hold Bit A50012 is ON Auxiliary Area control bit Initial value IOM Hold Bit 50012 The initial value will not be set Function Block Specifications Note Section 2 1 ENO Enable Output Variable The ENO variable is created as the default output variable The ENO output variable will be turned ON when the instance is called The user can change this value The ENO output variable can be used as a flag to check whether or not instance execution has been completed normally Input Output Variables Input output variables use addresses to pass data to and from a function block instance An input output variable is displayed on both the left and right side of the instance The value of the input output variable immediately after the instance is executed is not stored in the addresses internally allocated to the input output variable by the system but rather the value is stored in the address an
87. placing the function block in a program and setting the parameters for the function block s I O The ability to reuse existing function blocks will save significant time when creating debugging programs reduce coding errors and make the program easier to understand Structured programs created with function blocks have better design quality and require less development time The I O operands are displayed as variable names in the program so the pro gram is like a black box when entering or reading the program and no extra time is wasted trying to understand the internal algorithm Many different processes can be created easily from a single function block by using the parameters in the standard process as input variables such as timer SVs control constants speed settings and travel distances Coding mistakes can be reduced because blocks that have already been debugged can be reused Read protection can be set for function blocks to prevent programming know how from being disclosed The variables in the function block cannot be accessed directly from the out side so the data can be protected Data cannot be changed unintentionally The function block s I O is entered as variables so it isn t necessary to change data addresses in a block when reusing it Processes that are independent and reusable such as processes for individ ual steps machinery equipment or control systems can be saved as func tion bloc
88. size range for the function block variable data type 50 Instance Specifications Section 2 3 2 3 3 Operating Specifications Calling Instances The user can call an instance from any location The instance will be executed when the input to EN is ON Instance 1 0 d EN ENO In this case the input to EN is bit 0 0 at the left of the diagram DO D10 e When the input to EN is ON the instance is executed and A B the execution results are reflected in bit 1 0 and word D10 e When the input to EN is OFF the instance is not executed bit 1 0 is turned OFF and the content of D10 is not changed Operation when the The system calls a function block when the input to the function block s EN Instance Is Executed input variable is ON When the function block is called the system generates the instance s variables and copies the algorithm registered in the function block The instance is then executed amp 20 ON TIME 1 The FB is called pace 1 Pulse 250N 1sOFF Algorithm Body 1 P On cLockPusE 72 dimb EN ENO O TMX tim a OFF TIME TIMX tim_b ON_TIME C d ENO 2 The system generates the instance MRRRRERRRRRRR I s RERO S ROREM UE variables and copies the algorithm 810 OFF_TIME FB instance Pulse 250N 1sOFF Usage Name Value Internal 200 100ms PULSE tim a Internal 200 100ms_PULSE_tim_b Input 200 100ms PU
89. the fol lowing illustration Function Descriptions Appendix C Example Variables Message 1 a p ROME E o o g Message2 G p p STRING Message1 STRING Message2 INT Result Result FIND Message1 Message3 2 is stored in the Result variable Data Shift Functions SHL Bitwise Shift Left Function Shifts a bit string to the left by n bits When shifted zeros are entered on the right side of the bit string Application Return value SHL Shift target data Number of bits Arguments and Return Values Variable name Data type Description Shift target data S1 BOOL WORD DWORD Specifies the data to be shifted LWORD Number of bits n INT UINT UDINT ULINT Specifies the number of bits by which the DINT LINT bit string is to be shifted Return value BOOL WORD DWORD Returns the output data LWORD Note The same data type must be set for the 1st argument and the return value Example Variables Me in Data1 B26E hex 1011 0010 0110 1110 binary WORD Result N 1 decimal 0 1 1 0 0 1 0 0 1 1 0 1 1 1 0 Z Le Reut O 1 1 0 o0 1 0 0 1 1 0 1 1 1 0J 0 Data1 Result SHL Data1 N 64DC is stored in the Result variable SHR Bitwise Shift Right Function Shifts a bit string to the right by n bits When shifted zeros are entered on the
90. the present value is decremented by one starting from the value specified in the timer set value once every 0 01 ms The present value will continue timing down as long as the execution condition remains TRUE When the present value reaches 0 the timer completion flag of the specified timer address will be turned ON If the present value is not zero the timer completion flag is OFF While the execution condition is FALSE the timer set value is set in the present value of the timer address and the timer completion flag is OFF Application TMUHX Execution condition Timer address Timer set value Arguments Variable name Data type Description Execution condition Executes the timer operation while this execution condition is TRUE Timer address Specifies the timer address TO to T4095 variable to use Timer set value Specifies the delay time in units of 0 01 ms amp 0 to amp 65535 0 to FFFF This timer may not operate properly when the cycle time is 10 ms or longer When the timer PV is referenced from the user program the present value may be different by one cycle from the actual value depending on the access timing When the timer completion flag is referenced from the user program the reflection of status change may be delayed by one cycle depending on the access timing TTIMX ACCUMULATIVE TIMER Function Operates an incrementing timer with units of 0 1 s Equivalent to the TTIMX 5
91. to TIMER or COUNTER 2 Bit data can be accessed even if the DM Area is specified for the non re tained area Retained Area None Timer Area Item Contents Allocated variables Variables with TIMER set as the data type Applicable areas T Timer Area Timer Flag 1 bit or timer PVs 16 bits Allocated words T206 to T255 Timer Flag 1 bit or timer PVs 16 bits default Counter Area Allocated variables Variables with COUNTER set as the data type 47 Instance Specifications Accessing Function Block Instance Area from the User Program Note Comments Creating Multiple Instances Calling the Same Instance Making Multiple Instances 48 Section 2 3 Applicable areas C Counter Area Counter Flag 1 bit or counter PVs 16 bits Allocated words C206 to C255 Counter Flag 1 bit or counter PVs 16 bits default If the user program contains an instruction to access the function block instance area an error will be displayed in the Compile Tab of the Output Win dow of CX Programmer if the following operations are attempted Attempting to write during online editing writing not possible Executing program check Selecting Compile from the Program Menu or Compile All PLC Programs from the PLC Menu Example If WO to W511 is specified as the non retained area of the function block instance area and WO 00 is used in the ladder program an error will occur when compiling and
92. uploading is possi ble 115 Procedures Section 3 2 3 2 18 Monitoring and Debugging Function Blocks The following procedures can be used to monitor programs containing func tion blocks Monitoring I O in Ladder With the CX Programmer Ver 6 0 and later versions it is possible to monitor Programs within the status of bits and content of words in a ladder program within an instance Instances when monitoring the program To monitor I O bits and words I O Bit Monitor either double click the instance or right click the instance and select Monitor FB Ladder Instance from the pop up menu At this point it is possible to monitor bits and words change PVs force set reset bits and perform differ entiation monitoring Note 1 Itis not possible to change timer counter SVs 2 Changing PVs and force setting resetting bits is not possible for input output variables Also if data structures are used as input output vari ables you cannot display forced set reset information key icons for any BOOL members of those data structures m sanen Dnet211 GetinPower Stat ok Bit Range Check ok bt ano po ecd won AME o Double click l O values can be es 6 n g Masler ritto Masler nitNo a monitored in the pevcenet m Devicenetw D200 Kan 800 wt ot k SE 80 80 E d algorithm within the oom orm P E er pon wo function block ange che
93. variable DINT data type 2 Use the MOVR 560 MOVE TO REGISTER instruction to store the real I O memory address for the first allocation address internal variable AT CIO 2000 in the Index Register e g IRO 3 Add the unit number offset to the real I O memory address within the Index Register e g IRO Example 2 Specifying the Designated Bit in the CIO Area e g CIO Word n a Bit b Programs Use either of the following methods 63 Function Block Applications Guidelines Section 2 5 Word addresses Specify the constant offset of the Index Register using an indirect specification e g a IRO Bit addresses Specify an instruction that can specify a bit address within a word e g amp b in second operand of SETB instruction when writing and TST instruction when reading Example Special I O Units E 1 Specify the first CIO Area word n n CIO 2000 unit number x 10 Instance for function block definition A Ris dead Unit number input variable INT data type Offset internal variable DINT data type Relay internal variable WORD data type 400 array elements AT setting 2000 amp 3 Unit No WP Multiplies unit number by amp 10 amp 10 and stores in offset Unit No Offset L MOVR Stores the real I O memory Relay address for the relay in IRO IRO La Adds offset to IRO IRO Offset IR
94. 0 0 000 Measur 0 000 0 000 Measur For Help press F1 ST Program Simulation Function NewPLC1 Net 0 Node 0 Monitor Mode 0 6ms SYNC Ui The ST program can be connected to a simulator and monitored 6 1 9 Online Editing of ST Programs Starting Online Editing 186 1 2 3 ST programs can be edited even when the PLC CPU Unit is operating This allows ST programs to be debugged or changed in systems that cannot be shut down such as systems that operate 24 hours day ST programs can be edited online when the PLC is in an operating mode other than RUN mode This function cannot be used with the simulator 1 Start monitoring 2 Select the desired ST program in the project workspace and display it in program view 3 Select Program Online Edit Begin At this point it will be possible to edit the ST program 4 Start editing the ST program Procedures Transferring the Changes 1 2 3 Cancelling the Changes Transfer Modes Standard Mode Quick Mode Selecting a Transfer Mode A Caution Note Section 6 1 1 After editing is completed select Program Online Edit Send Changes The Send Changes Dialog Box will be displayed 2 Select the desired transfer mode and click the OK Button The edited ST program will be transferred to the PLC For details on the transfer modes refer to Transfer Modes on page 187 and Selecting a Transfer Mode on
95. 0 END IF END CASE 216 Function Descriptions Appendix C Related Auxiliary Area Fag Address Communications Instruction A202 00 to ON when network communications can be executed The bit Enable Flag A202 07 numbers correspond directly to the internal logic port numbers Bits 00 to 07 Internal logic ports O to 7 Related CPU Bus Unit Area bits n CIO 150 25 x unit number ON when reception has been completed in no protocol mode Port 1 n 9 Port 2 n 19 n CIO 150 25 x unit number ON when a data overflow occurred during reception in no pro Port 1 n 9 tocol mode Port 2 n 19 n CIO 150 25 x unit number Contains the number of characters received in no protocol Port 1 n 10 mode Port 2 n 20 For further information and precautions on related Auxiliary Area flags refer to the section on RXDU Serial Communications Instruction in the CS CJ series Instruction Reference Manual Angle Conversion Functions DEG TO RAD Convert Degrees to Radians e Function Converts an angle in degrees to radians Application Return value DEG TO RAD argument Arguments and Return Values Argument REAL LREAL Specifies an angle in degrees Return value REAL LREAL Returns an angle in radians RAD TO DEG Convert Radians to Degrees Function Converts an angle in radians to degrees Application Return value RAD TO DEG argument Arguments and Return Values Data pe Argument REAL LREAL S
96. 0 000 characters long can be entered 2 2 Data Types Supported in Function Blocks 2 2 1 Basic Data Types Data type Content Range of values BOOL Bit data 0 FALSE 1 TRUE INT Integer 32 768 to 432 767 DINT Double integer 2 147 483 648 to 2 147 483 647 LINT Long 8 byte integer 9 223 372 036 854 775 808 to 9 223 372 036 854 775 807 UINT Unsigned integer amp 0 to 65 535 UDINT Unsigned double integer amp 0 to 4 294 967 295 ULINT Unsigned long 8 byte amp 0 to 18 446 744 073 709 551 615 integer REAL Real number 3 402823 x 10 8 to 1 175494 x 10738 0 41 175494 x 10738 to 3 402823 x 1098 LREAL Long real number 1 79769313486232 x 10908 to 2 22507385850720 x 10 908 0 2 22507385850720 x 10 908 to 1 79769313486232 x 10908 WORD 16 bit data 16 0000 to FFFF or amp 0 to 65 535 DWORD 32 bit data 32 00000000 to FFFFFFFF or amp 0 to 4 294 967 295 LWORD 64 bit data 64 0000000000000000 to FFFFFFFFFFFFFFFF or amp 0 to 18 446 744 073 709 551 615 STRING Text string Variable 1 to 255 ASCII characters TIMER Timer Flag 1 bit Timer number 0 to 4095 PV 16 bits Completion Flag 0 or 1 Timer PV 0 to 9999 BCD 0 to 65535 binary COUNTER Counter Flag 1 bit Counter number 0 to 4095 PV 16 bits Completion Flag 0 or 1 Counter PV 0 to 9999 BCD 0 to 65535 binary FUNCTION Function block instance BLOCK 2 2 2 Derivative Data Types
97. 0 words beginning from the automatically allocated address in variable a to the 10 words beginning with the automatically allocated address in variable b Therefore the CX Pro grammer will output a compile error Example XFER amp 10 a b variables a and b are WORD data types Example H700 Internally allocated address Internally allocated address Variable a 1 word Example H7L1 Variable b 1 word 10 words are B transferred regard less of the size of variable a i This area will be overwritten so the CX Programmer will output a compile error Array Variables 68 The result depends on the following conditions Precautions for Instructions with Operands Specifying the First or Last of Multiple Section 2 6 XFER amp 20 a 0 b 0 Size to Be Processed by Instruction Is Fixed If the size to be processed by the instruction is a fixed operand and this size does not match the number of array elements the CX Programmer will output a compile error Example LINE TO COLUMN 064 instruction COLM S D N S Bit number D First destination word N Source word E g COLM a b 0 C If an array for a WORD data type with 10 array elements is specified in D when it should be for 16 array elements the CX Programmer will output an error when compiling Size to Be Processed by Instruction Is Not Fixed When the operand size to be processed by the instruction is not fixed when
98. 10 ELSE X 0 END_IF Example 2 If variable A gt 0 and variable B gt 1 are both true variable X will be substituted with numerical value 10 and variable Y will be substituted with numerical value 20 If variable A gt 0 and variable B gt 1 are both false variable X and variable Y will both be substituted with numerical value O IF A20 AND B gt 1 THEN X 107 Y 220 ELSE X 20 Y 20 END IF Example 3 If the boolean BOOL data type variable A 1 ON variable X will be substituted with numerical value 10 If variable A O OFF variable X will be substituted with numerical value 0 IF A THEN X 10 ELSE X 0 END IF BH Summary This statement is used to execute an expression when a specified condition is met If the first condition is not met but another condition is met a corre sponding expression is executed If none of the conditions is met a different expression is executed B Reserved Words IF THEN ELSIF ELSE END IF 157 Statement Descriptions Section 5 5 Note ELSE can be omitted Statement Syntax IF lt condition_1 gt THEN lt expression_1 gt ELSIF lt condition_2 gt THEN lt expression_2 gt ELSIF condition 3 THEN expression 3 ELSIF condition n THEN expression n ELSE expression m END IF Processing Flow Chart Expression 1 False Expression m B Usage Use the IF statement to perform different operations depending which of mul tiple conditions
99. 110 3 2 14 Password Protection of Function Block Definitions 111 3 2 15 Comparing Function Blocks 0 00 00 0 0000005 114 3 2 16 Saving and Reusing Function Block Definition Files 114 3 2 17 Downloading Uploading Programs to the Actual CPU Unit 115 3 2 18 Monitoring and Debugging Function Blocks 116 3 2 19 Online Editing Function Block Definitions 124 81 Procedural Flow Section 3 1 3 1 Procedural Flow The following procedures are used to create function blocks save them in files transfer them to the CPU Unit monitor them and debug them Creating Function Blocks Create a Project Refer to 3 2 1 Creating a Project for details n Creating a New Project 1 2 3 1 Start the CX Programmer and select New from the File Menu 2 Select a Device type CS1G H CS1H H CJ1G H CJ1H H CJ1M or CP1H CP1L NSJ or FOM1 CM MMA MMP Reusing an Existing CX Programmer Project 1 2 3 1 Start the CX Programmer and read the existing project file cxp created using CX Programmer Ver 4 0 or earlier by selecting the file from the File Menu 2 Select a Device type CS1H H CS1G H CJ1G H CJ1H H CJ1M or CP1H CP1L NSJ or FQM1 CM MMA MMP Create a Function Block Refer to 3 2 2 Creating a New Function Block Definition for details Definition 1 2 3 1 Select Function Blocks in the project workspace and right click 2 Select Insert Function Bl
100. 2 ABEFGHC is stored in the Result variable Result DELETE Delete Characters Function ESBESEGEENES C D als Deletes the specified number of characters starting from the specified position of the specified text string Application Return value DEL Source string Number of characters Position Arguments and Return Values Variable name Source string Data type STRING Description Specifies the text string from which to delete characters Number of characters INT UINT Specifies the number of characters to delete Position INT UINT Specifies the position from which to delete characters The first character is position 1 e g position 1 is A in message 1 in the fol lowing illustration Return_value STRING Returns the text string with the specified number of characters deleted 199 Function Descriptions Appendix C Example Variables Message STRING Message1 STRING Result G c p E Result DEL Message1 4 2 AFGH is stored in the Result variable REPLACE Replace Characters e Function Replaces the specified number of characters starting from the specified position of the specified text string Application Heturn value REPLACE Source string Replace string Number of characters Position Arguments and Return Values
101. 2 5 X 2 6 10 X 3 11 12 15 20 X 4 ELSE Y 0 END CASE FOR Statement BH Summary This statement is used to execute a specified expression repeatedly until a variable referred to here as an iteration variable reaches a specified value B Reserved Words FOR TO BY DO END FOR Note BY can be omitted B Statement Syntax FOR iteration variable initial value TO final value equation BY increment value equation DO expression END FOR 161 Statement Descriptions 162 Note Section 5 5 B Processing Flow Chart Iteration variable Initial Iteration Iteration variable gt Final value True Expression Iteration variable Increment value End B Usage Use the FOR statement when the number of iterations has been determined beforehand FOR is particularly useful when switching the number of ele ments in an array variable according to the value of a specified iteration vari able B Description When the iteration_variable is the initial value the expression is executed After execution the value obtained from the increment_equation is added to the iteration variable and if the iteration variable final value equation see note 1 the expression is executed After execution the value obtained from the increment equation is added to the iteration variable and if the iteration variable final value equation value see note 1 the express
102. 2 S2 is output When n n extraction target data n 1 S n 1 is output Extraction target da ta1 S1 BOOL INT UINT UDINT ULINT DINT LINT WORD DWORD LWORD REAL LREAL Specifies the extraction target data Extraction target da ta2 S2 BOOL INT UINT UDINT ULINT DINT LINT WORD DWORD LWORD REAL LREAL Specifies the extraction target data Return value Note BOOL INT UINT UDINT ULINT DINT LINT WORD DWORD LWORD REAL LREAL Returns the output data Return value MUX Selection condition Extraction target data1 Extraction target data2 The same data type must be set for the return value and all arguments except for 1st one Extraction condition When any value other than 0 to 29 is specified for the extraction condition the value stored in the Result becomes undependable Example Variables INT N INT Data1 INT Data2 INT Data3 INT Result N 0 Data1 123 Data2 456 Data3 789 N 0 1 2 123 456 789 Result Result MUX N Data1 Data2 Data3 123 is stored in the Result variable 205 Function Descriptions Appendix C MAX Maximum Value Function Selects the maximum value from the target data Up to 31 data can be specified as target data Application Return value MAX Target data1 Target data2 Target dataG Target data31 Arguments and Return Values Variable name Data type Description
103. 21 44 setting 21 104 instances creating 23 99 multiple 48 number of 14 outline 14 registering in global symbol table 18 specifications 44 internal variables 37 internals 19 L ladder programming function block definition 86 restrictions in function blocks 53 223 Index M V menus 8 variable names 19 main 9 variables popup 10 address allocations 21 monitoring function blocks 116 checking address allocations 106 creating as needed 90 definitions 33 O introduction 18 properties 19 39 online editing PO ni4 registering in advance 87 function block definitions 124 A restrictions 53 restrictions 56 setting allocation areas 21 output variables 35 usage 19 34 outputs 19 P parameters outline 15 precautions xix applications xxi general xx safety xx Programming Consoles 56 projects creating 84 S safety precautions xx specifications CX Programmer Ver 5 0 5 function block operation 51 instances 44 structured text function block definition 86 restrictions 55 symbol name automatically generating 92 T timer instructions operation 77 restrictions 54 224 Revision History A manual revision code appears as a suffix to the catalog number on the front cover of the manual Cat No W447 E1 14 Revision code The following table outlines the changes made to the manual during each revision Page numbers refer to the
104. 3 1 Enterthe first letter of a function or a registered variable on the ST Program Editor to display the keyword list RP NewPLC1 NewProgram1 Structured Text Global symbol Local symbol You can identify whether each keyword is a function or a variable by the icon on the left side of the keyword Function Elements of ST statements Global symbol Local symbol Function block symbol 2 Select a function or a variable to enter on the list and press the Enter Space or Tab key The selection is entered and reflected onto the ST Pro gram Editor Note a To cancel the selection on the keyword list press the Esc key b You can directly enter functions and variables on the ST Program Editor without selecting from the keyword list Registering Variables When you use unregistered variables in writing ST language the dialog that While Entering ST asks you to register the variables to the symbol table will not appear while you Language enter the ST language 1 2 3 1 When you press the Enter key after writing a line a double underline is at tached to each unregistered variable IF average criterion margin THEN red laffip TRUE 182 Procedures Section 6 1 2 When you place the mouse cursor on the double underline a button will be displayed IF average criterion margin THEN red m TRUE 3 Pressthis button to display a dialog for registering new variables Set each i
105. 4 For details on structured text specifications refer to SECTION 5 Struc tured Text ST Language Specifications in Part 2 Structured Text ST Registering Variables as Required The ladder program or structured text program can be input first and variable registered as they are required Using a Ladder Program When using a ladder diagram a dialog box will be displayed to register the variable whenever a variable name that has not been registered is input The variable is registered at that time Use the following procedure 1 2 3 1 Press the C Key and input a variable name that has not been registered such as aaa in the New Contact Dialog Box Note Addresses cannot be directly input for instruction operands within function blocks Only Index Registers IR and Data Registers DR can be input directly as follows not as variables Addresses DRO to DR5 direct specifications IRO to IR15 and indirect specifications IRO to IR15 2 Click the OK Button The New Variable Dialog Box will be displayed With special instructions a New Variable Dialog Box will be display for each op erand in the instruction Name bI Data Type e Usage men o x hitial Vale FALSE v T Retein Comment Set the data type and other properties other than the name The properties for all input variables will initially be displayed as follows Usage Internal 90 Procedures 1 2 3 Section 3 2 e Data
106. 43H 63H 256 max per CPU Unit CJ1M CPU Units e CJ1M CPU11 12 13 21 22 23 256 max per CPU Unit CP1H CPU Units CP1H XA X Y 256 max per CPU Unit CP1L CPU Units CP1L M L 256 max per CPU Unit NSJ Controllers All models 2 048 max per Controller FQM1 Flexible Motion Controllers FQM1 CM002 MMA22 MMP22 256 max per Controller Number of instance CX Programmer Ver 5 0 nesting levels Nesting is not supported CX Programmer Ver 6 0 and later versions Supports nesting up to 8 levels The instance called from the program is counted as one nesting level Number of variables Maximum number of variables per function block definition ed oe ae Input output variables 16 max not including interna Input variables input output variables 64 max variables external vari 3 ables EN and ENO Output variables input output variables 64 max 32 Function Block Specifications Section 2 1 2 1 2 Function Block Elements The following table shows the items that must be entered by the user when defining function blocks Item Description Function block The name of the function block definition definition name Language The programming language used in the function block defini tion Select ladder programming or structured text Variable definitions Variable settings such as operands and return values
107. 532 and the bit number for SETB 532 is specified using amp 2 0 00 yf MOV 021 Move bo Source word wo Destination ae SETB 532 Bit Set wo Set Channel address amp 2 Bit In the following cases operand specifications must be changed using array settings after generating the function block definition Instructions with Multiword Operands Some of Which Are Changed by Another Instruction in the Program Circuits Example DO Specified as the First Word for MOVL 498 and D1 Specified for MOV 021 0 00 E H MOVL 498 Long Move 12345678 First source word bo First destination word H MOY 021 Move 1234 Source word D1 Destination 97 Procedures 98 Section 3 2 J As shown below the variables must be changed to specify the first word in an array and a specific word in the same array after the function block definition has been generated Example DT_WORD is set as a WORD array variable with 2 elements DT_WORDJ 0 is specified for MOVL 498 and DT_WORD 1 is specified for MOV 021 Bit01 MOVL 498 Long Move 12345678 First source word DT WORD 0 First destination word move2ty M 1234 Source word Move DT WORD 1 Destination Instructions with Two Operands Specifying Starting and Ending Words Example DO to D9 Specified for BSET 071 0 00 1 H H a BSET 0
108. 55 ladder instruction e As long as the execution condition is TRUE the present value is incremented accumulated 220 Function Descriptions Appendix C When the execution condition goes FALSE the timer will stop incrementing the present value but the present value will retain its value When the execution condition goes TRUE again it will resume incrementing the present value When the present value reaches the timer set value the timer completion flag will be turned ON The timer present value and the status of the timer completion flag will be maintained after the timer times out When the reset input is turned ON the timer will be reset Application TTIMX Execution condition Reset input Timer address Timer set value Arguments Variable name Data type Description Execution condition Increments accumulates the present value while the execu tion condition is TRUE Reset input Resets the timer s PV and completion flag when the reset input is ON Timer address Specifies the timer address TO to T4095 variable to use Timer set value Specifies the delay time in units of 0 1 s amp 0 to amp 65535 0 to FFFF Note Because the present value is incremented only when the instruction is executed this timer may not operate properly if the cycle time is 100 ms or longer When the timer completion flag is referenced from the user program the reflection of status change may be
109. 7 Maxi mum number of definitions Function blocks 1 024 1 024 1 024 1 024 1 024 Maxi mum number of instances Total for all files Kbytes Com ment Memory Unit ver 4 0 or later Function block pro gram memory Kbytes Inside com ment memory ver 3 0 or later Com ment files Kbytes Program index files Kbytes Variable tables Kbytes CJ1M CPU Units Specification Model Units with internal I O functions CJ1M CPU23 CJ1M CPU22 CJ1M CPU21 Units without internal I O functions CJ1M CPU13 CJ1M CPU12 CJ1M CPU11 I O points 640 320 160 640 320 160 Program capacity steps 20K 10K 5K 20K 10K 5K Number of Expan sion Racks 1 max Expansion not supported 1 max Expansion not supported Data memory 32K words Extended Data Memory None 73 CPU Unit Function Block Specifications Specification Section 2 8 Units with internal I O functions Units without internal I O functions Pulse start times 46 us without acceleration deceleration 70 us with acceleration decel eration 63 us without acceleration deceleration 100 us with acceleration deceleration Number of sched 2 1 2 1 uled interrupts PWM outputs 2 1 None Maximum value of 1 024 256 1 024 256
110. 71 Block Set 10 Source word bo Starting word D9 End word i As shown below the variables must be changed to specify the first word in an array and a specific word in the same array after the function block definition has been generated Example DT WORD is set as a WORD array variable with 10 elements DT WORDYJ O0 is specified for the first operand and DT WORDJ 9 is specified for the second operand of BSET 071 Bitoo BSET O71 Block Set 10 Source word DT_WORD 0 Starting word DT WORD 9 End word Procedures Section 3 2 Operands with Sizes Affected by Other Operands Example Five Transfer Words DO Specified for the First Source Word and D100 Specified for the First Destination Word for XFER 070 2 0 00 3 mou XFER 070 Transfer amp 5 Number of words bo First source word D100 First destination word ceccceccceececeettteets As shown below the variables must be changed to set the first elements in two different arrays after the function block definition has been generated Example DT_WORD1 and DT WORD are set as WORD array variables with 5 elements each DT_WORD1 0 is specified for the first word for the first operand and DT_WORD2 0 is specified for first word for the second operand of XFER 070 BiT00 1 XFER 070 Transfer 85 Number of words DT_ YORD1 0 First source word DT wWORD2 0 First destination word 3 2 4
111. 8 xl Je s m ee e S eo ola ule Jal m th m pe a cm 6 mms o nw 6n e a Q Ss infer me de ve nrun o e 8 amp xk C amp S e es e ts to ts s t Fe s Imm Ea E Exc ds e 5 E 39 2836 Me 3 35 gt WO Er no gt da Name oxange AT li avaee Retained Comment NewProject WorkMove FB ActuatorCo E E NewPLCI CI1 G H Monitor Mode DYDThickJudge FB AvgValue T C3 Symbols Judge BOOL FALSE E 10 Table and Unit Setup Judge BOOL FALSE Settings Internals Inputs Outputs In Out Externals S Memory card Error log PLC Clock Ge Memory The upper limit is 1 26mm the lower limit is 114mm 1 20mm 5 DVDThickJudge AvgValue ThresholdCheck ES Programs ay bisa jee Sg NewProgram1 00 Running N ENOL 2 Symbols Controls execut Gi Sectiont Measuret fean Goor Judge nput esuk 9 oat Measuremen S F Function Measure2 REAL A trol Input2 38F Avgvalue_ThresholdCheck Measuremen F DVD ThickSelectControl Measure3 REAL EF WorkMoveControl_LSONcount input3 Measuremen 1 26 REAL UpLimit 114 REAL LowLimit Judge Judge lA O 4 Project f xd sd Name Address or Value Comment 21fThe Function Block to be online edited is used in the following DIOISITS errem rrr NewProgrami Sectionl lL in For Help press F1 ja NewPLC1 Net 0 N
112. CJ1H CPULTDH R CJ1G CPULT The following information is included CJ1M CPULIU CJ1G CPUC TL TP C series Host Link commands CJ1G H CPULILIH CU2H CPU6LI EIP FINS commands CJ2H CPU6L CJ2M CPUL T I CS1W SCULIL V1 CS1W SCBLIL V1 Note This manual describes commands that can be sent to the CPU Unit without regard for the communications path CJ1W SCULTLI V1 CP1H X el which can be through a serial communications port on the CP1H XA LJ CP1H Y U CPU Unit a communications port on a Serial Communica CP1L M LO00 0 CP1E NOODL tions Unit Board or a port on any other Communications NSJO B G5D NSJO B M3D Unit SYSMAC CS CJ Series Communications Commands Reference Manual NSJ series NSJ Controller Manual Refer to the following manual for NSJ series NSJ Controller specifications and handling methods not given in this manual Models Name Description W452 NSJ5 TQOL B G5D NSJ Series Provides the following information about the NSJ series NSJ Con NSJ5 SQUIL1 B G5D Operation trollers NSJ8 TVLILI B G5D Manual Overview and features NSJ10 TVLIL B G5D Desianino th t fiau
113. Communica tions Unit Serial port INT UINT WORD 1 Serial port 1 2 Serial port 2 Internal logic port INT UINT WORD 0 to 7 Internal logic port number specified 16 F Automatic internal logic port allocation Example Serial Communications Unit SCU CPU Unit Unit No 0 Message Value to read Serial port 2 LLL Barcode reader i Variables I BOOL P DoRecvData Variable to control receive function i INT iProcess Process number STRING Message BOOL P RXDU Recv Status of Serial Communications Unit AT 1519 06 Unit No 0 Use serial port 2 I 1 I I I Variable to store received message i i 1 BOOL P ComilnstEnable Communications Port Enable Flag AT A202 07 Use port 7 i Use the following Unit number 0 Serial port number 2 Logical port number 7 Receive data when P DoRecvData is ON and iProcess is 0 IF P_DoRecvData TRUE AND iProcess 0 THEN iProcess 1 P_DoRecvData FALSE END_IF Execute receive processing according to process number CASE iProcess OF 1 Reception function executed if Communications Enabled Flag and Reception Completed Flag are ON IF P CominstEnable TRUE AND P RXDU Recv TRUE THEN RXD SCU Message 16 0 2 7 iProcess 2 END IF 2 Reception has been completed if Communications Port Enable Flag is ON IF P CominstEnable TRUE THEN iProcess
114. Creating Instances from Function Block Definitions If a function block definition is registered in the global symbol table either of the following methods can be used to create instances Method 1 Select the function block definition insert it into the program and input a new instance name The instance will automatically be registered in the global symbol table Method 2 Set the data type in the global symbol table to FUNCTION BLOCK specify the function block definition to use and input the instance name to register it Note When using ST language a function block can be called by select ing FUNCTION BLOCK as the variable s data type using the de sired instance name and entering a function block call statement 99 Procedures Section 3 2 n Method 1 Using the F Key in the Ladder Section Window and Inputting the Instance Name 1 2 3 1 In the Ladder Section Window place the cursor in the program where the instance is to be inserted and press the F Key Alternately select Func tion Block Invocation from the Insert Menu The New Function Block In vocation Dialog Box will be displayed When using ST language a function block can be called by selecting FUNCTION BLOCK as the variable s data type using the desired in stance name and entering the following function block call statement Specify arguments in parentheses after the instance name to pass input variable values from the callin
115. EAL LREAL Target data2 S2 BOOL INT UINT UDINT Specifies the target data ULINT DINT LINT WORD DWORD LWORD REAL LREAL Target data3 S3 BOOL INT UINT UDINT Specifies the target data ULINT DINT LINT WORD DWORD LWORD REAL LREAL Target data31 S31 BOOL INT UINT UDINT Specifies the target data ULINT DINT LINT WORD DWORD LWORD REAL LREAL Return value BOOL INT UINT UDINT Returns the output data ULINT DINT LINT WORD DWORD LWORD REAL LREAL Note Return value MIN Target data Target data2 Target data3 Target data31 The same data type must be set for all arguments and the return value Example Variables INT Data1 Data1 123 Data2 456 Data3 789 INT Data2 INT Data3 INT Result 123 456 789 Result Result MIN Data1 Data2 Data3 123 is stored in the Result variable 207 Function Descriptions Appendix C OMRON Expansion Function Memory Card Functions WRITE TEXT Create Text File Function Writes the specified text sting into the specified file in the Memory Card Application Write Text Write string Directory name and file name Delimiter Parameter Arguments and Return Values Variable name Data type Description Write string STRING Specifies the text string to write to a file Directory name and STRING Specifies the directory and file name including the root direc file name tory The file
116. HALL HAVE NO LIABILITY FOR SOFTWARE DEVELOPED BY THE USER OR ANY THIRD PARTY BASED ON THE SOFTWARE OR ANY CONSEQUENCE THEREOF APPLICABLE CONDITIONS USER SHALL NOT USE THE SOFTWARE FOR THE PURPOSE THAT IS NOT PROVIDED IN THE ATTACHED USER MANUAL CHANGE IN SPECIFICATION The software specifications and accessories may be changed at any time based on improvements and other reasons ERRORS AND OMISSIONS The information in this manual has been carefully checked and is believed to be accurate however no responsibility is assumed for clerical typographical or proofreading errors or omissions xvii xviii PRECAUTIONS This section provides general precautions for using the CX Programmer and the Programmable Logic Controller The information contained in this section is important for the safe and reliable application of the CX Programmer and Programmable Controller You must read this section and understand the information contained before attempting to set up or operate the CX Programmer and Programmable Controller 1 Intended Audience 15 usce tea VER Wat La ENT Sees XX 2 General Precautions cenie taea ea redii a i a hr XX 3 Safety Precautions i eene ek RR epp Rela 8 eee eds que tendo XX 4 Application Precautions 0 0 cece e xxi xix Intended Audience 1 2 3 XX Intended Audience This manual is intended for the following personnel who must also have knowledge of electrical systems an elec
117. IRO to IR15 always save the value of the Index Register at the point when the function block starts or before the Index Register is used and when the function block is completed or after the Index Register has been used incorporate processing in the program to return the Index Register to the saved value Example Starting function block or before using Index Register 1 Save the value of IR e g A C Value A Value A L1 d Within function block 2 Use IR Value B pi At start of function block or before Index Register is used 3 Return IR to saved value e g A Value A Value A A d 2 Always set the value before using Index Registers Operation will not be stable if Index Registers are used without the values being set 65 Function Block Applications Guidelines Section 2 5 Application Examples The following examples are for using Index Registers IRO to IR15 within func tion blocks Example Details Saving the Index Register Value before Using Index Register When Index Registers are used within this sie ia reni in Eae ea function block processing to save the Index Pon Register value is performed when the func tion starts or before the Index Register is used to enable the value to be returned to SavelR o First destination word the original Index Register value after the Ro function block is completed or after the Index Register is used Example
118. Index Register returns to the original Best delis ipo Wd tempos ier Re value after this function block is completed Fon rs ee or after the Index Register has been used 4 ong Move SeveR First source word Example The value for variable Save R 0 x aa scat that was saved is stored in Index Register IRO and the value is returned to the con tents from when this function started or prior to using the Index Register i i 1 H Always ON Flag 2 6 Precautions for Instructions with Operands Specifying the First or Last of Multiple Words When using ladder programming to create function blocks with instruction operands specifying the first or last of a range of words the following precau tions apply when specifying variables for the operand When the operand specifies the first or last word of multiple words the instruction operates according to the internally allocated address for AT set ting or external variable setting Therefore the variable data type and num ber of array elements are unrelated to the operation of the instruction Either specify a variable with an AT setting or an array variable with a size that matches the data size to be processed by the instruction Note To specify the first or last of multiple words in an instruction operand always specify a variable with AT setting or an external variable or a variable with the same size as the data size to be processed in the instruction T
119. LSE ON TIME amp 20 Input 200 100ms PULSE OFF TIME amp 10 PUN e ERR RC UE ERORIESTESTS 3 The contents of the Algorithm Image 7 instance are executed Pulse_2sON_1sOFF tim b Pulse 2sON 1sOFF tim a Pulse 250N 1sOFF OFF TIME Pulse 2s5ON 1sOFF tim a Pulse 2s5ON 1sOFF tim b Pulse 2sON 1sOFF ON TIME Pulse_2sON_1sOFF ENO The order of execution is as follows 1 Read data from parameters to input variables 2 Execute the algorithm 3 Write data from output variables to parameters Input to EN is ON Parameters 1 Read values from parameters to input variables 2 Execute the algorithm variables to parameters Data cannot be exchanged with parameters in the algorithm itself In addition if an output variable is not changed by the execution of the algo rithm the output parameter will retain its previous value 51 Instance Specifications Section 2 3 Operation when the Instance Is Not Executed When the input to the function block s EN input variable is OFF the function block is not called so the internal variables of the instance do not change val ues are retained In the same way the output variables do not change when EN is OFF values are retained Program FB definition Body P_Off FB 1 0 EN ENO IO P_On H O ENO Lc Internal variable a Execution results
120. LWORD Symbol data types CHANNEL NUMBER UINT BCD UDINT BCD or ULINT BCD however cannot be copied from the symbol table not the program and then pasted into the variable table in the function block definition Note Symbols with automatically generated symbol names AutoGen Address cannot be copied from a global symbol table and pasted into the function block definition symbol table Generating Function Block Definitions from Existing Ladder Programming One or more program circuits in a user program can be converted to the lad der programming in a function block definition 93 Procedures Section 3 2 Note This function is designed to help you create function block definitions based on existing ladder programming It does not automatically generate finish def initions After generating a function block definition with this function always check the warning messages in the FB Variable Allocation Dialog Box and Output Window and check the program that was generated and be sure to make any required changes 1 2 3 1 Right click one or more program circuits in the user program and select Function Block ladder generation from the pop up menu Note When any structure definitions exist on the data type view the Function Block ladder generation cannot be selected from the menu Program Name NewProgram1 Section Name Section Online Edit Go To Find Bit Addresses Find Addresses Find M
121. O 2 Specify the designated bit in the CIO Area e g CIO word n 1 bit 02 1 IRO bit 02 amp 2 B E SETB Turns ON CIO word n 1 2 5 6 Using Index Registers Index Registers IRO to IR15 function as pointers for specifying I O memory addresses These Index Registers can be used within function blocks to directly specify addresses using IRO to IR15 and not the variable names Index Register direct specification IRO to IR15 Index Register indirect speci fication IRO to IR15 Note After storing the real I O memory addresses in the Index Registers using the MOVR 560 instruction Index Registers can be indirectly specified using gen eral instructions This enables all I O memory areas to be specified dynami cally 64 Function Block Applications Guidelines Section 2 5 Pointer All 1 O memory areas MOVR 560 Index Register Example Specifying 5 IRO using F constant offset specification not Rn address variable name in IRO Function block 1 0 memory Indirect 45 offset specifi cation Specify ad dress at 5 offset from IRO Note 1 When Index Registers IRO to IR15 are used within function blocks using the same Index Register within other function blocks or in the program outside of function blocks will create competition between the two in stances and the program will not execute properly Therefore when using Index Registers
122. P will not be turned OFF even though input condition 0 00 goes OFF If Timer Instructions are being used always use the Always ON Flag P On for the EN input condition and include the instruction s input condition within the function block definition P On Body FBI i EN ENO y oo0 a UP The timer s completion flag UP is turned OFF when input condition a 0 00 goes OFF f the same instance containing a timer is used in multiple locations at the same time the timer will be duplicated 2 4 2 ST Programming Restrictions Restrictions when Only the following statements and operators are supported Using ST Language in Assignment statements Function Blocks Selection statements CASE and IF statements Iteration statements FOR WHILE REPEAT and EXIT statements RETURN statements Function block calling statements Arithmetic operators Logical operators Comparison operators Numerical functions Arithmetic functions Standard text string functions Numeric text string functions OMRON expansion functions Comments For further details refer to SECTION 5 Structured Text ST Language Speci fications in Part 2 Structured Text ST 55 Programming Restrictions Section 2 4 2 4 3 Programming Restrictions Restrictions in Locating Function Block Instances No Branches to the Left of the Instance Only One Instance per Rung No Function
123. PrevCycleLS LSright PrevCycleLS 0 LSright 0 Note When the program is being executed at a point outside of the function block instance the processing is the same as normal Step Run operation Step Out Use the following procedure to pause step execution of a ladder ST program within an instance Step Run operation and return to one level higher in the program the program or instance that was the source of the call 1 2 3 1 During Step Run operation move the cursor to any stopping point in the instance 2 Click the Step Out Icon or select Tools Simulation Mode Step Out 122 Procedures Section 3 2 Example Returning from an ST Program to the Calling Program or Instance Moves to here Stopped here 0 0000000 D4 Step Run 0 0000000 IF Reset TRUE THEN Reset 0 PrevCycleLS FALSE PrevCycleLS 0 END FF 2 yo WorkMove RightDirinout LeftDirinput LSright LSleft ActustorRightOn ActuatorLeQl eiseien i m o i eheu Sei n ISI nr elei dH Click the Step Out Icon to P_On IF PrevCycleLS FALSE and LSright TRUE THEN Always ON Flag LS GU ULM UHR return to the calling program wo E BOQ 400 D JF PrevCycleLS LSright PrevCycleLS 0 LSright 0 a On 5 3 Note The Step Out command can be executed only in a ladder ST program within an instance n Display when Operation is Paused by the Simulation Function The color of the cursor or
124. Programmer to input text strings in I O memory The data size in I O memory however must be considered Support for Input Output Variables The STRING data type text can be used in ST programming This enables for example substituting a text string for a variable e g a READ to easily set a variable containing text i e ASCII charac ters In doing this the user does not have to be concerned with the ASCII code or code size Text processing functions are supported for ST programming includ ing text extraction concatenation and searching This enables easily processing text strings and display messages in ST programming inside function blocks Functions are also supported for sending and receiving text strings This enables easily processing no protocol communications using ST programming in functions blocks without being concerned with ASCII codes Version 6 1 Version 7 0 Input output variables cannot be used in func tion blocks Only input variables internal vari ables and output variables can be used Arrays cannot be specified for input variables Values are passed from input parameters to input variables Input output variables can be used in function blocks Input output variables can be specified as arrays Addresses are passed from input parameters to input variables instead of values This enables using input output variable arrays inside function blocks to enable easily pa
125. Register IRO by the value for the variable Offset variable UnitNo X amp 25 H 1 Always ON Flag MOVL 498 Long Move IRO First source word 1 H Range Check O UnitNo Multiplier word Offset First addend word 66 Precautions for Instructions with Operands Specifying the First or Last of Multiple Words Section 2 6 Example Details 2 Specifying constant offset of Index Register Specifying a bit between The real I O memory address for CIO 1500 CIO n 0 to n 24 UnitNo X amp 25 is stored in Index Register IRO by the processing in step 1 above Therefore the word address is specified using the constant offset from IRO For example specifying 2 IRO will specify CIO 1500 UnitNo X amp 25 2 Note CIO 1500 UnitNo X amp 25 2 can also by specified by specifying SCPU relay 2 using the array set ting with SCPU relay Specify bit addresses using instructions that can specify bit addresses within words e g second operand of TST 350 351 SETB 532 instructions Check local node data link participation m Example Variable NodeSelf OK turns ON A m o when NetCheck_OK internal variable Local Node Net n Local Node Dat BOOL data type is ON and bit 15 of the word at the 6 offset from IRO CIO 1500 UnitNo X amp 25 6 is ON 815 Returning the Index Register to the Prior Value The
126. ST Language Configuration Section 5 4 Function Argument data type Return Description Example value data type CON Source_ STRING STRING Concatenates text a CONCAT b c CAT lt Source_string_1 gt lt S string strings text strings b c are joined ource string 2 Up to and stored in variable a 32 source strings INSERT Source string Source_ STRING STRING Insert one text a INSERT b c d lt nsert_string gt lt Position gt string string into another text string c inserted into text Insert_ STRING string b at position specified by string variable d and resulting string Position INT stored in variable a UINT DELETE Source string Source STRING STRING Deletes characters a DELETE b c d Number of characters string from a text string number of characters specified Position Number of INT by variable c deleted from text characters UINT string b starting from position Position INT specified by variable d and UINT resulting string stored in variable a REPLACE lt Source_string Source_ STRING STRING_ Replaces charac a REPLACE b c d e gt lt Replace_string gt string ters in a text string number of characters specified lt Number_of_characters gt Replace STRING by variable din source string b lt Position gt string replaced with text string c start INT ing from position specified by UINT variable e and resulting string stored in
127. Source string 1 STRING Specifies a text string to be joined Source string 2 STRING Specifies a text string to be joined Return value STRING Returns the joined text strings 198 Function Descriptions Appendix C Example Variables STRING Message1 STRING Message2 STRING Message3 STRING Result Message 1 Message 2 Message 3 D E G H Result CONCAT Message1 Message2 Message3 ABCDEFGH is stored in the Result variable Result INSERT Insert Characters e Function AJ B CI D EJF G Inserts the specified characters into a text string Application Heturn value INSERT Source string Insert string Position Arguments and Return Values Variable name Source string Data type STRING Description Specifies the text string into which to insert char acters Insert string STRING Specifies the text string to be inserted Position INT UINT Specifies the position at which to insert charac ters The first character is position 1 e g posi tion 1 is A in message 1 in the following illustration Return value Example Variables STRING Message1 STRING Message2 STRING Result STRING Message 1 Returns the text string with the characters inserted Message 2 G H Result INSERT Message1 Message2
128. Specifications Section 2 1 n External Variables External variables are either system defined variables that have been regis tered in CX Programmer before hand or variables that externally reference user defined variables in the global symbol table For details on system defined variables refer to Appendix A System defined external variables supported in function blocks To externally reference user defined variables in the global symbol table the variables of the same name and data type must be registered as an external variable However it is impossible to externally reference the variables user defined as a network symbol Variable Properties Variable Name The variable name is used to identify the variable in the function block The name can be up to 30 000 characters long The same name can be used in other function blocks Note A variable name must be input for variables even ones with AT settings spec ified address Data Type Any of the following types may be used Data type Content Outputs Internals Externals Bit data 1 bit OK OK Integer 16 bits OK OK Unsigned integer 16 bits OK OK Double integer 32 bits OK OK Unsigned double integer 32 bits OK OK Long 4 word integer 64 bits OK OK Unsigned long 4 word integer 64 bits OK OK 16 bit data 16 bits OK OK 32 bit data 32 bits OK OK 64 bit data 64 bits OK OK Real number 32 bits OK OK Long real number 64 bits OK OK Timer See note 1 Flag 1 bit Not su
129. Structure 0 0 00 0 000022 13 I 3 Wanables ele er Me eR ER 18 12321 Introduction o REPERI ER RI RD e HE 18 1 3 2 Variable Usage and Properties sllllsleleeeeeee ees 19 1 3 3 Variable Properties 0 0 0 eee eee e 19 1 3 4 Variable Properties and Variable Usage 20 1 3 5 Internal Allocation of Variable Addresses 21 1 4 Converting Function Block Definitions to Library Files 23 1 5 Usage Procedures rz bg Re RERUM ERE SES 23 1 5 1 Creating Function Blocks and Executing Instances 23 1 5 2 Reusing Function Blocks 0 0 0 0 eee eee 24 1 6 Version Upgrade Information 0 0 0 0 c eee eee eee 25 Introducing the Function Blocks Section 1 1 1 1 Introducing the Function Blocks 1 1 1 Overview and Features The CX Programmer Ver 5 0 and later versions is a Programming Device that can use standard IEC 61131 3 function blocks The CX Programmer function block function is supported for CJ2 CPU Units CP1H CPU Units NSJ series NSJ Controllers and FQM1 Flexible Motion Controllers as well as CS CJ series CPU Units with unit version 3 0 or later and has the following features User defined processes can be converted to block format by using func tion blocks Function block algorithms can be written in the ladder programming lan guage or in the structured text ST language See note When ladder programming
130. T UINT UDINT ULINT REAL LREAL STRING Subtraction INT DINT LINT UINT UDINT ULINT REAL LREAL Comparisons BOOL INT DINT LINT UINT UDINT ULINT WORD DWORD LWORD REAL LREAL STRING Equality BOOL INT DINT LINT UINT UDINT ULINT WORD DWORD LWORD REAL LREAL STRING Non equality BOOL INT DINT LINT UINT UDINT ULINT WORD DWORD LWORD REAL LREAL STRING Boolean AND BOOL WORD DWORD LWORD Boolean AND BOOL WORD DWORD LWORD Boolean exclusive BOOL WORD DWORD LWORD OR Boolean OR BOOL WORD DWORD LWORD 145 ST Language Configuration Section 5 4 Note Operations are performed according to the data type Therefore the addition result for INT data for example must be a variable using the INT data type Particularly care is required when a carry or borrow occurs in an operation for integer type variables For example using integer type variables A 3 and B 2 if the operation A B 2 is performed the result of A B is 1 1 5 with the value below the decimal discarded so A B 2 2 5 4 5 Standard Functions Function type Syntax Numerical Functions Absolute values trigonometric functions etc Arithmetic Functions Exponential EXPT Data Type Conversion Functions Source data type TO New data type Variable name Number String Conversion Functions Source data type TO STRING Variable name STRING TO New data type Variab
131. Time P Cycle Time Value UDINT A264 Cycle Time Error Flag P Cycle Time Error BOOL A401 08 Low Battery Flag P Low Battery BOOL A402 04 I O VerlFication Error Flag P IO Verify Error BOOL A402 09 Output OFF Bit P Output Off Bit BOOL A500 15 OMRON FB Library words see note CIO Area specification P CIO WORD A450 HR Area specification P HR WORD A452 WR Area specification P WR WORD A451 DM Area specification P DM WORD A460 EMO to C Area specification P EMO to P EMC WORD A461 to A473 Note These words are external variables for the OMRON FB Library Do not use these words for creating function blocks 191 System defined external variables supported in function blocks Appendix A 192 Error Messages Error Message s Input variables cannot be assigned a value Appendix B Structured Text Errors Cause of error A value was substituted for an input variable Example s operator not supported by 96s data type A numerical value or variable for a data type that is not sup ported by the operator was used A B 1 A and B are WORD type variables s variable had a read only memory AT Address and can not be assigned a value A value was substituted for a variable allocated to a read only memory address read only Auxiliary Area address or Condition Flag
132. U Unit The CPU Unit stores the source code and object code in user memory and built in flash memory Only when both the source code and object code exist in the CPU Unit can the CX Programmer transfer and restore the program for the upload operation Canceling Changes to Function Block Definitions Select FB online Edit Cancel to discard any changes made to a function block definition The function block definition will not be transferred to the CPU Unit and the original definition will be restored Effects on CPU Unit Operation Maximum Cycle Time Extensions for Online Editing Note A Caution The following will occur if online editing is performed with the CPU Unit oper ating in MONITOR mode 1 The cycle time of the CPU Unit will be extended by several cycle times when the program in the CPU Unit is rewritten and 2 The cycle time will again be extended when the results of online editing are backed up to built in flash memory At this time the BKUP indicator on the front of the CPU Unit will flash and the progress will be displayed on the CX Programmer The maximum extensions to the cycle time are given in the following table During online editing During backup of cycle time Cycle Time Monitor Time Be sure that the cycle time monitor time set in the PLC Setup is not exceeded when the program is rewritten as a result of online editing in MONITOR mode If the monitor time is exceeded a cycle time exceeded error will o
133. ULINT can be used as the vari able data type With an equation for ST language programming only Example a b c where b and c are variables Note Equations can contain only arithmetic operators and An array is a collection of data elements that are the same type of data Each array element is specified with the same variable name and a unique index The index indicates the location of the element in the array A one dimensional array is an array with just one index number Example When an internal variable named SCL is set as an array variable with 10 elements the following 10 variables can be used SCL 0 SCL 1 SCL 2 SCL 3 SCL 4 SCL 5 SCL 6 SCL 7 SCL 8 and SCLI 9 SUL WORD variable WORD variable WORD variable WORD variable WORD variable WORD variable WORD variable WORD variable WORD variable WORD variable 4 Specify SCL 3 to access this data element o o o00 0m5 o z Ei WORD axel Internal lt C Advanced Cetin Advanced Settings Array Settings v Array Variable Ailey Sie AT Setthes I AT Specified Address Name Data Type Cancel me Usage Initial Value Comment El il Settings for variable SCL as an array variable with element numbers 0 to 9 Use an array variable when specifying the first or last of multiple words in an instruction operand to enable r
134. WORD CMND tes P Error EmorBit z iu EE sr 3 Select Usage Data Type The FB Instance setting can also be selected The default Usage is N Internal and the other available selections are I Input O Output and E External The default Data Type is A All Special data types BOOL and INT can also be selected 4 Click the OK Button The selected variable will be registered in the Watch Window and the value will be displayed as shown below Procedures Section 3 2 Monitoring Input Variables and Output Variables in Instances Simulation of Ladder ST Programs in Instances 1 2 3 za o Program Name NewProgramt z sd HewProject o Select Register in Watch SE NewPLCI C21M oft Section Name Section symbols Windows G7 10 Table sampleot or Settings n 5 Pore Dnet214 GelinPower Stat Copy the instance and E Programs bo gpoo ea paste it in the Watch E Ge NewProgran A ji EN Window 3 Symbols Section Z a or D100 INT 1 B F oan Doe MasterUniNo 2 Enim Right click an empty row in E T Z Got i df Dei pue the Watch Window and D200 INT z SF Copy of f pute Eunction Block Definition select Register in Watch EF FunctionBloc Boe PLC a G zn FB Instance samplet z a Dele Usage Intemal z 1 i ls sin Rune Data Type an z lv Ls Project I Toje
135. X 1 bank EO 00000 to EO 32767 256 Maximum number of definitions Maximum number of instances Symbol tables comments pro gram indexes Function blocks 256 2 048 1MB See note Note There is no restriction on the memory capacity by the stored data The total capacity of source and comment areas is 1 MB 71 CPU Unit Function Block Specifications Section 2 8 Area Used for Function Blocks CS1 H CPU Units The area used for function blocks for CJ2 CPU Units depends on the model of the CPU Unit as shown in the following table CJ2M CPU Units have a special area for function blocks called the FB Program Area The CJ2H CPU Units do not have this area CPU Unit Modi Area used for function blocks CJ2H CPU6 Function blocks use memory in the user pro CJ2H CPU6 gram area CJ2M CPU3 Function blocks use memory in the FB Program CJ2M CPU1 Area If the capacity of the FB Program Area is exceeded the user program area is used Item Specification Model CS1H CS1H CS1H CS1H CS1H CS1G CS1G CS1G CS1G CPU67H CPU66H CPU65H CPU64H CPU63H CPU45H CPU44H CPU43H CPU42H I O points 5 120 1 280 960 Program capacity 250K 120K 60K 30K 20K 60K 30K 20K 10K steps Data memory 32K words Extended Data 32K 32K 32K 32K words X 1 bank 32K 32K words X 1 bank Memory words X words X words X Eo 00000 to wo
136. X Programmer crashes before the source code can be transferred In that happens it may be impossible to upload the program See note Note t may be still be possible to transfer the source code even if the above problem occurs a The following dialog box will be displayed the next time the CX Pro grammer is started CX Programmer v7 2 x FB SFC ST Source in the project D program sample3_NewPLC1 FBK i may not be transferred correctly Go online and check the status of the PLC b Click the OK Button c Goonline with the CPU Unit to which a transfer was made using Quick Mode d When you go online the CXP project automatically backed up in the computer will be started and the following dialog box will be displayed CX Programmer v7 2 s xi t Check if the backed up FB SFC ST Source can be transferred IF No is selected the program cannot be transferred from the PLC correctly after going online Yes No e Clickthe Yes Button and then following the instructions provided in the dialog boxes The source code automatically backed up in the comput er can be compared to the object code in the CPU Unit and if they match the source code can be transferred Procedures Note Section 3 2 Source Code and Object Code Before transferring a program the CX Programmer normally compiles the source code into object code so that the CPU Unit can execute it and then transfers both the source code and object code to the CP
137. a decrement ing counter CNTX a b c d The CNTX counter set to counter set value d in counter address c is exe cuted every time count input a is turned ON When the reset input b is ON the counter s PV and completion flag are reset CNTRX Increment count Decrement count Reset input Counter address Counter set value Increment count Decrement count Reset input Counter address Counter set value Name REVERSIBLE COUNTER Operation Operates an increment ing decrementing counter CNTRX a b c d e The CNTRX counter set to counter set value e in counter address dis executed The PV is incremented when increment count input a is turned ON and decremented when dec rement count input b is turned ON When the reset input c is ON the counter s PV and completion flag are reset TRSET lt Execution_condition gt lt Timer_address gt 154 Execution_ condition Timer_address Name TIMER RESET Operation Resets the specified timer TRSET a b When execution condi tion a is satisfied the timer in timer address b is reset Statement Descriptions Section 5 5 5 5 Statement Descriptions 5 5 1 Assignment BH Summary The left side of the statement variable is substituted with the right side of the statement equation variable or constant B Reserved Words Combination of colon
138. abet characters following a dollar sign are interpreted as listed in the following table The dollar sign ASCII 24 A single quotation mark ASCII 27 L or I Line feed ASCII 0A N or n Carriage return line feed ASCII OD 0A P or p New page ASCII OC R or r Carriage return ASCII OD ST or t Tab ASCII 09 When a text string is being stored from the ladder program in an ST func tion blocks STRING variable append a NULL character 00 to the end of the text string Example Passing string data to the function block STRING variable StrX Ladder program that stores 123456 in STRING variable StrX MOV 3132 D100 MOV 3334 D101 MOV 3536 D102 MOV 0000 D103 1 Attach a NULL character 00 at the end STRING data is stored to the function block by the ladder program above STRING STRING POS StrX StrX D100 About TIMER and Describe the TIMER and COUNTER type variables as shown below COUNTER Data Types 1 How to describe the TIMER type variables in the structured text Timer completion flag TIMER_type_variable_name CF Timer PV TIMER_type_variable_name PV Example Timer completion flag Timer1 CF Timer PV Timer1 PV 2 How to describe the COUNTER type variables Counter completion flag COUNTER_type_variable_name CF Counter PV COUNTER_typ
139. ables only 2 AT settings can be used only with the CIO Core I O Area A Auxiliary Area D Data Memory Area E Extended Memory Area H Holding Relay Area W Internal Relay Area The AT property cannot be set in the following memory areas Index Register and Data Register Areas directly indirectly specified Indirectly specified DM EM binary mode BCD mode 3 AT settings can be used for the following allocations Addresses for Basic I O Units CPU Bus Units or Special I O Units Auxiliary Area bits not registered as external variables in advance PLC addresses for other nodes in the network Example If the READ DATA FILE instruction FREAD is being used in the function block definition and it is necessary to check the File Memory Operation Flag A34313 use an internal variable and specify the flag s address in the AT set ting Register an internal variable select the AT setting option and specify A34313 as the address The status of the File Memory Operation Flag can be checked through this internal variable I x Advanced Settings x jtm INOW CARD ACCESS Array Settings Data Type BOOL cum T gray Variable Cancel Usage Internal z ined s Initial Value FALSE r Retain AT Settings Comment TV AT Specified Address de f ge PER 00795915 Address A34313 is allocated to a boolean internal variable named NOW CARD ACCESS When the AT setting is used the function bl
140. ags for all differentiated instructions DIFU 013 instructions DIFD 014 and instructions will be initialized i e turned OFF when online editing is finished After performing online editing do not turn OFF the power supply to the PLC until the CPU Unit has finished backing up data to the built in flash memory i e until the BKUP indicator stops flashing If the power supply is turned OFF before the data is backed up the data will not be backed up and the program will return to the status it had before online editing was performed Part 2 Structured Text ST SECTION 4 Introduction to Structured Text This section introduces the structure text programming functionality of the CX Programmer and explains the features that are not contained in the non structured text version of CX Programmer 4 1 4 2 ST Language 4 1 1 Overview CX Programmer Specifications 0 0 0 eee eee eee eee PLC Models Compatible with ST Programs ST Tasks 4 2 1 4 2 2 Specifications 134 134 135 135 135 133 ST Language 4 1 4 1 1 134 Section 4 1 ST Language Overview This section explains the specifications and operating procedures for ST pro grams directly allocated to CX Programmer tasks ST tasks Refer to the fol lowing sections for information on functions and operations specific to ST programs used in other programs function blocks or SFC ST programs used in f
141. ally scroll the display and always show tion Point the pause point Break Point List Displays a list of the break points that have been set Operation can be jumped to a specified point Change Input mode Smart Input The Smart Input Mode can be used to automatically display Mode candidates for instructions and addresses Classic Mode The Classic Mode is the input mode that is used previous version of CX Programmer Main Pop up Menus Pop up Menu for Function Block Definitions Pop up menu Function Insert Function Block Ladder Creates a function block definition with a ladder programming language algo rithm Structured Text Creates a function block definition with an ST language algorithm From file Reads a function block definition from a function block library file cxf Pop up Menu for Inserted Function Blocks Pop up menu Function Open Displays the contents of the selected function block definition on the right side of the window Save Function Block File Saves the selected function block definition in a file Compile Compiles the selected function block definition FB online Edit Begin Starts online editing of a function block Send Change Transfers changes made during online editing of a function block Cancel Cancels changes made to a function block being edited online Transfer FB Source Transfers only the function block source Release FB Online Forcefully releases the a
142. am check on it Use the following procedure 1 2 3 1 Select the ST program right click and select Compile from the pop up menu Alternately press the Ctrl F7 Keys 2 The ST program will be compiled and the results of the program check will be automatically displayed on the Compile Table Page of the Output Win dow xix Name Address Value Rack Local E NewProject flag INT bo EP NewPLCt C31H H Offline green lamp BOOL 15 01 m Symbols margin REAL D6 10 Table and Unit Setup red lamp BOOL 15 00 3 eig B thickness1 REAL Di o thickness2 REAL D2 2 Nh Programs thickness3 REAL D3 R Work piece Measurement 00 sni 3 Symbols n 5 QJ Default Setting average thickness1 thickness2 thickness3 3 0 KJ Measurement END emer z ER Average Value Calculation 01 IF flag 3 THEN a Symbols IF average lt criterion margin THEN gl Result Display 02 gf oda TRUE C3 symbols ELSIF average gt criterion margin THEN zio red lamp TRUE EJ LED Display LSE END green lamp TRUE GF Function Blocks END IF END IF Project Ladder Section Name Measurement Ladder Section Name END PLC Program Name NewPLC1 amp verage Value Calculation WARNING Program Name exceeds 24 characters may be truncated when downloaded to PLC PLC Program Name NewPLC1 Result_Display Ladder Section Name LED Display Ladder Section Name END Results of program check displayed
143. am1 Sectioni Diagram ni x EB File Edt view Insert PLC Program Tools Window Help 8 x Du E rR amp A S8 o c a 5 5 2 S 34 40 RAR RFR DEPTS w P a XQ ssl viw o 2 8 8t a CB x bg ER Je Fi Ko m m REIS a5 RIS 5 ED 22 39 26 oB peH s p XC ax o o Bi Program Name NewProgramt E EEP NewPLCI CI1G H Offline Section Name Sectiont eic p ion Name Sectio Hoe sme Instance name 49 Memory Functions Function block definition ER Sus m 0 00 B001 000 NewProgram S symbols a An instance called sample FL e001 woo is created from the function c dE Function Blocks initi ATF FunctionBlockt ome block definition called ae FunctionBlock1 The instance will be automatically registered in the global symbol table with an instance name of sample and a data type of FUNCTION BLOCK n Method 2 Registering the Instance Name in the Global Symbol Table in Advance and Then Selecting the Instance Name If the instance name is registered in the global symbol table in advance the instance name can be selected from the global symbol table to create other instances 100 Procedures 1 2 3 Restrictions Note 3 2 5 Section 3 2 1 For a ladder diagram select a data type of Function block in the global symbol table input the instance name and registered the instance For ST select a data type of Function block use the instance name and use a call statement for th
144. ams Refer to the Programmable Controllers Instructions Reference Manual Cat No W474 Addresses in the following areas cannot be used for AT settings Index Registers neither indirect nor direct addressing is supported and Data Registers Note Input the address directly not the AT setting Indirect addressing of DM or EM Area addresses Neither binary mode nor BCD mode indirect addressing is supported Addresses not variables can be directly input in Index Registers both indirect and direct addressing and Data Registers The following values can be input in instruction operands Direct addressing IRO to IR15 Indirect addressing IRO to IR15 Con stant offset example 5 IRO DR offset DRO IRO Auto increment RO Auto decrement IRO Direct addressing in instruction operands is not supported for any other areas in I O memory Addresses in the following data areas cannot be used as parameters for input variables output variables and input output variables Index Registers neither indirect nor direct addressing is supported and Data Registers Indirect addressing of DM or EM Area addresses Neither binary mode nor BCD mode indirect addressing is supported When a function block is called from an interlocked program section the con tents of the function block definition will not be executed The interlocked func tion block will behave just like an interlocked subroutine e FB O e ILC
145. areas not used by the user program If another area is set the addresses may overlap with addresses that are used in the user program If the addresses in the function block instance areas overlap with any of the addresses used in the user program an error will occur when compil ing This error will also occur when a program is downloaded edited on line or checked by the user x PLC NewPLCT PLE Model Cola HIFB CPUS Lo Compiling PLC Program Name NewPLC1 NewProgramt Section Name Section ERROR Step at rung 0 0 0 Address W0 00 is reserved for Function Block use Work Area Addresses ERROR Step at rung 0 1 0 Address W0 01 is reserved for Function Block use ERROR Step at rung 0 2 0 Address W3 00 is reserved for Function Block use used in the user ERROR Step at rung D 3 0 Address W5 00 is reserved for Function Block use ith ERROR Step at rung 0 4 0 Address W3 01 is reserved for Function Block use ERROR Step at rung 0 5 0 Address W2 00 is reserved for Function Block use program over ap wi ERROR Step at rung 0 6 0 Address W100 01 is reserved for Function Block use the instance areas Section Name END NewProgram 7 errors 0 warnings Compile Find Report Transfer 7 Id gt If addresses are duplicated and an error occurs either change the function block instance areas or the addresses used in the user program FQM1 Flexible Motion Controllers
146. ariables For details refer to Initial Value under the preceding descriptions of input variables internal variables and output variables Retained Comme EN BOOL Contre CD BOOL LD BOOL PY UINT Name Data Type UINT m Internals Inputs Usage Input m 0 E LD BH 3 md Initial Value 30 hetain D uessirey toot onera 1 OS Retaining Data through Power Interruptions and Start of Operation The values of internal variables can be retained through power interruptions and the start of operation When the Retain Option is selected the variable will be allocated to a region of memory that is retained when the power is interrupted and PLC operation starts Enter the logic programming using the registered variables Addresses cannot be directly input into instruction operands within function blocks Addresses that are directly input will be treated as variable names Exception Input directly or indirectly specified addresses for Index Registers IRO to IR15 and Data Registers DRO to DR15 directly into the instruction operand Do not input variables Input constants directly into instruction operands Ladder programming Enter decimal values after the amp and enter hexadecimal numerical values after the Data Types Supported in Function Blocks Section 2 2 Structured text ST language Enter decimal numerical values as is and enter hexadecimal numerical values after 161 Comment A comment of up to 3
147. at instance only The break point is not valid for other instances created from the same function block definition 123 Procedures Section 3 2 3 2 19 Online Editing Function Block Definitions Ladder diagrams for ST programs in function block definitions can be edited even when the CPU Unit is operating in MONITOR mode This enables debugging or changing function block definitions even in systems that cannot be shut down such as systems that operate 24 hours a day To edit function block definitions online you must use CX Programmer version 7 0 or higher i e CX One version 2 0 or higher and a CS CJ series CPU Unit with unit version 4 0 or later See note or a CJ2 series CPU Unit This function cannot be used for simulations on CX Simulator Note With CS CJ series CPU Units with unit version 3 0 online editing can be used to change peripheral aspects of function block instanc es Parameters passing data to from instances can be changed in structions not in instances can be changed and instances can be deleted Instances cannot be added instance names cannot be changed and changes cannot be made to variable tables or algorithms in function block definitions Editing Reserved Memory to Add an Internal Variable with Online Editing 124 1 2 3 To add an internal variable to the variable table in a function block definition the memory required for the size of the variable being added must be reserved in ad
148. at was registered from the pull down menu on the FB Instance Field Refer to 3 2 5 Setting Function Block Parameters Using the Enter Key for details 1 Place the cursor at the position of the input variable or output variable and press the P Key 2 Input the source address for the input variable or the destination address for the output variable Refer to 3 2 6 Setting the FB Instance Areas for details 1 Select the instance and select Function Block SFC Memory Function Block SFC Memory Allocation from the PLC Menu 2 Set the function block memory allocations Printing Saving and Reusing Function Block Files Compile the Function Block Definition and Save It as a Library File 1 2 3 Refer to 3 2 12 Compiling Function Block Definitions Checking Program and 3 2 16 Saving and Reusing Function Block Definition Files for details Compile the function block that has been saved Print the function block Save the function block as a function block definition file cxf Read the file into another PLC project Boe Transferring the Program to the PLC Refer to 3 2 17 Downloading Uploading Programs to the Actual CPU Unit Monitoring and Debugging the Function Block Refer to 3 2 18 Monitoring and Debugging Function Blocks 83 Procedures Section 3 2 3 2 Procedures 3 2 1 Creating a Project Creating New Projects with CX Programmer 1 2 3 1 Start the CX Programmer and select New from the File Me
149. ayed on the left side of the instance Displayed on the right side of the instance Displayed on the left and right sides of the instance Not displayed Not displayed Number allowed 64 max per func tion block exclud ing EN 64 max per func tion block exclud ing ENO 16 max per func tion block Unlimited Unlimited AT setting No No No Supported No Array setting No No Supported Supported No Retain setting Supported See note 2 Supported No Supported No Variables cre ated by default EN Enable Receives an input condition ENO Enable Out put Outputs the func tion block s execu tion status None Pre defined sym bols registered in advance as vari ables in the CX Programmer such as Condition Flags and some Auxil iary Area bits Note 1 For details on Externals refer to Appendix A System defined external variables supported in function blocks 2 The value of the input parameter will be given 3 Structure variables and TIMER COUNTER type variables can be used only for the following variables Structure variables Internal variables input output variables and exter nal variables TIMER COUNTER type variables Internal variables and external vari ables 34 Function Block Specifications Section 2 1 n Input Variables Input variables pass external operands to the insta
150. be displayed as ERROR omitted Address WO 00 is reserved for Function Block use Program P Off FB 10 5 tart EN ENO LC Instance data area arses Size Non Retain 0 512 Retain fm sep 3 0 Timers Counters gt Compile error The allocations in the function block instance area for variables are automati cally reallocated when a variable is added or deleted A single instance requires addresses in sequence however so if addresses in sequence can not be obtained all variables will be allocated different addresses As a result unused areas will be created If this occurs execute the optimization opera tion to effectively use the allocated areas and remove the unused areas A comment of up to 30 000 characters long can be entered A single instance can be called from multiple locations In this case the inter nal variables will be shared Multiple instances can be created from a single function block definition In this case the values of internal variables will be different in each instance Example Counting Product A and Product B Prepare a function block definition called Down Counter CTD and set up counters for product A and product B There are two types of programs one for automatic operation and another for manual operation The user can switch to the appropriate mode of operation In this case multiple instances will be created
151. be passed even if an address is set in the parameter Note Input parameters must be set If even one input param eter has not been set a fatal error will occur and the input parameters will not be transferred to the actual PLC Output parameters Addresses program symbols global symbols local symbols See note 2 Input output parame Addresses program symbols global symbols local symbols ters Note The following table shows the methods for inputting values in parameters Input Contents Parameter value input Setting range variable method data type BOOL POP On O FALSE 1 TRUE 49 Instance Specifications Input variable data type Contents Integer 16 bits Parameter value input method Positive value amp or followed Double integer 32 bits by integer Long 8 byte integer 64 bits Negative value followed by integer Section 2 3 Setting range 32 768 to 32 767 2 147 483 648 to 2 147 483 647 9 223 372 036 854 775 808 to 9 223 372 036 854 775 807 Unsigned integer 16 bits Positive value amp or followed Unsigned double integer 32 bits by integer Unsigned long 8 byte 64 bits integer amp 0 to 65 535 amp 0 to 4 294 967 295 amp 0 to 18 446 744 073 709 551 615 Real number 32 bits Positive value amp or followed by real number with decimal point Long real number 64 bits Negative va
152. ble is an ENO Enable Out variable which passes the instance s execution status In Out Input output variables can input data from input parameters out side of the instance and can return the results of processing in a function block instance to external parameters Externals External variables are either system defined variables registered in advance with the CX Programmer such as the Condition Flags and some Auxiliary Area bits or user defined global symbols for use within instances For details on variable usage refer to the section on Variable Type Usage under Variable Definitions in 2 1 2 Function Block Elements The following table shows the number of variables that can be used and the kind of variable that is created by default for each of the variable usages 1 3 3 Variable Properties Variable Name Note Data Type AT Settings Allocation to an Actual Addresses Variables have the following properties The variable name is used to identify the variable in the function block It doesn t matter if the same name is used in other function blocks The variable name can be up to 30 000 characters long but must not begin with a number Also the name cannot contain two underscore characters in a row The character string cannot be the same as that of a an index register such as in IRO to IR15 For details on other restrictions refer to Variable Defi nitions in 2 1 2 Function Block Elements Select one of the foll
153. but variables The user sets addresses or constants in those vari ables These address or constants are called parameters The addresses used by the variables themselves are allocated automatically by the CX Pro grammer for each program 11 Function Blocks Section 1 2 With the CX Programmer a single function block can be saved as a single file and reused in other PLC programs so standard processing functions can be made into libraries Program 2 Copy of function block A eet Function block A Program 1 se L Copy of function block A Variable Output Standard i pe program section ril written with VT 7 variables Input Variable Variable Output Define in advance Insert in program Set Set N Copy of function block A N IL N Input Variable Variable Output Save function block as a file Convert to library function Function block A _____ To another PLC program Reuse 1 2 2 Advantages of Function Blocks Structured Programming Easy to read Black Box Design Use One Function Block for Multiple Processes Reduce Coding Errors Black boxing Know how Data Protection Improved Reusability with Variable Programming Creating Libraries 12 Function blocks allow complex programming units to be reused easily Once standard programming is created in a function block and saved in a file it can be reused just by
154. c xi sl Name BUSY TT rr A P ER BODL Error Bit nn i Data T FUSCO lick the OK Button Nose Gi ss BOOL Range Che BOOL Internal B NEB BOOL ies Ch amp 00LC InemalO register f Bit lange Che BOOL Internal AddressOk_Bit BOOL Addiss Rat BOOLC Internal Control Data WORD CMND cor T UE TAS Tmp Data WORD For intema WORD Tanker Phase WORD Process ot a WORD Internal Proces Command Data WORD CMND cor WORD Internal CMND Response Data WORD CMND tea WORD Internal CMNDr PE Boot EE s BOOL Internal Error Bit 4 gt BOOL Internal NewPLC1 sample H543 INT Si Internal Zi 4 4T X sheet A sheet A sheets punc Dj Select variables to register in Watch Window NewPLC1 Net 0 Node 0 Offline rung 0 3 2 100 Z The present values of input variables and output variables parameters are displayed below the parameters Function001 Function Block1 Lum Roo ENH oY Neut OE PUT AR tNeut PV of parameter for I O variable The CX One Ver 1 1 CX Programmer Ver 6 1 and later versions have a sim ulation function that can simulate the operation of a ladder program or ST pro gram within a function block instance Both step execution and break point operation are supported To return to the original instance right click in the ST program monitor window and select To Upper Layer from the pop up menu Enabling the Simulation Function Use the following procedure to enable the simulati
155. caution in the middle of the page Page 142 Changed notations in top two tables Page 145 Changed data types for Exponential Page 147 Changed data types for Exponent Page 148 Added information on rounding the fractional part of variable C Page 151 Reversed TRUE and FALSE in the example column for SEL October 2015 Added upgrade information from Ver 9 5 to Ver 9 6 and corrected mistakes 225 Revision History 226 Authorized Distributor
156. ccess rights for function block online editing held by Edit Access Rights another user 10 Function Blocks Section 1 2 Pop up Menu for Function Block Variable Tables Pop up menu Function Edit Edits the variable Insert Variable Adds a variable to the last line Above Insert Variable Inserts the variable above the current cursor position Below Inserts the variable below the current cursor position Cut Cuts the variable Copy Copies the variable Paste Pastes the variable Find Searches for the variable Variable names variable comments or all text strings can be searched Replace Replaces the variable Delete Deletes the variable Rename Pop up Menu for Instances Changes only the name of the variable Pop up menu Function Edit Changes the instance name Update Invocation When a function block definition s input variables output variables or input output vari ables have been changed after the instance was created an error will be indicated by displaying the instance s left bus bar in red This command updates the instance with the new information and clears the error Monitor FB Ladder Instance When monitoring the program online monitors I O bit and word status I O bit monitor of the ladder diagram in the instance Supported by CX Programmer Ver 6 0 and later only
157. ccur and CPU Unit operation will stop If this occurs switch to PROGRAM mode and then to MONITOR or RUN mode to restart operation If synchronous unit operation is being used an increase in the synchronous processing time caused by online editing may result in unexpected operation timing Perform online editing only after confirming that an increased synchro nous processing time will not affect the operation of the main and slave axes Restrictions in Online Editing of Function Block Definitions The following restrictions apply to online editing of function block definitions Online editing is not possible for function block definitions that exceed 4 Ksteps except for CJ2 series CPU Units A maximum of 0 5 Ksteps can be added to or deleted from a function block definition during one online editing operation except for CJ2 series CPU Units Input variables output variables and input output variables cannot be added or deleted New function block instances cannot be added Instance names cannot be changed 129 Procedures 130 Section 3 2 Internal variables can be added internal variable comments can be changed and internal variables can be deleted from the variable table in the function block definition To add an internal variable however memory must be reserved in advance Refer to Editing Reserved Memory to Add an Internal Variable with Online Editing on page 124 for details The previous status fl
158. characters INT UINT Specifies the number of char acters to extract Return value STRING Returns the extracted charac ters Example Variables STRING Message Message A B C D EJ F GH STRING Result Result RIGHT Message 3 FGH is stored in the Result variable MID Extract Characters from Middle Function Extracts the specified number of characters starting from the specified position of the specified text string Application Heturn value MID Source string Number of characters Position Arguments and Return Values Variable name Data type Description Source string STRING Specifies the text string from which to extract characters Number of characters INT UINT Specifies the number of characters to extract Position INT UINT Specifies the position from which to start extracting characters The first character is position 1 e g position 1 is A in mes sage 1 in the following illustration Return value STRING Returns the extracted characters Example Variables Message A B C D E F GI H STRING Message STRING Result Result MID Message 3 2 BCD is stored in the Result variable CONCAT Concatenate Strings Function Joins the specified text strings Up to 31 text strings can be specified Application Return value CONCAT Source string 1 Source string 2 Arguments and Return Values Variable name Data type Description
159. ck me em A E 38 egg wom n Node Nodo EE qoo oa 3 Eu PT 0000 He x RD D220 h SET Set wean Range Check EM s TERE ferae creen at 1 q Autoriai program a standard UK trattic ight sequence o a Red liebt an anh z Ki visi Isl 2i 3 If an array variable is used in a function block and a symbol is used for the array variable s arguments the present value cannot be monitored if that array variable is used as the operand of an input condition or special in struction In this case the input condition or instruction will be displayed in red Swih Swi MOV 021 Ei DATA 116 Procedures Section 3 2 Monitoring Variables of ST Programs within Instances With the CX Programmer Ver 6 1 and later versions it is possible to monitor the ST programs within an instance when monitoring the program To monitor I O bits and words I O Bit Monitor either double click the instance or right click the instance and select Monitor FB Instance from the pop up menu To return to the original instance right click in the ST program monitor window and select To Upper Layer from the pop up menu B 0 Function Block Name DVD ThickSelectControl B Instance Name Stage amp DVDThickSelect The upper limit is 1 26mm the lower limit is 1 14mm 1 20mm 5 1777 SS bg 2 AvgValue Th esholdCheck ES GROG mm Bo ccc ENO Controls exec Measure REAL BOOL Judge Measuremen J
160. ck definition A 1 Algorithm Input a condition 5 The system automatically allocates the addresses used by these Standard _ variables Set the data area in Progra section T which these addresses are allocated with variable Insert in Input0 00 a I Output 2 00 names a b c program etc NI Nu P4 c Output 3 00 PA d d 2 Variables L f o p Table defini A land propertis of 4 Specify the input source and variables a b c etc output destination addresses 1 5 2 Reusing Function Blocks Use the following procedure to save a function block definition as a file and use it in a program for another PLCs 24 1 2 3 Note 1 Select the function block that you want to save and save it as a function block definition file cxf 2 Open the other PLC s project and open read the function block definition file cxf that was saved 3 Insert the function block definition in the program when creating the new program Function block definition A 1 Algorithm Program Input Instance of function block definition A Standard condition program section with variable names a b c eic Input 1 00 a b Output 5 00 2 Variables c Output 6 00 Table defining usage land properties of Read and variables a b c etc insert Function block definition A id LLL Function block definition file cxf In the CX Programmer Ver 5 0 each functio
161. ction 3 2 Ladder program Note Function block definitions are not displayed in the default settings for OMRON FB Library files cxf To display definitions select the Display the inside of FB option in the function block properties Select the OMRON FB Library file in the project workspace right click select Properties and select the Dis play the inside of FB option in the General Tab 3 2 3 Defining Function Blocks Created by User A function block is defined by registering variables and creating an algorithm There are two ways to do this Register the variables first and then input the ladder program or structure text Register variables as they are required while inputting input the ladder program or structure text Registering Variables First Registering Variables in The variables are divided by type into five sheets in the variable table Inter the Variable Table nals Inputs Outputs Input Output and Externals These sheets must be switched while registering or displaying the variables 1 2 3 1 Make the sheet for the type of variable to be registered active in the vari able table See note Place the cursor in the sheet right click and per form either of the following operations To add a variable to the last line select Insert Variable from the pop up menu To add the variable to the line ab
162. ction 5 4 5 4 2 Variables For details on variable specifications and setting methods refer to the CX Programmer Operation Manual W469 5 4 3 Inputting Constants Numerical values can be expressed in decimal hexadecimal octal or binary as shown in the following examples Notation Method Example for the decimal value 12 Decimal Numerical value only 12 Hexadecimal 16 followed by numerical value 16 C Octal 8 followed by numerical value 8 14 Binary 2 followed by numerical value 2 1100 Text string Place in single quotation marks Hello world Note Negative hexadecimal octal and binary numbers are expressed as 2 s com plements The valid range of INT data is 32 768 to 32 767 in decimal but 0000 to FFFF in hexadecimal so the 2 s complement is used for negative integers For example when a value of 10 decimal is set in an INT variable it will be expressed as 164 FFF6 in hexadecimal 5 4 4 Operators Operation Data types supported by operator Priority 1 Lowest 11 Highest Parentheses and expression brackets array index Function evaluation identifier Depends on the function refer to Appendix C Func tion Descriptions Exponential Base REAL LREAL Exponent INT DINT LINT UINT UDINT ULINT REAL LREAL Complement BOOL WORD DWORD LWORD Multiplication INT DINT LINT UINT UDINT ULINT REAL LREAL Division INT DINT LINT UINT UDINT ULINT REAL LREAL Addition INT DINT LIN
163. ction condition BOOL Selects S2 if the selection condition g is 9 TRUE 1 Selects S1 if it is FALSE 0 Selection_target_dat BOOL INT UINT UDINT Specifies the selection target data a1 S1 ULINT DINT LINT WORD DWORD LWORD REAL LREAL Selection_target_dat BOOL INT UINT UDINT Specifies the selection target data a2 S2 ULINT DINT LINT WORD DWORD LWORD REAL LREAL Return_value BOOL INT UINT UDINT Returns the output data ULINT DINT LINT WORD DWORD LWORD REAL LREAL Note The same data type must be set for both Selection target data arguments 204 Function Descriptions Appendix C Example Variables BOOL G INT Data1 INT Data2 INT Result MUX Multiplexer Function G 1 Data1 123 Data2 456 Gz 0 1 123 456 Result Result SEL G Data1 Data2 456 is stored in the Result variable Extracts a specified data according to the extraction condition Up to 30 data can be specified as extraction targets Application Return value MUX Extraction condition Extraction target data1 Extraction target data2 Arguments and Return Values Variable name Description Extraction condition n Data type INT UINT UDINT ULINT DINT LINT Specifies the data to be extracted Extraction condition n Q 1 2 29 When n 0 extraction target data1 S1 is output When n 1 extraction target data
164. ction output is illegal A non boolean BOOL variable or numeral has been specified as the ENO transfer destina tion Y SIN X1 ENO gt 1 Missing The call for a data format con version instruction or function does not contain a open ing parenthesis Y INT_TO_DINT X Missing The operator parentheses or the call for a data format con version instruction or function does not contain a closing parenthesis corresponding to opening parenthesis Y X1 X2 2 Missing The integer equation in the CASE statement is not fol lowed by a colon CASE A OF 1 X 1 END_CASE Missing is not included in the assignment equation Missing The statement is not con cluded by a semicolon Missing DO DO is not provided in the FOR or WHILE statement Missing END_CASE END_CASE is not provided at the end of the CASE state ment Missing END_FOR END_FOR is not provided at the end of the FOR statement Missing END_IF END IF is not provided at the end of the IF statement Missing END REPEAT 194 END REPEAT is not pro vided at the end of the REPEAT statement Structured Text Errors Error Message Missing END_WHILE Cause of error END_WHILE is not pro vided at the end of the WHILE statement Appendix B Example Missing Input Parameter All inp
165. d Internal and I O ON TIME variables 88 OFF_TIME If internal variables are not used if processing will not be affected or if the internal variables are used in other locations the same instance name can be used at multiple locations in the program Cyclic task SIDE 10 P On CONTROL N EN ENO amp 100 O The same instance can be PARAI used at multiple locations amp 180 PARA 2 Function block definition Example CONTROL oe CASCADE P_On CONTROL 1 1 Algorithm Algorithm F EN ENO amp 50 3 Internal and 1 O PARA 1 Variables arlables ais pana 2 Gyclic task cape 1 2 P Qe CONTROL 1 EN ENO amp 100 O PARA 1 amp 200 PARA 2 Some precautions are required when using the same memory area For example if the same instance containing a timer instruction is used in more than one program location the same timer number will be used causing coil duplication and the timer will not function properly if both instructions are exe cuted 17 Section 1 3 Variables Registration of Instances Each instance name is registered in the global symbol table as a file name Program Instance sample of function block definition A m E a be i The instance is registered in the global symbol table with the instance name as the symbol name Name Data type Addr
166. d following addresses depending on the data size of the parame ter used to pass data to and from the input output variable Address D200 is passed to the input output variable CAL Inside the function block the specified data size of I O memory starting from D200 is processed and changes are thus passed outside the function block instance Input output variables are specified a CX Programmer variable table by selecting In Out for the variable usage n Internal Variables Internal variables are used within an instance These variables are hidden within each instance They cannot be referenced from outside of the instance and are not displayed in the instance The values of internal variables are retained until the next time the instance is executed i e when EN turns OFF the value of the internal variable is retained Consequently even if instances of the same function block defini tion are executed with the same I O parameters the result will not necessarily be the same Example The internal variable tim a in instance Pulse_2sON_1sOFF is different from internal variable tim a in instance Pulse 4sON 1sOFF so the instances can not reference and will not affect each other s tim a value M VanzpI DS Pulse 250ON 1sOFF Usage Name Data type P On CLOCK PULSE Internal tim a TIMER H EN ENO Internal tim b TIMER amp 20 Input ON TIME INT ON TIME Input OFF TIME INT
167. ddress areas Non Retain CIO WR HR DM See note Retain HR DM See note Timers TIM Counters CNT Note DM area of CP1L L Address CP1L L D0000 to D9999 Provided D10000 to D31999 Not Provided D32000 to D32767 Provided 45 Instance Specifications Function Block Instance Area Types Note Note 46 Section 2 3 The following settings are made in the function block instance area CS CJ series CPU Units Ver 3 0 or Later CP series PLCs and NSJ Controllers Non retained Areas Item Contents Allocated variables Variables for which the retain property for power OFF and operation start is set as non retained See note 1 Applicable areas H Function block Special Holding Area I O CIO Area H Holding Area W Internal Relay Area D Data Memory Area see note 2 E Extended Data Memory Area See notes 2 and 3 Setting unit Set in words Allocated words default H512 to H1407 1 Except when the data type is set to TIMER or COUNTER 2 Bit data can be accessed even if the DM or EM Area is specified for the non retained area or retained area 3 The same bank number cannot be specified as the current bank in the user program if the EM Area is specified for the non retained area or re tained area Retained Area Item Contents Allocated variables Variables for which the retain property for power OFF and operat
168. der and SFC programs can also be created To create these pro grams right click the Programs Item in the project workspace to display the pop up menu and select Insert Program Ladder or Insert Pro gram SFC For details on ladder programming refer to the CX Programmer Opera tion Manual W446 For details on SFC programming refer to the CX Programmer Operation Manual SFC W469 178 Procedures Section 6 1 2 When a new project has been created ST programs can be set as the PLC s initial program type Select Tools Options and click the PLCs Tab to set this option Ortons xj Ladder Information General SFC Diagrams PLCs Symbols Appearance IV Confirm all operations affecting the PLC Prohibit the online operations until the PC and PLC data matches Check forced status after online connection Default PLC details PLC Type CM m Use Current PLC CPU CPUTI IV Use comment instructions jv Use section marker instructions Default Program Type in new PLC E Select the ST Option Work Online Simulator IV Automatically Transfer Program to Simulator Continuous Step Interval 5 100 ms Cancel Apply Help 6 1 3 Allocating the ST Program to a Task The ST program that was inserted in the project must be allocated to a task as an execution unit If a program has not been allocated to a task there will be a check mark over that program s icon in the project workspace Note The foll
169. der program in a function block The following dialog box will be displayed before the FB Online Editor is started CX Programmer v7 2 x All Instances which were created from the FB Definition will be affected d Check for the affected Instances which are listed in the Output window Do you start FB Online Edit At the same time a list of instances that will be affected is displayed in the Output Window xj Hf NewProgram Sect NewProgram1 Sectionl 3 Step Note Affect of Function Block Definition Changes on Instances When a function block definition is changed the contents of all in stances that call that function block definition will also be changed This is illustrated below Function Block Definition FB1 User Program Instance calling FB1 Programming changed O stances that will t ibe affected is displayed in ithe Output Window Instance calling FB1 O Change function block definitions only after considering the affect of the change on overall program operation 2 Click the Yes Button The contents of the function block definition will be displayed and can be edited 125 Procedures Section 3 2 7 sample e2 CX Programmer NewPLC1 D D_ThickSelectControl FB Ladder E laj xi t Ele Edit view Insert PLC Program Tools Window Help 1
170. dis played using the memory view function Version 8 3 to 9 0 Upgrade Information Data Structures Supported as Symbol Data Types Data structures are not supported CJ2 CPU Units now support data structures as symbol data type Version 8 0 to 8 1 Upgrade Information The new PLC models of CJ2H CPU6L supporting function blocks and struc tured text are now supported 27 Version Upgrade Information Section 1 6 Version 7 2 to 8 0 Upgrade Information The new PLC models of CJ2H CPU6LI EIP supporting function blocks and structured text are now supported Version 7 0 to 7 2 Upgrade Information Improved Support for For details on the other improvements to CX Programmer functions in this Function Blocks and upgrade refer to the CX Programmer Operation Manual W446 Structured Text n IEC61131 3 Language Improvements Support has been improved for the structured text and SFC languages which are IEC61131 3 languages Ladder structured text ST and SFC program ming can be combined freely so that the best language for each process can be used which reduces program development time and makes the program easier to understand Support for ST Language in the Program Task Allocation Version 7 0 Version 7 2 The ST language could be used only in function The ST language can be used in programs task allocation other than blocks function blocks ST programs can be allocated to ta
171. e OMRON products are manufactured for use according to proper procedures by a qualified operator and only for the purposes described in this manual The following conventions are used to indicate and classify precautions in this manual Always heed the information provided with them Failure to heed precautions can result in injury to people or dam age to property N DANGER Indicates an imminently hazardous situation which if not avoided will result in death or serious injury Additionally there may be severe property damage Z N WARNING Indicates a potentially hazardous situation which if not avoided could result in death or serious injury Additionally there may be severe property damage Caution Indicates a potentially hazardous situation which if not avoided may result in minor or moderate injury or property damage OMRON Product References All OMRON products are capitalized in this manual The word Unit is also capitalized when it refers to an OMRON product regardless of whether or not it appears in the proper name of the product The abbreviation Ch which appears in some displays and on some OMRON products often means word and is abbreviated Wd in documentation in this sense The abbreviation PLC means Programmable Controller PC is used however in some Program ming Device displays to mean Programmable Controller Visual Aids The following headings appear in the left column
172. e been made in the function block definition and the red bus bar display indicating an error will be cleared Setting Function Block Parameters Using the Enter Key 1 2 3 After an instance of a function block has been created input parameters must be set for input variables and output parameters must be set for output vari ables to enable external I O Values addresses and program symbols global symbols and local sym bols can be set in input parameters See note a Addresses and program symbols global symbols and local symbols can be set in output parameters See note b Note a The function block s input variable data size and the program s symbol data size must match b The function block s output variable data size and the program s symbol data size must match 1 Inputs are located on the left of the instance and outputs on the right Place the cursor where the parameter is to be set and press the Enter Key Al ternately select Function Block Parameter from the Insert Menu The New Parameter Dialog Box will be displayed as shown below 101 Procedures Section 3 2 JO SR R SR S BO QelaeE v OF G4a 40 RAR AS s DUTT Sw a QQ eE SE RR 4r v o o8 E EL Calle ts hz ts B EIE TE emm Ea Ei t 88 SP 5 D 22 39 25 em f t m 0 n dax o o J Program Name NewProgramt E NewProject ED NewPLCI C31 G H Offline SA Symbols 1 10 Table S Sett
173. e called function block Variable name in ST task SFC program IN1 Values passed to or received from variables in the called function block Passed to FB IN1 input variable IN2 Passed to FB IN 2 input variable IN3 Passed to FB IN3 input variable OUT1 Received from FB_OUT1 output variable OUT2 Received from FB_OUT2 output variable OUTS Received from FB OUTS output variable A Note Data type BOOL Passed to EN internal variable B Note Data type BOOL Received from ENO internal variable Instance FB Note Data type FUNC TIONBLOCK Calling function block definition Function block Function block call source variable settings The function block call source has the following variables and the follow ing values are passed with the called function block 170 Variable type Input variables Function block call source variable name Values passed to or received from variables in the called function block Passed to FB2 IN1 Passed to FB2 IN2 Passed to FB2 IN3 Output variables Received from FB2 OUT1 Received from FB2 OUT2 Received from FB2 OUT3 Statement Descriptions Section 5 5 Variable type Function block call Values passed to or received source variable name from variables in the called function block Internal variables A Passed to EN Note Data type BOOL B Receiv
174. e contents at the input address in the form and size specified by the variable data type that is passed to the function block In a similar fashion it is not the output destination address itself but the contents for the output address in the form and size specified by the variable data type that is passed from the function block Even if an input source address i e an input parameter or an output desti nation address i e an output parameter is a word address the data that is passed will be the data in the form and size specified by the variable data type starting from the specified word address Program Instance of Function Block Definition A InputD100 4 m k Output D300 Input D200 Examples If m is type WORD one word of data from D100 will be passed to the variable If n is type DWORD two words of data from D200 and D201 will be passed to the variable If k is type L WORD four words of data from the variable will be passed to the D300 to D303 1 Only addresses in the following areas can be used as parameters CIO Area Auxiliary Area DM Area EM Area banks 0 to C Holding Area and Work Area The following cannot be used Index and Data Registers both direct and indirect specifications and indirect addresses to the DM Area and EM Area both in binary and BCD mode 2 Local and global symbols in the user program can also be specified as parameters To do so however the data size of t
175. e data type if required Name Data type Address or value Input the address Comment Link the definition to the project erver file Advanced Settings Cancel 4 The variables set in the symbol table will be registered Note When variables are being registered without specifying addresses the CX Programmer can be set to allocate addresses automatically For details on Automatic Allocation refer to the CX Programmer Operation Manual W446 2 Creating the ST Program 1 2 3 1 The ST language can be input directly in the ST Editor Window or the ST data can be created in a text editor and then pasted in the ST Editor Win dow by selecting Edit Paste Untitled CX Programmer File Edit View Insert PLC Program Simulation Tools Window Help bhe 2 QN A 59 ci dle NewProject fid NewPLCILCIZH Offline Data Type Rack Location Comment IS Data Types l INT A Symbols BOOL Green Lamp within tolerance BB 10 Table and Unit Setup REAL Tolerance Symbol table S Settings red BOOL Red Lamp within tolerance Taray REAL Measurement Value 1 rograms BR RergXEnT 00 REAL Measurement Value 2 8 Symbols REAL Measurement Value 3 v GF Function Blocks 2 D00 Three times Measurement Flag r Average Value Calculation 2 average Thickness Thickness Thickness3 3 0 Judgement IF average criterion margin THEN ST Programming Editor red lamp TRUE
176. e edited function block with a function block in the actual PLC or another project file to check whether the two function blocks are identical For details on comparing programs refer to the CX Programmer Operation Manual W446 3 2 16 Saving and Reusing Function Block Definition Files The function block definition that has been created can be saved indepen dently as a function block library file cxf to enable reusing it in other projects Note 1 Before saving to file or reusing in another project compile the function block definition and perform a program check 2 When function blocks are being nested the function block definition of the called nested function blocks are included and saved in the function block library file Saving a Function Block Use the following procedure to save a function block definition to a function Library File block library file 1 2 3 1 Select the function block definition right click and select Save Function Block to File from the pop up menu Alternately select Function Block Save Function Block to File from the File Menu 114 Procedures Section 3 2 2 The following dialog box will be displayed Input the file name Function Block Library Files cxf should be selected as the file type Select Function Block Library File _ 3 xl Save in C TMP gt ex E3 File name Save as type Function Block Library Files cxf Cancel Reading Function Block Use
177. e eee eee 139 22 1 Basic Data Types ente eek e eager Ete ens 139 5 2 2 Derivative Data Types 0 0 0 140 5 3 Inputting ST Programs 0 ee cee ee 140 3 3 Syntax Rules heces deep PER RR PEERS GBA 140 5 3 2 CX Programmer s ST Input Screen Display 143 5 4 ST Language Configuration 00 0 eee eee 144 9 4 l Statements i fos ee wad Haina SE RU Se aa 144 23 4 2 Variables as eR Nein Sey saa eet m 145 5 4 3 Inputting Constants 0 0 0 2 cee eee eee 145 3 4 4 Operators cess ek IB ed oi edie e eos dese tian 145 5 4 5 Standard Functions 146 5 4 6 OMRON Expansion Functions 0 000 000 00008 152 5 5 Statement Descriptions 0 0 e cee eee eee 155 5 5 1 Assignment e RGLenb E E ME nds 155 5 5 2 Control Statements 155 5 6 ST language Program Example 0 0 0 eese 173 5 6 1 Using an ST Program in a Function Block 173 25 7 R st uctions scere e se E RU aay a eI PR ER ER 174 5 7 1 Restrictions lees eee nee 174 5 7 2 Commonly Asked Questions 0 0 00 000 000000 175 137 Structured Text Language Specifications Section 5 1 5 1 Structured Text Language Specifications 5 1 1 Overview of the Structured Text Language ST Language Configuration 138 Structured text is a high level textual language that has selection and iteration structures and is similar to PASCAL B ST La
178. e function block as follows to call the function block Input the instance name any internal variable name with a function block data type followed by the arguments in parentheses i e specify the input variable values of the calling function block to pass to the input variables of the called function block Also include the return values i e specify the output variable values of the called function block to pass back to the out put variables of the calling function block 2 Press the F Key in the Ladder Section Window The Function Block Invo cation Dialog Box will be displayed 3 Selectthe instance name that was previously registered from the pulldown menu on the FB nstance Field The instance will be created Observe the following restrictions when creating instances Refer to 2 4 Pro gramming Restrictions for details No more than one function block can be created in each program circuit The rung cannot be branched to the left of an instance Instances cannot be connected directly to the left bus bar i e an EN must always be inserted If changes are made in the I O variables in a variable table for a function block definition the bus bar to the left of all instances that have been created from that function block definition will be displayed in red to indicate an error When this happens select the function block right click and select Update Invoca tion The instance will be updated for any changes that hav
179. e parameter the value for CIO 000000 0 00 or CIO 000001 0 01 will be passed Always input P Off for 0 OFF and P Onfor 1 ON 103 Procedures Section 3 2 3 2 6 Setting the FB Instance Areas The areas where addresses for variables used in function blocks are allocated can be set These areas are called the function block instance areas 1 2 3 1 Select the instance in the Ladder Section Window or in the global symbol table and then select Function Block SFC Memory Function Block SFC Memory Allocation from the PLC Menu The Function Block SFC Memory Allocation Dialog shown below will ap pear 2 Setthe FB instance areas ROTE Non retained area Memory Area Start Address End Address Size FB Non Retained H512 H1407 896 FB Retained H1408 H1535 128 Dem FB Timer T3072 T4095 1024 E FB Counter C3072 C4095 1024 SFC Bit Share with F SFC Word Share with F Retained area Timer area Default Counter area Hele Advanced IV Share SFC with FB Merhory First Last Size address address The non retained and retained areas are set in words The timer and counter areas are set by time and counter numbers The default values are as follows CJ2 series CPU Units FB Instance Applicable memory Default value Area Non Retain Start address End address arcas CIO WR HR DM EM See note Retain HR DM EM See note Timers TIM Count
180. e values are displayed in blue in the ST variable monitor window When you use a TIMER type variable in a TENTH MS TIMER or HUN DREDTH MS TIMER is displayed for the present value of the TIMER type variable Refer to the Section 5 7 Restrictions for details n Changing PVs To change a PV select the desired variable in the ST variable monitor window displayed in reverse video when selected right click and select Set Value from the pop up menu Select the variable eee acm EI EE The Set New Value Dialog Box will be displayed Input the new value in the Value field n Force setting and Force resetting Bits 1 2 3 To force set force reset or clear the forced status select the desired variable in the ST variable monitor window displayed in reverse video when selected right click and select Force On Force Off Force Cancel or Force Cancel All Forces from the pop up menu n Copying and Pasting in the Watch Window 1 To copy a variable to the Watch Window select the desired variable in the ST variable monitor window displayed in reverse video when selected right click and select Copy from the pop up menu 185 Procedures Section 6 1 FS File Edit Yiew Insert PLC Program Simulation Tools Window Help 81 x 2 Right click in the Watch Window and select Paste from the pop up menu 1nl x D c E cR S 3 5 RR amp WP ali n n pe SOR I was
181. e_variable_name PV Example Counter completion flag Counter1 CF Counter PV Counter1 PV The completion flags are read only Writing is not allowed The present values can be read written 142 Inputting ST Programs Section 5 3 5 3 2 CX Programmer s ST Input Screen Display Text Display Color The CX Programmer automatically displays text in the following colors when it is input or pasted in the ST Input Screen Text keywords reserved words Blue Comments Green Errors Red Other Black Changing Fonts To change font sizes or display colors select Tools Options click the Appearance Tab and then click the ST Font Button The font name font size default is 8 point and color can be changed 143 ST Language Configuration 5 4 ST Language Configuration 5 4 1 Statements Statement Function Section 5 4 Example End of statement Ends the statement Comment All text between and is treated as comment a comment Assign Assignment Substitutes the results of the expres A B ment state sion variable or value on the right for ment the variable on the left Control IF THEN ELSIF ELSE Evaluates an expression when the IF condition 1 THEN statements END IF condition for it is true expression 1 144 ELSIF condition 2 THEN expression 2 ELSE expression 3 END IF CASE ELSE END CASE Evaluates an express based on the value of a variable
182. eceives a text string from a serial port on a Serial Communications Board SCB Application RXD SCB Storage location Number of characters Serial port Conditions The serial communications mode of the serial port must be set to no protocol communications Arguments and Return Values Variable name Data type Description Storage location STRING Specifies the storage location for the received text string Number of characters INT UINT WORD Specifies the number of characters to receive 0 to 255 Serial port INT UINT WORD Specifies the number of the serial port 1 Serial port 1 2 Serial port 2 214 Function Descriptions Appendix C Example Serial Commu nications Board SCB CPU Unit Message Value to read Barcode reader Variables BOOL P DoRecvData Variable to control receive function i STRING Message Variable to store received message BOOL P EndRecvSCBPort1 Reception Completed Flag AT A356 06 l Use serial port 1 N Use serial port number 1 Receive data when P_DoRecvData is ON and reception has been completed IF P_DoRecvData TRUE AND P_EndRecvSCBPort1 TRUE THEN Get 16 characters RXD_SCB Message 16 1 P_DoRecvData FALSE END_IF Related Auxiliary Address Description Area Flag Port 1 Reception A356 06 ON when reception has been completed in no protocol mode Completed Flag Port 1 Receptio
183. eceives the function block s output variable value in parentheses after the instance name see note The two methods entry method 1 and entry method 2 that can be used to enter these parameters are described in the fol lowing paragraphs Note The data type is any of the function block s internal variable names when ST is used in the function block s instance or global variable names when ST is used in an ST task or SFC action program B Entry Method 1 Use this method to enter both the argument specification called function block definition s variable name and return value specification AUB SSC ye cuelga D gt E 167 Statement Descriptions Section 5 5 A Instance name B Called function block definition s input variable name C One of the following values depending on the ST program being used Calling function block s input variable or a constant when ST is being used in the function block s instance Global variable or local variable name when ST is being used in an ST task or SFC action program D Called function block definition s output variable name or constant E One of the following values depending on the ST program being used Calling function block s output variable or constant when ST is being used in the function block s instance Global variable or local variable name when ST is being used in an ST task or SFC action program Note Delimit all of the B C type assignments
184. ected syntax s A keyword reserved word or variable has been used ille gally FOR I 1 TO 100 DO BY 1 The DO position is illegal X X 1 END_FOR Usage mismatch in Function variable The function parameter has been used illegally Y SIN X1 EN gt BOOL1 The input parameter EN has been used as an output parameter Value out of range A value outside the range for the variable data type has been substituted in the vari able X 32768 X is an INT type variable Variable s is not a Function parameter A variable that cannot be specified in the function parameter has been specified in the parameter Y SIN Z X X and Y are REAL type variables and Z is not a SIN function parameter 195 Structured Text Errors Warning Messages Warning message Keyword s is redundant Cause of warning The keyword has been used in an invalid location For example use of the EXIT statement outside a loop syn tax Appendix B Example Conversion from s to s possible loss of data 196 Data may be lost due to con version of a data type with a large data size to a data type with a small data size Y DINT_TO_INT X X is a DINT type variable Y is an INT type variable Appendix C Function Descriptions Standard Functions Text String Functions LEN Detect String Length Function Finds the length of a specified text string Applica
185. ectory_name_and_file_ name gt lt Delimiter gt lt Param ter gt Communications Functions Function The following functions can be used with CS CJ series CPU Units with unit version 4 0 or later or CJ2 series CPU Units Write string Argument data type value STRING Directory name and file name e STRING Delimiter STRING Parameter INT UINT WORD Return data type Description Writes a text string to a Memory Card Example WRITE TEXT a b c d text string a is written to a file with the file name and directory specified by variable b if variable dis O the text string is added to the file along with delimiter speci fied by variable c if variable dis 1 a new file is created The following functions can be used with CS CJ series CPU Units with unit version 4 0 or later or CJ2 series CPU Units Description Example TXD CPU Send string Sends a text string to the RS 232C port on the CPU Unit TXD_CPU a text string a is sent from the RS 232C port on the CPU Unit TXD SCB Send string Serial port Sends a text string to the serial port on a Serial Communica tions Board TXD SCB a b text string a is sent from the serial port specified by variable b on the Serial Communications Board TXD SCU Send string SCU unit number Serial port Internal logic port
186. ed block of addresses The following procedure can be used to eliminate the unused areas in memory so that memory is used more efficiently 1 2 3 1 Select the instance in the Ladder Section Window right click and select Memory Allocation Function Block SFC Memory Optimize Func tion SFC Memory from the PLC Menu The following dialog box will be displayed Programmer E Optimising Function Block memory will Force the memory to be re allocated and therefore the project will no longer match with the PLC Do you wish to continue Yes No 107 Procedures Section 3 2 2 Click the OK Button Allocations to the function block instance areas will be optimized 3 2 8 Copying and Editing Function Block Definitions Use the following operation to copy and edit the function block definition that has been created 1 Select the function block to copy right click and select Copy from the pop up menu 2 Position the cursor over the function block item under the PLC in the project directory right click and select Paste from the pop up menu 3 The function block definition will be copied copy is indicated before the name of the function block definition at the copy source 4 To change the function block name left click or right click and select Re name from the pop up menu 5 Double click the function block definition to edit it 3 2 9 Checking the Source Function Block Definition from an Instance Use the follo
187. ed from ENO Note Data type BOOL Internal variables Instance_FB Calling function block definition instance Note Data type FUNC Function block 2 TIONBLOCK Function block call destination variable settings The function block call destination has the following variables and the following values are passed with the call source ST program SFC program or call source function block Variable type Function block call Values received from or destination variable name passed to variables in the calling function block Input variables FB IN1 Received from IN1 FB IN2 Received from IN2 FB IN3 Received from IN3 Output variables FB OUT1 Passed to OUT1 FB OUT2 Passed to OUT2 FB_OUT3 Passed to OUTS Examples B Example of Entry Method 1 Instance FB EN zA FB IN1 IN1 FB IN2 IN2 FB IN3 INS FB_OUT1 gt OUT1 FB_OUT2 gt OUT2 FB_OUT3 gt OUT3 ENO gt B It is all right for the arguments and return values to be listed in irregular order The input variables arguments must be at the beginning of the list or just after the EN variable if the EN variable is listed Output variables may be omitted if the data is not used Specification method 2 cannot be used together with specification method A in the same function block call statement B Examples of other Entry Formats EN not entered Instance FB FB IN1 IN1 FB IN2 IN2 FB IN3 IN3 FB_OUT1 gt OUT1 FB_OUT2 gt
188. ed the next time an instance is executed the same instance name can be used to save memory instance A H NI TIMER FB Function Block Definition i LT TIMER_FB Variable Definitions Internal variable WORK_NUM gt Use same internal variables instance_A ES NI TIMER FB im gt Use different internal variables instance_B I TIMER_FB Multiple instances can be created from a single function block definition Up to either 256 or 2 048 instances can be created for a single CPU Unit depending on the CPU Unit model The allowed number of instances is not related to the number of function block definitions and the number of tasks in which the instances are inserted Function Blocks Parameters Section 1 2 Each time an instance is created set the real I O memory addresses or con stants for input variables output variables and input output variables used to pass input data values to instances and obtain output data values from instances These addresses and constants are called parameters Instance of Function Block Definition A Input 0 00 a b Output 2 00 Inpuf3 00 c Set th tant Set the constants or output SUID i input source addresses address to which to pass from which to pass data data Using Input Variables and Output Variables With input variables and output variables it is not the input source address itself but th
189. editor can be copied and then pasted into the ST input area using the Paste Command on the Edit Menu Note The ST language conforms to IEC61131 3 For details refer to SECTION 5 Structured Text ST Language Specifications in Part 2 Structured Text ST 89 Procedures Section 3 2 Untitled CX Programmer NewPLC1 FunctionBlock1 FB Structured Text tU Ele Edit View Insert PLC Program Simulation Tools Window Help 8x Deak 6Q 28 oh 09258 amp 5 lame Data Type ar initial V Reta Comment INT 0 fig NewPLCILCI2H Offline INT o 3 Symbols QI 10 Table and Unit Setup ES Settings Internals Inputs Outputs In Out Externals 1 EFOR a 10 TOOBY 1 DO b b 1 END_FOR NewProgram1 00 3 Symbols 3 4 Sectiont SIHF c 0 THEN 6 END mir 7 ase S LEND IF ST program input directly or pasted from one created in a text editor Note 1 Tabs or spaces can be input to create indents They will not affect the al gorithm 2 When an ST language program is input or pasted into the ST input area syntax keywords reserved words will be automatically displayed in blue comments in green errors in red and everything else in black 3 To change the font size or colors select Options from the Tools Menu and then click the ST Font Button on the Appearance Tab Page The font names font size default is 8 point and color can be changed
190. efinition s program and monitor the I O status of a function block instance s ladder diagram The status of a function block instance s ST program can be monitored while monitoring the program To monitor the ST program s status either double click the function block instance or right click the instance and select Monitor FB Instance from the pop up menu At this point it will be possible to change PVs and force set reset bits Note Online editing is not supported 29 Version Upgrade Information Section 1 6 Password Protection of Function Blocks Previous version Ver 6 0 New version Ver 6 1 The following two kinds of password protection can be set The function block properties could be set to prevent the display of a function block defini tion s program Password protection restricting both reading and writing Password protection restricting writing only Version 5 0 to 6 0 Upgrade Information Nesting Function Blocks Previous version Ver 5 0 New version Ver 6 0 A function block could not be called from another function block Nesting not supported A function block can be called from another function block nested Up to 8 nesting levels are supported The languages of the calling function block and called function block can be either ladder language or ST language The nesting level relationship between function blocks can be displayed in a directory tree format Wh
191. en function blocks are nested just one Function Block Library file cxf extension is stored for the calling func tion block and its called nested function block definitions I O Bit Monitor Support for Ladder Programs in Function Blocks Previous version Ver 5 0 New version Ver 6 0 The I O status of a function block instance s lad der diagram could not be monitored while moni toring the program online It was only possible to check the program in the function block definition The I O status of a function block instance s ladder diagram can be monitored while monitoring the program online To monitor the I O status either double click the function block instance or right click the instance and select Monitor FB Ladder Instance from the pop up menu At this point it will be possible to monitor the status of I O bits and the content of words change PVs force set reset bits and monitor differentiation ON OFF transitions of bits Note Online editing is not supported and timer counter SVs cannot be changed Registering and Monitoring Function Block Instance Variables in a Watch Window Previous version Ver 5 0 New version Ver 6 0 To register a function block instance s variable in a Watch Window it was necessary to display the Watch Window double click the window and select the desired variable from a pull down list Other Function Block Improvements Multiple variables in a function bl
192. ened BRA i GR ALA ieee M Ce AUREUS 140 5 4 ST Language Configuration 0 0 0 cee ences 144 5 5 Statement Descriptions noera seeds oe oE EEE AEE n 155 5 6 ST language Program Example 0 0 0 173 2 7 RESWICHONS 2 lv in yee tetera SG ite Pea wien ge ex CHE AREE E Had Ee 174 SECTION 6 Creating ST Programs cceccccccececeeseee 177 6 l iProceduress sv wate Fate RW Vide De See eee Sy ee 178 Appendices A System defined external variables supported in function blocks 191 B Structured Text Brrors 272 ini SYA Poe awe elie ee ou E RS e E S 193 C Function Descriptions 2 ssszcl4 cL ee eee E Y e eee E RS 197 Indek eosdem 6 Kine PER I Rn esr 2 Revision History 5 uus cese we eer r5 sesrrr 225 About this Manual This manual describes the CX Programmer operations that are related to the function block functions and Structured Text ST functions The function block and structure text functionality of CX Program mer is supported by CJ2H CJ2M CPU Units by CS1 H CJ1 H and CJ1M CPU Units with unit version 3 0 or later by CP series CPU Units and by NSJ series and FQM1 series Controllers Some function block and structure text functionality however is supported only by CJ2H CPU Units by CS1 H CJ1 H and CJ1M CPU Units with unit version 4 0 or later For details refer to 1 6 Version Upgrade Information For information on functionality other than function blocks and structure text refe
193. ers CNT 104 Note Force setting resetting is enabled when the following EM banks are specified CJ2H CPU64 EIP CPU65 EIP EM bank 3 CJ2H CPU66 EIP EM banks 6 to 9 CJ2H CPU67 EIP EM banks 7 to E CJ2H CPU68 EIP EM banks 11 to 18 CS CJ series CPU Units Ver 3 0 or Later and NSJ Controllers FB Instance Default value Applicable memory Area Start address End address areas Non Retain H512 See H1407 See CIO WR HR DM EM See notes 1 note 2 note 2 and 3 Retain See H1408 See H1535 See HR DM EM note 1 note 2 note 2 Timers T3072 T4095 TIM Counters C3072 C4095 CNT Note 1 Bit data can be accessed even if the DM or EM Area is specified for the non retained area or retained area Procedures Section 3 2 2 The Function Block Holding Area words are allocated in H512 to H1535 These words cannot be specified in instruction operands in the user pro gram These words can also not be specified in the internal variable s AT settings 3 Words H512 to H1535 are contained in the Holding Area but the ad dresses set as non retained will be cleared when the power is turned OFF and ON again or when operation is started 4 To prevent overlapping of instance area addresses and addresses used in the program set H512 to H1535 Function Block Holding Area words for the non retained area and retained area If there are not sufficient words use words in
194. ess value sample FB FunctionBlock1 N A Auto The function block definition name is registered after FB in Instance name square parentheses 1 3 Variables 1 3 1 Introduction In a function block the addresses see note are not entered as real I O mem ory addresses they are all entered as variable names Each time an instance is created the actual addresses used by the variable are allocated automati cally in the specified I O memory areas by the CX Programmer Conse quently it isn t necessary for the user to know the real I O memory addresses used in the function block just as it isn t necessary to know the actual mem ory allocations in a computer A function block differs from a subroutine in this respect i e the function block uses variables and the addresses are like black boxes Example Program Function block definition A Instance of function block definition A Standard program section with variable names a b c etc Insert in a b program Aput 0 00 7 a b Output 2 00 Lae Input 3 00 c C Specify inputs and outputs MOV at the same time Status of 0 00 1 or 0 is Status of b 1 or 0 is Table indicating usage and passed to a passed to 2 00 properties of variables a b c etc oa 0 00 a jt b 4 2 00 4 Usage Inputs Status of 3 00 1 or 0 is Properties
195. et in program ang memory not yet Block instance in program with memory alocate allocated object abstract gt object ll Function Block Definition FB1 Program Instance 1 Algorithm Instance FB1_1 of function block definition FB1 memon Insert in 4 Automatic Standard program program unit Posea allocation Memory with variable Input a b for FB1 1 names a b c data Output data etc AO Automatic Memory 2 Parameters allocation for FB1 2 Table defining usage Insert in and properties of program variables a b c etc B1_2 of function block definition EB1 Different I O data can be processed F 4 with the same m function Input a b Output data Output data Instances are managed by names More than one instance with the same name can also be inserted in the program If two or more instances have the same name they will use the same internal variables Instances with different names will have different internal variables For example consider multiple function blocks that use a timer as an internal variable In this case all instances will have to be given different names If more than one instance uses the same name the same timer would be used in multiple locations resulting in duplicated use of the timer If however internal variables are not used or they are used only temporarily and initializ
196. ettings and Internal Function Block Processing Input output variables Set the input parameter to the address of the first word in the data ex ample D200 The data is set in D200 to D205 in advance from the main user program FREAD omitted read num 0 omitted omitted Specify the first element of the array in the instruction operand Internal variables Use ladder programming within the function block to set data into the array Ladder Programming MOVL amp 100 read num 0 No of words MOVL amp 0 read num 1 1st source word J Serda I SAC ATAV lemon FREAD omitted read num 0 omitted omitted mr aded us Agreed bu the array Function Block Applications Guidelines Section 2 5 Division Using Integer Array Variables Ladder Programming Only Note Handling a Block of Read Data in Multiple Words The allowed amount of read data must be determined in advance and an array must be prepared that can handle the maximum amount of data In this example an array receives the FREAD instruction s read data operand D Variable table Input output variable or internal variable data type WORD array setting with 100 elements variable names read data 0 to read data 99 Data Settings and Internal Function Block Processing Input output variables Set the input parameter to the address of the first word in the read data example D200 FREAD omitted omitted omitted read data O
197. eusing the function block if an internal variable with a AT property cannot be set for the operand and an external variable can not be set When using an array setting for an input output variable specify the address of the first word for the input parameter CX Programmer version 7 0 or higher When using an array setting for an internal variable prepare an array variable with the number of elements for the required size and after set 41 Function Block Specifications Algorithm Operand Input Restrictions 42 Note Note Section 2 1 ting the data in each array element specify the first or last element in the array variable for the operand Example Function block definition Instance Variable SCL I IA EN ENO SCL WORD 10 S p 10 Algorithm SCL BODY QQQA Specifying this array element in LD P On 0 0000 the SCL instruction is the same MOV 0000 SCL O0 1 amp 0 as specifying the first address MOV amp 0SCL 1 2 0300 MOV 0300 SCL 2 3 amp 4000 MOV amp 4000 SCL 3 SCL S SCL 0 D Write the operand data to the array variables Specify the beginning of the array in the SCL instruction For details refer to 2 6 Precautions for Instructions with Operands Specifying the First or Last of Multiple Words Initial Values When an instance is executed the first time initial values can be set for input variables internal variables and output v
198. fication of the first or last address in a range of words Examples are provided below Handling a Single String of Data in Multiple Words In this example an array contains the directory and filename operand S2 for an FREAD instruction Variable Table Input output variable or internal variable data type WORD array setting with 10 elements variable names filename 0 to filename 9 Data Settings and Internal Function Block Processing Input output variables Set the input parameter to the address of the first word in the data ex ample D100 The data 5C31 3233 0000 etc is set in D100 to D109 in advance from the main user program FREAD omitted omitted read numI0 omitted Specify the first element of the array omitted tern Lnum o ARIA in the instruction operand Internal variables Use ladder programming within the function block to set data into the array MOV 5C31 file name 0 MOV 3233 file name 1 Set data in each array element MOV 0000 file name 2 FREAD omitted omitted file name 0 omitted Specify the first element of the array in the instruction operand Handling Control Data in Multiple Words In this example an array contains the number of words and first source word operand S1 for an FREAD instruction Variable table Input output variable or internal variable data type DINT array setting with 3 elements variable names read num 0 to read num 9 Data S
199. g Area used for programs HOOO to H511 and are used only for the function block instance area internally allocated variable area These words cannot be specified in AT settings for internal variables These words cannot be specified as instruction operands These words are displayed in red if they are input when a function block is not being created Although the words can be input when creating a function block an error will occur when the program is checked e If this area is specified as non retained turn the power ON OFF or clear the area without retaining the values when starting operation To prevent overlapping of instance area addresses with addresses used in the program set H512 to H1535 Function Block Holding Area words for the non retained area and retained area If there are not sufficient words use words in areas not used by the user program FQM1 Flexible Motion controller FB Instance Default value Applicable memory Start address End address Non Retain CIO WR DM Area areas Retain Timers TIM Counters CNT Non retained Areas Item Contents Allocated variables Variables for which the retain property for power OFF and operation start is set as retained See note 1 Applicable areas I O CIO W Work Area and D DM Area See note 2 Setting unit Set in words Allocated words CIO 5000 to CIO 5999 default 1 Except when the data type is set
200. g function block to input variables in the called function block and also specify return values to receive output vari able values from the called function block to output variables in the calling function block The instance name can be set to any internal variable with the FUNCTION BLOCK data type Input the instance name select the function block from which to create an instance and click the OK Button B d Bl SR rB 9 C MES NW amp X 6E S n Es RR AP EDT S we a Q SESSA 0 2 8 S SEL tx i es t ts t ts BIE E IE ri m S ERIS d 3 2 8 25 39 25 Em t mum zoa Program Name NewProgram seen Press F Key with cursor here e NewProject Ei EB NewPLCI CILG H Offline f Symbols Following dialog box is displayed Input the instance name New Function Block Invocation FB Instance FB Definition c dE Function Blocks FunctionBlock1 FunctionBlock1 n c Cancel Select the function block from which to create an instance As an example set the instance name in the FB nstance Field to sample set the function block in the FB Definition Field to FunctionBlock1 and click the OK Button As shown below a copy of the function block definition called FunctionBlock1 will be created with an instance name of sample 28 Untitled CX Programmer NewPLC1 NewProgr
201. g the instructions in doc umentation for your computer and enable using the RS 232C port as a normal serial port With some notebook computers the default settings for saving energy do not supply the rated power to the RS 232C USB and Ethernet port There may be both Windows settings for saving energy as well as set ting for specific computer utilities and the BIOS Following the instruc tions in documentation for your computer disable all energy saving settings Do not turn OFF the power supply to the PLC or disconnect the connect ing cable while the CX Programmer is online with the PLC The computer may malfunction Confirm that no adverse effects will occur in the system before attempting any of the following Not doing so may result in an unexpected operation Changing the operating mode of the PLC Force setting force resetting any bit in memory Changing the present value of any word or any set value in memory Check the user program for proper execution before actually running it on the Unit Not checking the program may result in an unexpected opera tion When online editing is performed the user program and parameter area data in CJ2 CS1 H CJ1 H CJ1M and CP1H CPU Units is backed up in the built in flash memory The BKUP indicator will light on the front of the CPU Unit when the backup operation is in progress Do not turn OFF the power supply to the CPU Unit when the BKUP indicator is lit The data will not
202. gramming Restrictions Introducing the Function Blocks Item Specifications Functions not supported by CX Program mer Ver 4 0 or earlier Defining and creat ing func tion blocks Number of function block defini tions Section 1 1 CJ2H Units CJ2H CPU6 CJ2M CPU Units e CJ2M CPUL1 L12 L 13 256 max per CPU Unit e CJ2M CPUL14 L15 2 048 max per CPU Unit CS1 H CJ1 H CPU Units e Suffix CPU44H 45H 64H 65H 66H 67H 64H R 65H R 66H R 67H R 1 024 max per CPU Unit Suffix CPUA2H A3H 63H 128 max per CPU Unit CJ1M CPU Units e CJ1M CPU1 1 12 13 21 22 23 128 max per CPU Unit CP1H CPU Units All models 128 max per CPU Unit CP1L CPU Units CP1L M L 128 max per CPU Unit NSJ Controllers NSJLI G5D 1 024 max per Controller NSJL M3D 128 max per Controller FQM1 Flexible Motion Controllers e FQM1 CM002 MMA22 MMP22 128 max per Controller EIP 2 048 max per CPU Unit Function block names 64 characters max Introducing the Function Blocks Section 1 1 Item Specifications Functions not supported by CX Program mer Ver 4 0 or earlier Defining and creat ing func tion blocks Variables Variable names 30 000 characters max Variable types Input variables Inputs output variables Out puts input output variables In Out internal variables Internals and exte
203. grated Tool Package C V4 Xiv Overview of Contents Precautions provides general precautions for using the CX Programmer Part 1 Part 1 contains the following sections Section 7 introduces the function block functionality of the CX Programmer and explains the features that are not contained in the non function block version of CX Programmer Section 2 provides specifications for reference when using function blocks including specifications on function blocks instances and compatible PLCs as well as usage precautions and guidelines Section 3 describes the procedures for creating function blocks on the CX Programmer Part 2 Part 2 contains the following sections Section 4 introduces the structure text programming functionality of the CX Programmer and explains the features that are not contained in the non structured text version of CX Programmer Section 5 provides specifications for reference when using structured text programming as well as programming examples and restrictions Section 6 explains how to create ST programs Appendices provide information on structured text errors and ST function descriptions NWARNING Failure to read and understand the information provided in this manual may result in per sonal injury or death damage to the product or product failure Please read each section in its entirety and be sure you understand the information provided in
204. guments Variable name Data type Description Execution condition Executes the timer operation while this execution condition is TRUE Timer address Specifies the timer address TO to T4095 variable to use Timer set value Specifies the delay time in units of 1 ms amp 0 to amp 65535 0 to FFFF e Only when the Apply the same spec as T0 2047 to 12048 4095 option is selected in the PLC s property setting the present value is updated when all cyclic tasks are completed When the timer PV is referenced from the user program the obtained timer present value of timer numbers 16 and later may be different from that of timer numbers 0 to 15 The present value of the timer numbers 16 and later is refreshed only when the instruction is executed On the other hand the present value of the timer numbers 0 to 15 is updated once every 1 ms When the timer completion flag is referenced from the user program the reflection of the status change may be delayed by one cycle depending on the access timing TIMUX TENTH MS TIMER Function Operates a decrementing timer with units of 0 1 ms Equivalent to the TIMUX 556 ladder instruction When the execution condition goes from FALSE to TRUE the timer specified in the timer address is started and the present value is decremented by one starting from the value specified in the timer set value once every 0 1 ms The present value will continue timing down as long as the e
205. he WHILE statement when the number of iterations has not been deter mined beforehand depends on the condition being met to repeat specified processing for the duration that the condition is met This statement can be used to execute processing while the condition equation is true only pretest loop B Description Before the expression is executed the condition is evaluated If the condition is true the expression is executed Afterwards the condition is evaluated again This process is repeated If the condition is false the expres sion is not executed and the condition evaluation ends B Precautions WHILE must be used in combination with END WHILE Before executing the expression if the condition equation is false the pro cess will end without executing the expression Statements that can be used in the expression are assignment state ments IF CASE FOR WHILE or REPEAT Multiple statements can be executed in the expression Be sure to use a semicolon delimiter between multiple statements in an expression The condition can also be specified as a boolean variable BOOL data type only rather than an equation B Examples Example 1 The value exceeding 1000 in increments of 7 is calculated and substituted for variable A A 0 WHILE A lt 1000 DO A A 7 END WHILE 164 Statement Descriptions REPEAT Statement Section 5 5 Example 2 While X lt 3000 the value of X is doubled and the value is subs
206. he follow ing precautions apply 1 2 3 1 lfanon array variable is specified without AT setting and without a match ing data size the CX Programmer will output an error when compiling 2 The following precautions apply to when an array variable is specified Size to Be Processed in the Instruction Operand Is Fixed Make sure that the number of elements in the array is the same as size to be processed by the instruction Otherwise the CX Programmer will output an error when compiling 67 Precautions for Instructions with Operands Specifying the First or Last of Multiple Words Section 2 6 Non array Variables without Matching Data Size and without AT Setting Size to Be Processed in the Instruction Operand Is Not Fixed Make sure that the number of elements in the array is the same or greater than the size specified by another operand Other Operand Specifying Size Constant The CX Programmer outputs an error when compiling Other Operand Specifying Size Variable The CX Programmer will not output an error when compiling a warning mes sage will be displayed even if the number of elements in the array does not match the size specified in another operand variable In particular when the number of elements in the array is less than the size specified by another operand for example when instruction processing size is 16 and the number of elements actually registered in the variable table is 10 the instruction w
207. he local or global symbol must be the same as the data size of the function block variable 3 When an instance is executed input values are passed from parameters to input variables before the algorithm is processed Output values are 15 Function Blocks 16 Section 1 2 passed from output variables to parameters just after processing the al gorithm If it is necessary to read or write a value within the execution cy cle of the algorithm do not pass the value to or from a parameter Assign the value to an internal variable and use an AT setting specified address es Caution If an address is specified in an input parameter the values in the address are passed to the input variable The actual address data itself cannot be passed Caution Parameters cannot be used to read or write values within the execution cycle of the algorithm Use an internal variable with an AT setting specified addresses Alternatively reference a global symbol as an external variable Using Input Output Variables In Out When using an input output variable set the address for the input parameter A constant cannot be set The address set for the input parameter will be passed to the function block If processing is performed inside the function block using the input output variable the results will be written to I O starting at the address set for the size of the variable Program Instance of function block definition A Automatica
208. hed each time the instruction is executed If the PV is 0 the Completion Flag is turned ON If it is not 0 the Completion Flag is turned OFF When instruction is executed When execution of all tasks is completed Every 80 ms All PV are refreshed once each cycle If the cycle time exceeds 80 ms all PV are refreshed once every 80 ms Timer Operation for Timer Numbers T2048 to T4095 Refresh Description When instruction is The PV is refreshed each time the instruction is executed executed If the PV is 0 the Completion Flag is turned ON If it is not 0 the Completion Flag is turned OFF PV are not updated When execution of all tasks is completed Every 80 ms PV are not updated even if the cycle time exceeds 80 ms Select the Apply the same spec as TO 2047 to T2048 4095 Option to ensure consistent operation when using the timer numbers allocated by default to function block variables T3072 to T4095 2 9 Number of Function Block Program Steps and Instance Execution Time 2 9 1 Number of Steps Used for Function Blocks Guide for Number of Program Steps When Using Function Blocks 78 Note Number of Function Block Program Steps When function blocks are used program memory steps is used for the fol lowing two items 1 Function block definitions 2 Instances of function block definitions created in programs Therefore the more instances of function bloc
209. iable The data type is 1 word INT UINT or 6 steps shown in parenthe WORD input variable or ses output variable 2 word DINT UDINT 6 steps DWORD or REAL input variable or output variable 4 word LINT ULINT 18 steps LWORD or LREAL input variable or output variable Input output variables 6 steps Number of instruc The total number of instruction steps same as standard tion steps in func user program 27 steps tion block definition Example Input variables with a 1 word data type INT 5 Output variables with a 1 word data type INT 5 Function block definition section 100 steps Number of steps for 1 instance 57 5 5 x 6 steps 100 steps 27 steps 244 steps When the program is written in ST language the actual number of steps can not be calculated The number of instruction steps in each function block defi nition can be found in the function block definition s properties 2 9 2 Function Block Instance Execution Time This section applies only to CP series CPU Units with unit version Ver 1 0 or later and CS CJ series CPU Units with unit version Ver 3 0 or later NSJ Con trollers and FQM1 Flexible Motion Controllers Use the following equation to calculate the effect of instance execution on the cycle time when function block definitions have been created and the instances copied into the CPU Unit s user program Effect of Instance Execution on Cycle T
210. ill execute read write processing in the areas exceeding the number of elements In this example read write processing will be exe cuted for the next 6 words after the number of elements registered in the actual variable table If the same area is being used by another instruction including internal variable allocations unexpected operation may occur which may result in a serious accident Do not use variables with a size that does not match the data size to be pro cessed by the instruction in the operand specifying the first address or last address for a range of words Always use either non array variables data type with a size that is the same as the data size required by the instruction or array variable with the number of elements that is the same as the data size required by the instruction Otherwise the following errors will occur If the operand specifying the first address or last address of multiple words uses a non array variable data type with a size that does not match the data size required by the instruction and an AT setting is also not used the CX Pro grammer will output a compile error Example BLOCK TRANSFER 070 instruction XFER W S D W Number of words S First source word D First destination word When amp 10 is specified in W variable a with data type WORD is specified in S and variable b with data type WORD is specified in D XFER amp 10 a b The XFER 070 instruction will transfer the data in the 1
211. ily reused in function blocks as addresses and I O comments Note The prefix AutoGen is not added to Index Registers IR and Global Data Registers DR and they cannot be registered in the original global symbol table Automatically generate symbol name Option Not Selected in Symbols Tab under Options in Tools Menu Addresses and I O comments are not registered in the function block defini tion variable tables Addresses are displayed in the operand in red I O com ments will be lost Double click on the instruction and input the symbol name into the operand Index Registers IR and Data Registers DR however do not require modifi cation after pasting and function in the operand as is Source Instruction The user program symbol is automatically registered in the internal variables Operand Symbol of the function block definition variable table This operation however is sub ject to the following restrictions Addresses Symbol addresses are not registered Use AT settings to specify the same address Symbol Data Types The symbol data types are converted when pasted from the user program into the function block definition as shown in the following table Symbol data type in user program Variable data type after pasting in function block program WORD The variable will not be registered and the value number will be pasted directly into the operand as a con stant UINT BCD WORD UDINT BCD DWORD ULINT BCD
212. ime Startup time A I O parameter transfer processing time B Execution time of instructions in function block definition C 79 Number of Function Block Program Steps and Instance Execution Time Section 2 9 The following table shows the length of time for A B and C Operation CPU Unit model Startup time CS1H CS1G CJ1M CPU6LIH CPU4OH CPU CJ1H CJ1G CPU6LIH CPU4L TH NSJ Startup time not including I O parameter trans fer I O parameter transfer pro cessing time The data type is indicated in parentheses 1 bit input vari 0 24 us 59 52 us able or output variable BOOL 1 word input 0 19 us 13 16 us variable or out put variable INT UINT WORD 2 word input 15 08 us variable or out put variable DINT UDINT DWORD REAL 4 word input 30 16 us variable or out put variable LINT ULINT LWORD LREAL Input output vari 0 114 us 0 4us 0 4us 0 5 us Not sup Not sup able ported ported 80 Function block definition instruction execution time Total instruction processing time Same as standard user program Example CJ1H CPU67H R Input variables with a 1 word data type INT 3 Output variables with a 1 wo
213. in the expression are assignment state ments IF CASE FOR WHILE or REPEAT Multiple statements can be executed in the expression Be sure to use a semicolon delimiter between multiple statements in an expression The condition can also be specified as a boolean variable BOOL data type only rather than an equation B Examples Example 1 Numeric values from 1 through 10 are incremented and the total is substituted for the variable TOTAL Ads TOTAL 0 REPEAT TOTAL TOTAL A A A 1 UNTIL A gt 10 END REPEAT EXIT Statement BH Summary This statement is used within iteration statements FOR WHILE REPEAT only to force an iteration statement to end This statement can also be used within an IF statement to force an iteration statement to end when a specified condition is met B Reserved Words EXIT B Statement Syntax Example Using within IF Statement FOR WHILE REPEAT expression IF condition THEN EXIT END IF END FOR WHILE REPEAT B Usage Use the EXIT statement to force iteration processing to end before the end condition is met B Description Example Using within IF Statement When the condition equation is true the iteration statement FOR WHILE REPEAT is forced to end and any statements after EXIT will not be exe cuted Note 1 The condition can also be specified as a boolean variable BOOL data type only rather than an equation 2 Even if the condition equation is tr
214. ing with the previous function block definition 5 Click the Yes Button The user program in the CPU Unit will be updated with the new function block definition from the buffer memory of the CPU Unit If the No Button is click the new function block definition in the buffer memory will be discarded and the program will not be changed In either case the program will return to the status in which function block definitions cannot be edited To edit another function block definition se lect FB online Edit Begin and begin the online editing procedure from the beginning Normal Mode In Normal Mode both the source code and object code are transferred to the CPU Unit Some time may be required for Normal Mode transfers because of the quantity of data that must be sent Other editing or transfer operations cannot be performed until the transfer has been completed Note The Display confirmation of FB online edit changes Option can be selected to display a confirmation dialog box after the source code has been transferred but just before updating the user memory in the CPU Unit Quick Mode In Quick Mode only the object code is transferred to the CPU Unit The source code is not transferred making Quick Mode faster than Normal Mode After transferring the object code either 1 select Program Transfer FB Source to transfer the source code or 2 transfer the source code according to instructions displayed in a dialog box when you go
215. ings 4 Memory A Programs Sg NewProgram1 00 3 Symbols Section Name Sectiont sample amp Instance name FunctionBlockt Function block definition 0 00 BOOL BOOL ah ENO Press the P Key with the cursor on the left i of the instance The New Parameter eo _ ee Dialog Box will be displayed rv LAMP c dT Function Blocks j il AF Functiontlocki worn E FunctionBlock2 BOOL New Parameter x T Detail gt gt Cancel SCOT STS mrF H tie ee 2 Set the source address from which to pass the address data to the input variable Also set the destination address to which the address data will be passed from the output variable Untitled CX Programmer NewPLC1 NewProgram1 Sectioni Diagram FA Fie Edit View Insert PLC Program Tools Window Help JO sala E melo cess v a amp en ng Rt xS ws Je a fefe Ir me 3e nw o 2 8 8 EC t IER eo en n ts ta to e ER Te Fs T ja m Ea aos e I E End 39 39 25 En d wt rr gt o xix o o B Program Name NewProgramt E Tie NewProject NewPLCI C31 G H Offline Section Name Section 3 Symbols GF 10 Table sample S Settings Memory FunctionBlockt cS Programs 0 00 BOOL BOOL S NewProgramt 00 EN ENOL 3 Symbols Sectioni 0 o BOOL BOOL G END NO J CAMP l F Function Blocks WORD BOOL Pv
216. ings for Input Output Variables and Internal Variables 2 5 3 AT Settings for Internal Variables Always specify AT settings for internal variables under the following condi tions When addresses allocated to Basic I O Units Special I O Units or CPU Bus Units are used and these addresses are registered to global symbols that cannot be specified as external variables e g data set for global symbols is unstable Note The method for specifying Index Registers for Special I O Unit allo cation addresses requires AT settings to be specified for the first address of the allocation area For details refer to 2 5 5 Specifying Addresses Allocated to Special I O Units When Auxiliary Area bits that are not pre registered to external variables are used and these bits are registered to global symbols that are not specified as external variables When setting the first destination word at the remote node for SEND 090 and the first source word at the local node for RECV 098 When the instruction operand specifies the first or last of multiple words and an array variable cannot be specified for the operand e g the num ber of array elements cannot be specified 2 5 4 Array Settings for Input Output Variables and Internal Variables Using Array Variables to Specify First or Last Word in Multiword Operands Note 1 2 3 When specifying the first or last of a range of words in an instruction operand see note the ins
217. instances or changing instance names Note The instance s I O parameters can be changed instances can be deleted and instructions outside of an instance can be changed Programming Restrictions Section 2 4 If a fatal error occurs in the CPU Unit while a function block definition is being executed ladder program execution will stop at the point where the error Error related Restrictions occurred Program FB definition Instance name Body 0 0 FB 10 0 LD he EN ENO zt Fatal error occurs here D100 AAA BBB D200 MOV AAA BBB In this case the MOV AAA BBB instruction will not be executed and output variable D200 will retain the same value that it had before the function block was executed To use a function block the system requires memory areas to store the instance s internal variables input variables output variables and input out put variables CJ2 series CPU Units Function block instance Prohibiting Access to FB Instance Areas Initial value of Initial value Allowed data areas Note area Non retained start address of size CIO WR HR DM EM See note Retained HR DM EM See note Timer TIM Counter CNT Force setting resetting is enabled when the following EM banks are specified CJ2H CPU64 EIP CPU65 EIP EM bank 3 CJ2H CPU66 P EM banks 6 to 9 CJ2H CPU67 EI EI CJ2H CPU68 EIP
218. ion LEN String version 4 0 or later or CJ2 series CPU Units Argument data type String value STRING Return data type Description Detects the length of a text string The following functions can be used with CS CJ series CPU Units with unit Example a LEN b number of characters in string b stored in variable a LEFT Source string Number of characters Source string STRING STRING Number of characters INT UINT Extracts charac ters from a text string starting from the left a LEFT b c number of characters specified by variable c extracted from the left of text string b and stored in variable a RIGHT Source string Number of characters Source string STRING STRING Number of characters INT UINT Extracts charac ters from a text string starting from the right a RIGHT b c number of characters specified by variable c extracted from the eight of text string b and stored in variable a MID Source string Number of characters Position Source string STRING STRING Number of characters INT UINT Position INT UINT Extracts charac ters from a text string a MID b c d number of characters specified by variable c extracted from text string b starting at position spec ified by variable d and stored in variable a 147
219. ion Flag are ON IF P CominstEnable TRUE AND P TXDU Exe FALSE THEN TXD_SCU Message 0 2 7 iProcess 3 Use the following Unit number 0 Serial port number 2 Logical port number 7 Send data when P_DoSendData is ON and iProcess is 0 IF P_DoSendData TRUE AND iProcess 0 THEN iProcess 1 P_DoSendData FALSE Execute send processing according to process number 3 Sending has been completed if Communications Port Enable Flag is ON IF P CominstEnable TRUE THEN iProcess 0 END IF Function Descriptions Appendix C Related Auxiliary Address Area Flag Communications A202 00 to A202 07 ON when network communications can be executed The bit Instruction Enable numbers correspond directly to the internal logic port numbers Flags Bits 00 to 07 Internal logic ports O to 7 Related CPU Bus Unit Area bits n CIO 150 25 x ON when TXDU is being executed unit number Port 1 n 9 Port 2 n 19 For further information and precautions on related Auxiliary Area flags refer to the section on TXDU Serial Communications Instruction in the CS CJ series Instruction Reference Manual RXD_CPU Receive String via CPU Unit RS 232C Port e Function Receives a text string from the RS 232C port on the CPU Unit Application RXD CPU Storage location Number of characters Conditions The serial communications mode of the RS 232C port must be set to no protocol communicatio
220. ion conditions Timer address Timer set value Execution condition Timer address Timer set value Name TENTH MS TIMER Operation Operates a decrement ing timer with units of O 1 ms TIMUX a b c When execution condi tion a is satisfied the TIMUX timer set to timer set value c in timer address b is started TMUHX Execution conditions Timer address Timer set value Execution condition Timer address Timer set value Name HUNDREDTH MS TIMER Operation Operates a decrement ing timer with units of 0 01 ms TMUHX a b c When execution condi tion a is satisfied the TMUHX timer set to timer set value c in timer address b is started TTIMX Execution condition Reset input Timer address Timer set value Execution condition Reset input Timer address Timer set value Name ACCUMULATIVE TIMER Operation Operates an increment ing timer with units of O 1 s TTIMX a b c d While execution condi tion a is satisfied the TTIMX timer set to timer set value d in timer address c is started When the reset input bis ON the timer s PV and completion flag are reset CNTX Count input Reset input Counter address Counter set value Count input Reset input Counter address Counter set value Name COUNTER Operation Operates
221. ion is executed This process is repeated If the iteration variable gt final value equation see note 2 the processing ends 1 If the value from the increment equation is negative the condition is iteration variable final value equation value 2 If the value from the increment equation is negative the condition is iteration variable final value equation E Precautions A negative value can be specified in the increment equation FOR must be used in combination with END FOR The initial value final value equation and final value equation must be an integer data type INT DINT LINT UINT UDINT or ULINT After processing is executed with the final value the iteration value is incremented to the final value 1 and iteration processing ends Example In the following structured text the value of a becomes TRUE Statement Descriptions WHILE Statement Section 5 5 FOR i 0 TO 100 DO DATA i 0 END FOR IF i 101 THEN a TRUE ELSE a FALSE END_IF Do not use a FOR statement in which an iteration variable is changed directly Doing so may result in unexpected operations Example FOR i 0 TO 100 BY 1 DO DATA i 20 i i 5 END_FOR e Statements that can be used in the expression are assignment state ments IF CASE FOR WHILE or REPEAT Multiple statements can be executed in the expression Be sure to use a semicolon delimiter between multiple statements in an expres
222. ion start is set as retained See note 1 Applicable areas H Function block Special Holding Area H Holding Area D Data Memory Area see note 1 E Extended Data Memory Area See notes 2 and 3 Setting unit Set in words Allocated words default H1408 to H1535 1 Except when the data type is set to TIMER or COUNTER 2 Bit data can be accessed even if the DM or EM Area is specified for the non retained area or retained area 3 The same bank number cannot be specified as the current bank in the user program if the EM Area is specified for the non retained area or re tained area Timer Area Item Contents Allocated variables Variables with TIMER set as the data type Applicable areas T Timer Area Timer Flag 1 bit or timer PVs 16 bits Allocated words default Counter Area T3072 to T4095 Timer Flag 1 bit or timer PVs 16 bits Item Contents Allocated variables Variables with COUNTER set as the data type Applicable areas C Counter Area Counter Flag 1 bit or counter PVs 16 bits Allocated words default C3072 to C4095 Counter Flag 1 bit or counter PVs 16 bits Instance Specifications Note Note Section 2 3 Function Block Holding Area H512 to H1535 The default allocation of Function Block Holding Area words set as retained and non retained words is H512 to H1535 These words are different to the standard Holdin
223. k definitions and converted to library functions Function Blocks Supports Nesting and Multiple Languages Section 1 2 The function blocks are created with variable names that are not tied to actual addresses so new programs can be developed easily just by reading the def initions from the file and placing them in a new program Mathematical expressions can be entered in structured text ST language With CX Programmer Ver 6 0 and later versions function blocks can be nested The function block nesting function allows just special processing to be performed in a ST language function block nested within a ladder lan guage function block Function block ladder language 6 GreenTimerDo GreenLight 15 j Go 7 Special_Operation 17 SiNoperation Not B001 BOOL EN ENO input_data REAL REAL result data data RESULT Call Nesting Function block ST language RESULT 0 0 IF M TRUE THEN RESULT SIN data 1 2 3 Function Block Structure Function Block Definitions Number of Function Block Definitions Function blocks consist of function block definitions that are created in advance and function block instances that are inserted in the program Function block definitions are the programs contained in function blocks Each function block definition contains the algorithm and variable definitions as shown in the following diagram Function Block Definition Saws
224. k definitions that you create the more memory steps will be used This section applies only to CP series CPU Units with unit version Ver 1 0 or later and CS CJ series CPU Units with unit version Ver 3 0 or later NSJ Con trollers and FQM1 Flexible Motion Controllers Use the following equation to calculate the approximate number of program steps when function block definitions have been created and the instances copied into the user program of the CPU Unit Number of steps Number of instances x Call part size m I O parameter transfer part size n x Num ber of parameters Number of instruction steps in the function block definition p See note The number of instruction steps in the function block definition p will not be diminished in subsequence instances when the same function block definition is copied to multiple locations i e for multiple instances Therefore in the above equation the number of instances is not multiplied by the number of instruction steps in the function block definition p Number of Function Block Program Steps and Instance Execution Time Section 2 9 The following table applies only to CP series CPU Units with unit version Ver 1 0 or later and CS CJ series CPU Units with unit version Ver 3 0 or later NSJ Controllers and FQM1 Flexible Motion Controllers Contents Number of steps Call part 57 steps I O parameter 1 bit BOOL input vari 6 steps transfer part able or output var
225. l 1 79769313486232 X 10308 to point 2 22507385850720 x 10 308 0 42 22507385850720 x 10 908 to 1 79769313486232 x 109308 16 bit data followed by hexadecimal 0000 to FFFF or amp 0 to 65535 number 4 digits max amp or followed by decimal number 32 bit data 32 bits followed by hexadecimal 00000000 to FFFFFFFF or amp 0 number 8 digits max to 4294967295 amp or followed by decimal number 64 bit data 64 bits followed by hexadecimal 0000000000000000 to number 16 digits max FFFFFFFFFFFFFFFF or amp 0 to amp or followed by decimal 18446744073709551615 number Note lfanon boolean data type is used for the input variable and only a numerical value e g 20 is input the value for the CIO Area address e g CIO 0020 will be passed and not the numerical value To set a numerical value always insert an amp or prefix before inputting the numerical value Example Programs Instance for function block definition A INT H DATA 1 If the data format for DATA 1 is INT and 10 is input the value for CIO 0010 will be passed Instance for function block definition A CN ONT f N 98101 DATA 1 If the data format for DATA 1 is INT and the prefix amp is added so that amp 10 is input the numerical value will be passed If the input variable data type is boolean and a numerical value only e g O or 1 is input in th
226. l port WORD specified by variable c on the Serial Communications Seral port lt INT Board and stored in variable UINT WORD a RXD SCU Storage Storage STRING Receives a text string RXD_SCU a b c d e location Number of location from a serial port on number of characters characters gt lt SCU_unit_ Number ot INT Serial Communica specified by variable b are number Serial port characters UINT tions Unit received from the serial port Internal logic port WORD specified by variable d on SCU unit INT the Serial Communications number UINT Unit specified by variable C using the internal logic port WORD Je specified by variable e and Serial port INT stored in variable a The UINT variable e indicates the WORD internal logic port number Internal logic INT port UINT WORD Angle Conversion The following functions can be used with CS CJ series CPU Units with unit Instructions version 4 0 or later or CJ2 series CPU Units Function Argument Return value Description Example data type data type DEG TO RAD argument REAL LREAL REAL LREAL Converts an angle from a DEG TO RAD b degrees to radians an angle in degrees in variable b is converted to radians and stored in variable a RAD TO DEG argu REAL LREAL REAL LREAL Converts an angle from amp RAD TO DEG b ment radians to degrees an angle in radians in variable b is converted to degrees and stored in variab
227. le a Timer Counter The following functions can be used with CJ2 series CPU Units Functions Function Argument data type Return Description Example value data type TIMX Execution Name TIMX a b c Execution condition condition HUNDRED MS TIMER when execution condi Timer address Timer address Operation tion a is satisfied the Timer set value Timer servate Operates a decrement TIMX timer set to timer dice ing timer with units of set value c in timer 100 ms address b is started TIMHX Execution Name TIMHX a b c Execution condition condition TEN MS TIMER When execution condi Timer address Timer address Operation tion a is satisfied the Timer set value Timer set Vale Operates a decrement TIMHX timer set to timer x ing timer with units of 10 set value c in timer ms address b is started 153 ST Language Configuration Function TMHHX lt Execution_condition gt lt Timer_address gt lt Timer_set_value gt Argument data type Execution_ condition Timer_address Timer_set_value Return value data type Description Name ONE MS TIMER Operation Operates a decrement ing timer with units of 1 ms Section 5 4 Example TMHHX a b c When execution condi tion a is satisfied the TMHHX timer set to timer set value c in timer address b is started TIMUX Execut
228. le name Data Shift Functions Bitwise shift SHL and SHR bitwise rotation ROL and ROR etc Data Control Functions Upper lower limit control LIMIT etc Data Selection Functions Data selection SEL maximum value MAX minimum value MIN multiplexer MUX etc Numerical Functions Function Argument data type Return value Description Example data type ABS argument INT DINT LINT INT DINT LINT Absolute value argu a ABS b UINT UDINT ULINT UINT UDINT ment absolute value of variable REAL LREAL ULINT REAL b stored in variable a LREAL SQRT argument REAL LREAL REAL LREAL Square root a SQRT b argument square root of variable b stored in variable a LN argument REAL LREAL REAL LREAL Natural logarithm LOG a LN b argument natural logarithm of vari able b stored in variable a LOG argument REAL LREAL REAL LREAL Common logarithm a LOG b LOG1o argument common logarithm of vari able b stored in variable a gument natural exponential of vari able b stored in variable a SIN argument REAL LREAL REAL LREAL Sine SIN argument a SIN b sine of variable b stored in variable a COS argument REAL LREAL REAL LREAL Cosine COS argument a COS b cosine of variable b stored in variable a TAN argument REAL LREAL REAL LREAL Tangent TAN argument a TAN b tangent of variable b stored in variable a
229. left side of the bit string Application Heturn value SHR Shift target data Number of bits Arguments and Return Values Variable name Data type Description Shift target data S1 BOOL WORD DWORD Specifies the data to be shifted LWORD Number of bits n INT UINT UDINT ULINT Specifies the number of bits by which the DINT LINT bit string is to be shifted Return value BOOL WORD DWORD Returns the output data LWORD 201 Function Descriptions Appendix C Note The same data type must be set for the 1st argument and the return value Example Variables oo oi Datat B26E hex gt 1011 0010 0110 1110 binary WORD Result N 1 decimal Rut o 4 o 3 o o s e o o 1 1 Result SHR Data1 N 5937 is stored in the Result variable ROL Bitwise Rotate Left e Function Rotates a bit string to the left by n bits Application Return_value ROL Rotation_target_data Number_of_bits Arguments and Return Values Variable name Data type Description Rotation_target_data BOOL WORD DWORD Specifies the data to be rotated S1 LWORD Number_of_bits n INT UINT UDINT ULINT Specifies the number of bits by which the DINT LINT bit string is to be rotated Return_value BOOL WORD DWORD Returns the output data LWORD Note The same data type must be set for the 1st argument and the retur
230. les as required Right click the variable and select the desired variable type from the Change usage Menu Change usage gt 1 00 Internals 0 01 Limit BOOL Inputs D100 AutoGe WORC Outputs Ww0 00 SetCo BOOL Inputfoutputs 2nn Temn RANNI If necessary double click any variable in the variable list and change the name or comment The array and AT settings can also be changed Click the OK Button The following Function Block Ladder Generation Di alog Box will be displayed Function Block Ladder FB definition name FunctionBlock1 Comment Cancel Input the FB definition name and comment and then click the OK Button The function block definition will be generated based on the settings and will appear under the function blocks in the Workspace F Function Blocks dtFFunctionBlock1 The following dialog box will be displayed asking if you want to insert an instance of the function block definition below the original program circuits CX Programmer v6 1 x 2 Do you wish to insert a Function Block call at the position of the source ladder _ Click the Yes Button to insert an instance and click the No Button to not insert an instance 95 Procedures Section 3 2 Note 96 8 The following New Function Block Invocation Dialog Box will appear if the Yes Button was clicked New Function Block Invocation X FB Instance Gk FB Definition FunctionBlock1
231. liary Area bits other than those pre registered to external variables are registered to global symbols and these variables are not specified as external variables Use internal variables when specifying PLC addresses for another node on the network For example the first destination word at the re mote node for SEND 090 and the first source word at the remote node for RECV 098 Use internal variables when the first or last of multiple words is speci fied by an instruction operand and the operand cannot be specified as an array variable e g the number of array elements cannot be spec ified xxiii Application Precautions xxiv Part 1 Function Blocks SECTION 1 Introduction to Function Blocks This section introduces the function block functionality of the CX Programmer and explains the features that are not contained in the non function block version of CX Programmer 1 1 Introducing the Function Blocks 0 0 0c eee eee 4 1 1 1 Overview and Features 0 00 0 00 0 eee 4 1 1 2 Function Block Specifications 00 0000 00005 5 1 1 3 Files Created with CX Programmer Ver 6 0 or Later 8 1 1 4 Function Block Menus in CX Programmer Ver 5 0 and later VersionS 0 e cee eee nents 8 1 2 Function Blocks fees ceive RR eS RR REDE Pe 11 T2251 c Outline eese os in Dade EIOS TE RS 11 1 2 2 Advantages of Function Blocks 00 e ee eee eee 12 1 2 3 Function Block
232. licable memory Area Start address End address areas Non Retain CIO WR HR DM EM Retain HR DM EM Timers TIM Counters CNT FQM1 Flexible Motion Controllers FB Instance Default value Applicable memory Area Start address End address areas Non Retain CIO WR DM Retain Timers TIM Counters CNT CP series CPU Units FB Instance Default value Applicable memory Area Start address End address argas Non Retain CIO WR HR DM See note Retain HR DM See note Timers TIM Counters CNT Note DM area of CP1L L Address CP1L L D0000 to D9999 Provided D10000 to D31999 Not Provided D32000 to D32767 Provided 22 Converting Function Block Definitions to Library Files Section 1 4 Function Block Holding The Function Block Holding Area words are allocated from H512 to H1535 Area Words H512 to These words are different to the standard Holding Area used for programs H1535 HOOO to H511 and are used only for the function block instance area inter nally allocated variable area These words cannot be specified as instruction operands They are displayed in red if input when a function block is not being created Although the words can be input when creating a function block an error will occur when the program is checked If this area is specified not to be retained in the Function Block Memory Allocation Dialog Box turn the power ON OFF or
233. line editing of a function block Cancel Cancels changes made to a function block being edited online Transfer FB Source Transfers only the function block source Release FB Online Edit Access Rights Forcefully releases the access rights for function block SFC and ST online editing held by another user Introducing the Function Blocks Section 1 1 Submenu Shortcut Function Simulation Break Point Sets or clears a break point Set Clear Break Point Break Point Clears all break points Clear All Break Point Mode Run Executes continuous scanning Sets the ladder execution Monitor Mode engine s run mode to MONITOR mode Mode Stop Sets the simulator s operation mode to PROGRAM mode Program Mode Mode Pause Pauses simulator operation Step Run Executes just one step of the simulator s program Step Run When there is a function block call instruction this com Step In mand moves to execution of the internal program step Step Run When a function block s internal program step is being exe Step Out cuted this command returns to the next higher level call source and pauses execution Step Run Executes steps continuously for a fixed length of time Continuous Step Run Step Run Executes for one cycle and pauses execution Scan Run Always Display Used with the Step Run or Continuous Step Run com Current Execu mands to automatic
234. lly set Address passed Address passed a changed by function block processing D201 A Variable a Processing is performed inside the function block using variable a The resulting value is written to I O memory for the size of variable a starting at address D200 Note Input output variables are specified in a CX Programmer variable table by selecting In Out for the variable usage Function Blocks Section 1 2 n Reference Information A variety of processes can be created easily from a single function block by using parameter like elements such as fixed values as input variables and changing the values passed to the input variables for each instance Example Creating 3 Instances from 1 Function Block Definition Cyclic taskO Instance CASCADE_01 CASCADE_01 P_On CONTROL Xo Algorithm L EN ENO 820 on TIME Internal and I O lees variables amp i0 OFF TIME Function Block Definition Example CONTROL Instance CASCADE 02 z CASCADE 02 P_On CONTROL 11 Algorithm Algorithm em ENO O amp 15 Variables Internal and I O ON TIME variables amp 10 OFF TIME Example There are 3 FB instances and each Cyeli clic task 1 has its own I O and Instance y CASCADE 03 internal variables CASCADE 03 P On CONTROL 12 i 1 EN ENO Algorithm
235. log Box will be displayed 110 Procedures Note Section 3 2 Target Print Rung x Target Print ALL Rung C Select Rung Start Rung No J 4 End Rung No 3 4 Header Footer Information First Page No 1 to 99999 1 E Valid when Page number field is selected Print Item of FB Definition 5 Symb C Py Select the All Rung or Select Rung option When the Select Rung option is selected specify the start rung and end rung numbers When a page number has been specified in the header and footer fields in File Page Setup the first page number can be specified Select either of the following options for the function block printing range Symbol table and program default Symbol table Program Click the OK Button and display the Print Dialog Box After setting the printer number of items to print and the paper setting click the OK button The following variable table followed by the algorithm e g ladder program ming language will be printed MET Value PUT Eon Control mre Function Outputs BOOL FALSE successful execution of the Function Block Function Block Name FB sample04 000000 g Mov OP1 000000 f Gm OP2 EN D100 Controls D200 execution For details on print settings refer to the section on printing in the CX Pro grammer Operation Manual W446 3 2 14 Password Protection of Function Block Definitions Overview Password Protectio
236. lue followed by real number with decimal point 8 402823 x 1098 to 1 175494 x 10738 0 1 175494 x 10 38 to 3 402823 x 1038 1 79769313486232 x 10308 to 2 22507385850720 x 10 908 0 2 22507385850720 x 107308 1 79769313486232 x 10908 16 bit data followed by hexadecimal number 4 digits max amp or followed by decimal number 0000 to FFFF or amp 0 to 65 535 32 bit data 32 bits followed by hexadecimal number 8 digits max amp or followed by decimal number 00000000 to FFFFFFFF or amp 0 to 4 294 967 295 64 bit data followed by hexadecimal number 16 digits max amp or followed by decimal number 0000000000000000 to FFFFFFFFFFFFFFFF or amp 0 to 18 446 744 073 709 551 615 2 The size of function block input variables and output variables must match the size of program symbols global and local as shown in the fol lowing table 1 bit Function block variable data type BOOL Program symbol global local data type BOOL 16 bits INT UINT WORD INT UINT UINT BCD WORD 32 bits DINT UDINT REAL DWORD DINT UDINT UDINT BCD REAL DWORD 64 bits LINT ULINT LREAL LWORD LINT ULINT ULINT BCD LREAL LWORD More than 1 bit Non boolean CHANNEL NUMBER see note Note The program symbol NUMBER can be set only in the input param eters The value that is input must be within the
237. m num ber of instances 256 Inside comment memory Function block program mem ory Kbytes 256 Comment files Kbytes Program index files Kbytes Variable tables Kbytes 75 CPU Unit Function Block Specifications Section 2 8 CP1L CPU Units Model M models CP1L M4ODL CP1L M60DL CP1L MSODLT L models CP1L L14DL CP1L L20DL CP1L L10DL Max number of I O points 180 points 60 built in points 40 points Expansion Rack x 3 Racks 160 points 40 built in points 40 points Expansion Rack x 3 Racks 150 points 30 built in points 40 points Expansion Rack x 3 Racks 60 points 20 built in points 40 points Expansion Rack x 1 Rack 54 points 14 built in points 40 points Expansion Rack x 1 Racks 10 points Program capacity steps 10K 5K Data memory 32K words D00000 to D32767 10K words D00000 to D09999 and D32000 to D32767 Number of connectable Expan sion Units and Expansion I O Units 3 Units CP series Expansion Units and Expansion I O Units 1 Unit CP series Expan sion Unit or Expansion 1 O Unit None Function blocks Maximum num ber of definitions 128 Maximum num ber of instances 256 Inside comment memory
238. m or ST language Alternatively insert a function block library file that has been prepared in advance Note a Create the algorithm entirely with variable names b When entering the algorithm in ladder programming language project files created with versions of CX Programmer earlier than Ver 5 0 can be reused by reading the project file into CX Pro grammer Ver 5 0 or higher and copying and pasting useful parts c Existing ladder programming can be automatically turned into a function block using Edit Function Block ladder generation 2 When creating the program insert copies of the completed function block definition This step creates instances of the function block 3 Enteran instance name for each instance 23 Usage Procedures Section 1 5 4 Set the variables input source addresses and or constants and output destination addresses and or constants as the parameters to pass data for each instance Select the created instance select Function Block Memory Function Block Memory Allocation from the PLC Menu and set the internal data area for each type of variable 6 Transfer the program to the CPU Unit 7 Start program execution in the CPU Unit and the instance will be called and executed if their input conditions are ON The instance is executed if the input condition is established 3 Input instance name Function block definition A Program n Instance of function blo
239. m to the above mentioned appli cations Safety Precautions NWARNING A Caution Confirm safety sufficiently before transferring I O memory area status from the CX Programmer to the actual CPU Unit The devices connected to Output Units may malfunction regardless of the operating mode of the CPU Unit Caution is required in respect to the following functions Transferring from the CX Programmer to real I O CIO Area in the CPU Unit using the PLC Memory Window Transferring from file memory to real I O CIO Area in the CPU Unit using the Memory Card Window Variables must be specified either with AT settings or external variables or the variables must be the same size as the data size to be processed by the instruction when specifying the first or last address of multiple words in the instruction operand 1 If anon array variable with a different data size and without an AT setting is specified the CX Programmer will output an error when compiling 2 Array Variable Specifications Application Precautions A Caution A Caution A Caution A Caution e When the size to be processed by the instruction operand is fixed The number of array elements must be the same as the number of ele ments to be processed by the instruction Otherwise the CX Programmer will output an error when compiling e When the size to be processed by the instruction operand is not fixed The number of array elements must be greater than
240. n 0 00 is OFF If Differentiation Instructions are being used always use the Always ON Flag P On for the EN input condition and include the instruction s input condition within the function block definition C EN input condition is always ON so these Differentiation Instructions operate normally Input a decimal numerical value after when specifying the first operand of the following instructions MILH 517 MILR 518 MILC 519 DIM 631 MSKS 690 MSKR 692 CLI 691 FAL 006 FALS 007 TKON 820 TKOF 821 Note amp is not supported CNR 545 CNRX 547 RESET TIMER COUNTER instructions cannot be used to reset multiple timers and counters within a function block at the same time Always specify the same variable for the first operand timer counter num ber 1 and second operand timer counter number 2 Different variables cannot be specified for the first and second operand An instance will not be executed while its EN input variable is OFF so the fol lowing precautions are essential when using a Timer Instruction in a function block definition The Timer Instruction will not be initialized even though the instance s EN input variable goes OFF Consequently the timer s Completion Flag will not be turned OFF if the EN input variable goes OFF after the timer started operat ing Programming Restrictions Section 2 4 Body 00 FB1 _ x EN ENO P UP D E The timers Completion Flag U
241. n A356 07 ON when a data overflow occurred during reception in no pro Overflow Flag tocol mode Port 1 Reception A357 Contains the number of characters received in no protocol Counter mode Port 2 Reception A356 14 ON when reception has been completed in no protocol mode Completed Flag Port 2 Reception A356 15 ON when a data overflow occurred during reception in no pro Overflow Flag tocol mode Port 2 Reception A358 Contains the number of characters received in no protocol Counter mode For further information and precautions on related Auxiliary Area flags refer to the section on RXD Serial Com munications Instruction in the CS CJ series Instruction Reference Manual RXD SCU Receive String via Serial Port on Serial Communications Unit e Function Receives a text string from a serial port on a Serial Communications Unit SCU Application RXD SCU Storage location Number of characters SCU unit number Serial port Internal logic port Conditions The serial communications mode of the serial port must be set to no protocol communications 215 Function Descriptions Appendix C Arguments and Return Values Variable name Data type Description Storage location STRING Specifies the storage location for the received text string Number of characters INT UINT WORD Specifies the number of characters to receive 0 to 255 SCU unit number INT UINT WORD Specifies the number of the Serial
242. n be specified in 1 word units When the CX Programmer compiles the function it will output an error if there are any instructions in the user program that access words in these areas Memory Area Start Address End Address Size F Heared Hio SCISSOR Cancel FB Counter CO cms To Edt SFC Ward share wih Fo Defaut Advanced v Share SFC with FB Memory 44 Instance Specifications Section 2 3 CJ2 series CPU Units FB Instance Default value Applicable memory Start address End address Non Retain CIO WR HR DM EM See note Area areas Retain HR DM EM See note Timers TIM Counters CNT Note X Force setting resetting is enabled when the following EM banks are specified CJ2H CPU64 EIP CPU65 EIP EM bank 3 CJ2H CPU66 EIP EM banks 6 to 9 El CJ2H CPU67 EIP EM banks 7 to E CJ2H CPU68 EIP EM banks 11 to 18 CS CJ series CPU Units Ver 3 0 or Later and NSJ Controllers FB Instance Default value Applicable memory Area Start address End address areas Non Retain CIO WR HR DM EM Retain HR DM EM Timers TIM Counters CNT FQM 1 Flexible Motion Controllers FB Instance Default value Applicable memory Area Start address End address areas Non Retain CIO WR DM Retain Timers TIM Counters CNT CP series CPU Units FB Instance Default value Applicable memory Area Start address End a
243. n block definition square brackets surrounding the index will appear af ter the array name For example if you create a variable named PV with a maximum of 3 ele ments PV 0 PV 1 and PV 2 could be specified as instruction operands There are three ways to specify indices Directly with numbers e g PV 1 in the above example for ladder pro gramming or ST language programming e With a variable e g PV a in the above example where a is the name of a variable with a data type of INT for ladder programming or ST language programming e With an equation e g PV a b or PV a 1 in the above example where a and b are the names of variables with a data type of INT for ST language programming only When using structured text a dialog box will not be displayed to register the variable whenever a variable name that has not been registered is input Be sure to always register variables used in standard text programming in the variable table either as you need them or after completing the program Place the cursor in the tab page on which to register the variable right click and select nsert Variable from the pop up menu For details on structured text specifications refer to SECTION 5 Structured Text ST Language Specifications in Part 2 Structured Text ST Copying User Program Circuits and Pasting in Ladder Programming of Function Block Definitions Source Instruction Operand Address Only No
244. n block definition can be com piled and checked as a program We recommend compiling to perform a pro gram check on each function block definition file before saving or reusing the file Version Upgrade Information Section 1 6 1 6 Version Upgrade Information Refer to the CX Programmer Operation Manual W446 for information on upgraded functions other than those for function blocks and structure text Ver 9 5 to 9 6 Upgrade Information Functionality Improved Compatible PLC Models from Version 9 5 to 9 6 The following unit versions of CPU Units are supported Read protection with extended passwords has been enabled CJ2H unit version 1 5 CJ2M unit version 2 1 CS1G H unit version 4 1 CS1H H unit version 4 1 CJ1G H unit version 4 1 CS1D H unit version 1 4 CS1D S unit version 2 1 CP1H unit version 1 3 CP1L unit version 1 1 CP1L L unit version 1 1 and CP1E unit version 1 3 Read Protection with Passwords Read protection using longer passwords was added Read protection with extended passwords provides stronger protection for the design assets of the user Ver 9 2 to 9 3 Upgrade Information Changed ST Editor View e Added the indication of line numbers on the ST Editor View And you can also specify a line number to jump there Functions and registered Symbols are selectable from Word Lists e When you press the Tab key while the start function of a Control State ment is selected you can enter the frame
245. n on both Writing and Reading Function block definitions in a project can be protected by setting a password to restrict access The following two levels of password protection that can be set depending on the application This password protection level restricts both writing changing and displaying the contents of the function block definition 111 Procedures Password Protection on Writing Only Section 3 2 To set read write protection select Prohibit writing and display as the Protec tion type in the function block s properties This level of protection prevents unintended program changes modifications and also protects against misap propriation of program materials This password protection level restricts writing changing the contents of the function block definition To set write protection select Prohibit writing as the Protection type in the function block s properties This level of protection prevents unintentional pro gram changes modifications Setting Password Protection Protecting an Individual Function Block Definition 1 2 3 112 This operation can be performed offline only Password protection can be applied to individual function block definitions or multiple function block definitions together Use the following procedure to set the password protection for an individual function block definition 1 In the project workspace select the function block definition right click
246. n the program is allocated to a task the check mark over the ST pro gram s icon will be deleted The allocated task number will be shown in pa rentheses after the program name 6 1 4 Creating the ST Program There are two ways to create the ST program s content Input the ST language after registering the variables Register the variables as you input the ST language Inputting the ST There are two kinds of variables global variables and local variables This Language after section explains how to set local variables For details on setting global vari Registering Variables ables refer to the CX Programmer Operation Manual W446 1 Registering Variables with Local Addresses 1 2 3 1 Double click the inserted ST program s Symbols in the project workspace Ep Memory Reusable File d zi A Programs Gig NewProgr Allow Docking Symbc Hide Sectio Am G9 END Float In Main Window i2 NewProgr Properties F Function Blocks 2 The symbol table will be displayed Right click to display the pop up menu and select Insert Symbol from the pop up menu It is also possible to select Insert Symbol 3 The New Symbol Dialog Box will be displayed Set the following items and click the OK Button 180 Procedures Section 6 1 Name Input the variable name Data type Select the data type Address or Value Input the address Input the name The default is BOOL Change th
247. n value Example Variables en Data1 B26E hex 1011 0010 0110 1110 binary WORD Result N 1 decimal Data 1 Result Result ROL Data1 N 64DD is stored in the Result variable ROR Bitwise Rotate Right Function Rotates a bit string to the right by n bits Application Heturn value ROR Rotation target data Number of bits 202 Function Descriptions Appendix C Arguments and Return Values Variable name Data type Description Rotation_target_data BOOL WORD DWORD Specifies the data to be rotated S1 LWORD Number_of_bits n INT UINT UDINT ULINT Specifies the number of bits by which the DINT LINT bit string is to be rotated Return_value BOOL WORD DWORD Returns the output data LWORD Note The same data type must be set for the 1st argument and the return value Example Variables ae v Data1 B26E hex 1011 0010 0110 1110 binary WORD Result N 1 decimal Result Result ROR Data1 N 5937 is stored in the Result variable Data Control Functions LIMIT Upper Lower Limit Control Function Controls the output data depending on whether the input data is within the range between the upper and lower limits Application Return value LIMIT Lower limit data Input data Upper limit data Arguments and Return Values Variable name Data type Description Lower limit data BOOL INT UINT UDINT Specifies the lower limit ULINT
248. nL amp 10 RD BOOL 200 00 constant me 1 200 00 5 the value of 001 is passed to input variable aaa Note Set the data in all the input parameters If even a single input parameter remains blank the left bus bar for the instance will be displayed in red to indi cate an error If this happens the program cannot be transferred to the CPU Unit Inputting Values in Parameters The following table lists the methods for inputting values in parameters Input variable data Content Input method Setting range type Bit data 1 bit P Off P On 0 FALSE 1 TRUE Integer 16 bits Positive value amp or followed 32768 to 432767 by integer Double integer 32 bits 2147483648 to 2147483647 Negative value followed by Long 4 word inte 64 bits integer 9223372036854775808 to ger 9223372036854775807 Unsigned integer 16 bits Positive value amp or followed amp 0 to 65535 Unsigned double 32 bits by integer amp 0 to 4294967295 integer Unsigned long 4 64 bits amp 0 to 18446744073709551615 word integer 102 Procedures Section 3 2 Input variable data Content Input method Setting range type Real number 32 bits Positive value amp or followed 3 402823 x 1038 to 1 175494 by real number with decimal _ point X 10 98 0 1 175494 x 10 8 38 Negative value followed by t0 3 402823 X 10 Long real number real number with decima
249. nce The input variables are displayed on the left side of the instance The value of the input source data contained in the specified parameter just before the instance was called will be passed to the input variable P_On FB 10 Tia LO ENO DO D100 PV cv The value of the parameter specified as the input value of DO is passed to the instance s input variable PV Example fede wie ste alee een tinea 10 0 Algorithm Body 0 0 ADD_INT_DINT i l PO EN ENO 1 SIGN IN16 tmp D100 i i N16 DouT32 91000 i i L IN32 tmp OUT32 D20 ta A IN16 is an INT variable so the content of D100 is used Variable table IN32 is a DINT variable so the content of D200 and Usage Name Type D201 is used nternal tmp DINT Input EN BOOL Input IN16 INT Input IN32 DINT Output ENO BOOL Output OUT32 DINT Name Data Type AT Initial value Retained Comment EN 0 BOOL TTT FALSE 77 Controls execution of the Function Block INI6 INT o IN32 DINT 0 Internals Inputs Outputs Externals Note 1 The same name cannot be assigned to an input variable and output vari able If it is necessary to receive a value from an external variable change the variable inside the function block and then return the result to the ex ternal variable use an input output variable 2 When the instance is executed input values are passed from parameter
250. nds a text string from a serial port on a Serial Communications Unit SCU Application TXD SCU Send string SCU unit number Serial port Internal logic port Conditions The serial communications mode of the serial port must be set to no protocol communications 211 Function Descriptions Arguments and Return Values Variable name Send string Data type STRING Description Specifies the text string to send Appendix C SCU unit number INT UINT WORD Specifies the number of the Serial Communi cations Unit Serial port INT UINT WORD 1 Serial port 1 2 Serial port 2 Internal logic port Example Serial Communications Unit SCU CPU Unit Unit No 0 212 INT UINT WORD Get Scene Number command READ Barcode reader 0 to 7 Internal logic port number specified 164 F Automatic internal logic port allocation Variables BOOL P DoSendData i INT iProcess STRING Message BOOL P TXDU Exe BOOL P CominstEnable Variable to control send function Process number Send message TXDU Execution Flag AT 1519 05 Unit number 0 Use serial port 2 Communications Port Enable Flag AT A202 07 Use port 7 END IF CASE iProcess OF END IF END CASE 1 Create send text data Message READ iProcess 2 2 Execute send function if Communications Port Enable Flag and TXDU Execut
251. nemonics Cut Copy B Paste Delete lfi Function Block ladder generation 2 The following FB Variable Allocation Dialog Box will be displayed x Internals inputs Outputs Input Outputs Address Name Array Size AT Spe IO Com 0 00 Start 0 No w0 01 Setting No 1 00 Error No 0 01 Limit No D100 AutoGe No W0O 00 Set_Co No nn Run Nn Cancel The addresses of the operands used in the instructions in the selected pro gram circuits will be automatically allocated as listed below depending on application conditions Application outside selected Application inside selected program circuits 94 program circuits Not used See note Not used Used in input section Internal vari able Used in output section Internal vari able Used in input and output sections Internal variable Used Input variable Output vari able Input output vari able Procedures Section 3 2 Note Even if an address is allocated to I O it will be considered to be not used and converted to an internal variable if it is not used outside the selected circuits no matter where it is used inside the selected circuits Note Names will be automatically set for addresses without symbol names as fol lows AutoGen_address AT specifications will be automatically removed 3 Change the allocations to internal input output or input output variab
252. ng the present value is updated when all cyclic tasks are completed and also once every 80 ms When the timer completion flag is referenced from the user program the reflection of the status change may be delayed by one cycle depending on the access timing TIMHX TEN MS TIMER Function Operates a decrementing timer with units of 10 ms Equivalent to the TIMHX 551 ladder instruction When the execution condition goes from FALSE to TRUE the timer specified in the timer address is started and the present value is decremented by one starting from the value specified in the timer set value once every 10 ms The present value will continue timing down as long as the execution condition remains TRUE When the present value reaches 0 the timer completion flag of the specified timer address will be turned ON If the present value is not zero the timer completion flag is OFF While the execution condition is FALSE the timer set value is set in the present value of the timer address and the timer completion flag is OFF Application TIMHX Execution condition Timer address Timer set value Arguments Variable name Data type Description Execution condition Executes the timer operation while this execution condition is TRUE Timer address Specifies the timer address TO to T4095 variable to use Timer set value Specifies the delay time in units of 10 ms amp 0 to amp 65535 0 to FFFF Note e O
253. nge the value not the address itself to be passed to the function block for each instance use an input variable Program Instance for function block definition A The value itself is passed Changing the pass value to an input variable The following two restrictions apply An address can be set in an input parameter but an address itself cannot be passed to an input variable even if an address is set in the input parameter the value for the size of the input variable data type is passed to the function block Therefore when the first or last of multiple words is specified in the instruction operand within the function block an input vari able cannot be used for the operand Specify either to use internal vari ables with AT settings specify the first or last element in an input output array variable set the input parameter to the first address CX Program mer version 7 0 or higher specify the first or last element in an internal array variable or use an external variable as described in 2 5 4 Array Settings for Input Output Variables and Internal Variables Program An input variable cannot be used to specify the address of an operand that specifies Instance for function block definition A the first or last address of multiple words n For example the XFER BLOCK p e actual value is TRANSFER instruction cannot be used to f the size of the data type
254. nguage Configuration An ST language program is composed from statements There are two kinds of statements assignment and control Assignment statement This statement uses an equation to store a calcu lation result in a variable Control statement Includes statements such as selection statements and iteration statements For details on each kind of statement refer to 5 4 ST Language Configura tion B Statement Contents Statements are composed of the following elements Variables Refer to 5 4 2 Variables Constants Refer to 5 4 3 Inputting Constants Operators Refer to 5 4 4 Operators Functions Refer to 5 4 5 Standard Functions and 5 4 6 OMRON Expan sion Functions B Example of a Control Statement Statement e g CASE Configured using variables equations etc Variable Constant Equation Configured using operators and operands Statement e g IF Configured using variables equations etc Note In an ST program addresses are not input as actual I O memory addresses Variable names are used for all address inputs The addresses that use vari ables are set by the user For details on variable specifications and setting methods refer to the CX When NofRed or NofBlue exceeds 100 Variable COLOR value is 1 Increment variable NofRed by 1 2 Increment variable NofBlue by 1 Nei
255. ni cations Board SCB CPU Uni Get Scene Number command READ Barcode Reader BOOL P_SendEnableSCBPort1 Send Ready Flag AT A356 05 Serial port 1 used Variables BOOL P_DoSendData Variable to control send function 1 INT iProcess Process number i STRING Message Send message i i 1 I 1 I Use serial port number 1 Send data when P_DoSendData is ON and iProcess is 0 IF P_DoSendData TRUE AND iProcess 0 THEN iProcess 1 P_DoSendData FALSE END_IF Execute send processing according to process number CASE iProcess OF 1 Create send text data Message READ iProcess 2 2 Execute send function if sending is enabled IF P SendEnableSCBPort1 TRUE THEN TXD SCB Message 1 iProcess 3 END IF 3 Sending is finished if Send Ready Flag is ON IF P SendEnableSCBPort1 TRUE THEN iProcess 0 END IF END CASE Related Auxiliary Address Description Area Flag Port 1 Send Ready A356 05 ON when sending is enabled in no protocol mode Flag Port 2 Send Ready A356 13 ON when sending is enabled in no protocol mode Flag For further information and precautions on related Auxiliary Area flags refer to the section on TXD Serial Com munications Instruction in the CS CJ series Instruction Reference Manual TXD SCU Send String via Serial Port on Serial Communications Unit Function Se
256. nly when the Apply the same spec as T0 2047 to 12048 4095 option is selected in the PLC s property setting the present value is updated when all cyclic tasks are completed and also once every 80 ms When the timer PV is referenced from the user program the timer present values may be different between timer numbers 0 to 255 256 to 2047 and 2048 to 4095 due to different refresh timing 218 Function Descriptions Appendix C When the timer completion flag is referenced from the user program the reflection of the status change may be delayed by one cycle depending on the access timing TMHHX ONE MS TIMER Function Operates a decrementing timer with units of 1 ms Equivalent to the TMHHX 552 ladder instruction When the execution condition goes from FALSE to TRUE the timer specified in the timer address is started and the present value is decremented by one starting from the value specified in the timer set value once every 1 ms The present value will continue timing down as long as the execution condition remains TRUE When the present value reaches 0 the timer completion flag of the specified timer address will be turned ON If the present value is not zero the timer completion flag is OFF While the execution condition is FALSE the timer set value is set in the present value of the timer address and the timer completion flag is OFF Application TMHHX Execution condition Timer address Timer set value Ar
257. nputi Result 0 0000000 Measure2 REAL Measuremen _ Input2 0 0000000 Measures REAL Measuremen Inputs 2 755583e 1 26 REAL UpLimit 1414 REAL LoweLimit 1 Judge Judge A Right click and select Double click To Upper Layer the instance The ST program and variable monitoring areas are displayed Left side Right side ST program monitor window ST variable monitor window AvgYalue Input1 Input2 Input3 3 0 AvgValue 0 0000000 Float Input1 2 304856e 041 Float Inp IF AvgValue UpLimit AND AvgValue LowLimit THEN AvgValue 0000007 oat UpLimit 0 0000000 Float AvgVe Result TRUE Result 0 ELSE Result FALSE Result 0 END_IF The variable s PV is displayed in blue characters The ST program is displayed in the left side of the window called the ST pro gram monitor window The values of variables used in the ST program are displayed in the right side of the window called the ST variable monitor window At this point it is possible to monitor variable values change PVs force set or force reset bits and copy paste variables in the Watch Window These oper ations are described below 117 Procedures Section 3 2 Monitoring Variables Variable values are displayed in blue in the ST variable monitor window Note 1 With a CJ2 CPU Unit you cannot obtain the present value of the TIMER type variable argument of the TENTH MS TIMER or HUNDREDTH
258. ns Arguments and Return Values TEE Storage_location STRING Specifies the storage location for the received text string Number of characters INT UINT WORD Specifies the number of characters to receive 0 to 255 213 Function Descriptions Appendix C Example CPU Unit Message Value to read RS 232C port Barcode reader Variables 00000000000 d BOOL P DoRecvData Variable to control receive function STRING Message Variable to store received message i BOOL P EndRecvCPUPort Reception Completed Flag AT A392 06 Receive data when P DoRecvData is ON and reception has been completed IF P DoRecvData TRUE AND P EndRecvCPUPort TRUE THEN Get 16 characters RXD CPU Message 16 P DoRecvData FALSE END IF Related Auxiliary Description Area Flag RS 232C Port A392 06 ON when reception has been completed in no protocol mode Reception Com pleted Flag RS 232C Port A392 07 ON when a data overflow occurred during reception in no pro Reception Overflow tocol mode Flag RS 232C Port A393 Contains the number of characters received in no protocol Reception Counter mode For further information and precautions on related Auxiliary Area flags refer to the section on RXD Serial Com munications Instruction in the CS CJ series Instruction Reference Manual RXD SCB Receive String via Serial Port on Serial Communications Board Function R
259. ns 25 SECTION 2 Function Block Specifications 3 2 1 Function Block Specifications 0 2 0 2 cece eens 32 2 2 Data Types Supported in Function Blocks 0 00 cece eee eee 43 2 3 Instance Specifications el ue eles Pee ee Nee ee eae RR wee 44 2 4 Programming Restrictions llle n 53 2 5 Function Block Applications Guidelines eese 58 2 6 Precautions for Instructions with Operands Specifying the First or Last of Multiple Words 67 2 7 Instruction Support and Operand Restrictions 0 0 0 cece eee eee eee 70 2 8 CPU Unit Function Block Specifications 0 0 0c ec eee eee 71 2 9 Number of Function Block Program Steps and Instance Execution Time 78 SECTION 3 Creating Function Blocks I 3 21 Procedural Flows c er ee Ree Rr e Rer cere eo IR eer A e Rn 82 3 2 Brocedufes Meo Re E RR EO RI UU HORAS RAE P ERAN GEOP Se 84 ix TABLE OF CONTENTS Part 2 Structured Text ST SECTION 4 Introduction to Structured Text 133 4 ST Languages soi m doe erem Vani Vee Sade a NAR EROR RR E es 134 4 2 CX Programmer Specifications lese 135 SECTION 5 Structured Text ST Language Specifications 137 5 1 Structured Text Language Specifications 0 0 0 0 0c eee eee eee 138 5 2 Data Types Used in ST Programs 0 0 0 cece eee 139 5 3 Inputting ST Prosrams ss mae been poe
260. nu 2 In the Change PLC Window select a Device Type that supports function blocks These are listed in the following table Device CJ2H CPU68 67 66 65 64 68 EIP 67 EIP 66 EIP 65 EIP 64 EIP CJ2M CPU11 12 13 14 15 31 32 33 34 35 CS1G H CPU42H 43H 44H 45H CS1H H CPU63H 64H 65H 66H 67H CJ1G H CPU42H 43H 44H 45H CJ1H H CPU65H 66H 67H 64H R 65H R 66H R 67H R CJ1M CPU11 12 13 21 22 23 CP1H CP1H XA X Y CP1L CP1L M L NSJ G5D Used for the NSJ5 TQOL I G5D NSJ5 SQ0L1 G5D NSJ8 TVOLI G5D NSJ10 TVOLI G5D and NSJ12 TSOL G5D M3D Used for the NSJ5 TQO0LI M3D NSJ5 SQO0L M3D and NSJ8 TVOL M3D FQM1 CM FQM1 CM002 FQM1 MMA FQM1 MMA22 FQM1 MMP FQM1 MMP22 3 Press the Settings Button and select the CPU Type For details on other settings refer to the CX Programmer Operation Manual W446 3 2 2 Creating a New Function Block Definition 1 2 3 1 When a project is created a Function Blocks icon will appear in the project workspace as shown below 2 Untitled CX Programmer NewPLC1 NewProgram1 Section1 Diagram FA File Edit View Insert PLC Program Simulation Tools Window Help OS MA SR LBB MEBlerw ias4 a A Q iSi BIE Rik w 4ew Of 8S DARADE ARPA tee ees Ssi ax jo Program Name NewProgram1 NewProject c EB NewPLCi C31G H Offline Section Name Section 5 Symbols
261. number in square brackets after the vari able number For details on array settings refer to Variable Definitions in 2 1 2 Function Block Elements This is the initial value set in a variable before the instance is executed for the first time Afterwards the value may be changed as the instance is executed For example set a boolean BOOL variable bit to either 1 TRUE or 0 FALSE Set a WORD variable to a value between 0 and 65 535 between 0000 and FFFF hex If an initial value is not set the variable will be set to O For example a bool ean variable would be 0 FALSE and a WORD variable would be 0000 hex Select the Retain Option if you want a variable s data to be retained when the PLC is turned ON again and when the PLC starts operating Setting Procedure Select the Retain Option When a STRING variable is used the size required to store the text string can be set to between 1 and 255 characters 1 3 4 Variable Properties and Variable Usage 20 The following table shows which properties must be set can be set and can not be set based on the variable usage Property Variable usage Name Internals Must be set Inputs Must be set Outputs Must be set Must be set Data Type Must be set Must be set Must be set Must be set AT specified address Can be set Cannot be set Cannot be set Cannot be set Array specification Must be set Cannot be set
262. o the FB D200 D200 to D2009 can be us d in the rest of the program after being changed in the FB Contents can be changed in the FB Use an input output variable to pass large quantities of data to the FB only the fifst address is actually passed This address gt D200 Dat Data 0 indicates D200 is passed D201 WORD data Data 1 indicates D201 Array setting Etc D209 10 elements Function Block Applications Guidelines Section 2 5 External Variables Condition Flags Clock Pulses Auxiliary Area Bits Global Symbols in Program Internal Variables Internally Allocated Variables and Variables Requiring AT Settings Condition Flags e g Always ON Flag Equals Flag Clock Pulses e g 1 0 second clock pulse bit pre registered Auxiliary Area Bits e g First Cycle Flag and global symbols used in the program are all external variables defined by the system Variables that are not specified as Inputs Outputs In Out or Externals are Internals Internal variables include variables with internally allocated addresses and variables requiring addresses with AT settings e g I O alloca tion addresses addresses specially allocated for Special I O Units Variables requiring array settings include input output variables and internal variables For details on conditions requiring AT settings or array settings refer to 2 5 3 AT Settings for Internal Variables and 2 5 4 Array Sett
263. ock Ladder or Insert Function Blocks Structured Text from the pop up menu Define the Function Block Refer to 3 2 3 Defining Function Blocks Created by User for details n Registering Variables before Inputting the Ladder Program or ST Program 1 2 3 1 Register variables in the variable table 2 Create the ladder program or ST program n Registering Variables as Necessary while Inputting the Ladder Program or ST Program 1 2 3 1 Create the ladder program or ST program 2 Register a variable in the variable table whenever required Create an Instance from Refer to 3 2 4 Creating Instances from Function Block Definitions for details the Function Block Definition n Inserting Instances in the Ladder Section Window and then Inputting the Instance Name 1 2 3 1 Place the cursor at the location at which to create an instance i e a copy of the function block and press the F Key 2 Input the name of the instance 3 Select the function block definition to be copied Registering Instance Names in the Global Symbol Table and then Selecting the Instance Name when Inserting 1 2 3 1 Select Function Block as the data type for the variable in the global symbol table 2 Press the F Key in the Ladder Section Window 82 Procedural Flow Allocate External I O to the Function Block 1 2 3 Set the Function Block Memory Allocations Instance Areas 1 2 3 Section 3 1 3 Select the name of the instance th
264. ock definition names in parentheses The higher level is the calling block and the lower level is the called block The variable names data types addresses allocated internal addresses and comments are displayed for variables used in the active instance selected in the directory tree in the area on the left Also if there are array variables or timer counter variables they are displayed just below the instance 3 2 11 Checking Function Block Usage The following memory areas are used when you use function blocks n User Memory Area UM The object code for function blocks is stored in this area n FB Source Memory The function block source code is stored in this area so that the function block definitions and function block variable table can be displayed on the CX Pro grammer The CX Programmer can be used to check memory usage for function blocks The procedure is as follows 1 Select Memory View from the View Menu 109 Procedures Section 3 2 2 The Memory View Dialog Box will be displayed as shown below Example CJ2H CPU68 x UM FB Source Mem Used UM Used FB Used 1250 Steps 9908 Bytes 4 Free UM Free FB Free 409374 Steps 1693516 Bytes 2044 Total Total Max ft 410624 Steps 1703424 Bytes 2048 The Memory View Dialog Box varies with the PLC model For details refer to information on the memory view function in the CX Programmer Operation Manual Cat No W446
265. ock instance can be easily registered together in the Watch Window The FB variables registration Dialog Box can be displayed with any of the following methods and the variables can be registered together in that Dialog Box Right click the function block instance and select Register in Watch Window from the pop up menu Select the desired function block instance in the program or variable table and either copy paste or drag drop the instance into the Watch Window Move the cursor to an empty line in the Watch Window and select Register in Watch Window from the pop up menu The cross reference pop up function is supported in ladder programs within function blocks The ST language help program can be started from the pop up menu in ST Editor A function block s definitions can be opened just by double clicking the function block instance The cursor automatically moves down after a function block instance s parameter input is confirmed 30 SECTION 2 Function Block Specifications This section provides specifications for reference when using function blocks including specifications on function blocks instances and compatible PLCs as well as usage precautions and guidelines 2 1 Function Block Specifications 00 0 0 eee ee eee 32 2 1 1 Function Block Specifications 00 0 0 000 005 32 2 1 2 Function Block Elements 0 0 00000 33 2 2 Data Types Supported in Function
266. ock loses its flexibility This func tion should thus be used only when necessary Array Setting With internal variables and input output variables a variable can be defined as an array Only one dimensional arrays are supported by the CX Programmer With the array setting a large number of variables with the same properties can be used by registering just one variable An array set for an internal variable can have from 1 to 32 000 array ele ments An array set for an input output variable can have the number of elements given in the following table Data type Number of elements BOOL 2 048 2 048 INT UINT WORD Function Block Specifications Note Section 2 1 Data type Number of elements DINT UDINT DWORD 1 024 512 LINT ULINT LWORD An array can be set only for internal variables or input output variables Any data type except for STRING can be specified for an array variable as long as it is an internal variable When entering an array variable name in the algorithm of a function block definition enter the array index number in square brackets after the vari able name The following three methods can be used to specify the index In this case the array variable is a Directly with numbers for ladder or ST language programming Example a 2 With a variable for ladder or ST language programming Example a n where n is a variable Note INT DINT LINT UINT UDINT or
267. ode 0 Monitor Mode 0 4ms SYNC fungo 2 1 100 Nm 3 After editing the contents of the function block definition select FB online Edit Send Changes The following FB Online Edit Transfer Dialog Box will be displayed xi r Transfer mode Normal mode Transfer FB source Cancel Transfer takes time but upload can be done normally Quick mode Do not transfer FB Source Transfer can be done more quickly but it is then necessary to transfer the FB Source to the PLC later to enable program upload 4 Select one of the following transfer modes and click the Yes Button Normal Mode Quick Mode Refer to Transfer Modes on page 127 and Selecting a Transfer Mode on page 128 for details on the transfer modes 126 Procedures Transfer Modes Section 3 2 The new function block definition will be transferred to the buffer memory in the CPU Unit and the progress of the transfer will be displayed in a dialog box x Transfer FB programs to PLC NewPLC1 2 A G Transferring FB Program information Byte 374 of 2733 Downloading Don t power off PLC At this point the CPU Unit will still be operating with the previous function block definition The following dialog box will appear when the transfer has been complet ed CX Programmer v7 2 x gt JA Are you sure you want to reflect the changes to the program e At this point the CPU Unit will still be operat
268. of the Control Statement very easily Red wavy lines indicate ST syntax errors in a program No programming check is required Smart input on FB Ladder You can use the Smart Input Mode on the FB Ladder View in the same way as View on the Task Ladder View Ver 9 1 to 9 2 Upgrade Information Improvements on For the CJ2 CPU Units the available range of structures is expanded Structures Structures structure variables structure member variables and structure array variables are made available in ST Structured Text programs You can register and use structure variables as an external variable of FB Function Block ladder and ST Support of Structure Variables Comparison with Previous Versions Version 9 1 or earlier Version 9 2 or higher Global symbol table Ladder program Local symbol table Section view ST program Local symbol table ST editor 25 Version Upgrade Information SFC program Local symbol table Version 9 1 or earlier Section 1 6 Version 9 2 or higher SFC chart view Sub chart view Sub chart symbol table Action ladder view Action ST view Transition ladder view Transition ST view FB ladder Variables Internal variables Input variables Output variables Input Output variables External variables 26 Variables Internal variables Input variables Output variables Input Output variables
269. of these conditions is met variable X will be substituted with numeri cal value 0 IF A gt 0 THEN X 10 ELSIF B 1 THEN X 1 ELSIF B 2 THEN X 2 ELSE X 0 END IF CASE Statement BH Summary This statement executes an expression containing a selected integer that matches the value from an integer equation If the selected integer value is not the same either no expression or a specified expression is executed B Reserved Word CASE B Statement Syntax CASE integer equation OF integer equation value 1 expression 1 integer equation value 2 expression 2 integer equation value n expression n ELSE expression m END CASE 159 Statement Descriptions 160 Section 5 5 B Processing Flow Chart Expression m Same as selected value 1 Same as selected value 2 Same as selected value n Expression n Expression 1 B Usage Use the CASE statement to execute different operations depending on speci fied integer values B Description If the integer equation matches integer equation value n expression n is executed if the integer equation does not match any of integer equation value n expression m is executed E Precautions e CASE must be used together with END CASE The result of the integer equation must be in integer format INT DINT LINT UINT UDINT or ULINT Statements that can be used in expression are assignmen
270. offline After transferring the object code FB Source will be displayed in yellow at the bottom of the window to indicate that the source code has not yet been transferred This message will disappear when the source code is transferred 127 Procedures Selecting a Transfer Mode 128 Note Section 3 2 As a rule use Normal Mode to transfer function block definition changes If too much time is required increase the baud rate as much as possible before the transfer If too much time is still required and debugging efficiency is hin dered by continuous online editing use Quick Mode as an exception but be sure you understand the restrictions given in the following note Mode Restric tions in Quick Mode Guidelines for transfer times are given below for eight function block defini tions with a source code totaling 8 Kbytes for all 8 definitions and all instances Normal Mode Quick Mode At115 2kbps 5s 1s At 19 2 kbps 10s 2s Restrictions in Quick Mode A program containing function blocks cannot be uploaded correctly to the CX Programmer unless the source code for all function block definitions has been transferred to the CPU Unit Whenever using Quick Mode to transfer changes to function block definitions always select Program Transfer FB Source later to transfer the source code as well Even if the source code is not trans ferred it will be automatically transferred when you go offline unless the com puter or C
271. ollowing restrictions apply Values are passed from output variables to output parameters all at once after algorithm execution An input output variable can be used to implement the functionality of both input and output parameters Internal operation involves passing the address set for the parameter to the input output variable but the use of the input out put variable inside the function block is the same as that of other variables Program Section Instance of FB definition A Specify an address fdr the input parameter the address will be passed to the FB D100 D100 can be used in the rest of the program after being changed in the FB Use an input output variable to implement Contents can be changed in the FB both input and output variable functio while changing the value in the FB This address D100 HA a indicates D100 is passed Example WORD data type Input output variables can be set as arrays which is not possible for input variables and output variables If an input output array variable is used a range of addresses of the specified size starting from the address set for the input parameter can be used inside the FB Input output variables should thus be used when it s necessary to pass large quantities of data to a function block Program Section Instance of FB definition A Specify an address fdr the input parameter the address will be p ssed t
272. ompletion flag will be turned ON when the present value is incre mented from the set value back to 0 and it will be turned OFF again when the present value is incre mented from O to 1 When decrementing the counter completion flag will be turned ON when the present value is decre mented from O up to the set value and it will be turned OFF again when the present value is decre mented by one from the set value The present value will not be changed if the increment and decrement inputs both go from OFF to ON at the same time e When the reset input is ON the counter present value will become 0 and the count input is made invalid Application CNTRX Increment count Decrement count Reset input Counter address Counter set value Arguments Variable name Data type Description Increment count BOOL The counter present value is incremented every time the incre ment input is turned ON Decrement count BOOL The counter present value is decremented every time the dec rement input is turned ON Reset input BOOL When the reset input is ON the counter s PV and completion flag are reset Counter address COUNTER Specifies the counter address CO to C4095 variable to use Counter set value UINT Specifies the default value from which the counter value is decremented amp 0 to amp 65535 0 to amp FFFF TRSET TIMER RESET e Function Resets the specified timer Equivalent to the TRSET 549 ladder in
273. on function 1 Open the program containing the instance to be debugged 2 Select View Toolbars and select the Simulator Debug Option in the Tool bars Tab 3 Select Work Online Simulator from the CX Programmer s PLC Menu and transfer the program to the CX Simulator in the computer Note Steps 2 and 3 can be done in the opposite order n Step Execution Step Run Executes the program in step instruction increments When the instance is stopped this function can move to the first step instruction of the ladder or ST program in that instance The program in the instance can be executed with the Step Run or Continu ous Step Run method see note 121 Procedures Section 3 2 Note Set the duration of the step execution for Continuous Step Run operation by selecting the CX Programmers Tools Options command and setting the Continuous Step Interval on the PLCs Tab Page Step In Use the following procedure to begin step execution of a ladder ST program within an instance called Step Run operation 1 2 3 1 Pause execution of the instance See note 2 Click the Step In Icon or select Tools Simulation Mode Step In Example Step In from Instance to Internal Ladder Program Stopped here Click the Step In Icon to zem start Step In execution 2 StageA BoxSelect 2 WorkMoveControl_L icount BooL BOOL o l Program Name ava ptt R Sg
274. ondition gt lt Extraction_taget_data1 gt lt Extraction_target_data2 gt a Selects a speci fied data from a maximum of 30 data according to the extraction condition a MUX b c d The b 1 th data is stored in a MAX lt Target_data1 gt lt Target_data2 gt lt Target_data3 gt 2 Selects the maximum value from a maxi mum of 31 data a MAX b c d ws The maximum value of c d is stored in a MIN lt Target_data1 gt lt Target_data2 gt lt Target_data3 gt 2 Note extraction target data at the maximum Selects the min imum value from a maximum of 31 data a MIN b c d wa The minimum value of c d is stored in a 1 For MUX the arguments can be specified up to 31st argument i e 30 2 For MAX and MIN the target data can be specified from 1st argument up to 31st argument i e 31 target data at the maximum 151 ST Language Configuration 5 4 6 OMRON Expansion Functions Memory Card Functions Functions that write data to Memory Cards Section 5 4 Communications Functions Functions that send and received text strings Angle Conversion Functions Functions that convert between degrees and radians Timer Counter Functions Functions that execute various types of timers counters Memory Card Functions Function WRITE_TEXT lt Write_string gt lt Dir
275. or the same as the size specified in the other operands f the other operand specifying a size is a constant the CX Program mer will output an error when compiling e f the other operand specifying a size is a variable the CX Programmer will not output an error when compiling even if the size of the array variable is not the same as that specified by the other operand vari able A warning message however will be displayed In particular if the number of array elements is less than the size specified by the oth er operand e g the size of the instruction operand is 16 and the num ber of elements registered in the actual variable table is 10 the instruction will execute read write processing for the area that exceeds the number of elements For example read write processing will be ex ecuted for the 6 words following those for the number of elements reg istered in the actual variable table If these words are used for other instructions including internal variable allocations unexpected oper ation will occur which may result in serious accidents Check that the system will not be adversely affected if the size of the variable specified in the operand is less than the size in the operand definition before starting PLC operations Confirm safety at the destination node before transferring a program to another node or changing contents of the I O memory area Doing either of these without confirming safety may result in inj
276. ored in a ROL lt Rotation_target_dat a gt lt Number_of_bits gt Rotates a bit string to the left by n bits a ROL b c Result of rotating bit string b to the left by c bits is stored in a ROR Rotation target dat a Number of bits Data Control Functions 1st argument data type Function LIMIT Lower limit data Input data Upper limit data 150 2nd argument data type 3rd argument data type Rotates a bit string to the right by n bits Return value data type Description a ROR b c Result of rotating bit string bto the right by c bits is stored in a Example Controls the output data depending on whether the input data is within the range between the upper and lower limits a LIMIT b c d When c lt b bis stored in a When b lt c lt d c is stored in a When d c dis stored in a ST Language Configuration Data Selection Functions Function SEL lt Selection_condition gt lt Selection_target_data1 gt lt Selection_target_data2 gt ist argument data type 2nd argument data type 3rd argument data type Return value data type Description Selects one of two data according to the selection condi tion Section 5 4 Example a SEL b c d When bis FALSE cis stored in a When bis TRUE dis stored in a MUX lt Extraction_c
277. output and input output variables Select the variable right click and select Copy or Cut from the pop up menu and then select Paste 3 Variable names must also be input for variables specified with AT allocat ing actual address settings 4 The following text is used to indicate I O memory addresses in the PLC and thus cannot be input as variable names in the function block variable table A W H HR D DM E EM T TIM C or CNT followed by a numeric value Section 3 2 Procedures Creating the Algorithm Using a Ladder Program 1 2 3 1 Press the C Key and select aaa registered earlier from the pull down menu in the New Contact Dialog Box Da k gR amp Esm ocjatz Na s s np 3 t R EDEDEDED amp amp Q Siz ble s 3c uw 0o 2 eet amp ES eo du n ts tz t5 e ER Te e FG ra AAS dh 21 E BB 22 39 25 En B y o Rt 2 1x1 Name Data Type AT initial v Ret Comment SR NewProject EN BOOL FALSE Controls execution of the F 5 8 NewPLci ca1G H Offline e BOOL FALSE S Symbols 1 10 Table S Settings lt lt Memory ends cR SERES B Programs Internals Inputs Outputs Externals Ei gl NewProgramt 00 0 7 H 52 Symbols 0j Sectiont A H no H rtcoc E Function Blocks j AEF FunctionBlockt GF FunctionBlock2 Press the C Key and select aaa registered earlier from the pull down menu in the New Contact Dialog Box
278. ove or below a line within the list se lect Insert Variable Above or Below from the pop up menu Note The sheet where a variable is registered can also be switched when inserting a variable by setting the usage N Internals I In puts O Outputs E Externals P In Out The New Variable Dialog Box shown below will be displayed Name Input the name of the variable Data Type Select the data type Usage Select the variable type Initial Value Select the initial value of the variable at the start of oper ation Retain Select if the value of the variable is to be maintained when the power is turned ON or when the operating mode is changed from PROGRAM or MONITOR mode to RUN mode The value will be cleared at these times if Retain is not selected 87 Procedures Section 3 2 Note 88 Input the name of the function block variable The default data type is BOOL Change as required New ariable Type of variable to register i e the sheet Name Data Type ud Initial value Usage Initial Value Comment Select to maintain value for power interruptions Note a For user defined external variables the global symbol table can be browsed by registering the same variable name in the global symbol table b External variables defined by the system are registered in the ex ternal variable table in advance For example input aaa as the variable name and click the OK B
279. oven in actual operation into function blocks The application of addresses within the selected program cir cuits is analyzed both inside and outside the selection to allocate internal input output and input output variables as accurately as possible Program circuits that contain operands that are only symbols i e that are not addresses cannot be converted To create function blocks from program cir cuits that contain operands that are only symbols copy and past the program circuits into a function block definition Refer to Copying User Program Cir cuits and Pasting in Ladder Programming of Function Block Definitions on page 92 for details Procedures Program Circuits That Must Be Altered before Generating a Function Block Definition Program Circuits That Must Be Altered after Generating a Function Block Definition Section 3 2 In the following case the program circuits must be altered before a function block definition can be automatically generated Addresses Used Both as Bits and Words The bit and word addresses will be registered as different variables The pro gram can be altered in advance to avoid this Example MOV 021 for WO and SET for W0 02 0 00 E 1 4H MOV 021 Move bo Source word wo Destination 1 0 01 2 a SET Set 0 02 Bit l Here the instruction can be changed to specify a word instead of a bit As shown below WO is used both for MOV 021 and SETB
280. owing data types for the variable BOOL INT UINT DINT UDINT LINT ULINT WORD DWORD LWORD REAL LREAL TIMER COUNTER and STRING For details on variable data types refer to Variable Definitions in 2 1 2 Func tion Block Elements It is possible to set a variable to a particular I O memory address rather than having it allocated automatically by the system To specify a particular address the user can input the desired I O memory address in this property This property can be set for internal variables only Even if a specific address is set the variable name must still be used in the algorithm 19 Variables Array Settings Initial Value Retain Size Section 1 3 Refer to Variable Definitions in 2 1 2 Function Block Elements for details on AT settings and 2 5 3 AT Settings for Internal Variables for details on using AT settings A variable can be treated as a single array of data with the same properties To convert a variable to an array specify that it is an array and specify the maximum number of elements This property can be set for internal variables and input output variables only Only one dimensional arrays are supported by the CX Programmer Ver 5 0 and later versions Setting Procedure Click the Advanced Button select the Array Variable option and input the maximum number of elements When entering an array variable name in the algorithm in a function block definition enter the array index
281. owing procedure which allocates a program to a task can be per formed after the program has been created but always allocate the programs before transferring the user program to the PLC Use the following procedure to allocate a program to a task 1 2 3 1 Right click the inserted ST program item in the project workspace and se lect Properties from the pop up menu 4 Memory E A Programs 3 NewProgram1 00 3 Symbols 8 Section1 amp END Bg d Sa Sy Open F Function B E Partial Transfer gt amp Cut Copy 5j Paste Delete Rename lv Allow Docking Hide Float In Main Window ES Properties 179 Procedures Section 6 1 2 Click the General Tab in the displayed Program Properties Dialog box and select the task from the Task Type List To set a program name input the program name in the Name Text Box in this tab page Program Properties xj al General Protection Comments Name NewProgram2 Task type Unassigned Unassigned a v Cyclic Task 00 Startup Cyclic Task 02 Size Cyclic Task 03 Cyclic Task 04 Cyclic Task 05 3 Click the Close Button to close the Program Properties Dialog Box 4 Memory Ge Memory A Programs E A Programs El 3 NewProgram1 00 E 3 NewProgram1 00 3 Symbols 3 Symbols Kj Sectiont KS Section1 END i END Eee Unassigned gt Er 01 I Symbols 12 Symbols dT Function Blocks dT Function Blocks 4 Whe
282. p Not sup PV 16 bits ported ported Counter See note 2 Flag 1 bit Not sup Not sup PV 16 bits ported ported Text string data Variable Not sup OK ported User defined data type Variable Not sup OK ported Note 1 The TIMER data type is used to enter variables for timer numbers 0 to 4095 in the operands for TIMER instructions TIM TIMH etc When this variable is used in another instruction the Timer Completion Flag 1 bit or the timer present value 16 bits is specified depending on the in struction operand 2 The COUNTER data type is used to enter variables for counter numbers 0 to 4095 in the operands for COUNTER instructions CNT CNTR etc When this variable is used in another instruction the Counter Com pletion Flag 1 bit or the counter present value 16 bits is specified de pending on the instruction operand 39 Function Block Specifications Note Note 40 Section 2 1 AT Settings Allocation to Actual Addresses With internal variables it is possible to set the variable to a particular I O memory address rather than having it allocated automatically by the system To specify a particular address the user can input the desired I O memory address in this property It is still necessary to use variable name in program ming even if a particular address is specified 1 The AT property can be set for internal vari
283. passed to c Name Type AT Initial Value Retained 3 00 c 0 a BOOL c BOOL Usage Outputs The system automatically allocates the Properties addresses used by variables a b and c For Name e A nta Value Retained example when W100 to W120 is set as the system s non retained memory area bit addresses such as a W10000 b W10001 and c W10002 will be allocated Note Constants are not registered as variables Enter constants directly in instruc tion operands 18 Variables Section 1 3 Ladder programming language Enter hexadecimal numerical values after the and decimal values after the amp Structured text ST language Enter hexadecimal numerical values af ter 16 and enter decimal numerical values as is Exception Enter directly or indirectly specified addresses for Index Registers IRO to IR15 and Data Registers DRO to DR15 directly into the instruction operand 1 3 2 Variable Usage and Properties Variable Usage The following variable types usages are supported Internals Internal variables are used only within an instance They cannot be used pass data directly to or from I O parameters Inputs Input variables can input data from input parameters outside of the instance The default input variable is an EN Enable vari able which passes input condition data Outputs Output variables can output data to output parameters outside of the instance The default output varia
284. pecifies an angle in radians Return_value REAL LREAL Returns an angle in degrees Timer Counter Functions TIMX HUNDRED MS TIMER Function Operates a decrementing timer with units of 100 ms Equivalent to the TIMX 550 ladder instruction When the execution condition goes from FALSE to TRUE the timer specified in the timer address is started and the present value is decremented by one starting from the value specified in the timer set value once every 100 ms 217 Function Descriptions Appendix C The present value will continue timing down as long as the execution condition remains TRUE When the present value reaches 0 the timer completion flag of the specified timer address will be turned ON If the present value is not zero the timer completion flag is OFF While the execution condition is FALSE the timer set value is set in the present value of the timer address and the timer completion flag is OFF Application TIMX Execution condition Timer address Timer set value Arguments Variable name Data type Description Execution condition Executes the timer operation while this execution condition is TRUE Timer address Specifies the timer address TO to T4095 variable to use Timer set value Specifies the delay time in units of 100 ms amp 0 to amp 65535 0 to FFFF Note e Only when the Apply the same spec as T0 2047 to T2048 4095 option is selected in the PLC s property setti
285. quation is met B Description Condition If true execute expression_1 Condition If false execute expression 2 B Precautions IF must be used together with END_IF The condition must include a true or false equation for the evaluation result Example IF A gt 10 The condition can also be specified as a boolean variable only rather than an equation As a result the variable value is 1 ON True result 0 OFF False result Statements that can be used in expression 1 and expression 2 are assignment statements IF CASE FOR WHILE or REPEAT Example IF condition 1 THEN IF condition 2 THEN expression 1 ELSE expression 2 END IF END IF The processing flow diagram is as follows 156 Statement Descriptions IF Statement Multiple Conditions Section 5 5 ELSE corresponds to THEN immediately before it as shown in the above diagram Multiple statements can be executed within expression 1 and expression_2 Be sure to use a semicolon delimiter between multiple statements in an expression The ELSE statement can be omitted When ELSE is omitted no opera tion is executed if the result of the condition equation is false B Processing Flow Diagram Expression B Examples Example 1 If variable A gt 0 is true variable X will be substituted with numerical value 10 If A gt 0 is false variable X will be substituted with numerical value 0 IF A gt 0 THEN X
286. r inputting the variable name in the New Variable Dialog Box click the Advanced Button The Advanced Settings Dialog Box will be displayed Select AT Specified Address under AT Settings and input the desired ad dress el ternal hitial Value FA m Rea Comment Iv AT Cg ariete EX dress a Address Cheng B WOOO E AT d address The variable name is used to enter variables into the algorithm in the func tion block definition even when they have an address specified for the AT settings the same as for variables without a specified address For example if a variable named Restart has an address of A50100 spec ified for the AT settings Restart is specified for the instruction operand Array Settings An array can be specified to use the same data properties for more than one variable and manage the variables as a group Use the following procedure to set an array After inputting the variable name in the New Variable Dialog Box click the Advanced Button The Advanced Settings Dialog Box will be displayed 91 Procedures Using Structured Text Note Section 3 2 2 Select Array Variable in the Array Settings and input the maximum number of elements in the array Name Data Type Usage hhitial Value Comment Select Array Variable Input the number of elements When the name of an array variable is entered in the algorithm in the func tio
287. r to the following man uals CX Programmer CX Programmer Operation Manual W446 and CX Programmer Operation Manual SFC W469 CPU Unit The operation manuals for the CS series CJ series CP series and NSJ series Controllers CX Programmer Ver 9 Manuals Name Cat No Contents CXONE ALL IL IC V4 CXONE AL W447 Explains how to use the CX Programmer software s function CX Programmer Operation Manual this block and structured text functions For explanations of other Function Blocks Structured Text manual shared CX Programmer functions refer to the CX Program mer Operation Manual W446 CXONE ALL JL C V4 CXONE ALI D V4 W446 Provides information on how to use the CX Programmer for CX Programmer Operation Manu all functionality except for function blocks CXONE ALL L_IC V4 CXONE AL D V4 W469 Explains how to use the SFC programming functions For CX Programmer Operation Manual SFC explanations of other shared CX Programmer functions refer to the CX Programmer Operation Manual W446 CX Net Operation Manual Information on setting up networks such as setting data links routing tables and unit settings CXONE ALI J C VA4 CXONE AL Describes the operating procedures for the CX Integrator CX Integrator Operation Manual xi CJ2H CJ2M CS1 H CJ1 H and CJ1M CPU Uni
288. ramt Be NewProject NewPLCI CJ1M Offline Section Name Section FR Symbols GT 10 Table sample S settings e Memory Operation module 3 Programs 0 00 BOOL BOOL i gl NewPragramt 00 Hii ENO 52 Symbols IL woo Boo ND Di0o amp END StartFlag average averaga value TF Function Blocks GF Average calculation BF Condition check pmo nne EF Operation module bo leant Input Thickne jss target 1 D1 lant Input Thickne ss target 2 D2 nT Input Thickne ss target 3 wooo BOOL Execution Ena FB Instance Viewer oe egi xil Address or Value Comment Data Type Address 4 PLC Name Name Address Data Type Format FB Usage Valu E A Target 1 FB Operation module BOOL H538 04 NewPLC1 sample H538 06 BOOL On Off Co Internal 1 38F Condition 1 Condition check Condition01 FB Condition check NewPLC1 sample H551 INT Signed Deci Internal AIT sample Operation_module ExecutionFlag BOOL HS38 05 NewPLCI sample HS38 04 BOOL On Off Co Internal fF Conditioni Condition check Execution Enable Flag BOOL H538 06 A Ta rea Fo Average SUP Execution Hea BOOL 1590 07 Note Variables caribe ii Tine 1 A Ed registered by dragging and ickness_2 A Thickness 3 INT H550 dropping them in the Watch intemals Kinel ISI Window For Help press F1 7 z MM M When nesting this area shows the nesting level relationship between instances function bl
289. rati NSJ12 TSCIL B G5D esigning the system configuration NSJ5 TQUIL B M3D Installation and wiring inm EMD I O memory allocations NSJW ETN 1 Troubleshooting and maintenance NSJW CLK 1 V1 Use this manual in combination with the following manuals SYS NSJW IC101 MAC CS Series Operation Manual W339 SYSMAC CJ Series Operation Manual W393 SYSMAC CS CJ Series Programming Manual W394 and NS V1 V2 Series Setup Manual V083 xiii FQM 1 Series Manuals Unit Version 3 0 or Later Refer to the following manuals for specifications and handling methods not given in this manual for FQM1 Series unit version 3 0 FQM1 CM002 MMP22 MMA22 Models Name Description FQM1 CM002 FQM1 Series Provides the following information about the FQM1 series Modules FQM1 MMP22 Operation Manual unit version 3 0 FQM1 MMA22 Overview and features Designing the system configuration Installation and wiring I O memory allocations Troubleshooting and maintenance FQM1 CM002 FQM 1 Series Individually describes the instructions used to program the FQM1 FQM1 MMP22 Instructions Use this manual in combination with the FQM1 Series FQM1 MMA22 Reference Manual Operation Manual 0012 when programming CP series PLC Unit Manuals Refer to the following manuals for specifications and handling methods not given in this manual for CP series CPU Units Models Name Description CP1H X SYSMAC CP Series Provides the following information
290. rd data type INT 2 Total instruction processing time in function block definition section 10 us Execution time for 1 instance 3 3 us 8 2 x 0 19 us 10 us 14 25 us Note The execution time is increased according to the number of multiple instances when the same function block definition has been copied to multiple locations SECTION 3 Creating Function Blocks This section describes the procedures for creating function blocks on the CX Programmer 3 1 Procedural Flow neige RII BS Ses heuertb V ERE RR 82 3 2 Procedures oor RIED E eR Wd eI de es 84 3 221 Creating a Project oet eoe EDU RE este ada GERA 84 3 2 2 Creating a New Function Block Definition 84 3 2 3 Defining Function Blocks Created by User 87 3 2 4 Creating Instances from Function Block Definitions 99 3 2 5 Setting Function Block Parameters Using the Enter Key 101 3 2 6 Setting the FB Instance Areas esee 104 3 2 7 Checking Internal Address Allocations for Variables 106 3 2 8 Copying and Editing Function Block Definitions 108 3 2 9 Checking the Source Function Block Definition from an Instance 108 3 2 10 Checking Instance Information such as Nesting Levels 108 3 2 11 Checking Function Block Usage 000000 109 3 2 12 Compiling Function Block Definitions Checking Program 110 3 2 13 Printing Function Block Definition
291. rds X Ego 99000 to EO 32767 13 banks 7 banks 3 banks EO 32767 3 banks EO 00000 EO 00000 EO 00000 EO 00000 to to to to EC 32767 EG 32767 E2 32767 E2 32767 Function Maxi 1 024 1 024 1 024 1 024 128 1 024 1 024 128 128 blocks mum number of definitions Maxi 2 048 2 048 2 048 2 048 256 2 048 2 048 256 256 mum number of instances Com Total for 2 048 2 048 1 280 1 280 1 280 1 280 704 704 704 ment all files Memory Kbytes Unit ver 4 0 or later Inside Function 1 664 1 664 1 024 512 512 1 024 512 512 512 com block pro ment gram memory memory ver 3 0 Kbytes or later Com 128 128 64 64 64 64 64 64 64 ment files Kbytes Program 128 128 64 64 64 64 64 64 64 index files Kbytes Variable 128 128 128 64 64 128 64 64 64 tables Kbytes 72 CPU Unit Function Block Specifications Section 2 8 CJ1 H CPU Units Item Specification CJ1H CPU67H CPU67H R CJ1H CPU66H CPU66H R CJ1H CPU65H CPU65H R CJ1G CPU44H CJ1G CPU42H I O points 2 560 Program capacity steps 250K 120K 60K Data memory 32K words Extended Data Memory 32K words X13 banks EO 00000 to EC 32767 32K words X 7 banks EO 00000 to E6 32767 32K words X 3 banks EO 00000 to E2 32767 32K words X 1 bank EO 00000 to E2 32767 32K words X 3 banks EO 00000 to E2 32767 32K words X 1 bank EO 00000 to EO 3276
292. red As a rule use Standard Mode to transfer ST program changes unless online editing is performed frequently If too much time is required increase the baud rate as much as possible before the transfer If too much time is still required and debugging efficiency is hindered by continuous online editing use Quick Mode as an exception but be sure you understand the restrictions given in the following note Mode Restrictions in Quick Mode Restrictions in Quick Mode ST Source Code Not Transferred When the ST program s ST source code is not being transferred the CX Pro grammer cannot upload the program correctly the next time Consequently after the ST program s online editing changes have been trans ferred in Quick Mode it may be impossible to upload the program later see note if the computer or CX Programmer crashes before the source code can be transferred It may be still be possible to transfer the source code with the following proce dure even if the above problem occurs 187 Procedures Transferring Source Code from a Backup Project 1 2 3 1 Manually Transferring the ST Source Code 1 2 3 1 Section 6 1 Start the CX Programmer The following dialog box will be displayed if a project s ST source code was being transferred in Quick Mode and the transfer failed CX Programmer v7 2 X FB SFC ST Source in the project D program SFC 4verage Value Measurement NewPLCI FBK t may not be transfer
293. red correctly s Go online and check the status of the PLC UN Click the OK Button the CX Programmer will start the backup project from the previous Quick Mode transfer Connect online with the PLC that was the destination of the Quick Mode transfer The following dialog box will be displayed CX Programmer v7 2 X Check if the backed up FB SFC ST Source can be transferred e IF No is selected the program cannot be transferred From the PLC correctly after going online 9 Click the Yes Button If the PLC is not in RUN mode the program will be compared between the project and PLC and the ST source code will be transferred if the pro grams match If the PLC is in RUN mode switch the operating mode to another mode and execute the ST source code transfer from the CX Programmer menu Start the CX Programmer and open the project file with the ST source code to be transferred Connect online with the PLC that was the destination of the Quick Mode transfer The flashing yellow message Src Fail will be displayed in the CX Programmers status bar Select Program Online Edit Transfer SFC ST Source to PLC The ST source code transfer dialog box will be displayed Click the OK Button The ST source code that was automatically backed up in the computer will be compared with the object code in the actual PLC and the ST source code can be transferred if the code matches Note Before transferring a program
294. rnal variables Externals Number of variables used in a function block not including internal vari ables external variables EN and ENO Maximum number of variables per function block definition Input output variables 16 max Input variables input output variables 64 max Output variables input output variables 64 max Automatic allocation The allocation range can be set by the user Allocation of addresses used by variables Actual address specification Supported Array specifications Supported one dimensional arrays only and only for internal variables and input output variables Language Function blocks can be created in ladder programming language or structured text ST see note Creating instances Number of instances CJ2H CPU Units CJ2H CPU6 CJ2M CPU Units e CJ2M CPUL 1 LJ2 L 13 256 max per CPU Unit e CJ2M CPUL14 L15 2 048 max per CPU Unit CS1 H CJ1 H CPU Units Suffix CPU44H 45H 64H 65H 66H 67H 64H R 65H R 66H R 67H R 2 048 max per CPU Unit Suffix CPUA2H A3H 63H 256 max per CPU Unit CJ1M CPU Units e CJ1M CPU1 1 12 13 21 22 23 256 max per CPU Unit CP1H CPU Units All models 256 max per CPU Unit CP1L CPU Units CP1L M L 256 max per CPU Unit NSJ Controllers SJLI G5D 2 048 max per Controller NSJL M3D 256 max per Controller FQM 1 Flexible Motion Controllers e FQM1 CM0O02 MMA22 MMP22 256 max per Controller
295. rogramming language default or the 3 for ST language This icon contains the definitions for the newly created insert ed function block 3 Whenever a function block definition is created the name FunctionBlock will be assigned automatically where LI is a serial number These names can be changed All names must contain no more than 64 characters Using OMRON FB Library Files Use the following procedure to insert OMRON FB Library files cxf 1 Select Function Blocks in the project workspace right click and select Insert Function Blocks Library File from the pop up menu Or select Function Block Library File from the Insert Menu 2 The following Select Function Block Library File Dialog Box will be dis played Look in Sy CLK emet EB CLK CheckNode32 10 cxf js _CLK_Link_SetAutoMode4 10 cxf js CLK CheckNode64 10 cxf js CLK Link SetInitialParaOpt 10 cxf CI je CLK Link SetInitialParaWire 10 cxf a CLK Link SetManualMade 10 cxf a CLK Link StopDatalink 10 cxf js _CLK_Link_SetAutoMode3 10 cxf File name CLK Link RunDatalink 10 c f Files of type Function Block Library Files cxf m Cancel Note To specify the default folder file location in the Function Block Li brary File Dialog Box select Tools Options click the General Tab and the select the default file in the OMRON FB library storage location field 3 Specify the folder in which
296. rogramming to be easily converted to function blocks istered Online Function Block Editing Version 6 1 Version 7 0 Function block definitions i e the algorithms The algorithms and variables tables for function blocks can be changed and variable tables cannot be changed online while the PLC is operation See note This enables debugging and when the PLC is running Only I O parameters changing function block definitions in systems that cannot be stopped for function block instances can be changed such as systems that operate 24 hours a day Operation Right click the function block definition in the Work Space and select FB Online Edit Begin from the pop up menu Note Function block instances cannot be added Note This function cannot be used for simulations on CX Simulator 28 Version Upgrade Information Section 1 6 Support for STRING Data Type and Processing Functions in Standard Text Programs Version 6 1 Version 7 0 The STRING data type text cannot be used in ST programming See note There are no text processing functions sup ported for ST programming Even in a ladder program the user has to con sider the ASCII code and code size of text for display messages and no protocol communica tions see note when executing string process ing instructions data conversion instructions and serial communications instructions Note The user can use the PLC memory func tion of the CX
297. rom FB OUT2 The EN and ENO data cannot be entered as an argument or return value Specification method 1 cannot be used together with specification method B in the same function block call statement B Example 2 In the following example function block 1 calls function block 2 which calcu late the average value by calling a function block from within a function block The data1 data2 and data3 values are FB1 ST S1 passed to input1 input2 and input3 Program Instance_FB1 FB1 3 Average FB inputi data1 input2 data2 ___ input3 data3 average gt AVG T FB2 ST mei e average input input2 input3 3 The average value is returned in AVG Average FB is an instance name with data type FUNCTION BLOCK Function Block 1 Variable Table Variable type Variable name Data type Input variable EN BOOL Input variable data1 INT Passed to input Passage to from FB2 Input variable data2 INT Passed to input2 Input variable data3 INT Passed to input3 Input variable bCheck BOOL Output variable ENO BOOL Output variable AVG INT Received from average Internal variable 172 Average FB FUNCTION BLOCK Called function block definition Function block 2 ST language Program Example Section 5 6 e ST language Algorithm If bCheck is true function block 2 is called
298. rotection on an individual Protection on an function block definition Individual Function Block 1 2 3 1 In the project workspace select the function block definition right click and select Properties from the pop up menu Alternately select Proper ties from the View Menu 2 The Function Block Properties Dialog Box will be displayed Click the Pro tection Tab and click the Release Button 3 The Function Block Protection Release Dialog Box will be displayed Input the password in the Password Field and click the Release Button 4 Ifthe password was correct the protection will be cleared and the function block definition s icon will change to a normal icon in the project work space Clearing Password Use the following procedure to clear the password protection on two or more Protection on Multiple function block definitions at the same time Function Blocks 1 2 3 1 Select Function Blocks in the project workspace right click and select Function Block Protection Release from the pop up menu 2 The Function Block Protection Collective Release Dialog Box will be dis played Select the names of the function blocks that you want to be unpro tected input the password and click the Release Button 3 Ifthe password input matches the selected function blocks passwords the protection will be cleared for all of the function block definitions at once 3 2 15 Comparing Function Blocks It is possible to compare th
299. s Instruction Support Refer to the instruction help of the CX Programmer or the command reference manual of your PLC for whether or not each instruction of the CS CJ NSJ series CPU Units CP series CPU Units and FQM1 series Units can be used Restrictions on Operands When you use any instruction that has operands specifying the first or last of multiple words be sure to read the Section 2 6 Precautions for Instruc tions with Operands Specifying the First or Last of Multiple Words before using the instruction When specifying the first or last word of multiple words in an instruction operand input parameters cannot be used to pass data to or from vari ables Use an AT setting or an input output or internal variable array set ting When you use an input output variable array setting set the first word for the input parameter When you use an internal variable array setting prepare an array vari able with the required number of elements set the array data in the function block definition and then specify the first or last element in the array variable for the operand Use an AT setting variable for the operands for which an I O memory address on a remote node in the network must be specified 70 CPU Unit Function Block Specifications 2 8 CPU Unit Function Block Specifications The specifications of the functions blocks used in CS CJ series and CP series CPU Units are given in the following tables Refer to the other
300. s to input variables before the algorithm is processed Consequently values cannot be read from parameters to input variables within the algorithm If it is necessary to read a value within the execution cycle of the algorithm do not pass the value from a parameter Assign the value to an internal variable and use an AT setting specified addresses Alternatively refer ence the global symbol as external variables Initial Value Initial values can be set for input variables but the value of the input parame ter will be enabled the input parameter value will be set when the parameter for input variable EN goes ON and the instance is executed Note The input parameter setting cannot be omitted when using the CX Programmer EN Enable Variable When an input variable is created the default input variable is the EN variable The instance will be executed when the parameter for input variable EN is ON n Output Variables Output variables pass return values from the instance to external applications The output variables are displayed on the right side of the instance 35 Section 2 1 Function Block Specifications 36 Note After the instance is executed the value of the output variable is passed to the specified parameter POA 1 0 I 4 EN Eno IL Do__ py cry 7 The value of the output variable CV is passed to the parameter specified as the output destination which is D100 in this case
301. sed A In the following example the contents of the FOR statement is executed 101 times The loop processing ends when the value of i is equal to 101 FOR i 0 TO 100 BY 1 DO a a l1 END FOR Q What occurs when the array subscript is exceeded A For the array variable INT 10 with 10 elements an error will not be detected for the following type of statement Operation will be unstable when this statement is executed 1 15 INT i 10 Q Are the variables in the structured text editor automatically registered in the variable tables A No Register the variables in the variable table before using them Q Can ladder programming instructions be called directly A No 175 Restrictions Section 5 7 176 SECTION 6 Creating ST Programs This section explains how to create ST programs 6 I Procedures cs s aee a Rp REFR GGR GA eee le REA T Ed 178 6 1 1 CreatingaProject llle 178 6 1 2 Creating a New ST Program 0 00 00 eee 178 6 1 3 Allocating the ST Program to a Task 0004 179 6 1 4 Creating the ST Program 0 00 0 000 2 eee 180 6 1 5 Compiling the ST Program Checking Program 184 6 1 6 Downloading Uploading Programs to the Actual CPU Unit 184 6 1 7 Comparing ST Programs 0 0 00 eee 184 6 1 8 Monitoring and Debugging the ST Program 185 6 1 9 Online Editing of ST Programs 0004
302. sed as the operand of an instruction in the function block when the operand specifies the first or last of multiple words With CX Programmer version 7 0 use xxii Application Precautions 4 an input output variable specified as an array variable with the first address set for the input parameter and specify the first or last element of the array variable or with any version of CX Programmer use an internal variable with an AT setting Alternatively specify the first or last element in an internal variable specified as an array variable Values are passed in a batch from the input parameters to the input vari ables or input output variables before algorithm execution not at the same time as the instructions in the algorithm are executed Therefore to pass the value from a parameter to an input variable or input output vari able when an instruction in the function block algorithm is executed use an internal variable or external variable instead of an input variable or input output variable The same applies to the timing for writing values to the parameters from output variables Always use internal variables with AT settings in the following cases The addresses allocated to Basic I O Units Special I O Units and CPU Bus Units cannot be registered to global symbols and these vari ables cannot be specified as external variables e g the data set for global variables may not be stable Use internal variables when Auxi
303. sion BY increment equation can be omitted When omitted BY is taken as 1 Variables with integer data types INT DINT LINT UINT UDINT or ULINT or equations that return integer values can be specified in the initial value final value equation and increment equation Example 1 The iteration is performed when the iteration variable n 0 to 50 in increments of 5 and the array variable SP n is substituted with 100 FOR n 0 TO 50 BY 5 DO SP n 100 END FOR Example 2 The total value of elements DATA 1 to DATA 50 of array vari able DATA n is calculated and substituted for the variable SUM FOR n 0 TO 50 BY 1 DO SUM SUM DATA n END FOR Example 3 The maximum and minimum values from elements DATA 1 to DATA 50 of array variable DATA n are detected The maximum value is substituted for variable MAX and the minimum value is substituted for vari able MIN The value for DATA n is between 0 and 1000 MAX 20 MIN 1000 FOR n 1 TO 50 BY 1 DO IF DATA n gt MAX THEN MAX DATA n END IF IF DATA n MIN THEN MIN DATA n END IF END FOR BH Summary This statement is used to execute a specified expression repeatedly for as long as a specified condition is true 163 Statement Descriptions Section 5 5 B Reserved Words WHILE DO END WHILE B Statement Syntax WHILE condition DO expression END WHILE B Processing Flow Chart Iteration Expression B Usage Use t
304. sks Other programming languages can be combined freely in a single user program With this capability numerical calculations can be written as ST programs and other processing can be written as ladder or SFC programs Note Structured text is supported only by CS CJ series CPU Units with unit version 4 0 or later It is not supported by CP series CPU Units Comparison of Function Block Definitions and ST Programs Version 7 0 Version 7 2 Function block definitions could not be com Function block definitions can be compared With this capability it is pared easy to check for differences in function block definitions in programs ST programs can also be compared Version 6 1 to 7 0 Upgrade Information Convenient Functions to Convert Ladder Diagrams to Function Blocks Version 6 1 Version 7 0 Ladder programming can be copied into a func One or more program sections can be selected from the program and tion block definition to create a function block then Function Block ladder generation selected from the menu to The symbols and addresses in the ladder pro automatically create a function block definition and automatically allo gramming however have to be checked and cate variables according to symbols and addresses in the program sec input variables internal variables and output tions Allocations can later be changed as required This enables variables have to be identified and manually reg legacy p
305. ssing large amounts of data to function blocks using the input parameters Version 6 0 to 6 1 Upgrade Information Support for NSJ series NSJ Controllers Support for FQM1 Unit Version 3 0 The PLC model device type can be set to NSJ and the CPU type can be set to the G5D The new models of the FQM1 Flexible Motion Controller are now supported i e the FQM1 CM002 Coordinator Module and the FQM1 MMA22 MMP22 Motion Control Modules Instance ST Ladder Program Simulation Function Previous version Ver 6 0 New version Ver 6 1 The CX Simulator could be used to execute a ladder program step Step Run execute steps continuously Continuous Step Run execute a single cycle Scan Run and set I O break point conditions Improved Function Block Functions The Step Run Continuous Step Run Scan Run and Set Clear Break Point functions can be executed as CX Programmer functions All of these functions can be used with ladder programs and ladder ST programs in function blocks Note The CX Simulator Ver 1 6 sold separately must be installed in order to use these functions Note l O break conditions cannot be set Monitoring ST Programs in Function Blocks Previous version Ver 6 0 New version Ver 6 1 The operation of ST programs within function block instances could not be monitored while monitoring the program online It was possible to check the contents of a func tion block d
306. struction Application TRSET Execution condition Timer address Arguments Data type Execution condition The timer is reset when the execution condition is turned ON Timer address Specifies the timer address TO to T4095 variable to use 222 Index A addresses allocation areas 44 checking internal allocations 106 setting allocation areas 104 algorithm creating 89 applications precautions xxi array settings 20 40 61 91 AT settings 19 40 91 restrictions 53 automatically generating function block definitions 93 C compiling 110 D data types 19 39 determining 58 debugging function blocks 116 differentiation restrictions 53 E errors function blocks 57 external variables 39 externals 19 F features 4 files function block definitions 114 library 8 project text files 8 function block definitions 13 checking for an instance 108 compiling 110 creating 84 saving to files 114 function blocks advantages 12 application guidelines 58 creating 23 debugging 116 defining 87 elements 33 errors 57 monitoring 116 operating specifications 51 outline 11 restrictions 53 reusing 24 setting parameters 101 specifications 6 7 32 structure 13 functions 4 function blocks 6 7 restrictions 5 G global symbol table 18 IEC 61131 3 4 8 input variables 35 input output variables 37 inputs 19 instance areas
307. t Manuals Name Contents SYSMAC CJ Series CJ2H CPU6L EIP CJ2H CPU6 CJ2M CPU1L1 CU2M CPU3 Programmable Controllers Hardware User s Manual Provides an outline of and describes the design installation maintenance and other basic operations for the CJ series CJ2 CPU Units The following information is included Overview and features System configuration Installation and wiring Troubleshooting Use this manual together with the W473 SYSMAC CJ Series CJ2H CPU6L EIP CJ2H CPU6 CJ2M CPU1L1 CU2M CPU3 Programmable Controllers Software User s Manual Describes programming and other methods to use the func tions of the CJ2 CPU Units The following information is included CPU Unit operation Internal memory areas Programming Tasks CPU Unit built in functions Use this manual together with the W472 SYSMAC CS CJ Series CS1G H CPULT EV1 CS1G H CPU CS1D CPULIUH CS1D CPU CJ2H CPU6LI EIP CJ2H CPU6 CJ2M CPU1L CJ2M CPU3 CJ1H CPUCICH R S CJ1G CPUL TL CJ1G H CPU CJ1G CPULILIP CJ1M CPU SYSMAC One NSJ Series NSJLI B G5D NSJLIH B M3D Programmable Controllers Instructions Reference Manual
308. t state ments IF CASE FOR WHILE or REPEAT e Multiple statements can be executed in expression Be sure to use a semicolon delimiter between multiple statements in an expression Variables in integer format INT DINT LINT UINT UDINT or ULINT or equations that return integer values can be specified in the integer equation e When OR logic is used for multiple integers in the integer equation value n separate the numerical value using a comma delimiter To specify a sequence of integers use two periods as delim iters between the first and last integers Statement Descriptions Section 5 5 B Examples Example 1 If variable A is 1 variable X is substituted with numerical value 1 If variable A is 2 variable X is substituted with numerical value 2 If variable A is 3 variable X is substituted with numerical value 3 If neither of these cases matches variable Y will be substituted with O CASE A OF Lh A 2 X 22 3 X 23 ELSE Y 0 END CASE Example 2 If variable A is 1 variable X is substituted with numerical value 1 If variable A is 2 or 5 variable X is substituted with numerical value 2 If vari able A is a value between 6 and 10 variable X is substituted with numerical value 3 If variable A is 11 12 or a value between 15 and 20 variable X is substituted with numerical value 4 If neither of these cases matches variable Y will be substituted with O CASE A OF IX s
309. tables list menus related to function blocks in CX Programmer Ver 5 0 and later versions For details on all menus refer to the CX Program mer Operation Manual W446 Introducing the Function Blocks Section 1 1 Main Menu Submenu Function Block Load Function Block from File Shortcut Function Reads the saved function block library files cxf Save Function Block to File Saves the created function block definitions to a file func tion block library file cxf Update Function Block When a function block definition s input variables output variables or input output variables have been changed after the instance was created an error will be indicated by displaying the instance s left bus bar in red This command updates the instance with the new information and clears the error To Lower Layer Jumps to the function block definition for the selected instance Function Block ladder generation Generates a ladder programmed function block for the selected program section while automatically determining address application conditions Monitor FB Instance When monitoring the program online monitors ST variable status as well as I O bit and word status I O bit monitor of the ladder diagram in the instance Supported by CX Programmer Ver 6 1 and later only To Lower Layer Displays on the right side the contents of the function block definition of the selected
310. te Source Instruction Operand Address and I O Comment 92 A single circuit or multiple circuits in the user program can be copied and pasted in the ladder programming of function block definitions This operation however is subject to the following restrictions Addresses are not registered in the function block definition variable tables After pasting the addresses will be displayed in the operand in red Double click on the instruction and input the variable name into the operand Index Registers IR and Data Registers DR however do not require modifi cation after pasting and function in the operand as is Automatically generate symbol name Option Selected in Symbols Tab under Options in Tools Menu The user program symbol names in the global symbol table only will be gen erated automatically as AutoGen_ Address if the option is deselected the symbol names will be removed Procedures Section 3 2 Example 1 For address 100 01 the symbol name will be displayed as AutoGen_100_01 Example 2 For address DO the symbol name will be displayed as AutoGen DO If circuits in the user program are copied and pasted into the function block definition program as is the symbols will be registered automatically in the function block definition symbol table at the same time as copying the cir cuits as the symbol name AutoGen Adaress and I O comments as Com ment This function enables programmed circuits to be eas
311. tem on the dialog and click the OK button Entry Assistance Function 1 Entering a control statement on ST Editor You can easily enter a control statement frame in the following two ways 1 2 3 1 Select Insert Code Snippets from the pop up menu and select one from the following list Insert code snippets ac i 3 FOR END FOR A IF END IF 3 REPEAT END REPEAT 3 WHILE END WHILE 2 Select and enter the first element of the control statement from the key word list and press the Tab key Keyword Control Statement Frame IF EXE THEN ELSE END IF FOR expression TO expression2 BY expression3 DO END FOR CASE Essi OF ELSE END CASE REPEAT REPEAT UNTIL EEA END REPEAT WHILE Ganee DO END WHILE Note For each expression and variable you need to enter the execution condition of the control statement 183 Procedures Section 6 1 2 The content of the keyword selected on the list is displayed by a tool tip You can select the most appropriate item while confirming the operation of the keyword function and the comments for the variable 3 The indent of each line can be increased and decreased by a menu item or a tool button 4 Whether to handle the selected line as a comment or a part of the program can be switched by a menu item or a tool button 6 1 5 Compiling the ST Program Checking Program The ST program can be compiled to perform a progr
312. the CX Programmer normally compiles the program code ST source code into object code which can be executed in the CPU Unit and then transfers both the source code and object code to the CPU Unit The CPU Unit stores the programs ST source code and object code in user memory and built in flash memory Only when both the source code and object code exist in the CPU Unit can the CX Programmer transfer and restore the program for the upload operation Restrictions in Online Editing of ST Programs The following restrictions apply to online editing of ST programs 188 Procedures Section 6 1 For CJ2 series CPU Units there is no restriction on the number of steps that can be added to or deleted from a function block definition during one online editing operation Online editing is not possible for ST programs that exceed 4 Ksteps except for CJ2 series CPU Units e A maximum of 0 5 Ksteps can be added to or deleted from an ST program during one online editing operation except for CJ2 series CPU Units After performing online editing do not turn OFF the power supply to the PLC until the CPU Unit has finished backing up data to the built in flash memory i e until the BKUP indicator goes OFF If the power supply is turned OFF before the data is backed up the data will not be backed up and the program will return to the status it had before online editing was performed 189 Procedures Section 6 1 190 Classification
313. the OMRON FB Library file is located select the library file and click the Open Button The library file will be inserted as a function block definition after the IF 85 Procedures Section 3 2 Function Block Definitions Creating Function Block One of the following windows will be displayed when the newly created Func Definitions tion Block 1 icon is double clicked or if it is right clicked and Open is selected from the pop up menu A variable table for the variables used in the function block is displayed on top and an input area for the ladder program or struc tured text is displayed on the bottom Ladder Program FD Fie Edit View Insert PLC Program Tools Window Help OSHAR saacana v as enne Sc m RIBmEETE S tw a a Q ESEE e S 4e v IP o6 t 8 Ere C ix Ex d Es aun ts s ER Fe Fs c RARAS a 5 E EE 29 39 26 bye t RR c Ro c Hie NewProject BB nent Variable table 3 symbole 1 10 Table S settings Sa intemal Tops Ere f Ladder input area Eig NewProgram 00 3 Symbols Sectiont END c dE Function Blocks FunctionBlockt Structured Text Untitled CX Programmer NewPLCI FunctionBlock2 FB Structured Text F File Edt View Insert PLC Program Tools Window Help DEHRA SD sej clt Ww Ja es ug 3 e SPOTS w a Eee ferme 3e e unu n OGREEL amp B D E as ta 5 Bee Fi mm EEG I EE S3 Eat we P 2
314. the following procedure to read a function block library file cxf into a Library Files into Other project Projects 1 2 3 1 Select the function block definition item under the PLC directory in the Project Workspace right click and select Insert Function Block From File from the pop up menu or select File Function Block Load Func tion Block from File 2 The following dialog box will be displayed Select a function block library file cxf and click the Open Button Ad xl J omronlib a Operation module cxf n Average calculation cxf sS Stsample cxf a Condition check cxf FB_STO1 cxf Files of type Function Block Library Files cxf Cancel LZ 3 Afunction block called FunctionBlock1 will be automatically inserted after the Function Blocks icon This icon contains the definition of the function block 4 Double click the FunctionBlock1 Icon The variable table and algorithm will be display 3 2 17 Downloading Uploading Programs to the Actual CPU Unit After a program containing function blocks has been created it can be down loaded from the CX Programmer to an actual CPU Unit that it is connected to online Programs can also be uploaded from the actual CPU Unit It is also possible to check if the programs on the CX Programmer personal computer and in the actual CPU Unit are the same When the program contains function blocks however downloading in task units is not possible
315. the section and related sections before attempting any of the procedures or operations given XV xvi Terms and Conditions Agreement WARRANTY LIMITATION OF LIABILITY The warranty period for the Software is one year from the date of purchase unless otherwise specifically agreed If the User discovers defect of the Software substantial non conformity with the manual and return it to OMRON within the above warranty period OMRON will replace the Software without charge by offering media or download from OMRON s website And if the User discovers defect of media which is attributable to OMRON and return it to OMRON within the above warranty period OMRON will replace defective media without charge If OMRON is unable to replace defective media or correct the Software the liability of OMRON and the User s remedy shall be limited to the refund of the license fee paid to OMRON for the Software THE ABOVE WARRANTY SHALL CONSTITUTE THE USER S SOLE AND EXCLUSIVE REMEDIES AGAINST OMRON AND THERE ARE NO OTHER WARRANTIES EXPRESSED OR IMPLIED INCLUDING BUT NOT LIMITED TO WARRANTY OF MERCHANTABILITY OR FITNESS FOR PARTICULAR PURPOSE IN NO EVENT OMRON WILL BE LIABLE FOR ANY LOST PROFITS OR OTHER INDIRECT INCIDENTAL SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF USE OF THE SOFTWARE OMRON SHALL HAVE NO LIABILITY FOR DEFECT OF THE SOFTWARE BASED ON MODIFICATION OR ALTERNATION TO THE SOFTWARE BY THE USER OR ANY THIRD PARTY OMRON S
316. the size is specified by another operand in the instruction make sure that the number of array elements is the same or greater than the size specified in the other operand i e size to be processed by the instruction Other Operand Specifying Size Constant The CX Programmer will output an error when compiling Example BLOCK TRANSFER XFER W S D W Number of words S First source word D First destination word When amp 20 is specified in W array variable a with data type WORD and 10 elements is specified in S and array variable b with data type WORD and 10 elements is specified in D XFER amp 20 2a 0 b 0 Even though the array variables a 0 and b 0 are both 10 words the XFER 070 instruction will execute transfer processing for the 20 words spec ified in W As a result the XFER 070 instruction will perform read write pro cessing for the I O memory area following the number of array elements that was allocated as shown in the following diagram Therefore if a 10 elements is internally allocated words e g H700 to H709 and b 10 elements is internally allocated words e g H800 to H809 XFER 070 will transfer data in words H700 to H719 to words H800 to H819 In this operation if another internally allocated variable e g c is allocated words in H810 to H819 the words will be overwritten causing unexpected operation to occur To transfer 20 words make sure that the number of ele ments is specified as 20
317. ther 1 or 2 Increment variable NofOther by 1 pope cquo Assign TRUE for variable STOP DE m Ae i i O ace KIM CM CMM ee eee Comment A comment can be attached to a statement Configured using before the comment and after the comment Programmer Operation Manual W446 Data Types Used in ST Programs Section 5 2 5 2 Data Types Used in ST Programs The following tables show the data types used in ST programs For details on the data types that can be used in ST programs within function blocks refer to Part 1 Function Blocks in this manual 5 2 1 Data type BOOL Basic Data Types Content Bit data Range of values 0 FALSE 1 TRUE INT Integer 32 768 to 32 767 DINT Double integer 2 147 483 648 to 2 147 483 647 LINT Long 8 byte integer 9 223 372 036 854 775 808 to 9 223 372 036 854 775 807 UINT Unsigned integer amp 0 to 65 535 UINT BCD Unsigned BCD integer See note 1 UDINT Unsigned double integer amp 0 to 4 294 967 295 UDINT BCD Unsigned double BCD integer See note 1 ULINT Unsigned long 8 byte integer amp 0 to 18 446 744 073 709 551 615 ULINT BCD Unsigned long 8 byte BCD integer See note 1 REAL Real number 3 402823 x 1098 to 1 175494 x 10 98 0 41 175494 x 10 38 to 3 402823 x 1038 LREAL Long real number 64 1 79769313486232 x 10908 to
318. ti tuted for the array variable DATA 1 The value of X is then multiplied by 2 again and the value is substituted for the array variable DATA 2 This process is repeated bale Da WHILE X lt 3000 DO X X 2 DATA n X n n 1 END WHIE BH Summary This statement is used to repeatedly execute an expression until a specified condition is true B Reserved Words REPEAT UNTIL END REPEAT B Statement Syntax REPEAT lt expression gt UNTIL condition END REPEAT B Processing Flow Chart Expression Iteration B Usage Use the REPEAT statement to repeat processing for as long as a condition is met after specified processing when the number of iterations is undetermined beforehand depends on whether the condition is met This statement can be used to determine whether to repeat processing according to the results of specified processing execution post test loop n Description The expression will execute the first time without a condition Thereafter the condition equation will be evaluated If the condition is false the expression will be executed again If the condition is true processing will end without exe cuting the expression E Precautions REPEAT must be used together with END REPEAT Even if the condition equation is true before the expression has been exe cuted the expression will be executed 165 Statement Descriptions Section 5 5 Statements that can be used
319. tion Return value LEN string Arguments and Return Values ETT String Specifies the text string for which to find the length Return value Returns the size of the speci fied text string Example Variables STRING Message Message A B CI D EJF GIH INT Result Result LEN Message 8 is stored in Result variable LEFT Extract Characters from Left Function Extracts the specified number of characters from the left of the specified text string Application Return value LEFT Source string Number of characters Arguments and Return Values Variable name Data type Description Source string STRING Specifies the text string from which to extract characters Number of characters INT UINT Specifies the number of characters to extract Return value STRING Returns the extracted characters Example Variables STRING Message Message A B CID E F G H STRING Result Result LEFT Message 3 ABC is stored in the Result variable RIGHT Extract Characters from Right Function Extracts the specified number of characters from the right of the specified text string Application Return value RIGHT Source string Number of characters 197 Function Descriptions Appendix C Arguments and Return Values Variable name Data type Description Source_string STRING Specifies the text string from which to extract characters Number of
320. to calculate the average value The 3 values data1 data2 and data3 are passed to function block 2 input variables input1 input2 and input3 respectively The result of the calcula tion average is returned to AVG Note The following diagram shows the Average FB function block called with specification method A both function block s variables listed IF bCheck TRUE THEN Average inputl datal input2 data2 input3 data3 aver age gt AVG ELSE RETURN END_IF Function Block 2 Variable Table Variable type Variable name Data type Passage to from FB1 Input variable EN Input variable inputi Received from data1 Input variable input2 Received from data2 Input variable input3 Received from data3 Output variable ENO Output variable average Passed to AVG e ST language Algorithm Calculates the average value of input1 input2 and input3 and stores the result in average average inputl input2 input3 3 5 6 ST language Program Example 5 6 1 Using an ST Program in a Function Block Converting an Integer to BCD and Outputting It as a Text BOOL BOOL String an ENO Input_Num STRING STRING Output_String Output_String Input Variable INT Input_Num Input Output Variable STRING Output String Internal Variable WORD Num BCD Check Input BCD input parameter BCD data IF Input BCDNum 0 amp Input _BCD lt 16 Num lt 9999 THEN 173 Restrictions 5
321. trical engineer or the equivalent Personnel in charge of installing FA systems Personnel in charge of designing FA systems Personnel in charge of managing FA systems and facilities General Precautions NWARNING The user must operate the product according to the performance specifica tions described in the operation manuals Before using the product under conditions which are not described in the manual or applying the product to nuclear control systems railroad systems aviation systems vehicles combustion systems medical equipment amuse ment machines safety equipment and other systems machines and equip ment that may have a serious influence on lives and property if used improperly consult your OMRON representative Make sure that the ratings and performance characteristics of the product are sufficient for the systems machines and equipment and be sure to provide the systems machines and equipment with double safety mechanisms This manual provides information for programming and operating the product Be sure to read this manual before attempting to use the product and keep this manual close at hand for reference during operation It is extremely important that a PLC and all PLC Units be used for the speci fied purpose and under the specified conditions especially in applications that can directly or indirectly affect human life You must consult with your OMRON representative before applying a PLC Syste
322. truction operates according to the address after AT specifi cation or internal allocation Therefore the variable data type and number of elements for the variable are unrelated to the operation of the instruction Al ways specify a variable with an AT setting or an array variable with a number of elements that matches the data size to be processed by the instruction Some examples are the first source word or first destination word of the XFER 070 BLOCK TRANSFER instruction the first source word for SEND 090 or control data for applicable instructions For details refer to 2 6 Precautions for Instructions with Operands Specifying the First or Last of Multiple Words Use the following method to specify an array variable When using input output variables set the input parameter to the first address of multiple words Use the following procedure for internal variables 1 Prepare an internal array variable with the required number of elements 61 Function Block Applications Guidelines Section 2 5 62 Note Make sure that the data size to be processed by the instruction is the same as the number of elements For details on the data sizes processed by each instruction refer to 2 7 Instruction Support and Operand Restrictions 2 Set the data in each of the array elements using the MOV instruction in the function block definition 3 Specify the first or last element of the array variable for the operand This enables speci
323. ue before the expression has been ex ecuted the expression will be executed B Example Processing is repeated from when variable n 1 until 50 in increments of 1 and n is added to array variable DATA n If DATA n exceeds 100 however processing will end 166 Statement Descriptions Section 5 5 FOR n 1 TO 50 BY 1 DO DATA n DATA n n IF DATA n gt 100 THEN EXIT END IF END FOR RETURN Statement BH Summary The function of the RETURN statement depends on the type of program in which ST is used ST program Forcibly ends the ST task that is being executed and executes the next task ST used in SFC Forcibly ends the action program that is being executed and executes the next action program or transition program ST used in a function block Forcibly ends the ST language function block containing the RETURN statement returns to the place in the calling function block instance where the call occurred and executes the next instruction B Reserved Words RETURN B Statement Syntax RETURN B Usage Use the RETURN statement to forcibly end an SFC program and function block that is executing an ST task Function Block Call Statement BH Summary This statement calls a function block definition B Reserved Words None B Statement Syntax Enter the arguments specified variable values that are passed to the called function block s input variables and return value specified variable that r
324. unction block instances Refer to Part 1 Function Blocks in this manual ST programs used in SFC Refer to the CX Programmer Operation Manual SFC W469 The ST Structured Text language is a high level language code for industrial controls mainly PLCs defined by the IEC 61131 3 standard The standard control statements operators and functions make the ST language ideal for mathematical processing that is difficult to write in ladder programming The ST language does not support all of the processing that can be written in lad der language The ST language supported by CX Programmer Ver 7 2 or higher conforms with the IEC 61131 3 standard and these ST language programs can be allo cated to tasks The PLC must be a CS CJ series CPU Unit with unit version 4 0 or later or a CJ2 series CPU Unit The following list shows the features of the ST language eThere are many control statements available such as loop statements and IF THEN ELSE statements many operators such as arithmetic oper ators comparison operators and AND OR operators as well as many mathematical functions string extract and merge functions Memory Card processing functions string transfer functions and trigonometric func tions e Programs can be written like high level languages such as C and com ments can be included to make the program easy to read ST Program IF score gt setover THEN If score gt setover underNG FALSE T
325. urn OFF underNG OK FALSE Turn OFF OK overNG TRUE Turn ON overNG ELSIF score lt setunder THEN If score lt setover and score lt setunder overNG FALSE Turn ON overNG OK FALSE Turn OFF OK underNG TRUE Turn ON underNG ELSE If setover gt score gt setunder underNG FALSE Turn OFF underNG overNG FALSE Turn OFF overNG OK TRUE Turn OFF OK END IF End of IF statement eST programs can be uploaded and downloaded just like ordinary pro grams but ST program tasks cannot be uploaded and downloaded in task units e Function blocks ladder or ST language can be called in ST programs CX Programmer Specifications Section 4 2 e One dimensional array variables are supported for easier data handling in applications 4 2 CX Programmer Specifications This section describes the operating environment for CX Programmer ST pro grams ST tasks For details on the basic CX Programmer operating environ ment refer to the CX Programmer Operation Manual W446 For details on the CX Programmer operating environment used with other programs function block or SFC refer to Part 1 Function Blocks in this manual or the CX Programmer Operation Manual SFC W469 PLC Models Compatible with ST Programs ST Tasks The following PLC models support ST tasks PLC model CPU Unit model 4 2 1 CJ2H CJ2H CPU68 67 66 65 64 68 EIP 67 EIP 66 EIP 65 EIP 64 EIP
326. ury Execute online editing only after confirming that no adverse effects will be caused by extending the cycle time Otherwise the input signals may not be readable If synchronous unit operation is being used perform online editing only after confirming that an increased synchronous processing time will not affect the operation of the main and slave axes Confirm safety sufficiently before monitoring power flow and present value status in the Ladder Section Window or when monitoring present values in the Watch Window If force set reset or set reset operations are inadvertently per formed by pressing short cut keys the devices connected to Output Units may malfunction regardless of the operating mode of the CPU Unit 4 Application Precautions Observe the following precautions when using the CX Programmer User programs cannot be uploaded to the CX Programmer Observe the following precautions before starting the CX Programmer Exit all applications not directly related to the CX Programmer Partic ularly exit any software such as screen savers virus checkers E mail or other communications software and schedulers or other applica tions that start up periodically or automatically xxi Application Precautions 4 Disable sharing hard disks printers or other devices with other com puters on any network With some notebook computers the RS 232C port is allocated to a modem or an infrared line by default Followin
327. ut variables must be set The function argument is not specified or is insufficient Missing OF OF is not included in CASE statement Missing THEN THEN is not included in IF statement Missing TO TO is not included in FOR statement Missing UNTIL UNTIL is not included in REPEAT statement Missing The array index for the array variable has not been speci fied X Array Array is an array variable Missing The array index for the array variable has not been speci fied X Array 2 Array is an array variable Missing constant A constant is not provided in the integer equation of the CASE statement CASE A OF 2 X 1 2 X 2 END_CASE NOT operation not supported on a literal number The NOT operator was used for a numeric value Result NOT 1 Negation not supported by s data type A minus symbol was used before a variable with a data type that does not support negative values UINT UDINT ULINT Y X X is an UINT type variable Y is an INT type vari able There must be one line of valid code excluding com ments There is no line of valid code excluding comments Too many variables specified for Function Too many parameter settings are specified for the function Y zSIN X1 X2 Undefined identifier s A variable that is not defined in the variable table has been used Unexp
328. utton As shown below a BOOL variable called aaa will be created on the Inputs Sheet of the Variable Table Untitled CX Programmer NewPLC1 FunctionBlocki FB Ladder ini xi FD File Edit view Insert PLC Program Tools Window Help laj xl Dc E ca amp a 8 Clau 5575 9 M2 S 68 8 n Es AER Re AR ED ED ED SD s uw 63 P amp Ka Sis Sls e eV HP O0 g H Sx 273 0 42 4a 4a 45 BE Fa pa DAA Ed S a E22 39 25 zix Name Data Type ar Initial Value Retai Comment die NewProject N BOQ A ankrals execution a EB NewPLCILCIIG H Offline r NU NUNT NN NNI Symbols QT 10 Table s settings 9 Memory E S Programs ci gl NewProgramt 00 Inputs Outputs Externals 52 Symbols Sectiont Qj END ERE Function Bla QF FunctionBlockt BOOL variable called aaa created on Inputs Sheet 1 After a variable is added it can be selected to display in reverse video then moved to another line by dragging and dropping To select a variable for dragging and dropping select the variable in any of the columns ex cept the Name field 2 After inputting a variable the sheet where the variable is registered can be changed by double clicking and changing the setting in the Usage field N Internals I Inputs O Outputs E Externals P In Out The variable can also be copied or moved between the sheets for internal external in put
329. vance This memory is separate from the internally allocated range for the variable in the function block instance area Use the following procedure to reserve memory before starting online editing of the function block 1 In the Workspace right click the function block definition to be edited and select Properties from the pop up menu 2 Click the Memory Tab right click the area for which to reserve memory and select Online edit reserved memory from the pop up menu Function Block Properties x x General Protection Comments Memory Required Memory 75e Assigned area Hequred Reserved meme Non Retan qum i Retain Online edit reserved memory Timers 0 Counters D 3 Enter the size of memory to reserve in each field in the Memory Size Edit for FB Online Edit Dialog Box Memory Size Edit for FB Online Edit Address allocation area Nor Reserved memory size BOOLs 0 Cancel Reserved memory size non BOOLs p O Procedures Section 3 2 Editing and Transferring a Function Block Definition 1 2 3 1 While online with the PLC right click a function block definition in the Workspace see note and select FB online Edit Begin from the pop up menu Note Online editing can also be started from the Function Block Defini tion Window the Instance Ladder ST Monitor Window or a function block call instruction from the normal ladder program or from a lad
330. variable a Number of characters Position INT UINT FIND Source string Source STRING Finds characters a FIND b c lt Find_string gt string within a text string first occurrence of text string c Find_string STRING found in text string b and posi tion stored in variable a 0 stored if text string c is not found Data Type Conversion The following data type conversion functions can be used in structured text Functions Syntax Source data type TO New data type Variable name Example REAL TO INT C In this example the data type for variable C will be changed from REAL to INT The fractional part of the value of variable C is rounded off to the closest inte ger The following table shows how values are rounded Value of fractional Treatment Examples part Less than 0 5 The fractional part is truncated 0 5 If the ones digit is an even number the fractional part is truncated If the ones digit is an odd number the fractional part is rounded up Greater than 0 5 The fractional part is rounded up Data Type Combinations The combinations of data types that can be converted are given in the follow ing table 148 ST Language Configuration Section 5 4 YES Conversion possible No Conversion not possible Number String The follo
331. wing Additional Details The following two examples show how to actually use an ST program to call a function block Example 1 These examples show how to call a function block from each kind of source program ST task SFC and function block Conditions A function block is called The called function block is written in ladder language or ST language Call Details a Calling a function block from an ST task or SFC program ST task Function block FB ST Ladder diagram Example EM Instance FB ween ener EN M re F4 s L4 EN P S x Ug Function block FB SFC J EN Fi Ta ST 4 v F Lec rd fer toe ye ST INSTANCE_FB is an instance name of Example data type FUNCTIONBLOCK Instance_FB y Action program 169 Statement Descriptions b Calling a function block from another function block Function block ST Section 5 5 Function block FB Program Instance_ST Er wc Variable Settings Example Instance FB E noeeeet ST Ladder diagram p o N Function block FB ST Example INSTANCE FB is an instance name of data type FUNCTIONBLOCK Setting the variables of the ST program and SFC program call source The ST program and SFC program have the following variables and the following values are passed with th
332. wing number string conversion functions can be used in structured Conversion Functions text Syntax Source_data_type_TO_STRING Variable_name Example INT_TO_STRING C In this example the integer variable C will be changed to a STRING vari able STRING_TO_New_data_type Variable_name Example STRING_TO_INT C In this example the STRING variable C will be changed to an integer Data Type Combinations The combinations of data types that can be converted are given in the follow ing table YES Conversion possible No Conversion not possible STRING BOOL INT DINT LINT UINT UDINT ULINT WORD DWORD LWORD REAL LREAL STRING 149 ST Language Configuration Data Shift Functions Function ist argument data type SHL lt Shift_target_data gt lt Number_of_bits gt 2nd argument data type Return value data type Description Shifts a bit string to the left by n bits When shifted zeros are entered on the right side of the bit string Section 5 4 Example a SHL b c Result of shifting bit string b to the left by c bits is stored in a SHR lt Shift_target_data gt lt Number_of_bits gt Shifts a bit string to the right by n bits When shifted zeros are entered on the left side of the bit string a SHR b c Result of shifting bit string b to the right by c bits is st
333. wing procedure to check the function block definition from which an instance was created Either double click the instance or right click the instance and select To Lower Layer from the pop up menu The function block definition will be dis played 3 2 10 Checking Instance Information such as Nesting Levels When function blocks are nested in the created program the structure of the nesting levels can be checked by selecting Windows FB Instance Viewer from the View Menu The function block relationships will be shown in a direc tory tree format with the calling function blocks at the higher level and the called function blocks at the lower level The FB Instance Viewer Window will provide other information such as the array variables being used and internal addresses allocated to the variables as shown in the following diagram Variables can be registered in the Watch Window just by dragging the variable from the list of variables used in the instance and dropping the variable in the Watch Window 108 Procedures Section 3 2 FB manual sample CX Programmer NewPLC1 NewProgram1 Section Diagram File Edit View Insert PLC Program Tools Window Help PEAREN in az e M A S 5s n n 4 s xaker sd me s 3e nn 0 c8 EE EC amp ER b Ix x e m ga Ea gc cin 2 EJ 3939 35 ae a8 g o Program Name NewProg
334. with commas Delimit only the required number of D gt E type assignments with commas B Entry Method 2 Use this method to enter just the return value specification and omit the argu ment specification called function block definition s variable name A O aera ani e E A Instance name B Omitted called function block definition s input variable name C One of the following values depending on the ST program being used Calling function block s input variable or a constant when ST is being used in the function block s instance Global variable or local variable name when ST is being used in an ST task or SFC action program D Omitted called function block definition s output variable name or constant E One of the following values depending on the ST program being used Calling function block s output variable or constant when ST is being used in the function block s instance Global variable or local variable name when ST is being used in an ST task or SFC action program Note When B and D are omitted as shown above C is moved to the B position and passed automatically in the order that values are registered in that variable table In contrast the values from the D position are automatically received at E in the order that values are registered in that variable table B Usage Use the function block call statement to call a function block definition ST or ladder language from an ST language program B
335. xample INSTANCE FB A FB1__OUT1 B gt FB1_IN1 INSTANCE FB INSTANCE FBB 52 INSTANCE FB1 INSTANCE FB2 etc are the FUNCTION BLOCK data type instance names Note Any combination of ladder diagrams and structured text programming can be used between the called and the calling function block The function block nesting levels can also be displayed in a directory tree for mat with the FB Instance Viewer function S F sample Operation module Ci dtF Target 1 FB Operation module dsF Condition 1 Condition check 45F Conditiono1 Condition check The nested function blocks function block definitions are included in the func tion block library file cxf containing the calling function block s definitions Programming Restrictions Section 2 4 2 4 Programming Restrictions 2 4 1 Instructions Prohibited in Function Block Definitions AT Setting Restrictions Unsupported Data Areas Direct Addressing of I O Memory in Instruction Operands Restrictions for Input Variables Output Variables and Input Output Variables Unsupported Data Areas Interlock Restrictions Differentiation Instructions in Function Block Definitions Ladder Programming Restrictions There are some restrictions on instructions used in ladder progr
336. xecution condition remains TRUE When the present value reaches 0 the timer completion flag of the specified timer address will be turned ON If the present value is not zero the timer completion flag is OFF While the execution condition is FALSE the timer set value is set in the present value of the timer address and the timer completion flag is OFF Application TIMUX Execution condition Timer address Timer set value 219 Function Descriptions Appendix C Argument Variable name Data type Description Execution_condition Executes the timer operation while this execution condition is TRUE Timer_address Specifies the timer address TO to T4095 variable to use Timer_set_value Specifies the delay time in units of 0 1 ms amp 0 to amp 65535 0 to FFFF This timer may not operate properly when the cycle time is 100 ms or longer When the timer PV is referenced from the user program the present value may be different by one cycle from the actual value depending on the access timing When the timer completion flag is referenced from the user program the reflection of status change may be delayed by one cycle depending on the access timing TMUHX HUNDREDTH MS TIMER Function Operates a decrementing timer with units of 0 01 ms Equivalent to the TMUHX 557 ladder instruction When the execution condition goes from FALSE to TRUE the timer specified in the timer address is started and
337. y index A numeric equation with a non integer type operation result or a non integer vari able has been specified in the array index Array Index 10 ndex is a WORD type variable 193 Structured Text Errors Error Message Cause of error Appendix B Invalid constant A numeric equation with a non integer type operation result or a non integer vari able or numeric value has been specified in the integer equation of a CASE state ment Example CASE A OF A is a REAL type variable 1 X 1 2 X 2 END CASE Invalid expression The numeric equation is ille gal For example the integer equation or condition equation is illegal or has not been spec ified in the syntax IF WHILE REPEAT FOR CASE WHILE DO The WHILE statement does not contain a condition equation X X 1 END_WHILE Invalid parameter in FOR loop declaration A variable with data type other than INT DINT LINT UINT UDINT or ULINT has been used for variables in a FOR statement FOR I 1 TO 100 DO I is a WORD type variable X X 1 END_FOR Invalid statement The statement is illegal E g The statement IF WHILE REPEAT FOR CASE REPEAT does not contain an IF WHILE REPEAT FOR CASE or REPEAT in the syn tax respectively X X 1 There is no REPEAT in the syntax UNTIL X gt 10 END_REPEAT Invalid variable for Function output The specified variable for the fun
Download Pdf Manuals
Related Search
Related Contents
License Definitions and Rules Definitions and License Télécharger le document au format PDF Copyright © All rights reserved.
Failed to retrieve file