Subtraction - Mitsubishi Electric FX2N Beginners Manual

Hide thumbs Also See for FX2N:
Table of Contents

Advertisement

More Advanced Programming
5.4.2

Subtraction

The SUB instruction calculates the difference between two numerical values (contents of
16-bit or 32-bit devices or constants). The result of the subtraction is written to a third device.
Ladder Diagram
0
³ Minuend (the subtrahend is subtracted from this value)
· Subtrahend (this value is subtracted from the minuend)
» Difference (result of the subtraction)
In the example above the contents of D1 is subtracted from the contents of D0 and the differ-
ence is written to D2.
Examples
Subtract 100 from the contents of data register D11 and write the result to D101:
SUB D100 K100 D101
The signs of the values are taken into account by the SUB instruction:
SUB D10 D11 D12
You can also subtract 32-bit values by prefixing a "D" to the SUB instruction (DSUB):
DSUB D0 D2 D4
If you want you can also write the result to one of the source devices. However, if you do this
remember that the result will then change in every program cycle if the SUB instruction is exe-
cuted cyclically!
SUB D0 K25 D0
The SUB instruction can also be executed in pulse-triggered mode. Then it is only executed
when the signal state of the input condition changes from "0" to "1". To use this mode just add a
"P" suffix to the SUB instructions (SUBP, DSUBP).
In the following example the contents of D394 is only subtracted from contents of D50 once, in
the program cycle in which the signal state of relay M50 changes from "0" to "1":
Ladder Diagram
M50
0
FX Beginners Manual
SUB D0 D1 D2
D 100
247
D 10
D 1
D 0
65238
D 0
197
SUBP D50 D394 D51
Instruction List
0 SUB
100
D 11
5
-8
D 3
D 2
27643
25
Instruction List
0 LD
1 SUBP
Math Instructions
D0
D1
D2
D 101
147
D 12
13
D 5
D 4
37595
D 0
172
M50
D50
D394
D51
5 – 23

Advertisement

Table of Contents
loading

Table of Contents