You are on page 1of 34

Digital Operations

M0.0 CMP ==I Q 9.7

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

SIMATIC® S7 Date: 03.09.2018 SITRAIN Training for


Automation and Drives
Siemens AG 2003. All rights reserved. File: SERV1_10E.1
Digital Operations

M0.0 CMP ==I Q 9.7

IW0 IN1
IW2 IN2

T4
I 0.7 S_ODT Q8.5
S Q
S5T#35s TV BI MW0
I 0.5
R BCD AW12

SIMATIC® S7 Date: 03.09.2018 SITRAIN Training for


Automation and Drives
Siemens AG 2003. All rights reserved. File: SERV1_10E.2
Objectives

Upon completion of this chapter the participant will ...


... be familiar with the INT, DINT, REAL data types and the BCD display
... be able to apply the selectable display formats in the "Monitor /
Modify Variable" test function
... understand the "Load" and "Transfer" instructions
... be able to apply and program S5 counter functions for problem solving
... be able to apply and program S5 timer functions for problem solving
... be able to apply and program the conversion operations INT <-> BCD
for problem solving
... be able to apply and program comparison operations for problem
solving
... be able to apply and program basic mathematical functions for
problem solving

SIMATIC® S7 Date: 03.09.2018 SITRAIN Training for


Automation and Drives
Siemens AG 2003. All rights reserved. File: SERV1_10E.3
Acquisition, Processing and Outputting Data

Process 0248
Thumbwheel
operating V buttons,
& monitoring Potentiometer,
0 8 1 5 7-segment
displays
Operator Panel

Control Processing
unit the values
such as MPI

DI/ AI/
DO AO

such as PROFIBUS

Process Field devices


controller

SIMATIC® S7 Date: 03.09.2018 SITRAIN Training for


Automation and Drives
Siemens AG 2003. All rights reserved. File: SERV1_10E.4
Integer (INT, 16-Bit Integer) Data Type
Value Range -32768 to +32767 Arithmetic
(without sign: 0 to 65535) Operations: such as + I, * I, <I, ==I

Display Formats:
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

DEC: + 662 BIN.: 2# 0 0 0 0 0 0 1 0 1 0 0 1 0 1 1 0 HEX: W#16 0 2 9 6


9 without
+2 7 sign
Sign 2 0
4 6 x 16 = 6
positive +2 2 1
numbers +2 1 9 x 16 = 144
+2 2 x 16
2
= 512
+ 662 662

15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

DEC: - 662 BIN.: 2# 1 1 1 1 1 1 0 1 0 1 1 0 1 0 1 0 HEX: W#16 F D 6 A


15 without
-2
+2 13
14 sign
Sign
negative +2 12 0
+2 11 10 x 16 =16
numbers 1
6 x 16 = 96
+2 10 2
8 6
+2 +2 +2 5 13 x 16 = 3328
3 1 3
Representation as +2 +2 +2 15 x 16 = 61440
twos complement - 662 64874

SIMATIC® S7 Date: 03.09.2018 SITRAIN Training for


Automation and Drives
Siemens AG 2003. All rights reserved. File: SERV1_10E.5
Double Integer (DINT, 32-Bit Integer) Data Type

Value Range L# -2147483648 to L#+2147483647 Arithmetic


(without sign: 0 to 4294967295) Operations: such as + D, * D, <D, ==D

Display Formats:
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

DEC: L# +540809 BIN.: 2# 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 1 0 0 1

Sign
positive
numbers

HEX: DW#16# 0 0 0 8 4 0 8 9
(without sign)

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

DEC: L# -540809 BIN.: 2# 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 0 1 1 1 1 1 1 0 1 1 1 0 1 1 1

Sign
negative
numbers

Representation as HEX: DW#16# F F F 7 B F 7 7


twos complement
(without sign)

SIMATIC® S7 Date: 03.09.2018 SITRAIN Training for


Automation and Drives
Siemens AG 2003. All rights reserved. File: SERV1_10E.6
REAL (Floating-point Number, 32 Bit) Data Type

Value Range -1.175495•10-38 to 3.402823•10+38 Arithmetic


Operations: such as + R, * R, <R, ==R
sin, acos, ln, exp, SQR

General Format of a Real Number = (Sign) • (1.f) • (2e-127)

Example: 7.50000e-001 (7.5 * 10-1 = 0.75)

Sign of
Real No. e = Exponent (8 Bit) f = Mantissa (23 Bit)

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

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

Real No. = +1.5 * 2 126-127 = 0.75

SIMATIC® S7 Date: 03.09.2018 SITRAIN Training for


Automation and Drives
Siemens AG 2003. All rights reserved. File: SERV1_10E.7
The BCD Code for Inputting and Outputting Integers

Value Range 16 Bit: - 999 to + 999 Conversion


