You are on page 1of 35

Digital Operations

F1

SIMATIC S7 Date: 2/4/2012 SITRAIN Training for


Automation and Industrial Solutions
Siemens AG 2006. All rights reserved. File: PRO1_08E.1
Digital Operations

F1

SIMATIC S7 Date: 2/4/2012 SITRAIN Training for


Automation and Industrial Solutions
Siemens AG 2006. All rights reserved. File: PRO1_08E.2
Objectives

Upon completion of the 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 the S5 counter and timer


functions

... understand conversion operations for number formats

... be able to apply and program the comparison


operations

... understand basic mathematical functions

SIMATIC S7 Date: 2/4/2012 SITRAIN Training for


Automation and Industrial Solutions
Siemens AG 2006. All rights reserved. File: PRO1_08E.3
Acquiring, Processing and Outputting Data

Operating 0248
Thumbwheel
+ monitoring V buttons,
processes Potentiometer,
0 8 1 5 7-segment
display
Operator Panel

Control such as MPI


Processing
unit the values

DI/ AI/
DO AO

such as PROFIBUS

Process Field devices


controller

SIMATIC S7 Date: 2/4/2012 SITRAIN Training for


Automation and Industrial Solutions
Siemens AG 2006. All rights reserved. File: PRO1_08E.4
Integer (INT, 16-Bit Integer) Data Type
Value range -32,768 to +32,767 Arithmetic
(without sign: 0 to 65,535) 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 =10
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: 2/4/2012 SITRAIN Training for


Automation and Industrial Solutions
Siemens AG 2006. All rights reserved. File: PRO1_08E.5
Double Integer (DINT, 32-Bit Integer) Data Type

Value range L# -2,147,483,648 to L#+2,147,483,647 Operations: such as + D, * D, <D, ==D


(without sign: 0 to 4,294,967,295)

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: 2/4/2012 SITRAIN Training for


Automation and Industrial Solutions
Siemens AG 2006. All rights reserved. File: PRO1_08E.6
REAL (Floating-point Number, 32 Bit) Data Type

Value range -3.40282310+38 to -1.17549510-38 , 0.0, +1.17549510-38 to +3.40282310+38

Operations: such as + R, * R, <R, ==R


sin, acos, ln, exp, SQR

General format of a Real number = (Sign) (1 + f) (2e-127)

Example: 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: 2/4/2012 SITRAIN Training for


Automation and Industrial Solutions
Siemens AG 2006. All rights reserved. File: PRO1_08E.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: 2/4/2012 SITRAIN Training for


Automation and Industrial Solutions
Siemens AG 2006. All rights reserved. File: PRO1_08E.8
Conversion Operations BCD Integer

Number Conversion
Entered in BCD 0 81 5 BCD->Integer
User program
Task
with Integer
math operations
Number Conversion
displayed 0 2 4 8 BCD<-Integer
in BCD

LAD FBD STL

BCD_I BCD_I L IW4


EN ENO EN OUT MW20 BTI
T MW20
IW4 IN OUT MW20 IW4 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: 2/4/2012 SITRAIN Training for


Automation and Industrial Solutions
Siemens AG 2006. All rights reserved. File: PRO1_08E.9
Number Formats

Accessed in between Invalid value !!!

SIMATIC S7 Date: 2/4/2012 SITRAIN Training for


Automation and Industrial Solutions
Siemens AG 2006. All rights reserved. File: PRO1_08E.10
Loading and Transferring Data

Accumulator 1

SIMATIC S7 Date: 2/4/2012 SITRAIN Training for


Automation and Industrial Solutions
Siemens AG 2006. All rights reserved. File: PRO1_08E.11
Data Storage in Accumulator 1
Contents of Accumulator 1
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: 2/4/2012 SITRAIN Training for


Automation and Industrial Solutions
Siemens AG 2006. All rights reserved. File: PRO1_08E.12
Comparison Operations

LAD FBD STL

M 3.4 CMP >=I Q 9.7 CMP >=I A M 3.4


A(
IN1 L IW 0
IW0
L IW 2
IW 0 IN1 M 3.4 & Q9.7 >=I
IW 2 IN2 IW2 IN2 = )
= Q 9.7

SIMATIC S7 Date: 2/4/2012 SITRAIN Training for


Automation and Industrial Solutions
Siemens AG 2006. All rights reserved. File: PRO1_08E.13
Basic Mathematical Functions
LAD FBD STL

ADD_I ADD_I L MW4


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

SUB_I SUB_I L MW8


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

MUL_DI MUL_DI L MD6


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

DIV_R DIV_R L MD40


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

SIMATIC S7 Date: 2/4/2012 SITRAIN Training for


