![Mitsubishi Electric MELSEC FX3G Скачать руководство пользователя страница 307](http://html.mh-extra.com/html/mitsubishi-electric/melsec-fx3g/melsec-fx3g_programming-manual_239083307.webp)
305
FX
3G
/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
Int
roduct
ion
2
O
ver
view
3
In
str
uc
tion
Li
st
4
D
evices
in D
etail
5
Spec
ified t
he
D
evice &
C
onst
ant
6
Bef
ore
Pr
ogr
am
m
ing
7
B
asic
In
st
ru
ct
io
n
8
FN
C
00-FN
C
09
P
rogr
am
F
low
9
FN
C
10
-FN
C
19
Mo
ve
&
Co
mp
are
10
FNC2
0-F
NC2
9
Ar
ith.
&
Logic
O
per
ation
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 2’s complement.
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.
......
......