32 Bit: -9999999 to + 9999999 Operations: BTI, BTD, ITB, DTB
(no arithmetic!)

0 2 9 6

16 Bit: BIN.: 2# 0 0 0 0 0 0 1 0 1 0 0 1 0 1 1 0

Sign (+) 2 9 6

HEX: W#16# 0 2 9 6 DEC: + 662

Sign (+) 0 0 0 0 2 9 6

32 Bit: BIN.: 2# 0 x x x 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

HEX: DW#16# 0 0 0 0 2 9 6 DEC: + 662

SIMATIC® S7 Date: 03.09.2018 SITRAIN Training for


Automation and Drives
Siemens AG 2003. All rights reserved. File: SERV1_10E.8
"Monitor / Modify Variables": Display Formats

SIMATIC® S7 Date: 03.09.2018 SITRAIN Training for


Automation and Drives
Siemens AG 2003. All rights reserved. File: SERV1_10E.9
Loading and Transferring Data (1)

LAD FBD STL

MOVE MOVE
L +5
EN ENO EN OUT MB5
T MB5

5 IN OUT MB5 5 IN ENO

Examples L +5 // 16-bit constant (Integer)


of Load L L#523123 // 32-bit constant (Double
Integer)
L B#16#EF // byte in hexadecimal form
L 2#0010 0110 1110 0011 // 16-bit binary value
L 3.14 // 32-bit constant (Real)

SIMATIC® S7 Date: 03.09.2018 SITRAIN Training for


Automation and Drives
Siemens AG 2003. All rights reserved. File: SERV1_10E.10
Loading and Transferring Data (2)

Content of Content of
ACCU1 ACCU2
Program

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
:
:
:

SIMATIC® S7 Date: 03.09.2018 SITRAIN Training for


Automation and Drives
Siemens AG 2003. All rights reserved. File: SERV1_10E.11
Loading and Transferring Data (3)
Contents of ACCU1
Program
31 23 15 7 0

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

L MD 0 MB0 MB1 MB2 MB3

T QD 4
QD 4

Transfer T QW 4
QW 4

T QB 4
QB 4

SIMATIC® S7 Date: 03.09.2018 SITRAIN Training for


Automation and Drives
Siemens AG 2003. All rights reserved. File: SERV1_10E.12
S5 Counters in STEP 7
LAD FBD STL

A I0.4
C5 C5
CU C5
S_CUD S_CUD A I0.5
I 0.4 Q 8.3
CU QQ I 0.4 CU CD C5
A I0.3
I 0.5
L C#20
CD CV MW 4 I 0.5 CD
S C5
I 0.3 A I0.7
S CV_BCD QW 12 I 0.3 S CV MW 4 R C5
L C5
C#20 PV C#20 PV CV_BCD QW 12 T MW4
Q 8.3 LC C5
I 0.7
R I 0.7 R Q
Q = T QW12
A C5
= Q8.3

SIMATIC® S7 Date: 03.09.2018 SITRAIN Training for


Automation and Drives
Siemens AG 2003. All rights reserved. File: SERV1_10E.13
Counters: Function Diagram

CU

CD

5
4
3
Count
2
1
0

SIMATIC® S7 Date: 03.09.2018 SITRAIN Training for


Automation and Drives
Siemens AG 2003. All rights reserved. File: SERV1_10E.14
Counters: Bit Instructions
LAD FBD STL

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

SIMATIC® S7 Date: 03.09.2018 SITRAIN Training for


Automation and Drives
Siemens AG 2003. All rights reserved. File: SERV1_10E.15
Exercise: Counting the Transported Parts (FC 18, C 18)

DI DO Q 8....
Q 4....
I 0.0 T_System_ON .0 ACTUAL number of parts
I 0.1 T_System_OFF L_SYSTEM .1
I 0.2 T_Jog_RT L_MAN .2
I 0.3 T_Jog_LT L_AUTO .3 V

I 0.4 S_M/A_ModeSelect .4
I 0.5 T_M/A_Accept .5 QW 12 / QW 6
-15V...+15V -15V...+15V
I 0.6 .6 AI2 AO1
AI1 AO2
I 0.7 .7

AI1 AI2
V

0 8 1 5 AI1 AI2 AO1 AO2

SIMATIC® S7 Date: 03.09.2018 SITRAIN Training for


Automation and Drives
Siemens AG 2003. All rights reserved. File: SERV1_10E.16
Timers: ON Delay (SD)
LAD FBD STL

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

Data type 0.01s <-- 0 0


0.1s <-- 0 1
“S5TIME” 1s <-- 1 0 Units of time: 0 to 999 (BCD-coded)
10s <-- 1 1

SIMATIC® S7 Date: 03.09.2018 SITRAIN Training for


Automation and Drives
Siemens AG 2003. All rights reserved. File: SERV1_10E.17
Timers: Time Formats for S5-Timers in STEP 7

