You are on page 1of 18

Data Storage in Data Blocks

SIMATIC S7

Siemens AG 1999. All rights reserved.

Date:
File:

02/05/15
PRO1_10E.1

Information and Training Center


Knowledge for Automation

Storage Areas for Data

Bit memories

DBz

PIQ

DBy

PII

DBx

I/O area

L stack

SIMATIC S7

Siemens AG 1999. All rights reserved.

Date:
File:

02/05/15
PRO1_10E.2

.
.
.

Data blocks

Information and Training Center


Knowledge for Automation

Data Blocks (DBs)


Accessible to all blocks
OB1

Function
FC10

Global data
DB20

Function
FC20

Instance DB for FB1


Function
block
FB1

SIMATIC S7

Siemens AG 1999. All rights reserved.

Date:
File:

02/05/15
PRO1_10E.3

Instance data
DB5

Information and Training Center


Knowledge for Automation

Overview of Data Types in STEP 7

Elementary
data types
(up to 32 bits)

Bit data types (BOOL, BYTE, WORD, DWORD, CHAR)


Mathematical data types (INT, DINT, REAL)
Time types (S5TIME, TIME, DATE, TIME_OF_DAY)

Time (DATE_AND_TIME)

Complex
data types
(longer than 32 bits)

Array (ARRAY)
Structure (STRUCT)
Character chain (STRING)

User-defined data types


(longer than 32 bits)

SIMATIC S7

Siemens AG 1999. All rights reserved.

Data type UDT (User Defined Type)

Date:
File:

02/05/15
PRO1_10E.4

Information and Training Center


Knowledge for Automation

Elementary Data Types in STEP 7


Keyword

Length (in bits)

Example of a constant of this type

BOOL
BYTE
WORD
DWORD
CHAR

1
8
16
32
8

1 or 0
B#16#A9
W#16#12AF
DW#16#ADAC1EF5
'w'

S5TIME

16

S5T#5s_200ms

INT
DINT
REAL

16
32
32

123
65539
1.2 or 34.5E-12

TIME
DATE
TIME_OF_DAY

32
16
32

T#2D_1H_3M_45S_12MS
D#1993-01-20
TOD#12:23:45.12

SIMATIC S7

Siemens AG 1999. All rights reserved.

Date:
File:

02/05/15
PRO1_10E.5

Information and Training Center


Knowledge for Automation

Complex Data Types


Keyword

Length (in bits)

DATE_AND_TIME

64

DT#97-09-24-12:14:55.0

STRING
(character string with
max. 254 characters)

8 * (number of
characters +2)

This is a string
SIEMENS

ARRAY
(Group of elements
of the same data type)

user-defined

Measured values: ARRAY[1..20]


INT

STRUCT
(Group of elements
of different data types)

user-defined

Motor: STRUCT
Speed : INT
Current: REAL
END_STRUCT

