Академический Документы
Профессиональный Документы
Культура Документы
IW0 IN1
IW2 IN2
T4
I 0.7 S_ODT Q8.5
S Q
S5T#35s TV BI MW0
I 0.5
R BCD QW12
Contents Page
Sign (+) 2 9 6
BCD W#16#296
0 0 0 0 0 0 1 0 1 0 0 1 0 1 1 0
Positive
Numbers 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
0 0 0 0 0 0 0 1 0 0 1 0 1 0 0 0
INTEGER
+296 28 25 23
= = =
256 + 32 + 8 = 296
Sign (-) 4 1 3
BCD W#16#F413
1 1 1 1 0 1 0 0 0 0 0 1 0 0 1 1
Negative
Numbers 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
1 1 1 1 1 1 1 0 0 1 1 0 0 0 1 1
INTEGER
-413 28 27 24 23 22
= = = = =
256+ 128 + 16+8+ 4 = 412
- (412 + 1) = - 413
BCD Code Each digit of a decimal number is encoded in four bit positions. Four bits are
used because the highest decimal digit, 9, requires at least four bit positions in
binary code ( 1001).
The decimal digits from 0 to 9 are represented in BCD code in the same way as
the binary numbers from 0 to 9.
DW#16#296 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 1 0 1 1 0
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
DINT
+296 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 0 1 0 0 0
28 25 23
= = =
Integer (32 Bit) = 256 + 32 + 8 = 296
0 0 1 1 1 1 1 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
27 26 25 24 23 22 21 20 2-1 2-2 2-3 2-4 ..... 2-23
DINT 32-bit integers with sign are also referred to as "double integers" or "long
integers".
They cover the range from L# -2147483648 to L#+2147483647.
MOVE MOVE
L +5
EN ENO EN OUT MB5
T MB5
MOVE (LAD/FBD) If the EN input is active, the value at input “IN” is copied to the address at output
“OUT”.
“ENO” has the same signal state as “EN”.
L and T (STL) Load and Transfer instructions are executed regardless of the RLO. Data is
exchanged via the accumulator.
The Load instruction writes the value from the source address right-justified into
accumulator 1 and pads the remaining bits (32 bits in all) with "0"s.
The Transfer instruction copies some or all of the contents of the accumulator to
the specified destination (see next page).
Content of Content of
ACCU1 ACCU2
Programm
X X X X X X X X Y Y Y Y Y Y Y Y
:
:
L W#16#CAFE 0 0 0 0 C
0 A
0 F
0 E
0 X X X X X X X X
L W#16#AFFE 0 0 0 0 A
0 F
0 F
0 E
0 0 0 0 0 C A F E
:
:
:
ACCU1 ACCU 1 is the central register in the CPU. When a Load instruction is executed,
the value to be loaded is written into ACCU 1; for a Transfer instruction the
value to be transferred is read from ACCU 1, and the results of the
mathematical functions, Shift and Rotate operations, etc. are also entered in
ACCU 1.
ACCU2 When a Load instruction is executed, the old contents of ACCU 1 are first shifted
to ACCU 2 and ACCU 1 is cleared (reset to “0”) before the new value is written
into ACCU 1.
L MB 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 MB0
31 23 15 7 0
Load 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 MB0 MB1
L MW 0
31 23 15 7 0
T QD 4
QD 4
Transfer T QW 4
QW 4
T QB 4
QB 4
General Accumulators are auxiliary memories in the CPU for data exchange between
various addresses and for comparison and mathematical operations.
The S7-300 has 2 accumulators with 32 bits each and the S7-400 has 4
accumulators with 32 bits each.
Load The Load instruction loads the contents of the specified byte, word or double
word into ACCU 1.
Transfer When a Transfer instruction is executed, the contents of ACCU 1 are retained.
The same information can therefore be transferred to different destinations. If
only one byte is transferred, the eight bits furthest to the right are used (see
diagram).
RLO In LAD and FBD you can use the Enable input (EN) of the MOVE box to make
Load and Transfer operations dependent on the RLO.
In STL Load and Transfer operations are always executed, regardless of the
RLO, but you can implement RLO-dependent load and transfer by using
conditional jumps to skip the Load / Transfer instructions.
A I0.4
C5 C5
CU C5
S_CUD S_CUD A I0.5
I 0.4 Q 8.3
CU Q
Q I 0.4 CU CD C5
A I0.3
I 0.5
L C#20
CD I 0.5 CD
S C5
I 0.3 A I0.7
S I 0.3 S CV MW 4 R C5
L C5
C#20 PV CV MW 4 C#20 PV CV_BCD QW 12 T MW4
Q 8.3 LC C5
I 0.7
R CV_BCD QW 12 I 0.7 R Q
Q = T QW12
A C5
= Q8.3
Counter Value A 16-bit word is reserved for each counter in the system data memory. This is
used for storing the counter value for the counter (0...999) in binary code.
Count Up When the RLO at the "CU" input changes from "0" to "1" the current counter
reading is incremented by 1 (upper limit = 999).
Count Down When the RLO at the "CD" input changes from "0" to "1" the current counter
reading is decremented by 1 (lower limit = 0).
Set Counter When the RLO at the "S" input changes from "0" to "1" the counter is set to the
value at the "CV" input.
Reset Counter When RLO = 1 the counter is set to zero. If the Reset condition is fulfilled, the
counter cannot be set and counting is not possible.
CV / CV_BCD The counter value can be loaded as a binary number or BCD number into the
accumulator and transferred from there to other addresses.
CU
CD
5
4
3
Count
2
1
0
Notes If the counter reaches the value 999 during up counting, or the value 0 during
down counting, then the count remains unchanged even in the case of further
counting pulses.
If up counting and down counting is lined up at the same time, the count remains
the same.
Network 1: C5
I 0.0 SC
I 0.0 C5
A I 0.0
SC L C#20
C#20 CV
C#20 S C5
Network 2:
C5
I 0.1 C5
I 0.1 CU A I 0.1
CU
CU C5
Network 3:
I 0.2 C5 C5
A I 0.2
CD I 0.2 CD CD C5
Network 4:
C5 Q 4.0 Q 4.0
A C5
C5 = = Q 4.0
Bit Instructions All counter functions can also operate with simple bit instructions. The
similarities and differences between this method and the counter functions
discussed so far are as follows:
• Similarities:
- Setting conditions at the "SC" input
- Specification of the counter value
- RLO change at the "CU" input
- RLO change at the "CD" input
• Differences:
- It is not possible to check the current counter value
(there are no BI and BCD outputs).
- There is no binary output Q in the graphical representation.
DI DO Q 8....
Q 4....
I 0.0 System_ON .0 ACTUAL number of parts
I 0.1 System_OFF System .1
I 0.2 Jog_RIGHT MANUAL .2
I 0.3 Jog_LEFT AUTO .3 V
AI1 AI2
V
Function Up Till Now In AUTO mode, parts are transported from Location 1 or 2 to the location Final
Control or through past the light barrier. The transportation function starts as
soon as a part is placed on Location 1 or 2 and the associated location
momentary contact switch is pressed and it ends as soon as the part has
passed the light barrier.
Task: • The parts transported in AUTO mode are to be counted as soon as they
reach the Location - Final Control or they have passed the light barrier.
• The number of transported parts (ACTUAL number of parts) is to be
displayed on the BCD digital display.
• The counter is to be reset when the system is switched off (Q 8.1 / 4.1 = ´0).
What To Do: • Program the counting of the transported parts in block FC 18. Use the S5
counter C 18 in the FC 18 for this.
• Program the call of FC 18 in OB 1
T4 T4
I 0.7 S_ODT Q8.5 S_ODT A I 0.7
S Q I 0.7 S BI MW0 L S5T#35s
S5T#35s TV BI MW0 S5T#35s QW12
SD T4
TV BCD
I 0.5 Q8.5 A I 0.5
R BCD QW12 I 0.5 R Q = R T4
L T4
T MW0
RLO at S
LC T4
RLO at R T QW12
A T4
Timer = Q8.5
operation
Example
Start The timer starts when the RLO at the "S" input changes from “0” to “1”. The
timer runs starting with the time value specified at the TV input as long as the
signal state at input S =1.
Reset When the RLO at Reset input "R" is "1", the current time value and the time
base are deleted and output Q is reset.
Digital Outputs The current time value can be read as a binary number at the BI output and as a
BCD number at the BCD output.
The current time value is the initial value of TV minus the value for the time that
has elapsed since the timer was started.
Binary Output The signal at the "Q" output changes to "1" when the timer has expired without
error and input "S" has signal state "1".
If the signal state at the "S" input changes from "1" to "0" before the timer has
expired, the timer stops running. In this case output “Q” has signal state "0".
Time Specifications 1. Fixed time values specified as time constants (e.g.: S5T#100ms, S5T#35s,
S5T#5m2s200ms, S5T#2h2m2s50ms).
2. Time values to be changed by the machine operator using pushwheel buttons.
3. Process or recipe-dependent time values in memory words or data words.
Timer Cell A special area of memory is reserved for timers in your CPU. This area contains
a 16-bit word for each timer address.
Bits 0 to 9 of the timer word contain the time value in binary code.
When the timer is updated, the time value is decremented by one unit at the
interval defined by the time base.
Time Base Bits 12 and 13 of the timer word contain the time base in binary code:
0 = 10 ms
1 = 100 ms
2 = 1s
3 = 10 s.
The time base defines the interval at which the time value is to be decremented
by one unit.
When the time is specified as a constant (S5T#...), the time base is assigned
automatically by the system. If the time is to be specified using pushwheel
buttons or via a data interface, the user must also specify the time base.
L / BI The address at the “BI” output contains the time value in the form of a
10-digit binary number (without time base!).
LC / BCD The address at the “BCD” output contains both the time value as a 3-digit BCD
number (12 bits) and the time format (bits 12 and 13).
T4 T4 A I 0.7
I 0.7 S_ODTS Q8.5 S_ODTS L S5T#35s
S Q I 0.7 S BI MW0 SS T4
S5T#35s BI MW0 A I 0.5
TV S5T#35s TV BCD QW12
I 0.5 Q8.5 R T4
R BCD QW12 I 0.5 R Q = L T4
T MW0
LC T4
T QW12
A T4
= Q8.5
RLO at S
RLO at R
Timer
operation
Example
Start The timer starts when the RLO at the "S" input changes from "0" to "1". The
timer runs starting with the time value specified at input TV and continues to run
even if the signal at input "S" changes to "0" during that time.
If the signal at the Start input changes from “0” to “1” again while the timer is still
running, the timer starts again from the beginning.
Reset When the RLO at Reset input "R" is "1", the current time value and the time
base are deleted and output Q is reset.
Binary Output The signal state at output Q changes to "1" when the timer has expired without
error, regardless of whether the signal state at the "S" input is still "1".
T4 T4 A I 0.7
I 0.7 S_PULSE Q8.5 S_PULSE L S5T#35s
S Q I 0.7 S BI MW0 SP T4
S5T#35s BI A I 0.5
TV MW0 S5T#35s TV BCD QW12
I 0.5 Q8.5 R T4
R BCD QW12 I 0.5 R = L T4
Q
T MW0
LC T4
T QW12
A T4
= Q8.5
RLO at S
RLO at R
Timer
operation
Example
Start The timer starts when the RLO at the “S” input changes from “0” to “1”. Output
“Q” is also set to “1”.
T4 T4 A I 0.7
I 0.7 S_PEXT Q8.5 S_PEXT L S5T#35s
S Q MW0 SE T4
I 0.7 S BI
S5T#35s TV BI MW0 A I 0.5
S5T#35s TV BCD QW12
I 0.5 A8.5 R T4
R BCD QW12 I 0.5 R L T4
Q =
T MW0
LC T4
T QW12
A T4
= Q8.5
RLO at S
RLO at R
Timer
Operation
Example
Start The timer starts when the RLO at the "S" input changes from “0” to “1”. Output
"Q" is also set to “1”.
The signal state at output “Q” remains at “1” even if the signal at the "S" input
changes to “0”.
If the signal at the Start input changes from “0” to “1” again while the timer is
running, the timer is restarted.
T4 T4 A I 0.7
I 0.7 S_OFFDT Q8.5 S_OFFDT L S5T#35s
S Q I 0.7 S BI MW0 SF T4
S5T#35s BI MW0 A I 0.5
TV S5T#35s TV BCD QW12
I 0.5 Q8.5 R T4
R BCD QW12 I 0.5 R Q = L T4
T MW0
LC T4
T QW12
A T4
= Q8.5
RLO at S
RLO at R
Timer
operation
Example
Start The timer starts when the RLO at the "S" input changes from “1” to “0”. When
the timer has expired, the signal state at output Q changes to "0".
If the signal state at the "S" input changes from “0” to “1” while the timer is
running, the timer stops and the next time the signal state changes from "1" to
"0" it starts again from the beginning.
Reset When the RLO at Reset input "R" is "1", the current time value and the time
base are deleted and output Q is reset.
If both inputs (S and R) have signal state “1”, output “Q” is not set until the
dominant Reset is deactivated.
Binary Output Output "Q" is activated when the RLO at the "S" input changes from “0” to “1”. If
input “S” is deactivated, output “Q” continues to have signal state “1” until the
programmed time has expired.
Network 1:
T4
I 0.0 T4 I 0.0 & SD A I 0.0
SD L S5T#5s
S5T#5s TV SD T4
S5T#5s
Network 2:
T4 Q 8.0 Q 8.0
A T4
T4 & =
= Q 8.0
Network 3:
T4
I 0.1 T4 A I 0.1
R I 0.1 & R R T4
Bit Instructions All timer functions can also be started with simple bit instructions. The
similarities and differences between this method and the timer functions
discussed so far are as follows:
• Similarities:
- Start conditions at the "S" input
- Specification of the time value
- Reset conditions at the “R” input
- Signal response at output “Q”
• Differences (for LAD and FBD):
- It is not possible to check the current time value (there are no BI and
BCD outputs).
DI DO Q 8....
Q 4....
I 0.0 System_ON Disturbance .0 ACTUAL number of parts
I 0.1 System_OFF System .1
I 0.2 Jog_RIGHT MANUAL .2
I 0.3 Jog_LEFT AUTO .3 V
I 1.0 Ack_Dist
AI1 AI2
Weight V
Function Up Till Now: In AUTO mode, parts are transported from Location 1 or 2 to the location Final
(in FC 16) Control. The transportation function starts as soon as a part is placed on
Location 1 or 2 and the associated location momentary contact switch is
pressed and it ends as soon as the part has passed the light barrier.
Number Conversion
entered in BCD 0 81 5 BCD->Integer
User program with
Task
integer math
operations
Number Conversion
displayed 0 2 4 8 BCD<-Integer
in BCD
BCD_I BCD_I L I W4
EN ENO EN OUT MW20 BTI
T MW20
I W4 IN OUT MW20 I W4 IN ENO
Example A user program is to perform mathematical functions using values entered with
pushwheel buttons and display the result on a digital display. Mathematical
functions cannot be performed in BCD format, so the format must be changed.
EN, ENO If RLO is =1 at Enable input EN, the conversion is performed. Enable output
ENO always has the same signal state as EN. If this is not the case, it is clearly
indicated in the corresponding instructions.
OUT The result of the conversion is stored at the address at the OUT output.
BCD_I / BTI (Convert BCD to integer) reads the contents of the IN parameter as a three-digit
BCD number (+/- 999) and converts it to an integer value (16 bits).
I_BCD / ITB (Convert integer to BCD) reads the contents of the IN parameter as an integer
value (16 bits) and converts this value to a three-digit BCD number (+/- 999). If
an overflow occurs, ENO = 0.
BCD_DI / BTD Converts a BCD number (+/- 9999999) to a double integer (32 bits).
DI_BCD / DTB Converts a double integer to a seven-digit BCD number (+/- 9999999). If an
overflow occurs, ENO = 0.
CMP You can use comparison instructions to compare the following pairs of
numerical values:
I Compare integers (on the basis of 16 bit fixed-point number)
D Compare integers (on the basis of 32 bit fixed-point number)
R Compare floating-point numbers (on 32 bit real number basis =
IEEE floating-point numbers).
If the result of the comparison is “True", then the RLO of the operation "1",
otherwise "0".
The values at inputs IN1 and IN2 are compared for conformity with the specified
condition:
== 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.
IN1,IN2 The value at IN1 is read in as the first address and the value at IN2 as the
second.
OUT The result of the mathematical operation is stored at the address at output OUT.
Note The advanced mathematical functions (ABS, SQR, SQRT, LN, EXP, SIN, COS,
TAN, ASIN, ACOS, ATAN) are discussed in an advanced programming course.
DI DO Q 8....
Q 4....
I 0.0 System_ON Disturbance .0 ACTUAL number of parts
I 0.1 System_OFF System .1
I 0.2 Jog_RIGHT MANUAL .2
I 0.3 Jog_LEFT AUTO .3 V
I 1.0 Ack_Dist
AI1 AI2
Weight V
SETPOINT number of parts
IW 4 / IW 2
Function Up Till Now: • The parts transported in AUTO mode are to be counted (with S5 counter
in FC 18 C 18), as soon as they reach the location Final Control or have passed the
light barrier.
• The number of transported parts (ACTUAL number of parts) is displayed on
the BCD digital display.
• The counter is reset when the system is switched off (Q 8.1 / 4.1 = ´0)
Task: • The counting of the transported parts is no longer to be made with the S5
counter C 18, but rather by addition with MW 20. Use the bit memory M 18.0
as auxiliary memory marker for the necessary edge detection.
• The SETPOINT number of, how many parts are to be transported. When the
given SETPOINT number of parts is reached, it is displayed on the red LED
(Q 20.4 / Q 8.4) at the location Final Control.
• As long as the message SETPOINT number of parts reached (red LED)
exists, no other transport function can be started (lock-out in FC 16).
• The message can be acknowledged with the momentary contact switch at
location Final Control. The acknowledgement resets the ACTUAL number of
parts (MW 20) to 0, just as it was for switching off the system.
What To Do: • Insert the organization block OB 121 into your program and download it to
the CPU. A program in OB 121 is not necessary. Downloading the "empty"
OB 121 prevents the CPU from going into the STOP state during setting of
the SETPOINT number of parts by a "rebound" from the BCD pushwheel
button (more information on this in the Chapter OBs).
• Amend your current FC 18 for counting the parts to the new task
• Modify the FC 16 for controlling the conveyor motor according to the task
F AWL
I_DI
B MD14
EN OUT
D DI_R
ENO EN OUT MD26
MW12 IN L MW12
LAD ENO ITD
MD14 IN
DTR
T MD26
I_DI DI_R
EN ENO EN ENO
Example A user program that works with integers also needs to perform division, which is
likely to result in values less than 1. Since these values can only be represented
as real numbers, conversion to real numbers is necessary. To do this, the
integer must first be converted to a double integer.
WXOR_W L IW 0
WOR_W
L W#16#5F2A
WAND_W
AW / OW / XOW
EN ENO
T MW10
IW0 IN1
OUT MW10 15 0
W#16#5F2A IN2
IW0 = 0 1 0 0 0 0 0 0 0 0 1 1 0 0 1 0
W#16#5F2A = 0 1 0 1 1 1 1 1 0 0 1 0 1 0 1 0
AND OR XOR
WAND_W The "AND Word" operation gates the two digital values at inputs IN1 and IN2 bit
by bit in accordance with the AND truth table. The result of the AND operation Is
stored at the address at output OUT.
The instruction is executed when EN = 1.
Example: Masking out the 4th decade of the pushwheel buttons :
IW4= = 0100 0100 1100 0100
W#16#0FFF = 0000 1111 1111 1111
MW30 = 0000 0100 1100 0100
WOR_W The "OR Word" operation gates the two digital values at inputs IN1 and IN2 bit
by bit in accordance with the OR truth table. The result of the OR operation is
stored at the address at output OUT.
The instruction is executed when EN = 1.
Example: Setting bit 0 in MW32 :
MW32 = 0100 0010 0110 1010
W#16#0001 = 0000 0000 0000 0001
MW32 = 0100 0010 0110 1011
WXOR_W The "Exclusive OR Word" operation gates the two digital values at inputs IN1
and IN2 bit by bit in accordance with the XOR truth table. The result of the OR
operation is stored at the address at output OUT. The result of the XOR
operation is stored at the address at output OUT.
The instruction is executed when EN=1.
Example: detecting signal changes in IW0 :
IW0 = 0100 0100 1100 1010
MW28 = 0110 0010 1011 1001
MW24 = 0010 0110 0111 0011