Time specifications as constants


S5T#35s200ms
(Time base: 01 (100ms), Number of units of time: 352)

01 3 5 2

Time specifications per variable X X 0 1 0 0 1 1 0 1 0 1 0 0 1 0

Time base Units of time (BCD-coded)

29 28 27 26 25 24 23 22 21 20
Accu 1 contents after “L T...” exec. X X X X X X 0 1 0 1 1 0 0 0 0 0

Residual units of time (Integer)

01 3 5 2

Accu 1 cont. after “LC T...” exec. X X 0 1 0 0 1 1 0 1 0 1 0 0 1 0

Time base Residual units of time (BCD-coded)

SIMATIC® S7 Date: 03.09.2018 SITRAIN Training for


Automation and Drives
Siemens AG 2003. All rights reserved. File: SERV1_10E.18
Timers: Stored ON Delay (SS)
LAD FBD STL

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

SIMATIC® S7 Date: 03.09.2018 SITRAIN Training for


Automation and Drives
Siemens AG 2003. All rights reserved. File: SERV1_10E.19
Timers: Pulse (SP)
LAD FBD STL

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 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

SIMATIC® S7 Date: 03.09.2018 SITRAIN Training for


Automation and Drives
Siemens AG 2003. All rights reserved. File: SERV1_10E.20
Timers: Extended Pulse (SE)
LAD FBD STL

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

SIMATIC® S7 Date: 03.09.2018 SITRAIN Training for


Automation and Drives
Siemens AG 2003. All rights reserved. File: SERV1_10E.21
Timers: OFF Delay (SF)
LAD FBD STL

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

SIMATIC® S7 Date: 03.09.2018 SITRAIN Training for


Automation and Drives
Siemens AG 2003. All rights reserved. File: SERV1_10E.22
Timers: Bit Instructions
LAD FBD STL

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

SIMATIC® S7 Date: 03.09.2018 SITRAIN Training for


Automation and Drives
Siemens AG 2003. All rights reserved. File: SERV1_10E.23
Exercise: Locking-Out the Conveyor Motor Jog

Lock-out
time LEFT

T_Jog_RT
I 0.2
Run Conveyor
RIGHT
(Q20.5 / Q8.5)

Lock-out
RIGHT
T 15 (SF)

T_Jog_LT
I 0.3
Lock-out
time RIGHT
Run Conveyor
LEFT
(Q20.6 / Q8.6)

Lock-out
LEFT
T 16 (SF)

SIMATIC® S7 Date: 03.09.2018 SITRAIN Training for


Automation and Drives
Siemens AG 2003. All rights reserved. File: SERV1_10E.24
Exercise: Monitoring of the Transport Functions (FC 17)

DI DO Q 8....
Q 4....
I 0.0 T_System_ON .0 ACTUAL number of parts
Flt
I 0.1 T_System_OFF L_System .1
I 0.2 T_Jog_RT L_MAN .2
I 0.3 T_Jog_LT L_AUTO .3 V

I 0.4 S_M/A_ModeSelect .4
I 0.5 T_M/A_Accept .5 QW 12 / QW 6
-15V...+15V -15V...+15V
I 0.6 .6 AI2 AO1
AI1 AO2
I 0.7 .7

I 1.0 T_Fault_Rst
AI1 AI2
Weight V

0 8 1 5 AI1 AI2 AO1 AO2

SIMATIC® S7 Date: 03.09.2018 SITRAIN Training for


Automation and Drives
Siemens AG 2003. All rights reserved. File: SERV1_10E.25
Exercise: Counting the Conveyor Operation Faults

Conv. oper.
fault
M 17.0

3
Conv. oper.
2
fault
counter C 17 1
0

AUTO mode
Q 4.3 (Q 8.3)

SIMATIC® S7 Date: 03.09.2018 SITRAIN Training for


Automation and Drives
Siemens AG 2003. All rights reserved. File: SERV1_10E.26
Conversion Operations BCD <-> Integer

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

LAD FBD STL

BCD_I BCD_I L I W4
EN ENO EN OUT MW20 BTI
T MW20
I W4 IN OUT MW20 I W4 IN ENO

I_BCD I_BCD L MW10


EN ENO EN OUT QW12 ITB
T QW12
MW10 IN OUT QW12 MW10 IN ENO

SIMATIC® S7 Date: 03.09.2018 SITRAIN Training for


Automation and Drives
Siemens AG 2003. All rights reserved. File: SERV1_10E.27
Comparison Operations

LAD FBD STL

M3.4 CMP ==I Q 9.7 CMP ==I A M3.4


A(
L I W0
I W0 IN1
L I W2
I W0 IN1
==I
I W2 IN2 I W2 IN2 )
&
Q9.7
= Q9.7
=
M3.4

