Sei sulla pagina 1di 18

Data Storage in Data Blocks

SIMATIC S7 Date: 04.03.2019


File: 08_.1
Storage Areas for Data

Bit memories
DBz
PIQ
DBy . .
PII .
DBx
I/O area

L stack Data blocks

SIMATIC S7 Date: 04.03.2019


File: 08_.2
Data Blocks (DBs)

Accessible to all blocks

Function
OB1
FC10
Global data

DB20
Function
FC20

Instance DB for FB1

Function Instance data


block
FB1 DB5

SIMATIC S7 Date: 04.03.2019


File: 08_.3
Overview of Data Types in STEP 7

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


data types
• Mathematical data types (INT, DINT, REAL)
(up to 32 bits)
• Time types (S5TIME, TIME, DATE, TIME_OF_DAY)

• Time (DATE_AND_TIME)
Complex
data types • Array (ARRAY)
(longer than 32 bits)
• Structure (STRUCT)
• Character chain (STRING)

User-defined data types


(longer than 32 bits) Data type UDT (User Defined Type)

SIMATIC S7 Date: 04.03.2019


File: 08_.4
Elementary Data Types in STEP 7

Keyword Length (in bits) Example of a constant of this type

BOOL 1 1 or 0
BYTE 8 B#16#A9
WORD 16 W#16#12AF
DWORD 32 DW#16#ADAC1EF5
CHAR 8 'w'

S5TIME 16 S5T#5s_200ms

INT 16 123
DINT 32 65539
REAL 32 1.2 or 34.5E-12

TIME 32 T#2D_1H_3M_45S_12MS
DATE 16 D#1993-01-20
TIME_OF_DAY 32 TOD#12:23:45.12

SIMATIC S7 Date: 04.03.2019


File: 08_.5
Complex Data Types
Keyword Length (in bits) Example
DATE_AND_TIME 64 DT#97-09-24-12:14:55.0

STRING 8 * (number of ´This is a string´


(character string with characters +2) ´SIEMENS´
max. 254 characters)

ARRAY user-defined Measured values: ARRAY[1..20]


(Group of elements INT
of the same data type)

STRUCT user-defined Motor: STRUCT


(Group of elements Speed : INT
of different data types) Current: REAL
END_STRUCT

UDT UDT as block UDT as array element


(User Defined Data Type = user-defined
“Template" consisting of STRUCT Drive: ARRAY[1..4]
elementary or complex Speed : INT UDT1
data types Current: REAL
END_STRUCT

SIMATIC S7 Date: 04.03.2019


File: 08_.6
Example of a Structure
Motor_data
Operating Speed, data type Integer
Rated Current, data type Real Structure with the name "Motor_data"
(several elements
Startup Current, data type Real with different data types)
Turning Direction, data type Bool

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

SIMATIC S7 Date: 04.03.2019


File: 08_.7
Example of an Array
Measuring_point
1. Measuring_point, data type Real
2. Measuring_point, data type Real
Array with the name "Measuring_point"
3. Measuring_point, data type Real (several elements
• of the same data type)


10. Measuring_point, data type Real

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

SIMATIC S7 Date: 04.03.2019


File: 08_.8
Creating a New Data Block

SIMATIC S7 Date: 04.03.2019


File: 08_.9
Entering, Saving, Downloading and Monitoring a Data Block

Declaration View

Data View

SIMATIC S7 Date: 04.03.2019


File: 08_.10
Initial Value, Actual Value, Initialization, Retentivity

Load Memory Work Memory


DB CPU
DB
Initial values with
+ Actual values STEP 7
DB Actual values
(with data types) Program

Upload in PG
Initial values

Initialize DB is retentive until the


data block next transmission
PG  CPU
+ Actual values
With every CPU startup (i.e.
with every STOP-RUN
transition) the DB data are
reset to the initial loading
state x

SIMATIC S7 Date: 04.03.2019


File: 08_.11
Addressing Data Elements

8 Bits
7 0
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 DBB 8191

SIMATIC S7 Date: 04.03.2019


File: 08_.12
Accessing Data Elements
DB 18 "Parts" Traditional Fully-qualified Access
Access
Addr. Name Type absolute symbolic
0.0 Act_Quantity INT
OPN "Parts" L "Parts".ACT_
or L DB18.DBW0 or
2.0 FL_Aux BOOL L DBW0 Quantity

4.0 Number INT


OPN DB 18
or A DB18.DBX2.0 or A "Parts".FL_Aux
A DBX2.0
6.0 Weight[1] REAL

OPN "Parts"
or T DB18.DBW4 or T "Parts".Number
T DBW 4

OPN DB 18
10.0 Weight[2] REAL L DBD 10
or L DB18.DBD10 or L "Parts".Weight[2]

SIMATIC S7 Date: 04.03.2019


File: 08_.13
Validity of an Open DB

OB 1
FC 1
OPN DB 4
L DBW2 DB 4 T DBW 4 DB 4 FC 2

T DBW 8 DB 5
CALL FC 1 OPN DB 5
L DBB6 DB 5
OPN DB 6
CALL FC 2 L DBB6 DB 6
L DBW 0 DB 5 T DB2.DBB 0 DB 2
T DBW 2 DB 4
L DBW 4 DB 2
FB 1

CALL FB1, DB1

! DB ?? ???
L DBW 10

SIMATIC S7 Date: 04.03.2019


File: 08_.14
User-Defined Data Type (UDT)
UDT block as Template Global DB (Example)

Flour Flour
Milk Milk
Eggs Eggs Recipe
1
Yeast Yeast
Sugar Sugar

Flour
Milk
Eggs Recipe
2
Yeast
Array with
DB created according to UDT Sugar 3 elements
of type UDT
Flour Flour
Milk Milk
Eggs Eggs Recipe
3
Yeast Yeast
Sugar Sugar

SIMATIC S7 Date: 04.03.2019


File: 08_.15
Entering a UDT Block

SIMATIC S7 Date: 04.03.2019


File: 08_.16
Creating a Data Block Referencing a Data Type

SIMATIC S7 Date: 04.03.2019


File: 08_.17
Example: Array of UDTs

Declaration View

Data View

SIMATIC S7 Date: 04.03.2019


File: 08_.18

Potrebbero piacerti anche