Documentos de Académico
Documentos de Profesional
Documentos de Cultura
Pag
Training Center
for Automation and Drives
Page 1
2
3
4
5
6
7
8
9
10
11
12
13
15
16
17
18
19
20
21
22
24
25
26
27
ST-7PRO1
Digital Operations
BCD Code
Each digit of a decimal number is encoded in four bit positions. Four bits are used
b
because
th
the hi
highest
h td
decimal
i l di
digit,
it 9
9, requires
i
att lleastt ffour bit positions
iti
iin bi
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.
INTEGER
Training Center
for Automation and Drives
Page 2
ST-7PRO1
Digital Operations
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.
REAL
Training Center
for Automation and Drives
Page 3
ST-7PRO1
Digital Operations
MOVE (LAD/FBD)
If the EN input is active, the value at input IN is copied to the address at output
OUT.
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
ifi d d
destination
ti ti ((see nextt page).
)
Training Center
for Automation and Drives
Page 4
ST-7PRO1
Digital Operations
ACCU1
ACCU 1 is the central register in the CPU. When a Load instruction is executed, the
value
l tto be
b lloaded
d d iis written
itt into
i t ACCU 1
1; ffor a T
Transfer
f iinstruction
t ti th
the value
l tto b
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.
ACCU 2 is also used for comparison operations, digital logic operations,
mathematical
th
ti l and
d Shift operations.
ti
These
Th
operations
ti
will
ill b
be di
discussed
d iin d
detail
t il llater
t
on.
Training Center
for Automation and Drives
Page 5
ST-7PRO1
Digital Operations
General
Accumulators are auxiliary memories in the CPU for data exchange between
various
i
addresses
dd
and
d ffor comparison
i
and
d mathematical
th
ti l operations.
ti
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 onlyy 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.
Training Center
for Automation and Drives
Page 6
ST-7PRO1
Digital Operations
Time Specifications
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
d fi d b
defined
by th
the titime b
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.
Wh th
When
the titime iis specified
ifi d as a constant
t t (S5T#...),
(S5T# ) th
the titime b
base iis assigned
i
d
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).
)
Note
Training Center
for Automation and Drives
Page 7
ST-7PRO1
Digital Operations
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".
Training Center
for Automation and Drives
Page 8
ST-7PRO1
Digital Operations
Start
The timer starts when the RLO at the "S" input changes from "0" to "1". The timer
runs starting
t ti with
ith the
th time
ti
value
l specified
ifi d att input
i
t TV and
d continues
ti
to
t 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
Training Center
for Automation and Drives
Page 9
ST-7PRO1
Digital Operations
Start
The timer starts when the RLO at the "S" input changes from 1 to 0. When the
ti
timer
has
h expired,
i d the
th signal
i
l state
t t att output
t t Q changes
h
to
t "0".
"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
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.
Training Center
for Automation and Drives
Page 10
ST-7PRO1
Digital Operations
Start
The timer starts when the RLO at the S input changes from 0 to 1. Output Q is
also
l sett tto 1.
1
Reset
Training Center
for Automation and Drives
Page 11
ST-7PRO1
Digital Operations
Start
The timer starts when the RLO at the "S" input changes from 0 to 1. Output "Q"
i also
is
l sett tto 1
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.
Reset
Training Center
for Automation and Drives
Page 12
ST-7PRO1
Digital Operations
Bit Instructions
Training Center
for Automation and Drives
All timer functions can also be started with simple bit instructions. The similarities
and
d diff
differences b
between
t
thi
this method
th d and
d th
the titimer ffunctions
ti
di
discussed
d so ffar 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).
Page 13
ST-7PRO1
Digital Operations
Exercise
Training Center
for Automation and Drives
Page 14
ST-7PRO1
Digital Operations
Counter Value
A 16-bit word is reserved for each counter in the system data memory. This is used
f storing
for
t i the
th counter
t value
l for
f the
th counter
t (0...999)
(0 999) in
i bi
binary code.
d
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
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.
PV
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.
Types of Counter
Training Center
for Automation and Drives
S_CU
S_CD
S_CUD
Page 15
ST-7PRO1
Digital Operations
Bit Instructions
All counter functions can also operate with simple bit instructions. The similarities
and
d diff
differences between
b t
this
thi method
th d and
d th
the counter
t functions
f
ti
discussed
di
d so ffar 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.
.
Note
Training Center
for Automation and Drives
Page 16
ST-7PRO1
Digital Operations
Notes
If the counter reaches the value 999 during up counting, or the value 0 during down
counting,
ti
th
then th
the countt remains
i unchanged
h
d even iin th
the case off ffurther
th counting
ti
pulses.
If up counting and down counting is lined up at the same time, the count remains
the same.
Training Center
for Automation and Drives
Page 17
ST-7PRO1
Digital Operations
Goal
To add new functions to the bottling plant program. In addition to the already
programmed manual mode (FC15)
(FC15), a program for the automatic mode is to be
created.
Conveyor Control
in Automatic Mode
When the conveyor belt motor (Q 20.5 / Q 8.5) is switched on in automatic mode,
it remains on until it is switched off with the Stop switch (I 0.1) or until the sensor
(I 16.6 / I 8.6) detects a bottle. When the bottle has been filled, the conveyor must
automaticallly start moving again and keep moving until another bottle is detected or
the Stop switch is operated.
Bottle Filling
Bottle Counting
Another two sensors are provided for registering the full and empty bottles. Bottle
sensor I 16.5 (I 8.5) registers the empty bottles and bottle sensor I 16.7 (I 8.7)
registers the full bottles.
Both the empty bottles and the full bottles are to be counted from the time when the
plant is switched on (C 1 for the empty bottles and C 2 for the full bottles) and the
number of full bottles is to be displayed on digital display QW 12 (QW 6).
What to Do
Result
It should work.
Training Center
for Automation and Drives
Page 18
ST-7PRO1
Digital Operations
Example
Conversion
Instructions
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
p
g instructions.
IN
OUT
The result of the conversion is stored at the address at the OUT output.
BCD_I / BTI
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
DI_BCD / DTB
Training Center
for Automation and Drives
Page 19
ST-7PRO1
Digital Operations
Example
A user program that works with integers also needs to perform division, which is
lik l tto result
likely
lt iin values
l
lless th
than 1
1. Si
Since th
these values
l
can only
l b
be represented
t d as
real numbers, conversion to real numbers is necessary. To do this, the integer must
first be converted to a double integer.
I_DI / ITD
DI_R / DTR
Note
Training Center
for Automation and Drives
Page 20
ST-7PRO1
Digital Operations
CMP
Training Center
for Automation and Drives
You can use comparison instructions to compare the following pairs of numerical
values:
l
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
p
IN1 and IN2 are compared
p
for conformity
y with the specified
p
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.
Page 21
ST-7PRO1
Digital Operations
WAND_W
The "AND Word" operation gates the two digital values at inputs IN1 and IN2 bit by
bit iin accordance
d
with
ith th
the AND ttruth
th ttable.
bl Th
The result
lt off th
the AND operation
ti IIs stored
t d
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
WOR_W
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
Training Center
for Automation and Drives
Page 22
ST-7PRO1
Digital Operations
General
EN
ENO
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.
Instructions
Addition:
Subtraction:
M lti li ti
Multiplication:
Division:
Note
Training Center
for Automation and Drives
ADD_I
ADD_DI
ADD_R
SUB_I
SUB_DI
SUB_R
MUL I
MUL_I
MUL_DI
MUL_R
DIV_I
DIV_DI
DIV_R
Add integer
Add double integer
Add real number
Subtract integer
Subtract double integer
Subtract real number
M lti l iinteger
Multiply
t
Multiply double integer
Multiply real number
Divide integer
Divide double integer
Divide real number
The advanced mathematical functions (ABS, SQR, SQRT, LN, EXP, SIN, COS,
TAN,, ASIN,, ACOS,, ATAN)) are discussed in an advanced programming
p g
g course.
Page 23
ST-7PRO1
Digital Operations
Goal
What to Do
Training Center
for Automation and Drives
Page 24
ST-7PRO1
Digital Operations
Goal
To make the following addition to the program for the production data of the
bottling
b
ttli plant
l t:
The full bottles are packed in units of 6. The number of packs required is to
be calculated and displayed at QW12 (QW6).
The program for this task is to be written in FC19.
What to Do
Result
The number on the digital display (number of packs required ) is increased by 1 for
each multiple of 6 (bottles).
Training Center
for Automation and Drives
Page 25
ST-7PRO1
Digital Operations
Shift
SHL_W / SLW
The SHL_W operation shifts bits 0 to 15 of ACCU 1 bit-by-bit to the left by the number of
places specified at input N.
The bits on the right are padded with zeros.
SHR_W / SRW
The SHR_W operation shifts bits 0 to 15 of ACCU 1 bit-by-bit to the right by the number
of places specified at input N.
The bits on the left are padded with zeros.
ACCU1-H
OUT
The result of the shift operation is stored at the address at output OUT.
ENO
If the instruction is executed (EN = 1), ENO indicates the signal state of the last bit
shifted.
shifted
This means that other instructions dependent on ENO (cascading) are not executed if
the signal state of the last bit shifted is "0".
SHL_DW / SLD
SHR_DW / SRD
The procedure for the SHL_DW or SHR_DW operations is the same as that for the
SHL_W or SHR_DW operations, except that the entire contents of ACCU1 ( bits 0 to 31)
are shifted bit-by-bit to the left or right by the specified number of bits.
Training Center
for Automation and Drives
Page 26
ST-7PRO1
Digital Operations
SHR_I / SSI
The Shift Right Signed Integer operation shifts only ACCU1-L (bits 0 to 15) bit by bit
t the
to
th right.
i ht Th
The bit
bits th
thatt are vacated
t d are fill
filled
d with
ith th
the contents
t t off the
th sign
i bit (bit
15).
Bits 16 to 31 are not affected. Input N specifies the number of bit positions by which
the number is to be shifted. If N is greater than 16, N = 16 is assumed.
EN/ENO
If the instruction is executed (EN = 1), ENO indicates the signal state of the bit last
shifted (this bit corresponds to the CC1 and RLO bits in the status word). This
means that other instructions dependent on ENO (cascading) are not executed if
the signal
g
state of the last bit shifted is "0".
SHR_DI / SSD
The Shift Right Signed Double Integer operation shifts the entire contents of ACCU
1 (bits 0 to 31) to the right by the specified number of bits.
Permissible values for N: 0 to 32.
Note
Training Center
for Automation and Drives
Page 27
ST-7PRO1
Digital Operations
ROL_DW / RLD
The Rotate Left Doubleword operation rotates the entire contents of ACCU 1 to the
l ft The
left.
Th vacated
t d bits
bit are fill
filled
d with
ith th
the signal
i
l states
t t off th
the bit
bits th
thatt are pushed
h d out.
t
The last bit rotated is loaded in condition code bit 1 of the status word and also
stored at output ENO. This means that other instructions dependent on ENO
(cascading) are not executed if the signal state of the last bit rotated is "0".
ROR_DW / RRD
Note
Training Center
for Automation and Drives
Page 28
ST-7PRO1
Digital Operations