Vous êtes sur la page 1sur 35

Digital Operations

F1

SIMATIC S7
Siemens AG 2006. All rights reserved.

Date:
File:

2/4/2012
PRO1_08E.1

SITRAIN Training for


Automation and Industrial Solutions

Digital Operations

F1

SIMATIC S7
Siemens AG 2006. All rights reserved.

Date:
File:

2/4/2012
PRO1_08E.2

SITRAIN Training for


Automation and Industrial Solutions

Objectives
Upon completion of the chapter the participant will

SIMATIC S7
Siemens AG 2006. All rights reserved.

...

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

Date:
File:

2/4/2012
PRO1_08E.3

SITRAIN Training for


Automation and Industrial Solutions

Acquiring, Processing and Outputting Data


Operating
+ monitoring
processes

0248
V

0 8 1 5

Thumbwheel
buttons,
Potentiometer,
7-segment
display

Operator Panel

Control
unit

such as MPI

Processing
the values

DI/
DO

AI/
AO

such as PROFIBUS
Field devices

Process
controller

SIMATIC S7
Siemens AG 2006. All rights reserved.

Date:
File:

2/4/2012
PRO1_08E.4

SITRAIN Training for


Automation and Industrial Solutions

Integer (INT, 16-Bit Integer) Data Type


Value range

-32,768 to +32,767

Arithmetic
operations: such as + I, * I, <I, ==I

(without sign: 0 to 65,535)

Display Formats:
15 14 13 12 11 10 9 8 7

DEC: + 662

6 5

4 3 2 1 0

BIN.: 2# 0 0 0 0 0 0 1 0 1 0 0 1 0 1 1 0
+2

Sign
positive
numbers

+2

6 5

4 3 2 1 0

BIN.: 2# 1 1 1 1 1 1 0 1 0 1 1 0 1 0 1 0
-2
Sign
negative
numbers

Representation as
Twos complement

SIMATIC S7
Siemens AG 2006. All rights reserved.

15
14

+2 13
+2 12
+2 11
+2 10
8
6
+2 +2 +2 5
3
1
+2 +2 +2
- 662

Date:
File:

6 x 16 = 6
1
9 x 16 = 144
2
2 x 16
= 512
662

+2 1
+2
+ 662

15 14 13 12 11 10 9 8 7

DEC: - 662

without
sign

+2

HEX: W#16#0 2 9 6

2/4/2012
PRO1_08E.5

HEX: W#16#F D 6 A
without
sign
0

10 x 16 =10
1
6 x 16 = 96
2
13 x 16 = 3328
3
15 x 16 = 61440
64874

SITRAIN Training for


Automation and Industrial Solutions

Double Integer (DINT, 32-Bit Integer) Data Type


Value range

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

