You are on page 1of 17

Data Blocks

SIMATIC S7
Siemens AG 2006. All rights reserved.

Date: File:

2/8/2012 PRO1_10E.1

SITRAIN Training for


Automation and Industrial Solutions

Objectives
Upon completion of this chapter the participant will ...
... ... ... ... understand the purpose of global data blocks be familiar with elementary and complex data types be able to monitor a data block be familiar with the possibilities for addressing data block variables

SIMATIC S7
Siemens AG 2006. All rights reserved.

Date: File:

2/8/2012 PRO1_10E.2

SITRAIN Training for


Automation and Industrial Solutions

Data Blocks (DBs)


Accessible to all blocks OB1 Function FC10

Global (shared) data DB20

Function FC20

Instance DB for FB1 Function Block FB1 Instance data

DB5

SIMATIC S7
Siemens AG 2006. All rights reserved.

Date: File:

2/8/2012 PRO1_10E.3

SITRAIN Training for


Automation and Industrial Solutions

Overview of Data Types in STEP 7


Bit data types (BOOL, BYTE, WORD, DWORD, CHAR) Mathematical data types (INT, DINT, REAL) Time types (S5TIME, TIME, DATE, TIME_OF_DAY)

Elementary data types (up to 32 bits)

Time type (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)

UDT data type (User Defined Data Type)

SIMATIC S7
Siemens AG 2006. All rights reserved.

Date: File:

2/8/2012 PRO1_10E.4

SITRAIN Training for


Automation and Industrial Solutions

Elementary Data Types in STEP 7


Keyword
BOOL BYTE

Length (in bits)


1 8

Constants

Variables 1 or 0 I 1.0 B#16#A9

MB70

WORD
DWORD CHAR

16
MW72 32 QD40 8

W#16#12AF
DW#16#ADAC1EF5 'w' DBB4 S5T#5s_200ms

S5TIME

16

MW30
INT DINT 16 32 MD80 123 #Value L#65539

REAL SIMATIC S7
Siemens AG 2006. All rights reserved.

32
Date: File: 2/8/2012 PRO1_10E.5

1.2 or 34.5E-12
DBD60
SITRAIN Training for
Automation and Industrial Solutions

Complex Data Types


Keyword
DATE_AND_TIME

Length (in bits)


64

Example
DT#01-08-24-12:14:55:234-1

STRING (character string with max. 254 characters) ARRAY (Group of elements of the same data type) STRUCT (Group of elements of different data types) UDT

8 * (number of This is a string characters +2) SIEMENS userdefined Measured values: ARRAY[1..20] INT

userdefined

Motor: STRUCT Speed : INT Current : REAL END_STRUCT UDT as block UDT as array element Drive: ARRAY[1..4]

(User Defined Data Type =


"Template" consisting of elementary or complex data types SIMATIC S7
Siemens AG 2006. All rights reserved.

userdefined

STRUCT
Speed : INT

Date: File:

2/8/2012 PRO1_10E.6

Current : REAL UDT1 END_STRUCT

SITRAIN Training for


Automation and Industrial Solutions

Creating a Data Block

SIMATIC S7
Siemens AG 2006. All rights reserved.

Date: File:

2/8/2012 PRO1_10E.7

SITRAIN Training for


Automation and Industrial Solutions

Entering, Saving, Downloading and Monitoring a Data Block

Declaration View

Data View

SIMATIC S7
Siemens AG 2006. All rights reserved.

Date: File:

2/8/2012 PRO1_10E.8

SITRAIN Training for


Automation and Industrial Solutions

Initial Value, Actual Value, Initialization, Retentivity

Load Memory
DB Initial values + Actual values

Work Memory
DB Actual values

CPU
with STEP 7 Program

DB

(with data types) Upload in PG

Initial values

Initialize data block + Actual values

DB is retentive until the next transmission PG CPU With every CPU startup (i.e. with every STOP-RUN transition) the DB data are reset to the initial loading state

x
SITRAIN Training for
Automation and Industrial Solutions

SIMATIC S7
Siemens AG 2006. All rights reserved.

Date: File:

2/8/2012 PRO1_10E.9

Addressing Data Elements


8 Bits 7 0 DBB 0 DBW 0 DBD 0

Data Byte 0 Data Byte 1


Data Byte 2

Data Byte 3 DBX 4.1

DBD 2000 DBW 2002 DBB 2003

SIMATIC S7
Siemens AG 2006. All rights reserved.

Date: File:

2/8/2012 PRO1_10E.10

SITRAIN Training for


Automation and Industrial Solutions

Accessing Data Elements


DB 18 "Parts"
Addr. 0.0 2.0 Name Act_Quantity FL_Aux Type INT BOOL OPN "Parts" L DBW0
or

Traditional Access

Fully-qualified Access absolute


L DB18.DBW0
or

symbolic
L "Parts".ACT_ Quantity

4.0

Number

INT
OPN DB 18 A DBX2.0
or

DB18.DBX2.0

or

A "Parts".FL_Aux

6.0

Weight[1]

REAL
OPN "Parts" T DBW 4
or

DB18.DBW4

or

T "Parts".Number

10.0

Weight[2]

REAL

OPN L

DB 18 DBD 10

or

DB18.DBD10

or

L "Parts".Weight[2]

SIMATIC S7
Siemens AG 2006. All rights reserved.

Date: File:

2/8/2012 PRO1_10E.11

SITRAIN Training for


Automation and Industrial Solutions

Exercise 1: Replacing Bit Memory Variables with DB Variables

SIMATIC S7
Siemens AG 2006. All rights reserved.

Date: File:

2/8/2012 PRO1_10E.12

SITRAIN Training for


Automation and Industrial Solutions

Exercise 2: Connecting WinCC flexible Tags to DB Variables

Tags in WinCC flexible

Variables in STEP7

SIMATIC S7
Siemens AG 2006. All rights reserved.

Date: File:

2/8/2012 PRO1_10E.13

SITRAIN Training for


Automation and Industrial Solutions

If You Want to Know More

SIMATIC S7
Siemens AG 2006. All rights reserved.

Date: File:

2/8/2012 PRO1_10E.14

SITRAIN Training for


Automation and Industrial Solutions

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

Date: File:

2/8/2012 PRO1_10E.15

SITRAIN Training for


Automation and Industrial Solutions

Example of a STRUCTURE
Motor_data Speed, data type Integer Rated_current, data type Real Structure with the name "Motor_data" (several elements with different data types)

Starting_current, data type Real


Direction, data type Bool

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

SIMATIC S7
Siemens AG 2006. All rights reserved.

Date: File:

2/8/2012 PRO1_10E.16

SITRAIN Training for


Automation and Industrial Solutions

Defining the Address Priority (Symbolic/Absolute)

SIMATIC S7
Siemens AG 2006. All rights reserved.

Date: File:

2/8/2012 PRO1_10E.17

SITRAIN Training for


Automation and Industrial Solutions