267
FX
3U
/FX
3UC
Series Programmable Controllers
Programming Manual - Basic & Applied Instruction Edition
10 Arithmetic and Logical Operation (
+
,
−
,
×
,
÷
) – FNC 20 to FNC 29
10.10 FNC 29 – NEG / Negation
1
In
troduct
io
n
2
Ov
e
rv
ie
w
3
In
st
ru
ct
ion
Li
st
4
D
evi
ce
s
in
De
ta
il
5
Speci
fied t
h
e
D
evi
ce &
C
onst
a
nt
6
Bef
o
re
Pr
ogr
a
m
m
ing
7
Bas
ic
In
st
ru
cti
o
n
8
FNC0
0
-FNC0
9
P
ro
g
ra
m F
lo
w
9
FNC1
0
-FNC1
9
M
ov
e
&
C
om
par
e
10
FNC
20-
FNC
2
9
Ar
ith.
&
Logi
c
O
per
at
io
n
Program examples
The program examples below are provided to obtain the absolute value of a negative binary value.
1. Obtaining the absolute value of a negative value using NEG instruction
2. Obtaining the absolute value by SUB (subtraction) instruction
Even if NEG instruction is not used, D30 always stores the absolute value of the difference.
Negative value expression and absolute value (reference)
In PLCs, a negative value is expressed in complement of 2.
When the most significant bit is "1", it is a negative value, and its absolute value can be obtained by NEG
instruction.
M 0
FNC 29
NEGP
D 10
M8000
FNC 44
BON
D 10
M 0
K 15
RUN monitor
In BON (ON bit check) instruction, M0 turns ON
when the bit 15 (b15 among b0 to b15) of D10 is "1".
NEGP instruction is executed for D10 only when M0
turns ON.
D10
→
D10
X000
M 10
M 11
M 12
FNC 21
SUB
D 10
D 20
D 30
FNC 21
SUB
D 20
D 10
D 30
FNC 10
CMP
D 10
D 20
M 10
(D 10) > (D 20) (D10) = (D 20) (D 10) < (D 20)
M 10 = ON M 11 = ON M 12 = ON
In the case of "D10
≥
D20",
D10
−
D20
→
D30.
In the case of "D10 < D20",
D20
−
D10
→
D30.
(D 10) = 2
0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0
(D 10) = 1
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
(D 10) = 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
(D 10) =
−
1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
(D 10) =
−
2
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
(D 10) =
−
32767
(D 10) =
−
32768
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
(D 10) + 1 = 1
0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0
(D 10) + 1 = 2
0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
(D 10) + 1 = 32767
(D 10) + 1 =
−
32768
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
The absolute value can be obtained up to 32767.
.....
.
.....
.