Data Blocks
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
Data Blocks (DBs) Accessible to all blocks OB1
Function FC10
Function FC20
Global (shared) data DB20
Instance DB for FB1 Function Block FB1
Instance data DB5
Overview of Data Types in STEP 7
Elementary data types (up to 32 bits)
• Bit data types (BOOL, BYTE, WORD, DWORD, CHAR) • Mathematical Mathemati cal data types (INT, DINT, REAL) • Time types types (S5TIME, TIME, DATE, TIME_OF_DAY)
• Time type (DATE_AND_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)
UDT data type (User Defined Data Type)
Elementary Data Types in STEP 7 Keyword Keyword
Length (in bits)
BOOL
1
BYTE WORD DWORD
8
Constants
Variables 1 or 0 I 1.0 B#16#A9
MB70 16
W#16#12AF MW72
32 QD40
DW#16#ADAC1EF5
CHAR
8
'w' DBB4
S5TIME
16
S5T#5s_200ms
INT DINT REAL
16
MW30 123 #Value L#65539
32 MD80 32
1.2 or 34.5E-12
Complex Data Types Keyword Keyword
Length (in bits)
Example
DATE_AND_TIME
64
STRING (character string with max. 254 characters)
8 * (number of ´This is a string´ characters +2) ´SIEMENS´
ARRAY (Group of elements of the same data type)
userdefined
Measured values: ARRAY[1..20] ARRAY[1..20] INT
STRUCT (Group of elements of different data types)
userdefined
Motor: STRUCT Speed : INT Current : REAL END_STRUCT
UDT (User Defined Data Type = "Template" "Template" consisting of elementary or complex data types
DT#01-08-24-12:14:55:234-1 DT#01-08-24-12:14:55:234-1
UDT as block userdefined
UDT as array element
STRUCT Speed
: INT
Current : REAL UDT1 END_STRUCT
Drive: ARRAY[1..4] ARRAY[1..4]
Creating a Data Block
Entering, Saving, Downloading and Monitoring a Data Block
Declaration View
Data View
Initial Value, Actual Value, Initialization, Retentivity Retentivity
Load Memory
Work Memory
DB
DB
Initial values + Actual values
DB
Initial values
(with data types) Upload in PG
Initialize data block + Actual values
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
CPU with STEP 7 Program
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 2000 DBW 2002 DBB 2003
Accessing Data Elements DB 18
"Parts"
Addr.
Name
Type
0.0
Act_Quantity
INT
2.0
FL_Aux
BOOL
4.0
Number
INT
6.0
10.0
Weight[1]
Weight[2]
Traditional Access
Fully-qualified Fully-qualified Access absolute
symbolic
OPN "Parts" L DBW0
or
L
DB18.DBW0
or
L "Parts".ACT_ Quantity
OPN DB 18 A DBX2.0
or
A
DB18.DBX2.0 DB18.DBX2.0
or
A "Parts".FL_Aux
REAL
REAL
OPN "Parts" T DBW 4
or
T
DB18.DBW4
or
T "Parts".Number "Parts".Number
OPN L
or
L
DB18.DBD10
or
L "Parts".Weight[2]
DB 18 DBD 10
Exercise 1: Replacing Bit Memory Variables with DB Variables
Exercise 2: Connecting WinCC flexible Tags to DB Variables
Tags in W inCC flexible
Variables in STEP7
If You Want to Know More
Example of an ARRAY Measuring_point 1. Measuring_point, Measuring_point, data type Real 2. Measuring_point, Measuring_point, data type Real 3. Measuring_point, Measuring_point, data type Real • • • 10. Measuring_point, Measuring_point, data type Real
Array with the name "Measuring_point" "Measuring_point" (several elements of the same s ame data type)
Display in the Program Editor (Data Block DB 2):
Example of a STRUCTURE Motor_data Speed, data type Integer Rated_current, data type Real Starting_current, data type Real
Structure with the name "Motor_data" (several elements with different data types)
Direction, data type Bool Display in the Program Editor (Data block DB 1):
Defining the Address Priority (Symbolic/Absolute)