1.18
Immediate Write
Description
For the Immediate Write function, a network of symbols must be created as shown in the example
below.
For time-critical applications, the current state of a digital output may have to be sent to an output
module faster than the normal case of once at the end of the OB1 scan cycle. An Immediate Write
writes to a digital output to a input module at the time the Immediate Write rung is scanned.
Otherwise, you must wait for the end of the next OB1 scan cycle when the Q memory area is
updated with the P memory state.
To perform an immediate write of an output (or outputs) to an output module, use the peripheral
output (PQ) memory area instead of the output (Q) memory area. The peripheral output memory
area can be read as a byte, a word, or a double word. Therefore, a single digital output cannot be
updated via a coil element. To write the state of a digital output to an output module immediately, a
byte, word, or double word of Q memory that contains the relevant bit is conditionally copied to the
corresponding PQ memory (direct output module addresses).
!
Caution
•
Since the entire byte of Q memory is written to an output module, all outputs bits in that byte are updated
when the immediate output is performed.
•
If an output bit has intermediate states (1/0) occurring throughout the program that should not be sent to
the output module, Immediate Writes could cause dangerous conditions (transient pulses at outputs) to
occur.
•
As a general design rule, an external output module should only be referenced once in a program as a
coil. If you follow this design rule, most potential problems with immediate outputs can be avoided.
Example
Ladder network equivalent of Immediate Write to peripheral digital output module 5, channel 1.
The bit states of the addressed output Q byte (QB5) are either modified or left unchanged. Q5.1 is
assigned the signal state of I0.1 in network 1. QB5 is copied to the corresponding direct peripheral
output memory area (PQB5).
The word PIW1 contains the immediate status of I1.1. PIW1 is ANDed with W#16#0002. The result
is not equal to zero if I1.1 (second bit) in PB1 is true ("1"). The contact A<>0 passes voltage if the
result of the WAND_W instruction is not equal to zero.
I 0.1
Q 5.1
Network 1
MOVE
IN
ENO
EN
OUT
QB5
PQB5
Network 2
Bit Logic Instructions
1.18 Immediate Write
Ladder Logic (LAD) for S7-300 and S7-400 Programming
Reference Manual, 04/2017, A5E41524738-AA
31
In this example Q5.1 is the desired immediate output bit.
The byte PQB5 contains the immediate output status of the bit Q5.1.
The other 7 bits in PQB5 are also updated by the MOVE (copy) instruction.
Bit Logic Instructions
1.18 Immediate Write
Ladder Logic (LAD) for S7-300 and S7-400 Programming
32
Reference Manual, 04/2017, A5E41524738-AA
Ladder Logic (LAD) for S7-300 and S7-400 Programming
Reference Manual, 04/2017, A5E41524738-AA
33
2
Comparison Instructions
2.1
Overview of Comparison Instructions
Description
IN1 and IN2 are compared according to the type of comparison you choose:
== IN1 is equal to IN2
<> IN1 is not equal to IN2
> IN1 is greater than IN2
< IN1 is less than IN2
>= IN1 is greater than or equal to IN2
<= IN1 is less than or equal to IN2
If the comparison is true, the RLO of the function is "1". It is linked to the RLO of a rung network by
AND if the compare element is used in series, or by OR if the box is used in parallel.
The following comparison instructions are available:
•
CMP ? I Compare Integer
•
CMP ? D Compare Double Integer
•
CMP ? R Compare Real
Comparison Instructions
2.2 CMP ? I Compare Integer
Ladder Logic (LAD) for S7-300 and S7-400 Programming
34
Reference Manual, 04/2017, A5E41524738-AA
2.2
CMP ? I Compare Integer
Symbols
CMP
== I
IN2
IN1
CMP
<> I
IN2
IN1
CMP
< I
IN2
IN1
CMP
> I
IN2
IN1
CMP
<= I
IN2
IN1
CMP
>= I
IN2
IN1
Parameter
Data Type
Memory Area
Description
box input
BOOL
I, Q, M, L, D
Result of the previous logic operation
box output
BOOL
I, Q, M, L, D
Result of the comparison, is only
processed further if the RLO at the box
input = 1
IN1
INT
I, Q, M, L, D
or constant
First value to compare
IN2
INT
I, Q, M, L, D
or constant
Second value to compare
Description
CMP ? I
(Compare Integer) can be used like a normal contact. It can be located at any position
where a normal contact could be placed. IN1 and IN2 are compared according to the type of
comparison you choose.
If the comparison is true, the RLO of the function is "1". It is linked to the RLO of the whole rung by
AND if the box is used in series, or by OR if the box is used in parallel.
Status word
BR
CC 1
CC 0
OV
OS
OR
STA
RLO
/FC
writes:
x
x
x
0
-
0
x
x
1
Example
CMP
>= I
IN2
IN1
MW2
MW0
I 0.1
S
Q 4.0
I 0.0
Output Q4.0 is set if the following conditions exist:
•
There is a signal state of "1" at inputs I0.0 and at I0.1
•
AND MW0 >= MW2
Comparison Instructions
2.3 CMP ? D Compare Double Integer
Ladder Logic (LAD) for S7-300 and S7-400 Programming
Reference Manual, 04/2017, A5E41524738-AA
35
2.3
CMP ? D Compare Double Integer
Symbols
CMP
== D
IN2
IN1
CMP
<> D
IN2
IN1
CMP
< D
IN2
IN1
CMP
> D
IN2
IN1
CMP
<= D
IN2
IN1
CMP
>= D
IN2
IN1
Parameter
Data Type
Memory Area
Description
box input
BOOL
I, Q, M, L, D
Result of the previous logic operation
box output
BOOL
I, Q, M, L, D
Result of the comparison, is only
processed further if the RLO at the box
input = 1
IN1
DINT
I, Q, M, L, D
or constant
First value to compare
IN2
DINT
I, Q, M, L, D
or constant
Second value to compare
Description
CMP ? D
(Compare Double Integer) can be used like a normal contact. It can be located at any
position where a normal contact could be placed. IN1 and IN2 are compared according to the type
of comparison you choose.
If the comparison is true, the RLO of the function is "1". It is linked to the RLO of a rung network by
AND if the compare element is used in series, or by OR if the box is used in parallel.
Status word
BR
CC 1
CC 0
OV
OS
OR
STA
RLO
/FC
writes:
x
x
x
0
-
0
x
x
1
Comparison Instructions
2.3 CMP ? D Compare Double Integer
Ladder Logic (LAD) for S7-300 and S7-400 Programming
36
Reference Manual, 04/2017, A5E41524738-AA
Example
CMP
>= D
IN2
IN1
MD4
MD0
I 0.1
S
Q 4.0
I 0.0
I 0.2
Output Q4.0 is set if the following conditions exist:
•
There is a signal state of "1" at inputs I0.0 and at I0.1
•
And MD0 >= MD4
•
And there is a signal state of"1" at input I0.2
Comparison Instructions
2.4 CMP ? R Compare Real
Ladder Logic (LAD) for S7-300 and S7-400 Programming
Reference Manual, 04/2017, A5E41524738-AA
37
2.4
CMP ? R Compare Real
Symbols
CMP
== R
IN2
IN1
CMP
<> R
IN2
IN1
CMP
< R
IN2
IN1
CMP
> R
IN2
IN1
CMP
<= R
IN2
IN1
CMP
>= R
IN2
IN1
Parameter
Data Type
Memory Area
Description
box input
BOOL
I, Q, M, L, D
Result of the previous logic operation
box output
BOOL
I, Q, M, L, D
Result of the comparison, is only
processed further if the RLO at the box
input = 1
IN1
REAL
I, Q, M, L, D
or constant
First value to compare
IN2
REAL
I, Q, M, L, D
or constant
Second value to compare
Description
CMP ? R
(Compare Real) can be used like a normal contact. It can be located at any position
where a normal contact could be placed. IN1 and IN2 are compared according to the type of
comparison you choose.
If the comparison is true, the RLO of the function is "1". It is linked to the RLO of the whole rung by
AND if the box is used in series, or by OR if the box is used in parallel.
Status word
BR
CC 1
CC 0
OV
OS
OR
STA
RLO
/FC
writes:
x
x
x
x
x
0
x
x
1
Comparison Instructions
2.4 CMP ? R Compare Real
Ladder Logic (LAD) for S7-300 and S7-400 Programming
38
Reference Manual, 04/2017, A5E41524738-AA
Example
CMP
>= R
IN2
IN1
MD4
MD0
I 0.1
S
Q 4.0
I 0.0
I 0.2
Output Q4.0 is set if the following conditions exist:
•
There is a signal state of "1" at inputs I0.0 and at I0.1
•
And MD0 >= MD4
•
And there is a signal state of"1" at input I0.2
Ladder Logic (LAD) for S7-300 and S7-400 Programming
Reference Manual, 04/2017, A5E41524738-AA
39
3
Conversion Instructions
3.1
Overview of Conversion Instructions
Description
The conversion instructions read the contents of the parameters IN and convert these or change
the sign. The result can be queried at the parameter OUT.
The following conversion instructions are available:
•
BCD_I BCD to Integer
•
I_BCD Integer to BCD
•
BCD_DI BCD to Double Integer
•
I_DINT Integer to Double Integer
•
DI_BCD Double Integer to BCD
•
DI_REAL Double Integer to Floating-Point
•
INV_I Ones Complement Integer
•
INV_DI Ones Complement Double Integer
•
NEG_I Twos Complement Integer
•
NEG_DI Twos Complement Double Integer
•
NEG_R Negate Floating-Point Number
•
ROUND Round to Double Integer
•
TRUNC Truncate Double Integer Part
•
CEIL Ceiling
•
FLOOR Floor
Conversion Instructions
3.2 BCD_I BCD to Integer
Ladder Logic (LAD) for S7-300 and S7-400 Programming
40
Reference Manual, 04/2017, A5E41524738-AA
3.2
BCD_I BCD to Integer
Symbol
BCD_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
WORD
I, Q, M, L, D
BCD number
OUT
INT
I, Q, M, L, D
Integer value of BCD number
Description
BCD_I (Convert BCD to Integer) reads the contents of the IN parameter as a three-digit, BCD
coded number (+/- 999) and converts it to an integer value (16-bit). The integer result is output by
the parameter OUT. 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
MW10
BCD_I
ENO
EN
IN
OUT
MW12
NOT
If input I0.0 is "1" , then the content of MW10 is read as a three-digit BCD coded number and
converted to an integer. The result is stored in MW12. The output Q4.0 is "1" if the conversion is
not executed (ENO = EN = 0).
Conversion Instructions
3.3 I_BCD Integer to BCD
Ladder Logic (LAD) for S7-300 and S7-400 Programming
Reference Manual, 04/2017, A5E41524738-AA
41
3.3
I_BCD Integer to BCD
Symbol
I_BCD
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 number
OUT
WORD
I, Q, M, L, D
BCD value of integer number
Description
I_BCD (Convert Integer to BCD) reads the content of the IN parameter as an integer value (16-bit)
and converts it to a three-digit BCD coded number (+/- 999). 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
MW10
I_BCD
ENO
EN
IN
OUT
MW12
NOT
If I0.0 is "1", then the content of MW10 is read as an integer and converted to a three-digit BCD
coded number. The result is stored in MW12. The output Q4.0 is "1" if there was an overflow, or the
instruction was not executed (I0.0 = 0).
Conversion Instructions
3.4 I_DINT Integer to Double Integer
Ladder Logic (LAD) for S7-300 and S7-400 Programming
42
Reference Manual, 04/2017, A5E41524738-AA
3.4
I_DINT Integer to Double Integer
Symbol
I_DINT
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 value to convert
OUT
DINT
I, Q, M, L, D
Double integer result
Description
I_DINT (Convert Integer to Double Integer) reads the content of the IN parameter as an integer
(16-bit) and converts it to a double integer (32-bit). The result is output by the parameter OUT.
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
MW10
I_DINT
ENO
EN
IN
OUT
MD12
NOT
If I0.0 is "1", then the content of MW10 is read as an integer and converted to a double integer. The
result is stored in MD12. The output Q4.0 is "1" if the conversion is not executed (ENO = EN = 0).
Conversion Instructions
3.5 BCD_DI BCD to Double Integer
Ladder Logic (LAD) for S7-300 and S7-400 Programming
Reference Manual, 04/2017, A5E41524738-AA
43
3.5
BCD_DI BCD to Double Integer
Symbol
BCD_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
DWORD
I, Q, M, L, D
BCD number
OUT
DINT
I, Q, M, L, D
Double integer value of BCD number
Description
BCD_DI (Convert BCD to Double Integer) reads the content of the IN parameter as a seven-digit,
BCD coded number (+/- 9999999) and converts it to a double integer value (32-bit). The double
integer result is output by the parameter OUT. 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
BCD_DI
ENO
EN
IN
OUT
MD12
NOT
If I0.0 is "1" , then the content of MD8 is read as a seven-digit BCD coded number and converted to
a double integer. The result is stored in MD12. The output Q4.0 is "1" if the conversion is not
executed (ENO = EN = 0).
Conversion Instructions
3.6 DI_BCD Double Integer to BCD
Ladder Logic (LAD) for S7-300 and S7-400 Programming
44
Reference Manual, 04/2017, A5E41524738-AA
3.6
DI_BCD Double Integer to BCD
Symbol
DI_BCD
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 number
OUT
DWORD
I, Q, M, L, D
BCD value of a double integer number
Description
DI_BCD (Convert Double Integer to BCD) reads the content of the IN parameter as a double
integer (32-bit) and converts it to a seven-digit BCD coded number (+/- 9999999). 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
DI_BCD
ENO
EN
IN
OUT
MD12
NOT
If I0.0 is "1", then the content of MD8 is read as a double integer and converted to a seven-digit
BCD number. 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).
Conversion Instructions
3.7 DI_REAL Double Integer to Floating-Point
Ladder Logic (LAD) for S7-300 and S7-400 Programming
Reference Manual, 04/2017, A5E41524738-AA
45
3.7
DI_REAL Double Integer to Floating-Point
Symbol
DI_REAL
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 value to convert
OUT
REAL
I, Q, M, L, D
Floating-point number result
Description
DI_REAL (Convert Double Integer to Floating-Point) reads the content of the IN parameter as a
double integer and converts it to a floating-point number. The result is output by the parameter
OUT. 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
DI_REAL
ENO
EN
IN
OUT
MD12
NOT
If I0.0 is "1", then the content of MD8 is read as an double integer and converted to a floating-point
number. The result is stored in MD12. The output Q4.0 is "1" if the conversion is not executed
(ENO = EN = 0).
Conversion Instructions
3.8 INV_I Ones Complement Integer
Ladder Logic (LAD) for S7-300 and S7-400 Programming
46
Reference Manual, 04/2017, A5E41524738-AA
Dostları ilə paylaş: |