UDT
(User Defined Data Type =
Template" consisting of
elementary or complex
data types

SIMATIC S7

Siemens AG 1999. All rights reserved.

user-defined

Date:
File:

Example

UDT as block

UDT as array element

STRUCT
Speed : INT
Current: REAL
END_STRUCT

Drive: ARRAY[1..4]
UDT1

02/05/15
PRO1_10E.6

Information and Training Center


Knowledge for Automation

Example of a Structure
Motor_data
Operating Speed, data type Integer
Rated Current, data type Real
Startup Current, data type Real

Structure with the name "Motor_data"


(several elements
with different data types)

Turning Direction, data type Bool


Display in the Program Editor (Data block DB 1):

SIMATIC S7

Siemens AG 1999. All rights reserved.

Date:
File:

02/05/15
PRO1_10E.7

Information and Training Center


Knowledge for Automation

Example of an Array
Measuring_point
1. Measuring_point, data type Real
2. Measuring_point, data type Real
3. Measuring_point, data type Real

10. Measuring_point, data type Real

Array with the name "Measuring_point"


(several elements
of the same data type)

Display in the Program Editor (Data block DB 2):

SIMATIC S7

Siemens AG 1999. All rights reserved.

Date:
File:

02/05/15
PRO1_10E.8

Information and Training Center


Knowledge for Automation

Creating a New Data Block

SIMATIC S7

Siemens AG 1999. All rights reserved.

Date:
File:

02/05/15
PRO1_10E.9

Information and Training Center


Knowledge for Automation

Entering, Saving, Downloading and Monitoring a Data Block

SIMATIC S7

Siemens AG 1999. All rights reserved.

Date:
File:

02/05/15
PRO1_10E.10

Information and Training Center


Knowledge for Automation

Addressing Data Elements

8 Bits
7

Data Byte 0

DBB 0

Data Byte 1

DBW 0

Data Byte 2

DBD 0

Data Byte 3

DBX 4.1

DBD 8188
DBW 8190
Data Byte 8191

SIMATIC S7

Siemens AG 1999. All rights reserved.

DBB 8191

Date:
File:

02/05/15
PRO1_10E.11

Information and Training Center


Knowledge for Automation

Accessing Data Elements

DB 19
(Symbol name: Values)

Fully-qualified Access

Traditional
Access

absolute

symbolic

OPN DB19
A DBX 0.0

or

A DB19.DBX0.0

or

A Values".Start

Number

OPN DB19
L DBW2

or

L DB19.DBW2

or

L Values".Number

Loop

OPN DB19
L DBB5

or

L DB19.DBB5

or

L Values".Loop

1)

0
1
2
3
4
5
6
7
8
9

1) Data bit 0.0 with the


element name "Start"

SIMATIC S7

Siemens AG 1999. All rights reserved.

Date:
File:

02/05/15
PRO1_10E.12

Information and Training Center


Knowledge for Automation

Validity of an Open DB
OB 1
OPN
L

DB 4
DBW2

FC 1
DB 4

CALL FC 1

DBW 4 DB 4

T
OPN
L

DB 5
DBB6

DB 5

CALL FC 2
T

DBW 2

DB 4

DBW 0 DB 5

FC 2
T

DBW 8 DB 5

OPN

DB 6

DBB6

DB 6

T DB2.DBB 0 DB 2
L

DBW 4 DB 2

FB 1
CALL FB1, DB1

SIMATIC S7

DBW 10

Siemens AG 1999. All rights reserved.

DB ??

???

Date:
File:

02/05/15
PRO1_10E.13

Information and Training Center


Knowledge for Automation

User-Defined Data Type (UDT)


UDT block as Template

Global DB (Example)

Flour

Flour

Milk

Milk

Eggs

Eggs

Yeast

Yeast

Sugar

Sugar

Recipe
1

Flour
Milk
Eggs
Yeast

Flour

Flour

Milk

Milk

Eggs

Eggs

Yeast

Yeast

Sugar

Sugar

Siemens AG 1999. All rights reserved.

Array with
3 elements
of type UDT

Sugar

DB created according to UDT

SIMATIC S7

Recipe
2

Date:
File:

02/05/15
PRO1_10E.14

Recipe
3

Information and Training Center


Knowledge for Automation

Entering a UDT Block

SIMATIC S7

Siemens AG 1999. All rights reserved.

Date:
File:

02/05/15
PRO1_10E.15

Information and Training Center


Knowledge for Automation

Creating a Data Block Referencing a Data Type

SIMATIC S7

Siemens AG 1999. All rights reserved.

Date:
File:

02/05/15
PRO1_10E.16

Information and Training Center


Knowledge for Automation

Example: Array of UDTs


Declaration View

Data View

SIMATIC S7

Siemens AG 1999. All rights reserved.

Date:
File:

02/05/15
PRO1_10E.17

Information and Training Center


Knowledge for Automation

Exercise: Program for a Bottling Plant - Data Storage

Data block DB5


Empty bottles (MW 100)

Variable: empty

Full bottles (MW102)

Variable: full

Variable: broken

"Broken" bottles (MW 104)

SIMATIC S7

Siemens AG 1999. All rights reserved.

Date:
File:

02/05/15
PRO1_10E.18

Information and Training Center


Knowledge for Automation

You might also like