SIMATIC® S7 Date: 03.09.2018 SITRAIN Training for


Automation and Drives
Siemens AG 2003. All rights reserved. File: SERV1_10E.28
Basic Mathematical Functions
LAD FBD STL

ADD_I ADD_I L MW4


Addition EN ENO EN OUT MW6 L MW10
MW4 IN1 OUT MW6 MW4 IN1 +I
MW10 IN2 MW10 IN2 ENO T MW6

SUB_I SUB_I L MW8


Subtrac- MW6
tion EN ENO EN OUT L MW12
MW8 IN1 OUT MW6 MW8 IN1 -I
MW12 IN2 ENO
T MW6
IN2 MW12

MUL_R MUL_R L MD6


Multipli- MD66
cation EN ENO EN OUT L MD12
MD6 IN1 OUT MD6 IN1 *R
MD66
MD12 IN2 MD12 IN2 ENO T MD66

DIV_R DIV_R L MD40


EN OUT MD32
Division EN ENO L MD4
MD40 IN1 OUT MD32 MD40 IN1 /R
MD4 IN2 MD4 IN2 ENO T MD32

SIMATIC® S7 Date: 03.09.2018 SITRAIN Training for


Automation and Drives
Siemens AG 2003. All rights reserved. File: SERV1_10E.29
Exercise: Counting the Transported Parts (FC 18, MW 20)

DI DO Q 8....
Q 4....
I 0.0 T_System_ON Flt .0 ACTUAL number of parts
I 0.1 T_System_OFF L_System .1
I 0.2 T_Jog_RT L_MAN .2
I 0.3 T_Jog_LT L_AUTO .3 V

I 0.4 S_M/A_ModeSelect .4
I 0.5 T_M/A_Accept .5 QW 12 / QW 6
-15V...+15V -15V...+15V
I 0.6 .6 AI2 AO1
AI1 AO2
I 0.7 .7

I 1.0 T_Fault_Rst
AI1 AI2
Weight V
SETPOINT number of parts

0 8 1 5 AI1 AI2 AO1 AO2

IW 4 / IW 2

SIMATIC® S7 Date: 03.09.2018 SITRAIN Training for


Automation and Drives
Siemens AG 2003. All rights reserved. File: SERV1_10E.30
Exercise: Counting the Transported Parts (FC 18), Solution Hints
NW 1: Set "counter" to 0

MOVE
Condition
for resetting EN OUT MW 20
0 IN ENO

NW 2: Counting using memory word, ACTUAL number of parts


ADD_I
Positive edge
of counter event EN ENO

MW 20 IN1 OUT MW 20

1 IN2

NW 3: Display ACTUAL number of parts on BCD digital display

Convert ACTUAL number of parts (MW 20) from Integer to BCD


-> Result on BCD digital display (QW 12 or QW 6)

NW 4: Readin SETPOINT number of parts and convert from BCD to Integer

Convert value from thumbwheel button (IW 4 or IW 2) from BCD to Integer


-> store SETPOINT number of parts (Integer) in MW 200

NW 5: ACTUAL-SETPOINT comparison, LED (red LED Q 20.4 or Q8.4)

Compare ACTUAL (MW 20) to SETPOINT (MW 200), send comparison result to LED

SIMATIC® S7 Date: 03.09.2018 SITRAIN Training for


Automation and Drives
Siemens AG 2003. All rights reserved. File: SERV1_10E.31
Exercise: Controlling LEDs

Steady light for


ACTUAL=SETPOINT
Steady light
at both bays when a new part can be placed on the conveyor

1 Hz flashing light
at the bay where the part was placed and from which the conveyor can
be started

2 Hz flashing light
at both bays as long as the transport function is running

SIMATIC® S7 Date: 03.09.2018 SITRAIN Training for


Automation and Drives
Siemens AG 2003. All rights reserved. File: SERV1_10E.32
Conversion Operations I -> DI -> REAL

Data in integer format


(16 bits)

Conversion from Conversion from Math


Task integer to double integer program
double integer to real number with
real numbers

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

MW12 IN OUT MD14 MD14 IN OUT MD26

SIMATIC® S7 Date: 03.09.2018 SITRAIN Training for


Automation and Drives
Siemens AG 2003. All rights reserved. File: SERV1_10E.33
Digital Logic Operations

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

MW10 after “AW” ex. 0 1 0 0 0 0 0 0 0 0 1 0 0 0 1 0

MW10 after “OW” ex. 0 1 0 1 1 1 1 1 0 0 1 1 1 0 1 0

MW10 after “XOW” ex. 0 0 0 1 1 1 1 1 0 0 0 1 1 0 0 0

SIMATIC® S7 Date: 03.09.2018 SITRAIN Training for


Automation and Drives
Siemens AG 2003. All rights reserved. File: SERV1_10E.34

You might also like