L# -2,147,483,648 to L#+2,147,483,647
(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

DEC: L# +540809

6 5

4 3 2 1 0

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#

(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

DEC: L# -540809

6 5

4 3 2 1 0

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

SIMATIC S7
Siemens AG 2006. All rights reserved.

HEX: DW#16#

(without sign)

Date:
File:

2/4/2012
PRO1_08E.6

SITRAIN Training for


Automation and Industrial Solutions

REAL (Floating-point Number, 32 Bit) Data Type


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

Value range

+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.
31

30

f = Mantissa (23 Bit)

e = Exponent (8 Bit)
29

28

27 26

25

24

23

22

21

20 19

18

17

16 15

14

13

12

11 10

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
Siemens AG 2006. All rights reserved.

Date:
File:

2/4/2012
PRO1_08E.7

SITRAIN Training for


Automation and Industrial Solutions

The BCD Code for Inputting and Outputting Integers


Value range

16 Bit:
32 Bit:

- 999 to + 999
-9999999 to + 9999999

Conversion
operations:

Sign (+)

HEX:

32 Bit:

BIN.: 2# 0 0 0 0 0 0 1 0 1 0 0 1 0 1 1 0

16 Bit:

Sign (+)

BTI, BTD, ITB, DTB


(no arithmetic!)

W#16#
0

DEC: + 662

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#

SIMATIC S7
Siemens AG 2006. All rights reserved.

Date:
File:

2/4/2012
PRO1_08E.8

DEC: + 662
SITRAIN Training for
Automation and Industrial Solutions

Conversion Operations BCD Integer


Number
Entered in BCD

Conversion
BCD->Integer

0 81 5

Task
Number
displayed
in BCD

Conversion
BCD<-Integer

0 2 4 8

LAD

FBD

BCD_I

IW4

EN

ENO

IN

OUT

IN

SIMATIC S7
Siemens AG 2006. All rights reserved.

OUT

STL

MW20

L
IW4
BTI
T
MW20

QW12

L
MW10
ITB
T
QW12

BCD_I

MW20

IW4

I_BCD
EN
ENO

MW10

User program
with Integer
math operations

EN

OUT

IN

ENO

I_BCD

QW12

MW10

Date:
File:

EN

OUT

IN

ENO

2/4/2012
PRO1_08E.9

SITRAIN Training for


Automation and Industrial Solutions

Number Formats

Accessed in between

SIMATIC S7
Siemens AG 2006. All rights reserved.

Invalid value !!!

Date:
File:

2/4/2012
PRO1_08E.10

SITRAIN Training for


Automation and Industrial Solutions

Loading and Transferring Data

Accumulator 1

SIMATIC S7
Siemens AG 2006. All rights reserved.

Date:
File:

2/4/2012
PRO1_08E.11

SITRAIN Training for


Automation and Industrial Solutions

Data Storage in Accumulator 1


Contents of Accumulator 1
Program
31

L MB 0

23

L MW 0

23

15

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
31

L MD 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
31

Load

15

23

MB0

MB0
7

MB0
15

MB1

MB1
7

MB2

MB3

T QD 4
QD 4

Transfer

T QW 4
QW 4

T QB 4
QB 4

SIMATIC S7
Siemens AG 2006. All rights reserved.

Date:
File:

2/4/2012
PRO1_08E.12

SITRAIN Training for


Automation and Industrial Solutions

Comparison Operations
LAD

M 3.4

CMP >=I

FBD

CMP >=I

Q 9.7

IW0
IW 0

IN1

IW 2

IN2

SIMATIC S7
Siemens AG 2006. All rights reserved.

STL

IN1

M 3.4
IW2

Date:
File:

IN2

2/4/2012
PRO1_08E.13

&

Q9.7
=

A
A(
L
L
>=I
)
=

M 3.4

IW 0
IW 2

Q 9.7

SITRAIN Training for


Automation and Industrial Solutions

Basic Mathematical Functions


LAD

Addition

MW4
MW10

MW4
MW6

MW10

SUB_I
EN ENO

Subtraction

MW8
MW12

Multiplication

ADD_I
EN ENO
IN1
IN2 OUT

FBD

MD6
MD12

Division

MD40
MD4

SIMATIC S7
Siemens AG 2006. All rights reserved.

IN1
IN2

MW8

OUT

MUL_DI
EN ENO
IN1
IN2
DIV_R
EN ENO
IN1
IN2 OUT

MW6

MW12

ADD_I
EN OUT
IN1
IN2 ENO

SUB_I
EN OUT
IN1
IN2 ENO

MUL_DI
EN OUT
MD6
MD66

MD12

MD40
MD32

Date:
File:

MD4

2/4/2012
PRO1_08E.14

IN1
IN2

STL

MW6

MW6

MD66

ENO

DIV_R
EN OUT
IN1
IN2 ENO

MD32

L
L
+I
T

MW4
MW10

L
L
-I
T

MW8
MW12

L
L
*D
T

MD6
MD12

L
L
/R
T

MD40
MD4

MW6

MW6

MD66

MD32

SITRAIN Training for


Automation and Industrial Solutions

S5 Counter Functions
LAD

FBD

C5

C5

S_CUD

I 0.4

S_CUD

Q 8.3

CU

Q
Q

CD

CV

STL

I 0.4

CU

MW 4

I 0.5

CD

QW 12

I 0.3

C#5

PV

I 0.5

I 0.3
S
C#5

PV

CV_BCD

CV
CV_BCD

MW 4
QW 12

Q 8.3

I 0.7
R

SIMATIC S7
Siemens AG 2006. All rights reserved.

I 0.7

Date:
File:

2/4/2012
PRO1_08E.15

Q
Q

A
CU
A
CD
A
L
S
A
R
L
T
LC
T
A
=

I 0.4
C5
I 0.5
C5
I 0.3
C#5
C5
I 0.7
C5
C5
MW4
C5
QW12
C5
Q8.3

SITRAIN Training for


Automation and Industrial Solutions

Counters: Function Diagram


CU

CD

5
4

Count

2
1
0

SIMATIC S7
Siemens AG 2006. All rights reserved.

Date:
File:

2/4/2012
PRO1_08E.16

SITRAIN Training for


Automation and Industrial Solutions

Exercise 1: Counting the Transported Parts (FC 18, C 18)

DI

DO

Act Quantity

I 0.0
I 0.1

T_System_ON

I 0.2
I 0.3

T_Jog_RIGHT

I 0.4

S_M/A_ModeSelect

I 0.5

T_M/A_Accept

T_System_OFF

L_SYSTEM

Q 4.1

L_MAN

Q 4.2

L_AUTO

Q 4.3

T_Jog_LEFT

"QW_DigDisp" (QW 6)
-15V...+15V

AI2

AO1

-15V...+15V
AO2

AI1

AI1

AI2

0 8 1 5

SIMATIC S7
Siemens AG 2006. All rights reserved.

Date:
File:

2/4/2012
PRO1_08E.17

AI1

AI2

AO1

AO2

SITRAIN Training for


Automation and Industrial Solutions

S5 Timer Functions
T44
S_PULSE
S
BI

I 0.7
S5T#35s

TV

BCD

I 0.5

MW0

I 0.7

QW12
M8.5

S5T#35s
I 0.5

Pulse Timer (SP)

S5T#35s
I 0.5

I 0.5

TV

BCD

Siemens AG 2006. All rights reserved.

QW12
M8.5

T44
S_ODT
S
BI
TV

BCD

MW0
QW12
M8.5

=
OFF Delay (SF)

T44
S_ODTS
S
BI

SIMATIC S7

BCD

Extended Pulse (SE)

Stored ON Delay (SS)

S5T#35s

MW0

TV

ON Delay (SD)

I 0.7

I 0.7

T44
S_PEXT
S
BI

MW0

I 0.7

QW12
M8.5

S5T#35s

I 0.5

Date:
File:

2/4/2012
PRO1_08E.18

T44
S_OFFDT
S
BI

MW0

TV

BCD

QW12
M8.5

SITRAIN Training for


Automation and Industrial Solutions

Timers: ON Delay (SD)


LAD

FBD

T4
S_ODT

I 0.7
S

S5T#35s
I 0.5

STL

T4

S_EVERZ

Q8.5
Q

I 0.7
S5T#35s

TV

BI

MW0

BCD

QW12

I 0.5

Data type
S5TIME

0.01s <-0.1s <-1s <-10s <--

BI

TV

BCD

RLO at S

RLO at R
Time
operation

MW0
QW12
Q8.5
=

A
L
SD
A
R
L
T
LC
T
A
=

I 0.7
S5T#35s
T4
I 0.5
T4
T4
MW0
T4
QW12
T4
Q8.5

Example
Q

SIMATIC S7
Siemens AG 2006. All rights reserved.

Date:
File:

0
0
1
1

2/4/2012
PRO1_08E.19

0
1
0
1

Units of time: 0 to 999 (BCD-coded)

SITRAIN Training for


Automation and Industrial Solutions

Exercise 2: Monitoring the Transport Functions (FC 17)


DI

DO

I 0.0
I 0.1

T_System_ON

I 0.2
I 0.3

T_Jog_RIGHT

L_MAN

Q 4.2

T_Jog_LEFT

L_AUTO

Q 4.3

I 0.4

S_M/A_ModeSelect

I 0.5

T_M/A_Accept

T_System_OFF

T_Ackn
_Fault

SIMATIC S7
Siemens AG 2006. All rights reserved.

L_SYSTEM

Q 4.1

L_Conv
_Fault

Date:
File:

2/4/2012
PRO1_08E.20

SITRAIN Training for


Automation and Industrial Solutions

Exercise 3: Counting the Transported Parts (FC 19)

DI

SETPOINT Quantity

DO

I 0.0
I 0.1

T_System_ON

I 0.2
I 0.3

T_Jog_RIGHT

L_MAN

Q 4.2

T_Jog_LEFT

L_AUTO

Q 4.3

I 0.4

S_M/A_ModeSelect

I 0.5

T_M/A_Accept

T_System_OFF

T_Ackn_Fault

L_SYSTEM

Q 4.1

ACTUAL Quantity

0 8 1 5
"IW_Thumbw" (IW 2)

"QW_DigDisp" (QW 6)

L_Conv_Fault

ACT=SET
"L_Bay-LB" (Q 8.4)

SIMATIC S7
Siemens AG 2006. All rights reserved.

Date:
File:

2/4/2012
PRO1_08E.21

Acknowledgement
"T_Bay-LB" (I 8.4)

SITRAIN Training for


Automation and Industrial Solutions

Exercise 3: Counting the Transported Parts (FC 19), Solution Hints


NW 1:

Set "Counter" to 0
MOVE
EN
OUT

Condition
for resetting

0
NW 2:

ENO

Counting via memory word, ACT quantity

ADD_I

Rising edge of
counting event

NW 3:

IN

MW 20

EN
MW 20

IN1

OUT

IN2

ENO

MW 20

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
Siemens AG 2006. All rights reserved.

Date:
File:

2/4/2012
PRO1_08E.22

SITRAIN Training for


Automation and Industrial Solutions

If You Want to Know More

SIMATIC S7
Siemens AG 2006. All rights reserved.

Date:
File:

2/4/2012
PRO1_08E.23

SITRAIN Training for


Automation and Industrial Solutions

Additional Exercise 4: Counting the Conveyor Belt Faults (FC17)

Conv
Fault
M 17.0

Conv
2
Fault
Counter C 17 1
0

M/A AUTO
Q 4.3

SIMATIC S7
Siemens AG 2006. All rights reserved.

Date:
File:

2/4/2012
PRO1_08E.24

SITRAIN Training for


Automation and Industrial Solutions

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

Conv motor
LEFT
(Q8.6)

lock-out
time RIGHT

Lock-out
LEFT
T 16 (SF)

SIMATIC S7
Siemens AG 2006. All rights reserved.

Date:
File:

2/4/2012
PRO1_08E.25

SITRAIN Training for


Automation and Industrial Solutions

Counters: Bit Instructions


LAD

FBD

Network 1:

I 0.0

STL

C5
I 0.0

C5
SC

C#20

SC

A
L
S

CV

C#20

I 0.0
C#20
C5

Network 2:

I 0.1

C5

C5
I 0.1

CU

CU

A I 0.1
CU C5

C5

A I 0.2
CD C5

Network 3:

I 0.2

C5

CD

I 0.2

CD

Network 4:

C5

Q 4.0

Q 4.0
C5

SIMATIC S7
Siemens AG 2006. All rights reserved.

Date:
File:

2/4/2012
PRO1_08E.26

A
=

C5
Q 4.0

SITRAIN Training for


Automation and Industrial Solutions

Timers: Stored ON Delay (SS)

I 0.7
S5T#35s
I 0.5

LAD

FBD

T4
S_ODTS
Q
S

T4

TV
R

BI
BCD

S_ODTS

Q8.5
MW0

STL

I 0.7
S5T#35s

QW12

I 0.5

BI

TV

BCD

MW0
QW12
Q8.5
=

A
L
SS
A
R
L
T
LC
T
A
=

I 0.7
S5T#35s
T4
I 0.5
T4
T4
MW0
T4
QW12
T4
Q8.5

RLO at S
RLO at R
Timer
operation
Example
Q

SIMATIC S7
Siemens AG 2006. All rights reserved.

Date:
File:

2/4/2012
PRO1_08E.27

SITRAIN Training for


Automation and Industrial Solutions

Timers: Pulse (SP)


LAD

FBD

T4
S_PULSE
Q
S

I 0.7

S5T#35s
I 0.5

TV
R

BI

BCD

STL

T4

S_PULSE

Q8.5
MW0

I 0.7
S5T#35s

QW12

I 0.5

BI

TV

BCD

MW0
QW12
Q8.5
=

A
L
SP
A
R
L
T
LC
T
A
=

I 0.7
S5T#35s
T4
I 0.5
T4
T4
MW0
T4
QW12
T4
Q8.5

RLO at S
RLO at R

Timer
operation
Example

SIMATIC S7
Siemens AG 2006. All rights reserved.

Date:
File:

2/4/2012
PRO1_08E.28

SITRAIN Training for


Automation and Industrial Solutions

Timers: Extended Pulse (SE)


LAD

FBD

T4
S_PEXT
Q
S

I 0.7
S5T#35s
I 0.5

TV
R

BI

BCD

STL

T4
Q8.5
MW0

S_PEXT
I 0.7
S5T#35s

QW12

I 0.5

BI

TV

BCD

MW0
QW12
Q8.5
=

A
I 0.7
L
S5T#35s
SE T4
A
I 0.5
R
T4
L
T4
T
MW0
LC T4
T
QW12
A
T4
=
Q8.5

RLO at S
RLO at R
Timer
operation
Example
Q

SIMATIC S7
Siemens AG 2006. All rights reserved.

Date:
File:

2/4/2012
PRO1_08E.29

SITRAIN Training for


Automation and Industrial Solutions

Timers: OFF Delay (SF)


LAD

FBD

T4
S_OFFDT
Q
S

I 0.7
S5T#35s
I 0.5

TV
R

BI
BCD

STL

T4
S_OFFDT

Q8.5
MW0

I 0.7
S5T#35s

QW12

S
TV

I 0.5

B
I
BCD
Q

MW0
QW12
Q8.5
=

A
L
SF
A
R
L
T
LC
T
A
=

I 0.7
S5T#35s
T4
I 0.5
T4
T4
MW0
T4
QW12
T4
Q8.5

RLO at S
RLO at R
Timer
operation
Example
Q

SIMATIC S7
Siemens AG 2006. All rights reserved.

Date:
File:

2/4/2012
PRO1_08E.30

SITRAIN Training for


Automation and Industrial Solutions

Time Formats for Traditional S5-Timers in STEP 7


S5T#35s200ms

Time specifications as constants

(Time base: 01 (100ms), Number of units of time: 352)

01

Time specifications per variable

5
1

Time base

Accu 1 contents after L T... exec.

2
0

Units of time (BCD-coded)

29

28

27

26

25

24

23

22

21 20

Residual units of time (Integer)


3

01

Accu 1 cont. after LC T... exec.

Time base

SIMATIC S7
Siemens AG 2006. All rights reserved.

Date:
File:

2/4/2012
PRO1_08E.31

5
1

2
0

Residual units of time (BCD-coded)

SITRAIN Training for


Automation and Industrial Solutions

Timers: Bit Instructions


LAD

FBD

STL

Network 1:

I 0.0

T4
T4

&

I 0.0

SD

SD
S5T#5s

S5T#5s

TV

A I 0.0
L S5T#5s
SD T4

Network 2:

T4

Q 8.0

Q 8.0
T4

&

A
=

T4
Q 8.0

A
R

I 0.1
T4

Network 3:

I 0.1

T4

T4
I 0.1

SIMATIC S7
Siemens AG 2006. All rights reserved.

Date:
File:

2/4/2012
PRO1_08E.32

&

SITRAIN Training for


Automation and Industrial Solutions

Conversion Operations I DI REAL


Data in integer format
(16-bit integer)
Conversion from
integer to
double integer

Task

F
B
D

Conversion from
double integer
to real number

STL

I_DI

MW12

EN

OUT

IN

ENO

LAD

MD14
DI_R

MD14

I_DI
EN
ENO
MW12

SIMATIC S7
Siemens AG 2006. All rights reserved.

IN

OUT

Math
program
with
real numbers

EN

OUT

IN

ENO

MD26

L
MW12
ITD
DTR
T
MD26

DI_R
EN
ENO
MD14

MD14

Date:
File:

IN

2/4/2012
PRO1_08E.33

OUT

MD26

SITRAIN Training for


Automation and Industrial Solutions

Digital Logic Operations


WXOR_W

WOR_W
WAND_W
EN
IW0
W#16#5F2A

IW 0

W#16#5F2A

AW / OW / XOW

ENO

MW10

IN1
IN2

OUT

15

MW10
IW0 =
W#16#5F2A =

0 1 0 0 0 0 0 0 0 0 1 1 0 0 1 0

0 1 0 1 1 1 1 1 0 0 1 0 1 0 1 0

AND

SIMATIC S7
Siemens AG 2006. All rights reserved.

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

Date:
File:

2/4/2012
PRO1_08E.34

SITRAIN Training for


Automation and Industrial Solutions

Application Example: Digital Edge Detection

SIMATIC S7
Siemens AG 2006. All rights reserved.

Date:
File:

2/4/2012
PRO1_08E.35

SITRAIN Training for


Automation and Industrial Solutions