Mitsubishi Electric MELSEC Q Series Structured Programming Manual

Fundamentals
Hide thumbs Also See for MELSEC Q Series:
Table of Contents

Advertisement

MELSEC-Q/L/F Structured
Programming Manual (Fundamentals)

Advertisement

Table of Contents
loading

Summary of Contents for Mitsubishi Electric MELSEC Q Series

  • Page 1 MELSEC-Q/L/F Structured Programming Manual (Fundamentals)
  • Page 3: Safety Precautions

    SAFETY PRECAUTIONS (Read these precautions before using this product.) Before using MELSEC-Q, -L, or -F series programmable controllers, please read the manuals included with each product and the relevant manuals introduced in those manuals carefully, and pay full attention to safety to handle the product correctly.
  • Page 4: Conditions Of Use For The Product

    CONDITIONS OF USE FOR THE PRODUCT (1) Mitsubishi programmable controller ("the PRODUCT") shall be used in conditions; i) where any problem, fault or failure occurring in the PRODUCT, if any, shall not lead to any major or serious accident; and ii) where the backup and fail-safe function are systematically or automatically provided outside of the PRODUCT for the case of any problem, fault or failure occurring in the PRODUCT.
  • Page 5: Revisions

    REVISIONS The manual number is written at the bottom left of the back cover. Print date Manual number Revision Jul., 2008 SH(NA)-080782ENG-A First edition Jan., 2009 SH(NA)-080782ENG-B Model Addition Q00UJCPU, Q00UCPU, Q01UCPU, Q10UDHCPU, Q10UDEHCPU, Q20UDHCPU, Q20UDEHCPU, FX series Addition MANUALS Correction Generic Terms and Abbreviations in This Manual, Section 1.3, Section 4.3.3, Section 4.3.4, Section 4.4.1, Section 4.4.2, Appendix 1...
  • Page 6 This manual confers no industrial property rights or any rights of any other kind, nor does it confer any patent licenses. Mitsubishi Electric Corporation cannot be held responsible for any problems involving industrial property rights which may occur as a result of using the contents noted in this manual.
  • Page 7: Table Of Contents

    INTRODUCTION Thank you for purchasing the Mitsubishi MELSEC-Q, -L, or -F series programmable controllers. Before using this product, please read this manual and the relevant manuals carefully and develop familiarity with the programming specifications to handle the product correctly. When applying the program examples introduced in this manual to an actual system, ensure the applicability and confirm that it will not cause system control problems.
  • Page 8 4.2.9 EN and ENO ..........................4 - 13 4.3 Labels 4 - 15 4.3.1 Global labels ..........................4 - 15 4.3.2 Local labels..........................4 - 15 4.3.3 Label classes ..........................4 - 16 4.3.4 Setting labels ..........................4 - 17 4.3.5 Data types............................
  • Page 9 APPENDICES App - 1 to App - 14 Appendix 1Correspondence between Generic Data Types and Devices App - 2 Appendix 2Character Strings that cannot be Used in Label Names and Data Names App - 6 Appendix 3Recreating Ladder Programs App - 9 Appendix 3.1Procedure for creating a structured program ..............
  • Page 10: Manuals

    MANUALS The manuals related to this product are listed below. Please place an order as needed. (1) Structured programming Manual number Manual name (Model code) MELSEC-Q/L Structured Programming Manual (Common Instructions) SH-080783ENG Specifications and functions of common instructions, such as sequence instructions, basic instructions, and application instructions, that can be used in structured programs (13JW07) (Sold separately)
  • Page 11 OVERVIEW Overview............1-2 Purpose of This Manual .
  • Page 12: Purpose Of This Manual

    Overview This manual describes program configurations and content for creating sequence programs using a structured programming method, and provides basic knowledge for writing programs. Purpose of This Manual This manual explains programming methods, programming languages, and other information necessary for creating structured programs. Manuals for reference are listed in the following table according to their purpose.
  • Page 13 (2) Operations in each programming language For details of instructions used in each programming language, refer to the section 3 on the next page. GX Works2 GX Works2 Version 1 Beginner's Manual Operating Manual Purpose Simple Structured Simple Structured Project Project Project Project...
  • Page 14 (3) Details of instructions in each programming language (for QCPU (Q mode)/LCPU) MELSEC-Q MELSEC- MELSEC- Programming Manual for Q/L/F MELSEC-Q/L MELSEC-Q/L/QnA Structured /Structured module to Structured Programming Manual Programming Programming Manual Programming Programming be used Manual Purpose Manual Manual Process Common Special Application...
  • Page 15 (4) Details of instructions in each programming language (for FXCPU) MELSEC- Q/L/F FXCPU Structured Programming Structured FXCPU Programming Manual Manual Programming Manual Purpose , FX , FX , FX Basic & Device & Application Fundamentals Applied , FX Common Functions Instruction , FX Learning the types...
  • Page 16: Terms

    Terms This manual uses the generic terms and abbreviations listed in the following table to discuss the software packages and programmable controller CPUs. Corresponding module models are also listed if needed. Term Description GX Works2 GX Developer The product name of the software package for the MELSEC programmable controllers GX IEC Developer Basic model QCPU A generic term for the Q00JCPU, Q00CPU, and Q01CPU...
  • Page 17: Features Of Structured Programs

    Features of Structured Programs This section explains the features of structured programs. (1) Structured design A structured design is a method to program control content performed by a programmable controller CPU, which are divided into small processing units (components) to create hierarchical structures.
  • Page 18: Applicable Cpu Modules

    Applicable CPU Modules The following table shows the applicable CPU modules for programs in the Structured project. Table 1.5-1 Applicable CPU modules Programmable controller type Basic model QCPU Q00JCPU, Q00CPU, Q01CPU High Performance model QCPU Q02CPU, Q02HCPU, Q06HCPU, Q12HCPU, Q25HCPU Process CPU Q02PHCPU, Q06PHCPU, Q12PHCPU, Q25PHCPU Redundant CPU...
  • Page 19: Structured Design Of Sequence Programs

    STRUCTURED DESI G N OF SEQUENCE PROGRAMS What is a Hierarchical Sequence Program?......2-2 What is a Structured Sequence Program? .
  • Page 20: What Is A Hierarchical Sequence Program

    What is a Hierarchical Sequence Program? The hierarchy is to create a sequence program by dividing control functions performed in a programmable controller CPU into a number of levels. In higher levels, the processing order and timing in a fixed range is controlled. With each move from a higher level to a lower level, control content and processes are progressively subdivided within a fixed range, and specific processes are described in lower levels.
  • Page 21: What Is A Structured Sequence Program

    What is a Structured Sequence Program? A structured program is a program created by components. Processes in lower levels of hierarchical sequence program are divided to several components according to their processing information and functions. In a structured program design, segmenting processes in lower levels as much as possible is recommended.
  • Page 22 MEMO...
  • Page 23: Procedure For Creating Programs

    PROCEDURE FOR CREATING PROGRAMS Procedure for Creating Sequence Programs in Structured Project ..3-2...
  • Page 24: 3.1 Procedure For Creating Sequence Programs In Structured Project

    Procedure for Creating Sequence Programs in Structured Project This section explains the basic procedure for creating a sequence program in the Structured project. (1) Creating the program configuration Procedure Create program files. Create tasks. (2) Creating POUs Procedure Create POUs. Define global labels.
  • Page 25: Program Configuration

    PROGRAM CONFIGURATION Overview of Program Configuration ....... . . 4-2 POUs .
  • Page 26: Overview Of Program Configuration

    Overview of Program Configuration A sequence program created in the Structured project is composed of program files, tasks, and POUs. For details of program components, refer to the following sections. For projects: Section 4.1.1 Project For program files: Section 4.1.2 Program files For tasks: Section 4.1.3 Tasks For POUs:...
  • Page 27: Project

    4.1.1 Project A project is a generic term for data (such as programs and parameters) to be executed in a programmable controller CPU. One or more program files need to be created in a project. 4.1.2 Program files One or more tasks need to be created in a program file. (Created tasks are executed under the control of the program file.) The execution types (such as scan execution and fixed scan execution) for executing program files in a programmable controller CPU are set in the program setting of the parameter.
  • Page 28: Tasks

    4.1.3 Tasks A task is an element that contains multiple POUs, and it is registered to a program file. One or more programs of POU need to be registered in a task. (Functions and function blocks cannot be registered in a task.) Project Program file 1 Program file 2...
  • Page 29: Pous

    POUs A POU (abbreviation for Program Organization Unit) is a program component defined by each function. 4.2.1 Types of POU The following three types can be selected for each POU according to the content to be defined. • Program • Function •...
  • Page 30: Program

    4.2.2 Program A program is an element that is stated at the highest level of POU. Functions, function blocks, and operators are used to edit programs. Function Program Function block Operator Sequence programs executed in a programmable controller CPU are created by programs of POU.
  • Page 31: Function Blocks

    4.2.4 Function blocks Functions, function blocks, and operators are used to edit function blocks. Function blocks can be used by calling them from programs or function blocks. Note that they cannot be called from functions. Function Function block Function block Operator Function blocks can retain the input status since they can store values in internal and output variables.
  • Page 32: Ladder Blocks

    4.2.6 Ladder blocks In the structured ladder/FBD language, a program is divided into units of ladder blocks. In the ST language, ladder blocks are not used. ● Ladder block labels A ladder block label can be set to a ladder block. A ladder block label is used to indicate a jump target for the Jump instruction.
  • Page 33: Programming Languages For Pous

    4.2.7 Programming languages for POUs Two types of programming language are available for programs of POU. The following explains the features of each programming language. (1) ST: Structured text Control syntax such as selection branch by conditional syntax or repetitions by iterative syntax can be described in the structured text language, as in the high-level language such as C language.
  • Page 34: Functions, Function Blocks, And Operators

    4.2.8 Functions, function blocks, and operators The following table shows differences among functions, function blocks, and operators. Table 4.2.8-1 Differences among functions, function blocks, and operators Item Function Function block Operator Output variable assignment Cannot be assigned Can be assigned Cannot be assigned Internal variable Not used...
  • Page 35 (2) Internal variables A function does not use internal variables. It uses devices assigned directly to each input variable and repeats operations. (a) A program that outputs the total of three input variables (When using a function (FUN1)) Function D109 D109 FUN1 D120...
  • Page 36 (3) Creating instances When using function blocks, create instances to reserve internal variables. Variables can be called from programs and other function blocks by creating instances for function blocks. To create an instance, declare as a label in a global label or local label of POU that uses function blocks.
  • Page 37: En And Eno

    4.2.9 EN and ENO An EN (enable input) and ENO (enable output) can be appended to a function and function block to control their execution. A Boolean variable used as an executing condition of a function is set to an EN. A function with an EN is executed only when the executing condition of the EN is TRUE.
  • Page 38 ● Usage example of EN and ENO Control description When the EN input is directly connected from the left power rail, the EN input is always TRUE and the instruction is always executed. ➀ If the ADD_E instruction is used in this manner, the operation result is the same as the ADD instruction without the EN input.
  • Page 39: Labels

    Labels Labels include global labels and local labels. 4.3.1 Global labels The global labels are labels that can be used in programs and function blocks. In the setting of a global label, a label name, a class, a data type, and a device are associated with each other.
  • Page 40: Label Classes

    4.3.3 Label classes The label class indicates from which POU and how a label can be used. Different classes can be selected according to the type of POU. The following table shows label classes. Table 4.3.3-1 Label classes Applicable POU Class Description Function...
  • Page 41: Setting Labels

    4.3.4 Setting labels Labels used in a program require setting of either global label or local label. The following describes setting examples of the arguments g_int1 and g_int2 of the DMOV instruction. DMOV g_int1 g_int2 ● Using the arguments of the DMOV instruction as global labels Set the Class, Label Name, Data Type, Device, and Address.
  • Page 42: Data Types

    4.3.5 Data types Labels are classified into several data types according to the bit length, processing method, or value range. (1) Elementary data types The following data types are available as the elementary data type. • Boolean type (bit): Represents the alternative status, such as ON or OFF. •...
  • Page 43 (2) Generic data types Generic data type is the data type of labels summarizing some elementary data types. Data type name starts with 'ANY'. ANY data types are used when multiple data types are allowed for function arguments and return values. Labels defined in generic data types can be used in any sub-level data type.
  • Page 44: Expressing Methods Of Constants

    4.3.6 Expressing methods of constants The following table shows the expressing method for setting a constant to a label. Table 4.3.6-1 Constant expressing method Constant Expressing method Example type Bool Input FALSE or TRUE, or input 0 or 1. TRUE, FALSE Binary Append '2#' in front of a binary number.
  • Page 45: Method For Specifying Data

    Method for Specifying Data The following shows the six types of data that can be used for instructions in CPU modules....... Section 4.4.1 Bit data Data that can be handled by CPU module ..Section 4.4.2 Numeric data Word (Signed) data Integer data ..
  • Page 46: Bit Data

    4.4.1 Bit data Bit data are data handled in units of 1 bit, such as contacts and coils. 'Bit devices' and 'bit-specified word device' can be used as bit data. (1) Using bit devices A bit device is specified in unit of one point. One point of M0 is the target bit device One point of Y10 is...
  • Page 47: Word (16 Bits) Data

    4.4.2 Word (16 bits) data Word data are 16-bit numeric value data used in basic instructions and application instructions. The following shows the two types of word data that can be handled in CPU modules. • Decimal constants ....-32768 to 32767 •...
  • Page 48 (b) The following table shows the numeric values that can be used as source data when digits are specified at the source Table 4.4.2-2 List of digit specification and numeric values that can be used Number of specified Value range digits 0 to 15 K1 (4 points)
  • Page 49 (2) Using word devices A word device is specified in unit of one point (16 bits). X010 One point (16 bits) of D0 is the target word device 1. When performing the process with digit specification, a desired value can be used for the start device number of bit devices.
  • Page 50: Double Word (32 Bits) Data

    4.4.3 Double word (32 bits) data Double word data are 32-bit numeric value data used in basic instructions and application instructions. The following shows the two types of double word data that can be handled in CPU modules. • Decimal constants ....-2147483648 to 2147483647 •...
  • Page 51 (b) The following table shows the numeric values that can be used as source data when digits are specified at the source Table 4.4.3-1 List of digit specification and numeric values that can be used Number of Number of specified Value range Value range specified digits...
  • Page 52 1. When performing the process with digit specification, a desired value can be used for the start device number of bit devices. 2. Digits cannot be specified for direct access inputs/outputs (DX, DY). (2) Using word devices Devices used in lower 16 bits are specified for a word device. 'Specified device number' and 'specified device number +1' are used for instructions that process 32-bit data.
  • Page 53: Single-Precision Real/Double-Precision Real Data

    4.4.4 Single-precision real/double-precision real data Single-precision real/double-precision real data are 32-bit floating-point data used in basic instructions and application instructions. Real number data can be stored only in word devices. For FXCPU, double-precision real data is not supported. (1) Single-precision real (single-precision floating-point data) Devices used in lower 16 bits are specified for instructions that use real number data.
  • Page 54 Transfers real number data EDMOV Var_R100 Var_D0 Four points (64 bits) of D0, D1, D2, and D3 are the target word devices Four points (64 bits) of R100, R101, R102, and R103 are the target word devices Remark 1) Floating-point data are represented by four word devices. [Exponent] [Sign] 1.
  • Page 55 (3) Precautions for when setting input values of single-precision real data/double-precision real data from the programming tool (a) Single-precision real Single-precision real data are processed as 32-bit single precision in the programming tool, and thus the number of significant figures becomes approximately 7. If the input value of single-precision real data exceeds 7 digits, the 8th digit is rounded.
  • Page 56 1. Floating-point data in a CPU module can be monitored by the monitoring function of the programming tool. 2. To express 0 in floating-point data, set all of the following bits to 0. (a) Single-precision floating-point data: b0 to b31 (b) Double-precision floating-point data: b0 to b63 3.
  • Page 57: String Data

    4.4.5 String data String data are character data used in basic instructions and application instructions. From the specified character to the NULL code (00H) that indicates the end of the character string are the target string data. (1) When the specified character is NULL code The NULL code is stored by using one word.
  • Page 58: Time Data

    4.4.6 Time data Time data are used in time type operation instructions of application functions. Specify time data in the T#10d20h30m40s567ms form. For example. the following adds ‘1 Day, 2 Hours, 3 Minutes, and 4 Seconds’ to ‘10 Days, 20 Hours, 30 Minutes, 40 Seconds, and 567 Milliseconds’.
  • Page 59: Arrays

    4.4.7 Arrays An array represents a consecutive aggregation of same data type labels. Arrays can be defined by the elementary data types or structures. GX Works2 Version 1 Operating Manual (Structured Project)) The maximum number of arrays differs depending on the data types. One-dimensional array Two-dimensional array Label name...
  • Page 60 [Structured ladder/FBD] [ST] FOR Index1:=0 TO 4 BY 1 DO INC(TRUE,Var_D0[Index1]); END_FOR; 1. When a label or a device is specified for an array index, the operation is performed with a combination of multiple sequence instructions. Therefore, if an interruption occurs during the operation of the array label, an unintended operation result may be produced.
  • Page 61: Structures

    4.4.8 Structures A structure is an aggregation of different data type labels. Structures can be used in all POUs. To use structures, first create the configuration of structure, and define a structure label name for the created structure as a new data type GX Works2 Version 1 Operating Manual (Structured Project)) To use each element of structure, append an element name after the structure label name with '.' as a delimiter in between.
  • Page 62: Device And Address

    Device and Address This section explains the method for expressing programmable controller CPU devices. The following two types of format are available. • Device: This format consists of a device name and a device number. • Address: A format defined in IEC61131-3. In this format, a device name starts with %. 4.5.1 Device Device is a format that uses a device name and a device number.
  • Page 63: Address

    4.5.2 Address Address is a format defined in IEC61131-3. The following table shows details of format that conforms to IEC61131-3. Table 4.5.2-1 Address definition specifications 1st character: 3rd character and later: Start 2nd character: data size Number position classification Input (Omitted) Numeric characters used for Number...
  • Page 64: Correspondence Between Devices And Addresses

    4.5.3 Correspondence between devices and addresses This section explains the correspondence between devices and addresses. (1) Correspondence between devices and addresses The following table shows the correspondence between devices and addresses. (a) QCPU (Q mode)/LCPU Table 4.5.3-1 Correspondence between devices and addresses (1/2) Example of correspondence between Expressing method device and address...
  • Page 65 Table 4.5.3-1 Correspondence between devices and addresses (2/2) Example of correspondence between Expressing method Device device and address Device Address Device Address Step relay %MX2.n S127 %MX2.127 SFC transition device %MX18.n %MX18.3 SFC block device %MX17.n %MX17.3 Link input Jx\Xn %IX16.x.n J1\X1FFF %IX16.1.8191...
  • Page 66 (2) Digit specification of bit devices The following table shows the correspondence between devices and addresses when specifying digits of bit devices. Table 4.5.3-3 Correspondence of formats with digit specification Device Address %[Position of memory area][Data size]19.[Number of K[Number of digits][Device name][Device number] digits].[Classification].[Number] (Number of digits: 1 to 8) (Number of digits: 1 to 8)
  • Page 67: Index Setting

    Index Setting (1) Overview of the index setting (a) The index setting is an indirect setting that uses index registers. When the index setting is used in a sequence program, the device consists of ‘directly specified device number’ + ‘content of index register’. For example, when D2Z2 is specified and the value of Z2 is 3, D(2+3)=D5 is set as the target.
  • Page 68 2) Devices with restrictions on index registers Device Description Example TS0Z0 OUT_T Only Z0 or Z1 can be used for contacts or TC1Z1 coils of the timer. CS0Z1 OUT_C Only Z0 or Z1 can be used for contacts or coils of the counter. CC1Z0 (c) Devices that can be used for the index setting (for FXCPU) The following table shows the devices that can be used for the index setting.
  • Page 69 (d) The following figure shows the examples of index setting and their actual processing devices. (With the setting of Z0=20 and Z1=5) Ladder example Actual processing device K2X64 K1M33 Description K2X(50 + 14) = K2X64 K2X50Z0 Converts K20 to a hexadecimal number. K1M38Z1 K1M(38 - 5) = K1M33 K2X50Z0...
  • Page 70 (a) Specifying a range of index registers used for a 32-bit index setting 1) Values from 2147483648 to 2147483647 can be set to index registers. The following shows how the index is set. DMOV Stores 40000 to Z0 40000 Var_Z0 Stores the data of ZR {10+40000} = ZR40010 to D0 ZR10Z0...
  • Page 71 4) Usage range of index registers The following table lists the usage range of index registers when setting indexes in 32-bit range. Since the specified index register (Zn) and next index register (Zn+1) are used for index setting in 32-bit range, make sure not to overlap index registers being used.
  • Page 72 (b) Specifying a 32-bit index setting using 'ZZ' 1) A 32-bit index can be specified to the index register by specifying an index using 'ZZ', for instance, 'ZR0ZZ4'. The following figure shows the 32-bit index setting using 'ZZ'. DMOVP Set 100000 to Z4 and Z5. K100000 MOVP Set 32-bit (Z4, Z5) index to ZR.
  • Page 73 5) The following figure shows the examples of 32-bit index setting using 'ZZ' and their actual processing devices. (With the setting of Z0 (32 bits) =100000 and Z2 (32 bits)=-20) Ladder example Actual processing device DMOV ZR101000 D12980 K100000 Description DMOV ZR1000Z0 ZR(1000+100000)
  • Page 74 (4) Applying index settings to extended data registers (D) and extended link registers (W) (for Universal model QCPU (excluding Q00UJCPU), and LCPU) As an index setting can be applied to internal user devices, data registers (D) and link registers (W), the device specification by the index setting can be used within the range of extended data registers (D) and extended link registers (W).
  • Page 75 2) Index settings that cross file registers (ZR), extended data registers (D), and extended link registers (W) Even when an index setting that crosses file registers (ZR), extended data registers (D), and extended link registers (W) is applied, an error does not occur.
  • Page 76 (b) An index setting is applicable to both start I/O numbers of the intelligent function module and buffer memory addresses for intelligent function module devices U10Z1\G0Z2 If Z1=2 and Z2=8, then U(10+2)\G(0+8)=U12\G8 (c) An index setting is applicable to both network numbers and device numbers for link direct devices J1Z1\K4X0Z2 If Z1=2 and Z2=8,...
  • Page 77 (6) Precautions (a) Using the index setting for arguments of instruction/application function/function/ function block When "Use ZZ" is checked in "Indexing Setting for ZR Device" setting in the <<Device>> tab of the PLC parameter, and Z device is used for the argument of instruction/application function/function/function block, the expression is converted to "ZZ"...
  • Page 78 (c) Applying the index setting in the CALL instruction The pulse can be output by using edge relays (V) with the CALL instruction. Note that the pulse cannot be output by the PLS, PLF, or pulse ( P) instruction. [When using an edge relay] [When not using an edge relay] (M0Z1 pulse is output normally.) (M0Z1 pulse is not output normally.)
  • Page 79: Libraries

    Libraries A library is an aggregation of data including POUs, global labels, and structures organized in a single file to be utilized in multiple projects. The following are the advantages of using libraries. • Data in library files can be utilized in multiple projects by installing them to each project. •...
  • Page 80: User Libraries

    4.7.1 User libraries A user library is a library for storing created structures, global labels, POUs, and other data that can be used in other projects. (1) Composition of a user library The following table shows data that can be registered in a user library. Table 4.7.1-1 Composition of a user library Name Description...
  • Page 81: Precautions On Assigning A Name

    Precautions on Assigning a Name This section explains the conditions for assigning a name to a label, function block instance, or structure label. • Conditions (1) Specify a name within 32 characters. (2) Do not use reserved words. For reserved words, refer to the following section. Appendix 2 Character Strings that cannot be Used in Label Names and Data Names (3) Use alphanumeric and underscores (_).
  • Page 82 MEMO 4-58...
  • Page 83: Writing Programs

    WRITING PROGRAMS ST ............5-2 Structured Ladder/FBD.
  • Page 84: Standard Format

    The ST language is a text language with a similar grammatical structure to the C language. Controls such as conditional judgement and repetition process written in syntax can be described. This language is suitable for programming complicated processes that cannot be easily described by a graphic language (structured ladder/FBD language).
  • Page 85: Operators In St Language

    5.1.2 Operators in ST language The following table shows the operators used in the ST program and their priorities. Table 5.1.2-1 Operators in the ST language Operator Description Example Priority Highest Parenthesized expression (1+2)*(3+4) Function ( ) Function (Parameter list) ADD_E(bo01, in01, in02, in03) Exponentiation re01:= 2.0 ** 4.4...
  • Page 86: Syntax In St Language

    5.1.3 Syntax in ST language The following table shows the syntax that can be used in the ST program. Table 5.1.3-1 Syntax in the ST language Type of syntax Description Assignment syntax Assignment syntax IF THEN conditional syntax, IF ELSE conditional syntax, and IF ELSIF conditional syntax Conditional syntax CASE conditional syntax FOR DO syntax...
  • Page 87 (2) IF THEN conditional syntax (a) Format IF <Boolean expression> THEN <Syntax ...>; END_IF; (b) Description The syntax is executed when the value of Boolean expression (conditional expression) is TRUE. The syntax is not executed if the value of Boolean expression is FALSE. Any expression that returns TRUE or FALSE as the result of the Boolean operation with a single bit type variable status, or a complicated expression that includes many variables can be used for the Boolean expression.
  • Page 88 (4) IF ...ELSIF conditional syntax (a) Format IF <Boolean expression 1> THEN <Syntax 1 ...>; ELSIF <Boolean expression 2> THEN <Syntax 2 ...>; ELSIF <Boolean expression 3> THEN <Syntax 3 ...>; END_IF; (b) Description Syntax 1 is executed when the value of Boolean expression (conditional expression) 1 is TRUE.
  • Page 89 (6) FOR...DO syntax (a) Format FOR <Repeat variable initialization> TO <Last value> BY <Incremental expression> DO <Syntax ...>; END_FOR; (b) Description The FOR...DO syntax repeats the execution of several syntax according to the value of a repeat variable. (c) Example (7) WHILE...DO syntax (a) Format WHILE <Boolean expression>...
  • Page 90 (8) REPEAT...UNTIL syntax (a) Format REPEAT <Syntax ...>; UNTIL <Boolean expression> END_REPEAT; (b) Description The REPEAT...UNTIL syntax executes one or more syntax while the value of Boolean expression (conditional expression) is FALSE. The Boolean expression is evaluated after the execution of the syntax. If the value of Boolean expression is TRUE, the syntax in the REPEAT...UNTIL syntax are not executed.
  • Page 91: Calling Functions In St Language

    (10) EXIT syntax (a) Format EXIT; (b) Description The EXIT syntax is used only in iteration syntax to end the iteration syntax in a middle of the process. When the EXIT syntax is reached during the execution of the iteration loop, the iteration loop process after the EXIT syntax is not executed.
  • Page 92: Calling Function Blocks In St Language

    5.1.5 Calling function blocks in ST language The following description is used to call a function block in the ST language. Instance name(Input variable1:= Variable1, ... Output variable1: = Variable2, ...); Enclose the assignment syntax that assigns variables to the input variable and output variable by '( )' after the instance name.
  • Page 93: Precautions When Using Conditional Syntax And Iteration Syntax

    5.1.6 Precautions when using conditional syntax and iteration syntax The following explains the precautions when creating ST programs using conditional syntax and iteration syntax. (1) Once the conditions (boolean expression) are met in the conditional syntax or iteration syntax, the bit device which is turned ON in the <syntax> is always set to ON. •...
  • Page 94 (2) When Q00UCPU, Q00UJCPU or, Q01UCPU is used, and the string type is applied to Boolean expression (conditional expression) with conditional syntax or iteration syntax, a compilation error may occur. • Program example which causes compilation error ST program Compilation error occurs when specifying string type data.
  • Page 95: Structured Ladder/Fbd

    Structured Ladder/FBD The structured ladder/FBD is a graphic language for writing programs using ladder symbols such as contacts, coils, functions, and function blocks. 5.2.1 Standard format Contact Coil Function Ladder block label Function block Left power rail Input variables Output variables In the structured ladder/FBD language, units of ladder blocks are used for programming.
  • Page 96: Ladder Symbols In Structured Ladder/Fbd Language

    5.2.2 Ladder symbols in structured ladder/FBD language The following table shows the ladder symbols that can be used in the structured ladder/FBD language. For details, refer to the following manual. MELSEC-Q/L Structured Programming Manual (Common Instructions) Table 5.2.2-1 Ladder symbols in the structured ladder/FBD language (1/2) Element Ladder symbol Description...
  • Page 97 Table 5.2.2-1 Ladder symbols in the structured ladder/FBD language (2/2) Element Network element Description Pointer branch instruction Jump Unconditionally executes the program at the specified pointer number in the same POUs. Return Indicates the end of a subroutine program. Function Executes a function.
  • Page 98: Executing Order

    5.2.3 Executing order The following figures explain the program executing order. The operation order in a ladder block is from the left power rail to the right and from the top to the bottom. The program is executed from the left power rail to the right when the ladder is not branched and ENs and ENOs are connected in series.
  • Page 99: Ladder Branches And Compilation Results

    5.2.4 Ladder branches and compilation results When the ladder is branched, different compilation results are produced for the program after the branch depending on the program up to the branch. The following explains the precautions on compilation results depending on ladder branches. (1) When one contact is used up to the branch, the instruction of the contact is used multiple times in the compilation result.
  • Page 100 (2) When multiple contacts are used, or a function/function block is used up to the branch, the temporary variable is appended to the branch in the compilation result. Connect the instructions in series as shown in < Precautions > of (1) to avoid using temporary variables in the compilation result.
  • Page 101: Precautions On Creating Programs With Structured Ladder/Fbd

    5.2.5 Precautions on creating programs with structured ladder/FBD The following explains the Precautions on creating a program with structured ladder/FBD. When Q00UCPU, Q00UJCPU, Q01UCPU is used, and the string type is applied to enter the standard comparison functions, a compilation error may occur. •...
  • Page 102 MEMO 5-20...
  • Page 103 APPENDICES Appendix 1 Correspondence between Generic Data Types and Devices ..App-2 Appendix 2 Character Strings that cannot be Used in Label Names and Data Names . . App-6 Appendix 3 Recreating Ladder Programs ....... . . App-9 App-1...
  • Page 104 Appendix 1 Correspondence between Generic Data Types and Devices The following table shows the correspondence between generic data types and devices. Table App. 1-1 Correspondence between generic data types and devices Device Classification Type Device name Device symbol Input Output Internal relay Latch relay Annunciator...
  • Page 105 Generic data type ANY_SIMPLE ANY_NUM ANY_BIT ANY_INT ANY_REAL Double Array Structure Word Double Single- Double- Time String word Word (unsigned)/ word precision precision ANY16 ANY32 (unsigned)/ (signed) 16-bit string (signed) real real 32-bit string       ...
  • Page 106 Device Classification Type Device name Device symbol Link input Jn\X Link output Jn\Y Bit device Link relay Jn\B Link direct device Link special relay Jn\SB Link register Jn\W Word device Link special register Jn\SW Intelligent function module Word device Intelligent function module device Un\G device Index register...
  • Page 107 Generic data type ANY_SIMPLE ANY_NUM ANY_BIT ANY_INT ANY_REAL Double Array Structure Word Double Single- Double- Time String word Word (unsigned)/ word precision precision ANY16 ANY32 (unsigned)/ (signed) 16-bit string (signed) real real 32-bit string       ...
  • Page 108 Appendix 2 Character Strings that cannot be Used in Label Names and Data Names Character strings used for application function names, common instruction names, special instruction names, and instruction words are called reserved words. These reserved words cannot be used for label names or data names. If the character string defined as a reserved word is used for a label name or data name, an error occurs during registration or compilation.
  • Page 109 Table App. 2-1 Character strings that cannot be used for label names and data names (2/3) Category Character string LD, LDN, ST, STN, S, S1, R, R1, AND, ANDN, OR, ORN, XOR, XORN, ADD, SUB, MUL, DIV, GT, GE, EQ, NE, LE, LT, JMP, JMPC, JMPCN, CAL, CALC, CALCN, RET, RETC, RETCN IL operator...
  • Page 110 Table App. 2-1 Character strings that cannot be used for label names and data names (3/3) Category Character string String that starts with K1  Such as K1AAA to K8 Address Such as %IX0 ;FB BLK START, ;FB START, ;FB END, ;FB BLK END, ;FB IN, ;FB Statement in ladder OUT, ;FB_NAME;,INSTANCE_NAME, language...
  • Page 111: Appendix 3.1Procedure For Creating A Structured Program

    Appendix 3 Recreating Ladder Programs This section provides an example of creating a structured program same as the program created in the ladder programming language using GX Works2. Appendix 3.1 Procedure for creating a structured program The following explains the basic procedure for creating a structured program based on the program created in the ladder programming language.
  • Page 112: Appendix 3.2Example Of Creating A Structured Program

    Appendix 3.2 Example of creating a structured program This section shows an example of creating a sequence program same as the program created in GX Developer using GX Works2. The following examples explain the method for creating a structured program same as the data receive program for a Q-compatible serial communication module, using the structured ladder/ FBD and ST languages.
  • Page 113 (2) Setting labels Set global labels and local labels. • Setting examples of global labels • Setting examples of local labels *1: Devices of local labels are automatically assigned within the range specified in the device/label automatic-assign setting in GX Works2. To assign the same devices as those in the original ladder program, set them as global labels.
  • Page 114 (3) Creating a structured program The following examples show how a structured program is created based on the original program. • Original program (Programming language: ladder) • Structured program (Programming language: structured ladder/FBD) Appendix 3 Recreating Ladder Programs App-12 Appendix 3.2 Example of creating a structured program...
  • Page 115 • Original program (Programming language: ladder) • Structured program (Programming language: ST) *1: When using multiple contacts for execution conditions, enclose them by '( )' to be programmed in a group. Appendix 3 Recreating Ladder Programs App-13 Appendix 3.2 Example of creating a structured program...
  • Page 116 MEMO App-14...
  • Page 117 INDEX Index-1...
  • Page 118 [Numeric character] 32-bit index setting ..........4-45 operators ..............5-3 output variables ..........4-10,4-16 address ............4-39,4-40 array ..............4-35 POU................. 4-5 precautions on assigning label names ....4-57 priority..............4-4 Bit data ..............4-22 program ..............4-5 program blocks............4-6 program components ........
  • Page 119 WARRANTY Please confirm the following product warranty details before using this product. 1. Gratis Warranty Term and Gratis Warranty Range If any faults or defects (hereinafter "Failure") found to be the responsibility of Mitsubishi occurs during use of the product within the gratis warranty term, the product shall be repaired at no cost via the sales representative or Mitsubishi Service Company.
  • Page 120 Mcrosoft, Windows, Windows Vista, Windows NT, Windows XP, Windows Server, Visio, Excel, PowerPoint, Visual Basic, Visual C++, and Access are either registered trademarks or trademarks of Microsoft Corporation in the United States, Japan, and other countries. Pentium is a trademark of Intel Corporation in the United States and other countries. Ethernet is a registered trademark of Xerox Corp.
  • Page 122 SH-080782ENG-M(1307)KWIX MODEL: Q/FX-KP-KI-E MODEL CODE: 13JW06 HEAD OFFICE : TOKYO BUILDING, 2-7-3 MARUNOUCHI, CHIYODA-KU, TOKYO 100-8310, JAPAN NAGOYA WORKS : 1-14 , YADA-MINAMI 5-CHOME , HIGASHI-KU, NAGOYA , JAPAN When exported from Japan, this manual does not require application to the Ministry of Economy, Trade and Industry for service transaction permission.

This manual is also suitable for:

Melsec l seriesMelsec-f

Table of Contents