Basic Instructions for Programmable Controllers
Basic Instructions for Programmable Controllers
A programmable controller is assemblies of relays, timers, and counters. The internal sequences can be
wired by programming for a programmable controller.
Rules according to the contact, connection type of coil, or the coil type are required for the wiring, and
this rule is called instruction.
Some instructions contain instruction words and device numbers, others have only instruction words to
operate.
This chapter introduces basic instructions for the programming of the programmable controller.
Remember the meaning of each instruction.
2.1.1 Instruction
ANB
Series connection of blocks
And block
ORB
Parallel connection of blocks
Or block
OUT ***
Coil drive instruction ( )
Out
SET Operation hold output ***
instruction
SET (S)
Set
RST Operation hold cancel ***
instruction
RET (R)
Reset
PLS Turns on the specified device ***
for one scan at rising edge of PLS |P|
Pulse an input condition
PLF Turns on the specified device ***
for one scan at falling edge of PLF |N|
Pulf an input condition
END End of the program and return to
Program end
End step 0
2-1
2.1.2 LD, LDI, OUT, and END instructions
Step Instruction
This line is called a "bus". 0 LD X0
OUT (Note 2)
LD (Note 1) 1 OUT Y10
X0
0 Y10 2 LDI X0
X0 3 OUT Y11
2 Y11 4 END
LDI (Note 1)
[Step number]
4 END
The step number indicates the order of the
program and the program size.
When the instructions are programmed
according to the order of the list program,
[Timing chart] the programmable controller assigns the
step number automatically.
ON (Note 1) Use LD (Load) as the first normally
Contact X0 OFF open contact and LDI (Load
ON inverse) as the first normally closed
contact.
Coil Y10 OFF The contact instructions such as LD
and LDI are used for devices such
Coil Y11 as the input relay X, the output relay
Y, the timer T, the counter C, and
OFF the auxiliary relay M.
2-2
2.1.3 SET and RST instructions
Step Instruction
X0 0 LD X0
0 SET Y10 1 SET Y10
X1 2 LD X1
2 RST Y10 3 RST Y10
4 END
4 END
These instructions drive the coil as
well
as the OUT instruction.
[Timing chart] With the OUT instruction, when the
contact to drive the coil turns off from
on, the coil programmed with the OUT
ON instruction turns off as well. With the
Contact X0 SET (Set) instruction, even when the
contact turns off from on, the coil
ON
remains on and the operation is held.
Contact X1 Use the RST (Reset) instruction to turn
ON off the coil driven by the SET (Set)
i i
Coil Y10
[Sequence]
Turning on the input X0 turns on the output Y10.
Even when the input X0 is turned off from on, Y10 remains on and the status is held.
Turning on the input X1 turns off the output Y10.
2-3
2.1.4 AND and ANI instructions
Step Instruction
AND ANI 0 LD X0
1 AND X1
X0 X1 X2
2 ANI X2
0 Y10
3 OUT Y10
X3
Y11 4 AND X3
AND (Note 1) 5 OUT Y11
6 END
6 END
[Sequence]
When the input X0 and X1 are on and X2 is off, the output Y10 is on.
When the input X0, X1, and X3 are on and X2 is off, the output Y11 turns on.
2-4
2.1.5 OR and ORI instructions
Step Instruction
0 LD X0
X0
1 OR X1
0 Y10
X1 2 ORI X2
3 OUT Y10
X2
4 END
4 END
Use the OR (Or) instruction for the
normally open contact or the ORI (Or
inverse) instruction for the normally
closed contact connected to LD or LDI
[Timing chart] in parallel.
In the left figure, the output Y10 turns on
when one of the contacts connected to
ON Y10 in parallel is on.
Contact X0
ON
Contact X1
Contact X2
OFF
ON
Coil Y10
[Sequence]
Even when one of the conditions (the input X0 is on, X1 is on, or X2 is off) is met, the output Y10 turns on.
2-5
2.1.6 ANB instruction
ANB And block : Series connection instruction for parallel ladder block
ON
Contact X3
ON ON
Coil Y10
[Sequence]
Y10 turns on when either of the input X0 or X1 and X2 or X3 are turned on simultaneously.
POINT
In the programmable controller-related works, programs are monitored or edited in
the ladder diagram style in most cases. In the practical test (written test), questions
about the knowledge of list programs may be asked, and thus it is recommended to
read this section.
2-6
2.1.7 ORB instruction
Step Instruction
X0 X1 0 LD X0
0 Y10 1 AND X1
2 LD X2
X2 X3 3 AND X3
ORB
4 ORB
Series ladder block 5 OUT Y10
6 END 6 END
[Sequence]
The output Y10 turns on when the input X0 and X1 are turned on simultaneously or X2 and X3 are
turned on simultaneously.
POINT
In the programmable controller-related works, programs are monitored or edited in
the ladder diagram style in most cases. In the practical test (written test), questions
about the knowledge of list programs may be asked, and thus it is recommended to
read this section.
2-7
2.1.8 PLS and PLF instructions
PLS Pulse : Turns on the specified device for one scan at rising edge of an
input condition
PLF Pulf : Turns on the specified device for one scan at falling edge of an
input condition
X2 Step Instruction
0 PLS M0
0 LD X2
M0 X0
3 Y10 1 PLS M0
Y10 3 LD M0
4 OR Y10
X3
7 PLF M1 5 ANI X0
M1 X1
Y11 6 OUT Y10
10
Y11 7 LD X3
8 PLF M1
14 END
10 LD M1
11 OR Y11
[Timing chart] 12 ANI X1
13 OUT Y11
(PLS instruction) ON
14 END
Contact X2 The PLS instruction turns on the
ON (One scan) specified device only for one scan when
the execution condition is turned on from
Coil M0
off.
ON The PLF instruction turns on the
Coil Y10 specified device only for one scan when
the execution condition is turned off from
ON
on.
Contact X0
[Sequence]
(PLF instruction) Y10 turns on when X2 is turned on. Y10
ON
turns off when X0 is turned on.
Contact X3 To turn on Y10 again, turn X2 on from
ON (One scan) off.
Y11 turns on when X3 is turned on. Y11
Coil M1
turns off when X1 is turned on.
ON To turn on Y11 again, turn X3 off from
Coil Y11 on.
ON
Contact X1
2-8
2.1.9 Timer
This section describes the programming of the digital timer of programmable controllers.
X0 Step Instruction
0 Y10 0 LD X0
K100
1 OUT Y10
T0
2 OUT T0 K100
T0
Y11 6 LD T0
6
7 OUT Y11
8 END
8 END
[Timing chart]
Contact X0
The timer contact operates delaying by
a set time after the coil is energized.
Coil Y10, T0 (On-delay timer)
10sec. This set time is called set value, and
Contact T0 indicated by K.
When X0 is turned off while the timer is
driving, the current value of the timer
Coil Y11 returns to 0 and the timer contact turns
off.
[Sequence]
Turning on the input X0 turns on Y10, and Y11 turns on in 10 seconds after Y10 has turned on.
2-9
2.1.10 Counter
Step Instruction
X0
RST C0 0 LD X0
0
Reset input 1 RST C0
K10
X1 5 LD X1
5 C0
Count value input 6 OUT C0 K10
C0 10 LD C0
10 Y10
11 OUT Y10
12 END 12 END
[Timing chart]
2-10
2.2 Application Instruction
[Sequence]
CPU
(Input module) D0 (Output module)
X0 Y10
X1 Y11
K1 X0 K1 Y10
Number Start X2 Y12 Number Start
of digits number
X3 Y13 of digits number
MOV MOV
S1 D1 S2 D2
Sequential 4-bit data Sequential 4-bit data
from X0 from Y10
K1 4 bits
K2 8 bits
K3 12 bits
K4 16 bits The following shows a program which is
created without the MOV instruction.
X0
Y10
X1
Turning on the input X0 turns on Y10. Y11
Turning on the input X1 turns on Y11. X2
Y12
Turning on the input X2 turns on Y12. X3
Turning on the input X3 turns on Y13. Y13
END
2-12
2.2.2 BIN
S D
X0
0 BIN K1X0 D0
When the input condition is turned on, the data in the device specified in S is recognized as a
binary-coded decimal (BCD code), converted into binary (BIN code), and transferred to the device
specified in D .
Becomes 0.
Digital switch
In programmable controllers, numeric values are converted into BIN
values.
The ordinary digital switches generate BCD codes.
Therefore, the BCD BIN data conversion instruction is required for
5
writing data from the digital switches to the programmable controller. 8 4 2 1
K1X0
D0
4 BIN
0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1
+) 1
5
2-13
2.2.3 BCD
14 END
The ordinary 7-segment LED displays display numbers in the BCD code. Therefore, the BCD instruction is
required for displaying data of the programmable controller (current values of timers and counters, data
resister values of operation results).
[Sequence]
After the input X0 has been turned on for 75 times and X1 is turned on, the display of the 7-segment LED
display is as follows.
C0
0 0 0 0 0 0 0 0 0 1 0 0 1 0 1 1
(BIN)
64
8
2
+) 1
75 0 0 0 0 0 0 0 0 0 1 1 1 0 1 0 1
(BCD)
K2Y10
8 4 2 1 8 4 2 1
7-segment
LED display
2-14
2.2.4 Comparison operation instruction
X0 K30
0 C0
X1
5 BCD C0 K2Y10
S1 S2
9 > K10 C0 Y18
< K20 C0
16 = K30 C0 RST C0
23 END
The comparison operation instruction compares the data of source 1 ( S1 ) and source 2 ( S2 ), and brings
the devices into conduction if the conditions are met.
The instruction can be regarded as one normally open contact ( ) since it is conducted only when
the conditions are met.
< K20 C0
<= S1 S2 ... Becomes conducted when source 1 and source 2 match or when source
>= S1 S2 ... Becomes conducted when source 1 and source 2 match or when source
<> S1 S2 ... Becomes conducted when source 1 and source 2 do not match.
2-15
2.2.5 Arithmetic operation instruction
[Overview]
This instruction adds two values to obtain the result.
X0 S D
0 +P K5 D0 (Note 1)
X1 S1 S2 D
4 +P D0 K100 D1 (Note 2)
(Note 1) Every time the input condition is turned on, the content of the device specified in S is added to
the content of the device specified in D and the result is stored in the device specified in D .
D S D
D0 + (5) D0
(Input condition)
First ON 0 + 5 5
(example)
Second ON 5 + 5 10
Third ON 10 + 5 15
The content of
D0 is changed.
(Note 2) When the input condition is turned on, the content of the device specified in S1 is added to the
content of the device specified in S2 and the result is stored in the device specified in D .
S1 S2 D
D0 + (100) D1
(Input condition)
ON 15 + 100 115
(example)
The content of D0 is not changed.
NOTE
+P or -P must be used for the addition or subtraction instructions.
When + or - is used, an addition or subtraction operation is
executed every scanning. To use + or - , operands must be
converted into pulse in advance.
X0 X0
+P K5 D0 PLS M0
M0
+ K5 D0
2-16
Reference
Command
input
ADD S1 S2 D
S1 + S2 D
NOTE
The same device number can be specified as source S 1 a nd destination D .
In this case, note that the addition result changes in every operation cycle if a continuous operation
type instruction (+ or ADD) is used.
X1
(D0) + 25 (D0)
+ D0 K25 D0
X001
(D0) + 25 (D0)
ADD D0 K25 D0
2-17
- (P) Minus : BIN 16-bit subtraction
(For FX-series programmable controllers, use the SUB instruction. Refer to the reference on the next
page.)
[Overview]
This instruction subtracts a value from another value to obtain the result.
X0
0 MOVP K1000 D2
X0 S D
3 -P K10 D2 (Note 1)
X1 S1 S2 D
7 -P D2 K50 D3 (Note 2)
(Note 1) Every time the input condition is turned on, the content of the device specified in S is
subtracted from the device specified in D and the result is stored in the device specified in
D .
D S D
D2 - (10) D2
(Input condition)
First ON 1000 - 10 990
(example)
Second ON 990 - 10 980
Third ON 980 - 10 970
The content of
D2 is changed.
(Note 2) When the input condition is turned on, the content of the device specified in S2 is
subtracted from the content of the device specified in S1 and the result is stored in the
device specified in D .
S1 S2 D
D2 - (50) D3
(Input condition)
ON 970 - 50 920
(example)
NOTE
+P or -P must be used for the addition or subtraction instructions.
When + or - is used, an addition or subtraction operation is
executed every scanning. To use + or - , operands must be
converted into pulse in advance.
X0 X0
+P K5 D0 PLS M0
M0
+ K5 D0
2-18
Reference
NOTE
The same device number can be specified as source S 1 a nd destination D .
In this case, note that the addition result changes in every operation cycle if a continuous operation
type instruction (- or SUB) is used.
X1
- (D0) - 25 (D0)
D0 K25 D0
X001
(D0) - 25 (D0)
SUB D0 K25 D0
2-19
* (P) Asterisk : BIN 16-bit data multiplication
(For FX-series programmable controllers, use the MUL instruction. Refer to the reference on the next
page.)
/ (P) Slash : BIN 16-bit data division
(For FX-series programmable controllers, use the DIV instruction. Refer to the reference on the next
page.)
[Overview]
This instruction multiplies two values to obtain the result.
This instruction divides a value by another value to obtain the result.
X1 S1 S2 D
3 *P K30 D0 D10 (Note 1)
X2 S1 S2 D
7 /P D0 K600 D20 (Note 2)
(Note 1) When the input condition is turned on, the content of the device specified in S1 is multiplied by
the content of the device specified in S2 and the result is stored in the device specified in D .
S1 S2 D
K30 D0 D11 D10
30 2000 = 60000
To store the result of 16-bit data ~ 16-bit This device is regarded as a 32-bit register to
data, 16 bits (1 word) is not enough. hold the result. Left-most bit of D10 (B15) is not
Thus, D10 and D11, which is the next device a bit to determine positive and negative.
number, work as the holder of the result. It is regarded as a part of the data.
(Note 2) When the input condition is turned on, the content of the device specified in S1 is divided by
the content of the device specified in S2 and the result is stored in the device specified in D .
S1 S2 D
D0 K600 D21 D20
2000 600 = 200 3
Remainder
Quotient
The remainder is stored to D21, which and The quotient is stored to D20, which is specified
is the next device number. in the program.
Values after the decimal point of the operation result are ignored.
When a bit device is specified in D , the quotient is stored, but the remainder is not stored.
2-20
Reference
DIV(P): The contents of S 1 a re divided by S 2 i n binary format, and the quotient is transferred to D ,
and the remainder is transferred to D +1.
Dividend Divisor Quotient Remainder
DIV S1 S2 D ( S1 ) ÷ ( S2 ) ( D ) ... ( D +1 )
16 bits 16 bits 16 bits 16 bits
2-21