Automation and Industrial Solutions
Siemens AG 2006. All rights reserved. File: PRO1_08E.14
S5 Counter Functions
LAD FBD STL

A I 0.4
C5 C5
CU C5
S_CUD S_CUD A I 0.5
I 0.4 Q 8.3
CU Q
Q I 0.4 CU CD C5
A I 0.3
I 0.5
L C#5
CD CV MW 4 I 0.5 CD
S C5
I 0.3 A I 0.7
S CV_BCD QW 12 I 0.3 S CV MW 4 R C5
L C5
C#5 PV C#5 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: 2/4/2012 SITRAIN Training for


Automation and Industrial Solutions
Siemens AG 2006. All rights reserved. File: PRO1_08E.15
Counters: Function Diagram

CU

CD

5
4
3
Count
2
1
0

SIMATIC S7 Date: 2/4/2012 SITRAIN Training for


Automation and Industrial Solutions
Siemens AG 2006. All rights reserved. File: PRO1_08E.16
Exercise 1: Counting the Transported Parts (FC 18, C 18)

DI DO
I 0.0 T_System_ON Act Quantity
I 0.1 T_System_OFF L_SYSTEM Q 4.1
I 0.2 T_Jog_RIGHT L_MAN Q 4.2
I 0.3 T_Jog_LEFT L_AUTO Q 4.3 V

I 0.4 S_M/A_ModeSelect
I 0.5 T_M/A_Accept "QW_DigDisp" (QW 6)
-15V...+15V -15V...+15V
AI2 AO1
AI1 AO2

AI1 AI2
V

0 8 1 5 AI1 AI2 AO1 AO2

SIMATIC S7 Date: 2/4/2012 SITRAIN Training for


Automation and Industrial Solutions
Siemens AG 2006. All rights reserved. File: PRO1_08E.17
S5 Timer Functions
T44 T44
S_PULSE S_PEXT
I 0.7 S BI MW0 I 0.7 S BI MW0
S5T#35s BCD QW12 S5T#35s QW12
TV M8.5 TV BCD M8.5
I 0.5 R Q = I 0.5 R Q =

Pulse Timer (SP) ON Delay (SD) Extended Pulse (SE)


T44
S_ODT
I 0.7 S BI MW0
S5T#35s BCD QW12
TV M8.5
I 0.5 R Q =
Stored ON Delay (SS) OFF Delay (SF)
T44 T44
S_ODTS S_OFFDT
I 0.7 S BI MW0 MW0
I 0.7 S BI
S5T#35s BCD QW12 S5T#35s QW12
TV M8.5 TV BCD M8.5
I 0.5 R Q = I 0.5 R Q =

SIMATIC S7 Date: 2/4/2012 SITRAIN Training for


Automation and Industrial Solutions
Siemens AG 2006. All rights reserved. File: PRO1_08E.18
Timers: ON Delay (SD)
LAD FBD STL

T4 T4
I 0.7 S_ODT Q8.5 S_EVERZ 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
Time = 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: 2/4/2012 SITRAIN Training for


Automation and Industrial Solutions
Siemens AG 2006. All rights reserved. File: PRO1_08E.19
Exercise 2: Monitoring the Transport Functions (FC 17)

DI DO

I 0.0 T_System_ON
I 0.1 T_System_OFF L_SYSTEM Q 4.1
I 0.2 T_Jog_RIGHT L_MAN Q 4.2
I 0.3 T_Jog_LEFT L_AUTO Q 4.3
I 0.4 S_M/A_ModeSelect
I 0.5 T_M/A_Accept

T_Ackn L_Conv
_Fault _Fault

SIMATIC S7 Date: 2/4/2012 SITRAIN Training for


Automation and Industrial Solutions
Siemens AG 2006. All rights reserved. File: PRO1_08E.20
Exercise 3: Counting the Transported Parts (FC 19)

DI DO SETPOINT Quantity ACTUAL Quantity


I 0.0 T_System_ON
I 0.1 L_SYSTEM Q 4.1
T_System_OFF
0 8 1 5
I 0.2 T_Jog_RIGHT L_MAN Q 4.2
I 0.3 T_Jog_LEFT L_AUTO Q 4.3
I 0.4 S_M/A_ModeSelect "IW_Thumbw" (IW 2) "QW_DigDisp" (QW 6)
I 0.5 T_M/A_Accept

T_Ackn_Fault L_Conv_Fault

ACT=SET Acknowledgement
"L_Bay-LB" (Q 8.4) "T_Bay-LB" (I 8.4)

SIMATIC S7 Date: 2/4/2012 SITRAIN Training for


Automation and Industrial Solutions
Siemens AG 2006. All rights reserved. File: PRO1_08E.21
Exercise 3: Counting the Transported Parts (FC 19), Solution Hints
NW 1: Set "Counter" to 0

