The text of a manual · part 4 of 11
MELSEC FX Family Programmable Logic Controllers Beginners Manual, pages 31 to 40
Pages 31 to 40 of 106
The original document is the PDF (969 KB). This is its text as extracted, unedited; tables and drawings read best in the PDF, and each page heading opens it at that page.
For the Mitsubishi FX2NC-32MT
Page 31
An Introduction to Programming
3.4
The Basic Instruction Set
The Basic Instruction Set The instructions of the PLCs of the MELSEC FX family can be divided into two basic categories, basic instructions and applied instructions, which are sometimes referred to as “application instructions”. The functions performed by the basic instructions are comparable to the functions achieved by the physical wiring of a hard-wired controller. All controllers of the MELSEC FX family support the instructions in the basic instruction set, but the applied instructions supported vary from model to model (see Chapter 5). Basic instruction set quick reference
Instruction
Function
Description
LD
Load
Initial logic operation, polls for signal state “1” (normally open)
LDI
Load invers
Initial logic operation, polls for signal state “0” (normally closed)
OUT
Output instruction
Assigns the result of a logic operation to a device
AND
Logical AND
Logical AND operation, polls for signal state “1”
ANI
AND NOT
Logical AND NOT operation, polls for signal state “0”
OR
Logical OR
Logical OR operation, polls for signal state “1”
ORI
OR NOT
Logical OR NOT operation, polls for signal state “0"
ANB
AND Block
Connects a parallel branch circuit block to the preceding parallel block, in series.
ORB
OR Block
Connects a serial block of circuits to the preceding serial block, in parallel.
LDP
Load Pulse, load on detection of rising edge of device signal pulse
LDF
Load Falling Pulse, load on falling device signal pulse
ANDP ANDF
Pulse signal instructions
AND Pulse, logical AND on rising device signal pulse AND Falling Pulse, logical AND on falling device signal pulse
ORP
OR Pulse, logical OR on rising device signal pulse
ORF
OR Falling Pulse, logical OR on falling device signal pulse
SET
Set device
RST
Reset device
MPS MRD MPP
Store, read and delete intermediate operation results
PLS Pulse instructions PLF
Assigns a signal state that is retained even if after input condition is no longer true
Reference Chapter 3.4.1 Chapter 3.4.2 Chapter 3.4.4
Chapter 3.4.5
Chapter 3.4.6
Chapter 3.4.7
Chapter 3.4.8
Memory Point Store, store an operation result in the stack Memory Read, read a stored operation result from the stack
Chapter 3.4.9
Memory POP, read a stored operation result and delete it from the stack Pulse, sets a device for one operation cycle on the rising pulse of the input condition (input turns ON) Pulse Falling, sets a device* for one operation cycle on the falling pulse of the input condition (input turns OFF)
Chapter 3.4.10
MC
Master Control
MCR
Master Control Reset
Instructions for activating or deactivating the execution of defined parts of the program
Chapter 3.4.11
INV
Invert
Inverts the result of an operation
Chapter 3.4.12
FX Beginners Manual
3–5
Page 32
The Basic Instruction Set
3.4.1
An Introduction to Programming
Starting logic operations Instruction
Function
Symbol
GX Developer FX
LD
Load instruction, starts a logic operation and polls the specified device for signal state “1”
F5
LDI
Load instruction, starts a logic operation and polls the specified device for signal state “0”
F6
A circuit in a program always begins with an LD- or LDI instruction. These instructions can be performed on inputs, relays, timers and counters. For examples of using these instructions see the description of the OUT instruction in the next section.
3.4.2
Outputting the result of a logic operation Instruction OUT
Function
Symbol
GX Developer FX
Output instruction, assigns the result of an operation to a device
F7
The OUT instruction can be used to terminate a circuit. You can also program circuits that use multiple OUT instructions as their result. This is not necessarily the end of the program, however. The device set with the result of the operation using OUT can then be used as an input signal state in subsequent steps of the program. Example (LD and OUT instructions) Instruction List
Ladder Diagram
X000 0
Y000
0 1
LD OUT
X000 Y000
These two instructions result in the following signal sequence: ON (1)
X0
OFF (0) ON (1)
Y0 OFF (0)
The condition of the LD instruction (poll for signal state “1”) is true so the result of the operation is also true (“1”) and the output is set.
3–6 t
MITSUBISHI ELECTRIC
Page 33
An Introduction to Programming
The Basic Instruction Set
Example (LDI and OUT instructions) Ladder Diagram
Instruction List
X000 0
0 1
Y000
LDI OUT
X000 Y000
ON (1)
X0
OFF (0) ON (1)
Y0 OFF (0)
The condition of the LDI instruction (poll for signal state “0”) is no longer true so the output is reset.
t
Double assignment of relays or outputs Never assign the result of an operation to the same device in more than one place in the program! The program is executed sequentially from top to bottom, so in this example the second assignment of M10 would simply overwrite the result of the first assignment.
You can solve this problem with modification shown on the right. This takes all the required input conditions into account and sets the result correctly.
FX Beginners Manual
X001
X003 M10
X004
X005 M10
X001
X003 M10
X004
X005
3–7
Page 34
The Basic Instruction Set
3.4.3
An Introduction to Programming
Using switches and sensors Before we continue with the description of the rest of the instructions we should first describe how signals from switches, sensors and so on can be used in your programs. PLC programs need to be able respond to signals from switches, buttons and sensors to perform the correct functions. It is important to understand that program instructions can only poll the binary signal state of the specified input – irrespective of the type of input and how it is controlled.
Make contact
When a make contact is operated the input is set (ON, signal state “1”)
Break contact
When a break contact is operated the input is reset (OFF, signal state “0”)
As you can imagine, this means that when you are writing your program you need to be aware whether the element connected to the input of your PLC is a make or a break device. An input connected to a make device must be treated differently to an input connected to a break device. The following example illustrates this.
Usually, switches with make contacts are used. Sometimes, however, break contacts are used for safety reasons – for example for switching off drives (see section 3.5). The illustration below shows two program sequences in which the result is exactly the same, even though different switch types are used: When the switch is operated the output is set (switched on). 24 V LD X000 OUT Y000
X000 0
Y000
X0 Switch operated ON
X0
OFF ON
Y0 OFF t 24 V LDI X000 OUT Y000
X000 0
Y000
X0
Switch operated ON
X0
OFF ON
Y0 OFF t
3–8
MITSUBISHI ELECTRIC
Page 35
An Introduction to Programming
3.4.4
The Basic Instruction Set
AND operations Instruction
Function
Symbol
AND
Logical AND (AND operation with poll for signal state “1” or ON)
ANI
Logical AND NOT (AND operation with poll for signal state “0” or OFF)
GX Developer FX
F5 F6
An AND operation is logically the same as a serial connection of two or more switches in an electrical circuit. Current will only flow if all the switches are closed. If one or more of the switches are open no current flows – the AND condition is false.
Note that the programming software uses the same icons and function keys for the AND and ANI instructions as for the LD and LDI instructions. When you program in Ladder Diagram format the software automatically assigns the correct instructions on the basis of the insertion position. When you program in Instruction List format remember that you can’t use the AND and ANI instructions at the beginning of circuit (a program line in ladder diagram format)! Circuits must begin with an LD or LDI instruction (see Chapter 3.4.1). Example of an AND instruction Ladder Diagram
Instruction List AND instruction
X000
X001
0
Y000
0 1 2
LD AND OUT
X000 X001 Y000
In the example output Y0 is only switched on when inputs X0 and X1 are both on: ON (1)
X0
OFF (0) ON (1)
X1
OFF (0) ON (1)
Y0 OFF (0)
t
FX Beginners Manual
3–9
Page 36
The Basic Instruction Set
An Introduction to Programming
Example of an ANI instruction Instruction List
Ladder Diagram ANI instruction
X000
X001
0
Y000
0 1 2
LD ANI OUT
X000 X001 Y000
In the example output Y0 is only switched on when input X0 is on and input X1 is off: ON (1)
X0
OFF (0) ON (1)
X1
OFF (0) ON (1)
Y0 OFF (0)
t
3 – 10
MITSUBISHI ELECTRIC
Page 37
An Introduction to Programming
3.4.5
The Basic Instruction Set
OR operations Instruction
Function
Symbol
OR
Logical OR (OR operation with poll for signal state “1” or ON)
ORI
Logical OR NOT (OR operation with poll for signal state “0” or OFF)
GX Developer FX
F5 F6
An OR operation is logically the same as the parallel connection of multiple switches in an electrical circuit. As soon as any of the switches is closed current will flow. Current will only stop flowing when all the switches are open.
Example of an OR instruction Instruction List
Ladder Diagram
X000 0
Y000
0 1 2
LD OR OUT
X000 X001 Y000
X001 OR instruction
In the example output Y0 is switched on when either input X0 or input X1 is on: ON (1)
X0
OFF (0) ON (1)
X1
OFF (0) ON (1)
Y0 OFF (0)
t
FX Beginners Manual
3 – 11
Page 38
The Basic Instruction Set
An Introduction to Programming
Example of an ORI instruction Ladder Diagram
Instruction List
X000 0
0 1 2
Y000
LD ORI OUT
X000 X001 Y000
X001 ORI instruction
In the example output Y0 is switched on when either input X0 is on or input X1 is off: ON (1)
X0
OFF (0) ON (1)
X1
OFF (0) ON (1)
Y0 OFF (0)
t
3.4.6
Instructions for connecting operation blocks Instruction
Function
ANB
AND Block (serial connection of blocks of parallel operations/circuits)
ORB
OR Block (parallel connection of blocks of serial operations/circuits)
Symbol
GX Developer FX
F9 uF9
Although ANB- and ORB are PLC instructions they are only displayed and entered as connecting lines in the Ladder Diagram display. They are only shown as instructions in Instruction List format, where you must enter them with their acronyms ANB and ORB. Both instructions are entered without devices and can be used as often as you like in a program. However, the maximum number of LD and LDI instructions is restricted to 8, which effectively also limits the number of ORB or ANB instructions you can use before an output instruction to 8 as well.
3 – 12
MITSUBISHI ELECTRIC
Page 39
An Introduction to Programming
The Basic Instruction Set
Example of an ANB instruction Ladder Diagram ANB instruction
X000
X001
0
Y007 M2
M10
Instruction List 0 1 2 3 4 5
LD ORI LDI OR ANB OUT
X000 M2 X001 M10
1st parallel connection (OR operation) 2nd parallel connection (OR operation) ANB instruction connecting both OR operations
Y007
In this example output Y07 is switched on if input X00 is “1”, or if relay M2 is “0” and input X01 is “0”, or if relay M10 is “1”. Example of an ORB instruction Ladder Diagram
X000
X001
0
Y007 M2
ORB instruction
M10
Instruction List 0 1 2 3 4 5
LD ANI LDI AND ORB OUT
X000 X001 M2 M10 st
1 serial connection (AND operation) 2nd serial connection (AND operation) ORB instruction connecting both AND operations
Y007
In this example output Y07 is switched on if input X00 is “1” and input X01 is “0”, or if relay M2 is “0” and relay M10 is “1”.
FX Beginners Manual
3 – 13
Page 40
The Basic Instruction Set
3.4.7
An Introduction to Programming
Pulse-triggered execution of operations Instruction
Function
Symbol
LDP
Load Pulse, loads on the rising edge of the device’s signal
LDF
Load Falling Pulse, loads on the falling edge of the device’s signal
ANDP
AND Pulse, logical AND operation on the rising edge of the device’s signal
ANDF
AND Falling Pulse, logical AND operation on the falling edge of the device’s signal
ORP
OR Pulse, logical OR operation on the rising edge of the device’s signal
ORF
OR Falling Pulse, logical OR operation on the falling edge of the device’s signal
GX Developer FX
In PLC programs you will often need to detect and respond to the rising or falling edge of a bit device’s switching signal. A rising edge indicates a switch of the device value from “0” to “1”, a falling edge indicates a switch from “1” to “0”. During program execution operations that respond to rising and falling pulses only deliver a value of “1” when the signal state of the referenced device changes. When do you need to use this? For example, suppose you have a conveyor belt with a sensor switch that activates to increment a counter every time a package passes it on the belt. If you don’t use a pulse-triggered function you will get incorrect results because the counter will increment by 1 in every program cycle in which the switch registers as set. If you only register the rising pulse of the switch signal the counter will be incremented correctly, increasing by 1 for each package. Note
Most applied instructions can also be executed by pulse signals. For details see chapter . 5). Evaluating a rising signal pulse Instruction List
Ladder Diagram
X001 M0
0
0 1
LDP OUT
X001 M0
ON (1)
X1
OFF (0) 1
M0 0
Relay M0 is only switched on for the duration of a single program cycle
3 – 14 t
MITSUBISHI ELECTRIC