Mitsubishi Electric MELSEC Q Series Programming Manual

Mitsubishi Electric MELSEC Q Series Programming Manual

Structured. fundamentals
Hide thumbs Also See for MELSEC Q Series:
Table of Contents

Quick Links

MELSEC-Q/L/F Structured
Programming Manual (Fundamentals)
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. Make sure that the end users read the manuals included with each product, and keep the manuals in a safe place for future reference.
  • Page 4: Introduction

    INTRODUCTION Thank you for purchasing the Mitsubishi Electric 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.
  • Page 5 MEMO...
  • Page 6: Table Of Contents

    CONTENTS SAFETY PRECAUTIONS ..............1 CONDITIONS OF USE FOR THE PRODUCT .
  • Page 7 Device ................. 52 Address .
  • Page 8: Manuals

    MANUALS Related Manuals The manuals related to this product are listed below. Please place an order as needed. ■Structured programming Manual name Description MELSEC-Q/L Structured Programming Manual (Common Specifications and functions of common instructions, such as sequence instructions, basic Instructions) instructions, and application instructions, that can be used in structured programs ...
  • Page 9: 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 Application function A generic term for the functions, such as functions and function blocks, defined in IEC 61131-3. (The functions are executed with a set of common instructions in a programmable controller.) Basic model QCPU A generic term for the Q00JCPU, Q00CPU, and Q01CPU...
  • Page 10: Chapter 1 Overview

    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.
  • Page 11 Details of instructions in each programming language ■QCPU (Q mode)/LCPU Purpose Summary Detail   User's Manual (Hardware Design, All languages Learning details of programmable controller CPU error codes, special Maintenance and Inspection) for the CPU relay areas, and special register areas module used Using ladder Learning the types and details of...
  • Page 12: Features Of Structured Programs

    Features of Structured Programs This section explains the features of structured programs. 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. A user can design programs knowing the component structures of sequence programs by using the structured programming.
  • Page 13: Chapter 2 Structured Design Of Sequence Programs

    STRUCTURED DESIGN OF SEQUENCE PROGRAMS 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 14: Structured Sequence Program

    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. Each component is designed to have a high degree of independence for easy addition and replacement.
  • Page 15: Chapter 3 Procedure For Creating Programs

    PROCEDURE FOR CREATING PROGRAMS This section explains the basic procedure for creating a sequence program in the Structured project. Creating the program configuration • Create program files. • Create tasks. Creating POUs • Create POUs. • Define global labels. • Define local labels. •...
  • Page 16 MEMO 3 PROCEDURE FOR CREATING PROGRAMS...
  • Page 17: Chapter 4 Program Configuration

    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. Item Reference Projects Page 16 Project Program files Page 16 Program files Tasks Page 17 Tasks...
  • Page 18: Project

    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. 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 19: Tasks

    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 20: Pous

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

    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. For a simplest sequence program, only one program needs to be created and registered to a task in order to be executed in a programmable controller CPU.
  • Page 22: Function Blocks

    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 23: Operators

    Operators Operators can be used by calling them from programs, functions, or function blocks. Operators cannot be edited. Operators always output same processing results for the same input values. 4 PROGRAM CONFIGURATION 4.2 POUs...
  • Page 24: Ladder Blocks

    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. Ladder block label Jump instruction Ladder block...
  • Page 25: Programming Languages For Pous

    Programming languages for POUs Two types of programming language are available for programs of POU. The following explains the features of each programming language. 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 26: Functions, Function Blocks, And Operators

    Functions, function blocks, and operators The following table shows 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 Used Not used Creating instances Not necessary Necessary...
  • Page 27 Internal variables A function does not use internal variables. It uses devices assigned directly to each input variable and repeats operations. A program that outputs the total of three input variables When using a function (FUN1) Function D109 D109 FUN1 D120 D110 D110...
  • Page 28 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. Same function blocks can be instantiated with different names in a single POU.
  • Page 29: En And Eno

    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 30 Precautions The following example shows that the operation results an undefined value. When Variable_1 is OFF, the MOV or SET instruction is executed though the ADD_E or TEST instruction is not executed. Even though Variable_1 is OFF, a value may be set in D2 by the MOV instruction or M1 may turn ON by the SET instruction. Input ENO of the first instruction to EN of the next instruction not to perform the sequential operation when EN is OFF.
  • Page 31: Labels

    Labels Labels include global labels and local labels. 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. Local labels The local labels are labels that can be used only in declared POUs.
  • Page 32: Label Classes

    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. Class Description Applicable POU Program Function Function block VAR_GLOBAL Common label that can be used in programs and function blocks...
  • Page 33: Setting Labels

    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 34: Data Types

    Data types Labels are classified into several data types according to the bit length, processing method, or value range. The following data types are available. • Elementary data types • Generic data types Elementary data types The following data types are available as the elementary data type. •...
  • Page 35 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 36: Expressing Methods Of Constants

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

    Method for Specifying Data The following shows the seven types of data that can be used for instructions in CPU modules. Data that can be handled by CPU module Reference Bit data Page 36 Bit data Numeric data Integer data Word (Signed) data Page 37 Word (16 bits) data Double word (Signed) data...
  • Page 38: Bit Data

    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. 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 39: Word (16 Bits) Data

    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: K-32768 to K32767 •...
  • Page 40 The following table shows the numeric values that can be used as source data when digits are specified at the source (s). Number of specified digits Value range K1 (4 points) 0 to 15 K2 (8 points) 0 to 255 K3 (12 points) 0 to 4095 K4 (16 points)
  • Page 41: Double Word (32 Bits) Data

    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: K-2147483648 to K2147483647 •...
  • Page 42 The following table shows the numeric values that can be used as source data when digits are specified at the source (s). Number of specified digits Value range Number of specified digits Value range K1 (4 points) 0 to 15 K5 (20 points) 0 to 1048575 K2 (8 points)
  • Page 43 When digits are specified at the destination (d), the points by the specified digit are the target of destination. (Data_d1:K5M0, Data_d2:K5M10, Data_s:D0) Bit devices below the number of points designated as digits do not change. Ladder example Processing • When the source (s) is a numeric value H78123456 0 0 1 1 DMOV...
  • Page 44: Single-Precision Real/Double-Precision Real Data

    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. For FXCPU, double-precision real data is not supported. Real number data can be stored only in word devices. Single-precision real (single-precision floating-point data) Devices used in lower 16 bits are specified for instructions that use real number data.
  • Page 45 Double-precision real (double-precision floating-point data) Devices used in lower 16 bits are specified for instructions that use real number data. Real number data are stored in 64 bits of 'specified device number' and 'specified device number + 3'. Transfers real number data EDMOV Var_R100 Var_D0...
  • Page 46 Precautions Precautions when an input value of a single/double-precision real number is set using a programming tool are shown below. ■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.
  • Page 47 Floating-point data in a CPU module can be monitored by the monitoring function of the programming tool. To express 0 in floating-point data, set all of the following bits to 0. • Single-precision floating-point data: b0 to b31 • Double-precision floating-point data: b0 to b63 The setting range of floating decimal point data is as follows.
  • Page 48: String Data

    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. When the specified character is NULL code The NULL code is stored by using one word.
  • Page 49: Time Data

    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 50: Arrays

    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. •...
  • Page 51 Expression of arrays To identify individual labels of an array, append an index enclosed by '[ ]' after the label name. Values that can be specified for indexes are within the range from -32768 to 32767. For an array with two or more dimensions, delimit indexes in '[ ]' by ','. Example) boolary1 [0] boolary2 [0.3]...
  • Page 52 Maximum number of array elements The maximum number of array elements differs depending on data types as shown below. Data type Maximum number Bit, word (signed), word (unsigned)/16-bit string, timer, counter, and retentive timer 32768 Double word (signed), double word (unsigned)/32-bit string, single-precision real, and time 16384 Double-precision real 8192...
  • Page 53: Structures

    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 (...
  • Page 54: 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 IEC 61131-3. In this format, a device name starts with %. Device Device is a format that uses a device name and a device number.
  • Page 55: Address

    Address Address is a format defined in IEC 61131-3. The following table shows details of format that conforms to IEC 61131-3. Start 1st character: 2nd character: data size 3rd character and later: Number position classification I: Input (Omitted) Numeric characters used for detailed Number corresponding to the Q: Output classification.
  • Page 56: Correspondence Between Devices And Addresses

    Correspondence between devices and addresses This section explains the correspondence between devices and addresses. Correspondence between devices and addresses The following table shows the correspondence between devices and addresses. ■QCPU (Q mode)/LCPU Device Expressing method Example of correspondence between device and address Device Address Device...
  • Page 57 Device Expressing method Example of correspondence between device and address Device Address Device Address SFC block device %MX17.n %MX17.3 Link input Jx\Xn %IX16.x.n J1\X1FFF %IX16.1.8191 Link output Jx\Yn %QX16.x.n J1\Y1FFF %QX16.1.8191 Link relay Jx\Bn %MX16.x.1.n J2\B3FFF %MX16.2.1.16383 Link register Jx\Wn %MW16.x.1.n J2\W3FFF %MW16.2.1.16383...
  • Page 58 Digit specification of bit devices The following table shows the correspondence between devices and addresses when specifying digits of bit devices. Device Address K[Number of digits][Device name][Device number](Number of digits: 1 to %[Position of memory area][Data size]19.[Number of digits].[Classification].[Number] (Number of digits: 1 to 8) •...
  • Page 59: Index Setting

    Index Setting Overview of the index setting 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 60 • Devices with restrictions on index registers*3 Device Description Example T, ST • Only Z0 or Z1 can be used for contacts or coils of the TS0Z0 OUT_T timer. TC1Z1 • Only Z0 or Z1 can be used for contacts or coils of the CS0Z1 OUT_C counter.
  • Page 61 ■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 K2X50Z0 K2X(50 + 14) = K2X64 Converts K20 to a hexadecimal number. K1M38Z1 K1M(38 - 5) = K1M33 K2X50Z0...
  • Page 62 32-bit index setting For Universal model QCPU (excluding Q00UJCPU) and LCPU, either of the following two methods can be selected to specify index registers used for a 32-bit index setting. • Specify a range of index registers used for a 32-bit index setting. •...
  • Page 63 • Devices that can be used for index settings Only the following devices can be used for index settings. Device Description Serial number access file register Extended data register Extended link register • 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 64 ■Specifying a 32-bit index setting using 'ZZ' 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 65 • 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 66 Applying index settings to extended data registers (D) and extended link registers (W) 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). The index setting applied to D device image the internal user device...
  • Page 67 ■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. However, if the result of the index setting applied to file registers (ZR), extended data registers (D) or extended link registers (W) exceeds the range of the file register files, an error occurs.
  • Page 68 Other applicable data For bit data, an index setting is applicable to device numbers whose digits are specified. Note that an index setting is not applicable to the digit-specified bit device. K4X0Z2 Index setting is applicable to the device number, If Z2=3, then (X0+3)=X3 K4Z3X0 Index setting is not applicable...
  • Page 69 Precautions ■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 <> 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" at the compilation.
  • Page 70 ■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.
  • Page 71 • For the QnUDVCPU and QnUDPVCPU: The device range is checked during index modification. It is also possible not to allow checking the device range using the parameters. The timings for checking the device change during index modification are shown below. Instruction Timings for checking Contact Instructions...
  • Page 72: 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 73: User Libraries

    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. Composition of a user library The following table shows data that can be registered in a user library. Name Description Structure...
  • Page 74: 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. • Specify a name within 32 characters. • Do not use reserved words. For reserved words, refer to the following section. Page 100 Character Strings That Cannot Be Used in Label Names and Data Names •...
  • Page 75: Chapter 5 Writing Programs

    WRITING PROGRAMS The ST language is a text language with a similar grammatical structure to the C language. Controls such as conditional judgment 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 76: Operators In St Language

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

    Syntax in ST language The following table shows the syntax that can be used in the ST program. Type of syntax Description Assignment syntax Assignment syntax Assignment syntax Page 75 Assignment syntax Conditional syntax IF conditional syntax IF THEN conditional syntax Page 76 IF THEN conditional syntax IF ELSE conditional syntax Page 76 IF ...ELSE conditional syntax...
  • Page 78 IF THEN conditional syntax ■Format IF THEN ; END_IF; ■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 79 IF ...ELSIF conditional syntax ■Format IF THEN ; ELSIF THEN ; ELSIF THEN ; END_IF; ■Description Syntax 1 is executed when the value of Boolean expression (conditional expression) 1 is TRUE. Syntax 2 is executed when the value of Boolean expression 1 is FALSE and the value of Boolean expression 2 is TRUE.
  • Page 80 FOR...DO syntax ■Format FOR TO BY DO ; END_FOR; ■Description First, initialize the data to be used as an iteration variable. One or more statements between the DO statement and the END_FOR statement are executed repeatedly, adding or subtracting the initialized iteration variable according to the increase expression until the final value is exceeded.
  • Page 81 REPEAT...UNTIL syntax ■Format REPEAT ; UNTIL END_REPEAT; ■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 82 EXIT syntax ■Format EXIT; ■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. The process continues from the line after the one where the iteration syntax is ended.
  • Page 83: Calling Functions In St Language

    Calling functions in ST language The following description is used to call a function in the ST language. Description of calling functions Function name (Variable1, Variable2, ...); Enclose the arguments by '( )' after the function name. When using multiple variables, delimit them by ','. The execution result of the function is stored by assigning the result to the variables.
  • Page 84: Precautions When Using Conditional Syntax And Iteration Syntax

    Precautions when using conditional syntax and iteration syntax The following explains the precautions when creating ST programs using conditional syntax and iteration syntax. Precaution 1 Once the conditions (boolean expression) are met in the conditional syntax or iteration syntax, the bit device which is turned ON in the ...
  • Page 85 Precaution 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 86 Precaution 3 The following table lists operations when the STMR instruction or instructions that are executed at the rising or falling edge are used in the IF or CASE conditional statement. Condition Operation result Conditional Instruction On/off On/off Rising edge Falling edge STMR formula of IF or...
  • Page 87: Operations When The Master Control Instruction Is Used

    Operations when the master control instruction is used Operations between the MC and MCR instructions when the master control is off will be as follows. • Off is assigned to the assignment statement (bit). • The assignment statement (word) performs no processing. •...
  • Page 88: 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. Standard format Contact Coil Function Function block Ladder block label Left power rail Input variables Output variables In the structured ladder/FBD language, units of ladder blocks are used for programming.
  • Page 89: Ladder Symbols In Structured Ladder/Fbd Language

    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) Element Ladder symbol Description *1*2 Normal Turns ON when a specified device or label is ON...
  • Page 90 Element Ladder symbol Description Function return value Outputs the return value from a function or function block. output Function inverted Inverts and inputs an argument to a function or function block. argument input Function inverted return Inverts the return value from a function or function block and outputs it value output *1 Not applicable in FBD.
  • Page 91: Executing Order

    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 92 The program is executed from the top to the bottom, when the ladder is branched and ENs and ENOs are connected in parallel. The program is executed in the order as shown below when the MOV instruction (4) in the above figure is moved to the top. Move to the top 5 WRITING PROGRAMS 5.2 Structured Ladder/FBD...
  • Page 93: Ladder Branches And Compilation Results

    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. One contact is used up to the branch The instruction of the contact is used multiple times in the compilation result.
  • Page 94: Precautions On Creating Programs With Structured Ladder/Fbd

    Multiple contacts are used up to the branch The temporary variable is appended to the branch in the compilation result. < Example > < Compilation result > The operation result up to the branch is output to the temporary variable. Temporary variable is appended.
  • Page 95: Appendices

    APPENDICES Appendix 1 Correspondence Between Generic Data Types and Devices The following table shows the correspondence between generic data types and devices. Internal user device Bit device Device Generic data type Device name Device symbol ANY_SIMPLE ANY_BIT ANY_NUM Time String ANY_INT ANY_REAL Word...
  • Page 96 Word device Device Generic data type Device name Device symbol ANY_SIMPLE ANY_BIT ANY_NUM Time String ANY_INT ANY_REAL Word Double Word Double Single- Double- (unsigned) word (signed) word precision precision /16-bit (unsigned) (signed) real real string /32-bit string    ...
  • Page 97: Internal System Device

    Internal system device Bit device Device Generic data type Device name Device symbol ANY_SIMPLE ANY_BIT ANY_NUM Time String ANY_INT ANY_REAL Word Double Word Double Single- Double- (unsigned) word (signed) word precision precision /16-bit (unsigned) (signed) real real string /32-bit string ...
  • Page 98: Link Direct Device

    Link direct device Bit device Device Generic data type Device name Device symbol ANY_SIMPLE ANY_BIT ANY_NUM Time String ANY_INT ANY_REAL Word Double Word Double Single- Double- (unsigned) word (signed) word precision precision /16-bit (unsigned) (signed) real real string /32-bit string Link input Jn\X ...
  • Page 99: Intelligent Function Module Device

    Intelligent function module device Word device Device Generic data type Device name Device symbol ANY_SIMPLE ANY_BIT ANY_NUM Time String ANY_INT ANY_REAL Word Double Word Double Single- Double- (unsigned) word (signed) word precision precision /16-bit (unsigned) (signed) real real string /32-bit string ...
  • Page 100: File Register

    File register Word device Device Generic data type Device name Device symbol ANY_SIMPLE ANY_BIT ANY_NUM Time String ANY_INT ANY_REAL Word Double Word Double Single- Double- (unsigned) word (signed) word precision precision /16-bit (unsigned) (signed) real real string /32-bit string File register R or ZR ...
  • Page 101: Constant

    Constant Device Generic data type Device name Device symbol ANY_SIMPLE ANY_BIT ANY_NUM Time String ANY_INT ANY_REAL Word Double Word Double Single- Double- (unsigned) word (signed) word precision precision /16-bit (unsigned) (signed) real real string /32-bit string  K, H  ...
  • Page 102: Appendix 2 Character Strings That Cannot Be Used In Label Names And Data Names

    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 103 Category Character string          Application instruction Application instructions such as DMOD, PCHK, INC(P) in GX Works2 For details, refer to the following. • QCPU (Q mode)/LCPU  MELSEC-Q/L Programming Manual (Common Instruction) ...
  • Page 104 Precautions on using labels • In a function, the same name as the function cannot be used for a label. • A space cannot be used. • A numeral cannot be used at the beginning of label name. • A label name is not case-sensitive. An error may occur at compilation when the same label names with different cases (example: 'AAA' and 'aaa') are declared.
  • Page 105: Appendix 3 Recreating Ladder Programs

    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. 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 106: Example Of Creating A Structured Program

    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 107 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 108 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) APPX Appendix 3 Recreating Ladder Programs...
  • Page 109 • 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. APPX Appendix 3 Recreating Ladder Programs...
  • Page 110: Index

    INDEX 0 to 9 ..... . 57 ......7 16-bit index setting IEC 61131-3 .
  • Page 111 ..... . . 10 Structured design ..... . . 86 Structured ladder .
  • Page 112: Revisions

    Japanese manual number: SH-080735-T This manual confers no industrial property 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 113: Warranty

    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 114: Trademarks

    TRADEMARKS Microsoft and Windows are either registered trademarks or trademarks of Microsoft Corporation in the United States and/or other countries. The company names, system names and product names mentioned in this manual are either registered trademarks or trademarks of their respective companies. ...
  • Page 116 SH(NA)-080782ENG-O(1809)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 f seriesMelsec l series

Table of Contents