MOVE
Condition
for resetting EN OUT MW 20
0 IN ENO

NW 2: Counting via memory word, ACT quantity

ADD_I
Rising edge of
counting event EN

MW 20 IN1 OUT MW 20

1 IN2 ENO

NW 3: Display ACT quantity on the BCD digital display

Convert ACT quantity (MW 20) from Integer to BCD -> Result on BCD digital display (QW 6)

NW 4: Read in SETP quantity and convert from BCD to Integer

Convert value from thumbwheel button (IW 2) from BCD to Integer -> Store SETP quantity (Integer) in MW 22

NW 5: ACT-SETP comparison, Conveyor indicator light Q 8.4

Compare ACT (MW 20) to SETP (MW 22) -> Place comparison result on indicator light

SIMATIC S7 Date: 2/4/2012 SITRAIN Training for


Automation and Industrial Solutions
Siemens AG 2006. All rights reserved. File: PRO1_08E.22
If You Want to Know More

SIMATIC S7 Date: 2/4/2012 SITRAIN Training for


Automation and Industrial Solutions
Siemens AG 2006. All rights reserved. File: PRO1_08E.23
Additional Exercise 4: Counting the Conveyor Belt Faults (FC17)

Conv
Fault
M 17.0

3
Conv
2
Fault
Counter C 17 1
0

M/A AUTO
Q 4.3

SIMATIC S7 Date: 2/4/2012 SITRAIN Training for


Automation and Industrial Solutions
Siemens AG 2006. All rights reserved. File: PRO1_08E.24
Additional Ex 5: Timely Lock-out of the Conveyor Motor Jogging

Lock-out
time LEFT

Jog RIGHT
I 0.2
Conv motor
RIGHT
(Q8.5)

Lock-out
RIGHT
T 15 (SF)

Jog LEFT
I 0.3
lock-out
time RIGHT
Conv motor
LEFT
(Q8.6)

Lock-out
LEFT
T 16 (SF)

SIMATIC S7 Date: 2/4/2012 SITRAIN Training for


Automation and Industrial Solutions
Siemens AG 2006. All rights reserved. File: PRO1_08E.25
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: 2/4/2012 SITRAIN Training for


Automation and Industrial Solutions
Siemens AG 2006. All rights reserved. File: PRO1_08E.26
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 A I 0.5
TV MW0 S5T#35s TV BCD QW12
Q8.5 R T4
I 0.5
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: 2/4/2012 SITRAIN Training for


Automation and Industrial Solutions
Siemens AG 2006. All rights reserved. File: PRO1_08E.27
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
BI A I 0.5
S5T#35s TV MW0 S5T#35s QW12
TV BCD R T4
I 0.5 Q8.5
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: 2/4/2012 SITRAIN Training for


Automation and Industrial Solutions
Siemens AG 2006. All rights reserved. File: PRO1_08E.28
Timers: Extended Pulse (SE)
LAD FBD STL

T4 T4 A I 0.7
I 0.7 S_PEXT Q8.5 S_PEXT L
S Q MW0 S5T#35s
I 0.7 S BI
S5T#35s TV BI MW0 SE T4
S5T#35s TV BCD QW12 A I 0.5
I 0.5 Q8.5
R BCD QW12 I 0.5 R R T4
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: 2/4/2012 SITRAIN Training for


Automation and Industrial Solutions
Siemens AG 2006. All rights reserved. File: PRO1_08E.29
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 B MW0 SF T4
S5T#35s BI I A I 0.5
TV MW0 S5T#35s TV BCD QW12
Q8.5 R T4
I 0.5
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: 2/4/2012 SITRAIN Training for


Automation and Industrial Solutions
Siemens AG 2006. All rights reserved. File: PRO1_08E.30
Time Formats for Traditional 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: 2/4/2012 SITRAIN Training for


Automation and Industrial Solutions
Siemens AG 2006. All rights reserved. File: PRO1_08E.31
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: 2/4/2012 SITRAIN Training for


Automation and Industrial Solutions
Siemens AG 2006. All rights reserved. File: PRO1_08E.32
Conversion Operations I DI REAL

Data in integer format


(16-bit integer)

Conversion from Conversion from Math


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

F STL
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: 2/4/2012 SITRAIN Training for


Automation and Industrial Solutions
Siemens AG 2006. All rights reserved. File: PRO1_08E.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: 2/4/2012 SITRAIN Training for


Automation and Industrial Solutions
Siemens AG 2006. All rights reserved. File: PRO1_08E.34
Application Example: Digital Edge Detection

SIMATIC S7 Date: 2/4/2012 SITRAIN Training for


Automation and Industrial Solutions
Siemens AG 2006. All rights reserved. File: PRO1_08E.35

You might also like