3.8
INV_I Ones Complement Integer
Symbol
INV_I
ENO
EN
IN
OUT
Parameter
Data Type
Memory Area
Description
EN
BOOL
I, Q, M, L, D
Enable input
ENO
BOOL
I, Q, M, L, D
Enable output
IN
INT
I, Q, M, L, D
Integer input value
OUT
INT
I, Q, M, L, D
Ones complement of the integer IN
Description
INV_I (Ones Complement Integer) reads the content of the IN parameter and performs a Boolean
XOR function with the hexadecimal mask W#16#FFFF. This instruction changes every bit to its
opposite state. ENO always has the same signal state as EN.
Status word
BR
CC 1
CC 0
OV
OS
OR
STA
RLO
/FC
writes:
1
-
-
-
-
0
1
1
1
Example
Q 4.0
I 0.0
MW8
INV_I
ENO
EN
IN
OUT
MW10
NOT
If I0.0 is "1", then every bit of MW8 is reversed, for example:
MW8 = 01000001 10000001 results in MW10 = 10111110 01111110.
The output Q4.0 is "1" if the conversion is not executed (ENO = EN = 0).
Conversion Instructions
3.9 INV_DI Ones Complement Double Integer
Ladder Logic (LAD) for S7-300 and S7-400 Programming
Reference Manual, 04/2017, A5E41524738-AA
47
3.9
INV_DI Ones Complement Double Integer
Symbol
INV_DI
ENO
EN
IN
OUT
Parameter
Data Type
Memory Area
Description
EN
BOOL
I, Q, M, L, D
Enable input
ENO
BOOL
I, Q, M, L, D
Enable output
IN
DINT
I, Q, M, L, D
Double integer input value
OUT
DINT
I, Q, M, L, D
Ones complement of the double integer
IN
Description
INV_DI (Ones Complement Double Integer) reads the content of the IN parameter and performs a
Boolean XOR function with the hexadecimal mask W#16#FFFF FFFF .This instruction changes
every bit to its opposite state. ENO always has the same signal state as EN.
Status word
BR
CC 1
CC 0
OV
OS
OR
STA
RLO
/FC
writes:
1
-
-
-
-
0
1
1
1
Example
Q 4.0
I 0.0
MD8
INV_DI
ENO
EN
IN
OUT
MD12
NOT
If I0.0 is "1", then every bit of MD8 is reversed, for example:
MD8 = F0FF FFF0 results in MD12 = 0F00 000F.
The output Q4.0 is "1" if the conversion is not executed (ENO = EN = 0).
Conversion Instructions
3.10 NEG_I Twos Complement Integer
Ladder Logic (LAD) for S7-300 and S7-400 Programming
48
Reference Manual, 04/2017, A5E41524738-AA
3.10
NEG_I Twos Complement Integer
Symbol
NEG_I
ENO
EN
IN
OUT
Parameter
Data Type
Memory Area
Description
EN
BOOL
I, Q, M, L, D
Enable input
ENO
BOOL
I, Q, M, L, D
Enable output
IN
INT
I, Q, M, L, D
Integer input value
OUT
INT
I, Q, M, L, D
Twos complement of integer IN
Description
NEG_I (Twos Complement Integer) reads the content of the IN parameter and performs a twos
complement instruction. The twos complement instruction is equivalent to multiplication by (-1) and
changes the sign (for example: from a positive to a negative value). ENO always has the same
signal state as EN with the following exception: if the signal state of EN = 1 and an overflow occurs,
the signal state of ENO = 0.
Status word
BR
CC 1
CC 0
OV
OS
OR
STA
RLO
/FC
writes:
x
x
x
x
x
0
x
x
1
Example
Q 4.0
I 0.0
MW8
NEG_I
ENO
EN
IN
OUT
MW10
NOT
If I0.0 is "1", then the value of MW8 with the opposite sign is output by the OUT parameter to
MW10.
MW8 = + 10 results in MW10 = - 10.
The output Q4.0 is "1" if the conversion is not executed (ENO = EN = 0).
If the signal state of EN = 1 and an overflow occurs, the signal state of ENO = 0.
Conversion Instructions
3.11 NEG_DI Twos Complement Double Integer
Ladder Logic (LAD) for S7-300 and S7-400 Programming
Reference Manual, 04/2017, A5E41524738-AA
49
3.11
NEG_DI Twos Complement Double Integer
Symbol
NEG_DI
ENO
EN
IN
OUT
Parameter
Data Type
Memory Area
Description
EN
BOOL
I, Q, M, L, D
Enable input
ENO
BOOL
I, Q, M, L, D
Enable output
IN
DINT
I, Q, M, L, D
Double integer input value
OUT
DINT
I, Q, M, L, D
Twos complement of IN value
Description
NEG_DI (Twos Complement Double Integer) reads the content of the IN parameter and performs a
twos complement instruction. The twos complement instruction is equivalent to multiplication by (-
1) and changes the sign (for example: from a positive to a negative value). ENO always has the
same signal state as EN with the following exception: if the signal state of EN = 1 and an overflow
occurs, the signal state of ENO = 0.
Status word
BR
CC 1
CC 0
OV
OS
OR
STA
RLO
/FC
writes:
x
x
x
x
x
0
x
x
1
Example
Q 4.0
I 0.0
MD8
NEG_DI
ENO
EN
IN
OUT
MD12
NOT
If I0.0 is "1", then the value of MD8 with the opposite sign is output by the OUT parameter to MD12.
MD8 = + 1000 results in MD12 = - 1000.
The output Q4.0 is "1" if the conversion is not executed (ENO = EN = 0).
If the signal state of EN = 1 and an overflow occurs, the signal state of ENO = 0.
Conversion Instructions
3.12 NEG_R Negate Floating-Point Number
Ladder Logic (LAD) for S7-300 and S7-400 Programming
50
Reference Manual, 04/2017, A5E41524738-AA
3.12
NEG_R Negate Floating-Point Number
Symbol
NEG_R
ENO
EN
IN
OUT
Parameter
Data Type
Memory Area
Description
EN
BOOL
I, Q, M, L, D
Enable input
ENO
BOOL
I, Q, M, L, D
Enable output
IN
REAL
I, Q, M, L, D
Floating-point number input value
OUT
REAL
I, Q, M, L, D
Floating-point number IN with negative
sign
Description
NEG_R (Negate Floating-Point) reads the contents of the IN parameter and changes the sign. The
instruction is equivalent to multiplication by (-1) and changes the sign (for example: from a positive
to a negative value). ENO always has the same signal state as EN.
Status word
BR
CC 1
CC 0
OV
OS
OR
STA
RLO
/FC
writes:
x
-
-
-
-
0
x
x
1
Example
Q 4.0
I 0.0
MD8
NEG_R
ENO
EN
IN
OUT
MD12
NOT
If I0.0 is "1", then the value of MD8 with the opposite sign is output by the OUT parameter to MD12.
MD8 = + 6.234 results in MD12 = - 6.234.
The output Q4.0 is "1" if the conversion is not executed (ENO = EN = 0).
Conversion Instructions
3.13 ROUND Round to Double Integer
Ladder Logic (LAD) for S7-300 and S7-400 Programming
Reference Manual, 04/2017, A5E41524738-AA
51
3.13
ROUND Round to Double Integer
Symbol
ROUND
ENO
EN
IN
OUT
Parameter
Data Type
Memory Area
Description
EN
BOOL
I, Q, M, L, D
Enable input
ENO
BOOL
I, Q, M, L, D
Enable output
IN
REAL
I, Q, M, L, D
Value to round
OUT
DINT
I, Q, M, L, D
IN rounded to nearest whole number
Description
ROUND (Round Double Integer) reads the content of the IN parameter as a floating-point number
and converts it to a double integer (32-bit). The result is the closest integer number ("Round to
nearest"). If the floating-point number lies between two integers, the even number is returned. The
result is output by the parameter OUT. If an overflow occurred ENO will be "0".
Status word
BR
CC 1
CC 0
OV
OS
OR
STA
RLO
/FC
writes:
x
-
-
x
x
0
x
x
1
Example
Q 4.0
I 0.0
MD8
ROUND
ENO
EN
IN
OUT
MD12
NOT
If I0.0 is "1", then the content of MD8 is read as a floating-point number and converted to the
closest double integer. The result of this "Round to nearest" function is stored in MD12. The output
Q4.0 is "1" if an overflow occurred or the instruction was not executed (I0.0 = 0).
Conversion Instructions
3.14 TRUNC Truncate Double Integer Part
Ladder Logic (LAD) for S7-300 and S7-400 Programming
52
Reference Manual, 04/2017, A5E41524738-AA
3.14
TRUNC Truncate Double Integer Part
Symbol
TRUNC
ENO
EN
IN
OUT
Parameter
Data Type
Memory Area
Description
EN
BOOL
I, Q, M, L, D
Enable input
ENO
BOOL
I, Q, M, L, D
Enable output
IN
REAL
I, Q, M, L, D
Floating-point value to convert
OUT
DINT
I, Q, M, L, D
Whole number part of IN value
Description
TRUNC (Truncate Double Integer) reads the content of the IN parameter as a floating-point
number and converts it to a double integer (32-bit). The double integer result of the ("Round to zero
mode") is output by the parameter OUT. If an overflow occurred, ENO will be "0".
Status word
BR
CC 1
CC 0
OV
OS
OR
STA
RLO
/FC
writes:
x
-
-
x
x
0
x
x
1
Example
Q 4.0
I 0.0
MD8
TRUNC
ENO
EN
IN
OUT
MD12
NOT
If I0.0 is "1", then the content of MD8 is read as a real number and converted to a double integer.
The integer part of the floating-point number is the result and is stored in MD12. The output Q4.0 is
"1" if an overflow occurred, or the instruction was not executed (I0.0 = 0).
Conversion Instructions
3.15 CEIL Ceiling
Ladder Logic (LAD) for S7-300 and S7-400 Programming
Reference Manual, 04/2017, A5E41524738-AA
53
3.15
CEIL Ceiling
Symbol
CEIL
ENO
EN
IN
OUT
Parameter
Data Type
Memory Area
Description
EN
BOOL
I, Q, M, L, D
Enable input
ENO
BOOL
I, Q, M, L, D
Enable output
IN
REAL
I, Q, M, L, D
Floating-point value to convert
OUT
DINT
I, Q, M, L, D
Lowest greater double integer
Description
CEIL (Ceiling) reads the contents of the IN parameter as a floating-point number and converts it to
a double integer (32-bit). The result is the lowest integer which is greater than the floating-point
number ("Round to + infinity"). If an overflow occurs, ENO will be "0".
Status word
BR
CC 1
CC 0
OV
OS
OR
STA
RLO
/FC
writes*:
X
-
-
X
X
0
X
X
1
writes**:
0
-
-
-
-
0
0
0
1
* Function is executed (EN = 1)
** Function is not executed (EN = 0)
Example
Q 4.0
I 0.0
MD8
CEIL
ENO
EN
IN
OUT
MD12
NOT
If I0.0 is 1, the contents of MD8 are read as a floating-point number which is converted into a
double integer using the function
Round. The result is stored in MD12. The output Q4.0 is "1" if an
overflow occured or the instruction was not processed (I0.0 = 0).
Conversion Instructions
3.16 FLOOR Floor
Ladder Logic (LAD) for S7-300 and S7-400 Programming
54
Reference Manual, 04/2017, A5E41524738-AA
3.16
FLOOR Floor
Symbol
FLOOR
ENO
EN
IN
OUT
Parameter
Data Type
Memory Area
Description
EN
BOOL
I, Q, M, L, D
Enable input
ENO
BOOL
I, Q, M, L, D
Enable output
IN
REAL
I, Q, M, L, D
Floating-point value to convert
OUT
DINT
I, Q, M, L, D
Greatest lower double integer
Description
FLOOR (Floor) reads the content of the IN parameter as a floating-point number and converts it to
a double integer (32-bit). The result is the greatest integer component which is lower than the
floating-point number ("Round to - infinity"). If an overflow occurred ENO will be "0".
Status word
BR
CC 1
CC 0
OV
OS
OR
STA
RLO
/FC
writes:
x
-
-
x
x
0
x
x
1
Example
Q 4.0
I 0.0
MD8
FLOOR
ENO
EN
IN
OUT
MD12
NOT
If I0.0 is "1", then the content of MD8 is read as a floating-point number and converted to a double
integer by the round to - infinity mode. The result is stored in MD12. The output Q4.0 is "1" if an
overflow occurred, or the instruction was not executed (I0.0 = 0).
Ladder Logic (LAD) for S7-300 and S7-400 Programming
Reference Manual, 04/2017, A5E41524738-AA
55
4
Counter Instructions
4.1
Overview of Counter Instructions
Area in Memory
Counters have an area reserved for them in the memory of your CPU. This memory area reserves
one 16-bit word for each counter address. The ladder logic instruction set supports 256 counters.
The counter instructions are the only functions that have access to the counter memory area.
Count Value
Bits 0 through 9 of the counter word contain the count value in binary code. The count value is
moved to the counter word when a counter is set. The range of the count value is 0 to 999.
You can vary the count value within this range by using the following counter instructions:
•
S_CUD Up-Down Counter
•
S_CD Down Counter
•
S_CU Up Counter
•
---( SC ) Set Counter Coil
•
---( CU ) Up Counter Coil
•
---( CD ) Down Counter Coil
Counter Instructions
4.1 Overview of Counter Instructions
Ladder Logic (LAD) for S7-300 and S7-400 Programming
56
Reference Manual, 04/2017, A5E41524738-AA
Bit Configuration in the Counter
You provide a counter with a preset value by entering a number from 0 to 999, for example 127, in
the following format: C#127. The C# stands for binary coded decimal format (BCD format: each set
of four bits contains the binary code for one decimal value).
Bits 0 through 11 of the counter contain the count value in binary coded decimal format.
The following figure shows the contents of the counter after you have loaded the count value 127,
and the contents of the counter cell after the counter has been set.
irrelevant
Count value in BCD (0 to 999)
1
1
1
0
0
1
0
0
1
0
0
0
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
7
2
1
1
1
1
1
1
1
1
0
0
0
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
irrelevant
Binary count value
Counter Instructions
4.2 S_CUD Up-Down Counter
Ladder Logic (LAD) for S7-300 and S7-400 Programming
Reference Manual, 04/2017, A5E41524738-AA
57
4.2
S_CUD Up-Down Counter
Symbol
S_CUD
S
Q
CV
PV
R
CV_BCD
CU
CD
English
German
C no.
Z no.
ZAEHLER
S
Q
DUAL
ZW
R
DEZ
ZV
ZR
Parameter
English
Parameter
German
Data Type
Memory Area
Description
C no.
Z no.
COUNTER
C
Counter identification number;
range depends on CPU
CU
ZV
BOOL
I, Q, M, L, D
Count up input
CD
ZR
BOOL
I, Q, M, L, D
Count down input
S
S
BOOL
I, Q, M, L, D
Set input for presetting counter
PV
ZW
WORD
I, Q, M, L, D
or constant
Enter counter value as
C# in the range from 0 to
999
PV
ZW
WORD
I, Q, M, L, D
Value for presetting counter
R
R
BOOL
I, Q, M, L, D
Reset input
CV
DUAL
WORD
I, Q, M, L, D
Current counter value,
hexadecimal number
CV_BCD
DEZ
WORD
I, Q, M, L, D
Current counter value, BCD
coded
Q
Q
BOOL
I, Q, M, L, D
Status of the counter
Description
S_CUD (Up-Down Counter) is preset with the value at input PV if there is a positive edge at input
S. If there is a 1 at input R, the counter is reset and the count is set to zero. The counter is
incremented by one if the signal state at input CU changes from "0" to "1" and the value of the
counter is less than "999". The counter is decremented by one if there is a positive edge at input
CD and the value of the counter is greater than "0".
If there is a positive edge at both count inputs, both instructions are executed and the count value
remains unchanged.
If the counter is set and if RLO = 1 at the inputs CU/CD, the counter will count once in the
next
scan cycle, even if there was no change from a positive to a negative edge or viceversa.
The signal state at output Q is "1" if the count is greater than zero and "0" if the count is equal to
zero.
Counter Instructions
4.2 S_CUD Up-Down Counter
Ladder Logic (LAD) for S7-300 and S7-400 Programming
58
Reference Manual, 04/2017, A5E41524738-AA
Status word
BR
CC 1
CC 0
OV
OS
OR
STA
RLO
/FC
writes:
-
-
-
-
-
x
x
x
1
Note
Avoid to use a counter at several program points (risk of counting errors).
Example
S_CUD
S
Q
CV
PV
R
CV_BCD
CU
CD
Q 4.0
I 0.0
I 0.1
I 0.2
I 0.3 MW10
C10
If I0.2 changes from "0" to "1", the counter is preset with the value of MW10. If the signal state of
I0.0 changes from "0" to "1", the value of counter C10 will be incremented by one - except when
the value of C10 is equal than "999". If I0.1 changes from "0" to "1", C10 is decremented by one -
except when the value of C10 is equal to "0". Q4.0 is "1" if C10 is not equal to zero.
Counter Instructions
4.3 S_CU Up Counter
Ladder Logic (LAD) for S7-300 and S7-400 Programming
Reference Manual, 04/2017, A5E41524738-AA
59
4.3
S_CU Up Counter
Symbol
S_CU
PV
Q
CV
R
CV_BCD
CU
S
Dostları ilə paylaş: |