Professional Documents
Culture Documents
SIMATIC S7
Siemens AG 2005. All rights reserved.
Date:
File:
14.10.2005
PRO1_11E.1
Contents
Page
Objectives ........................................................................................................................................
Storage Areas of Data .....................................................................................................................
Data Blocks (DBs) ............................................................................................................................
Overview of Data Types in STEP 7 ..................................................................................................
Elementary Data Types in STEP 7 ...................................................................................................
Complex Data Types ........................................................................................................................
Example of an ARRAY .....................................................................................................................
Example of a STRUCTURE ..............................................................................................................
Defining the Address Priority (Symbolic/Absolute) ...........................................................................
Creating a Data Block ......................................................................................................................
Initial Value, Actual Value, Initialization, Retentivity ...........................................................................
Entering, Saving, Downloading and Monitoring a Data Block ............................................................
Addressing Data Elements ...............................................................................................................
Accessing Data Elements .................................................................................................................
Exercise 1: Data Block as HMI Interface (DB99) ...............................................................................
Exercise 1: Hints on Tag Management + Startup Block ....................................................................
Page 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
ST-PRO1
Storing Process Data
Objectives
Upon completion of this chapter the participant will ...
...
...
...
...
SIMATIC S7
Siemens AG 2005. All rights reserved.
Date:
File:
14.10.2005
PRO1_11E.2
Page 2
ST-PRO1
Storing Process Data
SIMATIC S7
Date:
File:
14.10.2005
PRO1_11E.3
Overview
Data Blocks
Data blocks are blocks that are used by logic blocks of the user program for
storing values. Unlike temporary data, the data in data blocks is not overwritten
when execution of the logic block is completed or when the DB is closed.
Page 3
ST-PRO1
Storing Process Data
OB1
Function
FC20
Global (shared)
data
DB20
SIMATIC S7
Date:
File:
14.10.2005
PRO1_11E.4
Instance Data
DB5
Overview
Data blocks are used for storing user data. Like logic blocks, data blocks take up
space in the user memory. Data blocks contain variable data (such as numeric
values) that is used in the user program.
The user program can access the data in a data block with bit, byte, word or
doubleword operations. Symbolic or absolute addresses can be used.
Uses
You can use data blocks in different ways, depending on their contents. You
differentiate between:
Shared data blocks: These contain information that all the logic blocks (that
would include OB1) in the user program can access.
Instance data blocks: These are always assigned to a particular FB. The
data in each DB should be used only by the assigned FB.
Instance data blocks are dealt with in more detail in the "Functions and
Function Blocks" chapter.
Creating DBs
You can create global DBs with either the Program Editor or with a "user-defined
data type" (UDT) that you have already created.
Instance data blocks are created when a function block is called.
Registers
The CPU has two data block registers, the DB and DI registers. Therefore, you
can have two data blocks open at the same time.
This topic is dealt with in an advanced programming course.
Page 4
ST-PRO1
Storing Process Data
Elementary
data types
(up to 32 bits)
Complex
data types
(longer than 32 bits)
Array (ARRAY)
Structure (STRUCT)
Character chain (STRING)
SIMATIC S7
Date:
File:
14.10.2005
PRO1_11E.5
(User Defined
Data-Type)
Overview
Data types determine the properties of data, that is, how the contents of one or
more associated addresses are to be represented and what the permissible
range of values is.
The data type also determines which operations can be used.
Elementary
Data Types
Elementary data types are predefined in accordance with IEC 61131-3. The data
type determines the amount of memory space required. For example, the word
data type takes up 16 bits in the user memory.
Elementary data types are never more than 32 bits long and can be loaded into
the accumulators of the S7 processor in full and processed with elementary
STEP 7 instructions.
Complex
Data Types
Complex data types can only be used in conjunction with variables declared in
global data blocks. Complex data types cannot be completely loaded into the
accumulators with load instructions.
You use standard blocks from the IEC library ("IEC" S7 Program) to process
complex data types.
User-Defined
Data Types
A user-defined data type can be used for data blocks or as a data type in a
variable declaration table.
You use the Data Block Editor to create UDTs.
The structure of a UDT can contain groups of elementary and/or complex data
types.
Page 5
ST-PRO1
Storing Process Data
Examples
Variables
BOOL
BYTE
WORD
DWORD
CHAR
1
8
16
32
8
True or false
B#16#A9
W#16#12AF
DW#16#ADAC1EF5
'w'
I 1.0
MB70
MW72
QD40
DBB4
S5TIME
16
S5T#5s_200ms
MW30
INT
DINT
REAL
16
32
32
123
L#65539
1.2 or 3.45E-11
#Value
MD80
DBD60
TIME
DATE
TIME_OF_DAY
32
16
32
T#2D_1H_3M_45S_12MS
D#1993-01-20
TOD#12:23:45.12
QD44
MW32
#Time
SIMATIC S7
Date:
File:
14.10.2005
PRO1_11E.6
BOOL, BYTE, WORD Variables of the BOOL data type consist of one bit. Variables of BYTE, WORD,
DWORD, CHAR
and DWORD data types are sequences of 8, 16 and 32 bits respectively of
hexadecimal data (base 16). The individual bits are not evaluted in these data
types.
Special forms of these data types are the BCD numbers and the count value
used in conjunction with the count function. The CHAR data type represents a
character in ASCII code.
S5TIME
Variables of the S5TIME data type are required for specifying time values in
timer functions. The format is S5T#, followed by the time. You specify the time in
hours, minutes, seconds or milliseconds. You can enter the timer values with an
underline (1h_4m) or without an underline (1h4m).
Functions FC 33 and FC40 from the library convert S5TIME to TIME format and
TIME to S5TIME format.
TIME
A variable of data type TIME takes up a doubleword. This variable is used, for
example, for specifying timer values in IEC timer functions. The contents of the
variable are interpreted as a DINT number in milliseconds and can be either
positive or negative (for example: T#1s=L#1 000, T#24d20h31m23s647ms =
L#2147486470).
DATE
TIME_OF_DAY
Page 6
ST-PRO1
Storing Process Data
Example
DATE_AND_TIME
64
DT#01-08-24-12:14:55:234-1
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
STRUCT
(Group of elements
of different data types)
userdefined
Motor: STRUCT
Speed : INT
Current : REAL
END_STRUCT
UDT
UDT as block
SIMATIC S7
userdefined
STRUCT
Speed : INT
Current : REAL
END_STRUCT
Date:
File:
14.10.2005
PRO1_11E.7
UDT as array
element
Drive: ARRAY[1..4]
UDT1
Complex
Data Types
User-Defined
Data Type
Example
You need the same structure 10 times in a data block. First, you define the
structure and save it, for example, as UDT1. In the DB, you then define a
variable "Addresses" as an array with 10 elements of the type UDT 1:
Addresses: array[1..10]
UDT 1
That way, you have created 10 data ranges with the structure that is defined in
UDT 1 without "typing".
Page 7
ST-PRO1
Storing Process Data
Example of an ARRAY
Measuring_point
1. Measuring_point, data type Real
2. Measuring_point, data type Real
3. Measuring_point, data type Real
SIMATIC S7
Date:
File:
14.10.2005
PRO1_11E.8
Array
An array consists of several elements of the same data type. In the slide above,
you can see the "Measuring_point" array with 10 elements of the REAL data
type.
Later, various measured values are to be stored in this array.
Define Array in DB
The keyword for an array is "ARRAY[n..m]". The first element (n) and the last
element (m) are specified in the square brackets. In the example, [1..10] means
10 elements, whereby the first element is addressed with the index [1] and the
last with the index [10]. Instead of [1..10] you could, for example, define [0..9].
The first element would index [0] and the last element [9].
Initial Values
A single value entered provides the value for the first element only. Values,
separated by commas, provide the values in sequence. The formulea x(initial
value) inserts the initial value x times in sequence.
Data View
To see the actual values stored in the individual elements, you select the menu
option View Data View to switch to another display. In "Data View", you will
find the values currently stored in the column "Actual Value".
Page 8
ST-PRO1
Storing Process Data
Example of a STRUCTURE
Motor_data
Speed, data type Integer
Rated_current, data type Real
Starting_current, data type Real
SIMATIC S7
Date:
File:
14.10.2005
PRO1_11E.9
Structure
Define Structure
in DB
Page 9
ST-PRO1
Storing Process Data
SIMATIC S7
Date:
File:
14.10.2005
PRO1_11E.10
Address Priority
The address priority helps you to update the program code when you make
changes in the symbol table, changes in the parameter names of data blocks or
function blocks, or when you make changes to component names of referenced
UDTs or multi-instances.
What to Do
You select the Blocks folder in the SIMATIC Manager and choose the menu
options Edit Object Properties to define the address priority. In the tab
"Address Priority" you can make the desired settings.
Note
Symbol priority means that symbols have priority over absolute addresses.
Symbolic programming is recommended.
When you open blocks or generate sources, every address is displayed with the
symbolic address that it had the last time it was saved.
When the block consistency is checked, if no user intervention is necessary, the
blocks are compiled such that the symbol of their address remains as it was the
last time it was saved.
Page 10
ST-PRO1
Storing Process Data
SIMATIC S7
Date:
File:
14.10.2005
PRO1_11E.11
Creating a DB
You can insert a new data block - as shown in the slide - in the SIMATIC
Manager by first selecting the Blocks folder of the S7 program and then
following the menu options shown.
You can also create a new data block in the LAD/STL/FBD Editor using the
following menu options:
File New select Project and Project Name select Blocks folder of the S7
program Object Name: DB 99
Shared DB
Shared data blocks are used to store global data. That is, for storing general
data that can be accessed by every logic block (OB, FC, FB).
The user has to edit the global data blocks himself. He does so by declaring the
necessary variables for saving data in the data block.
Instance DB
Instance data blocks are used as the "private memory area" or as the "memory"
for a function block (FB). The parameters and the static variables of an FB are
managed in its instance DB.
Instance data blocks are generally not edited by the user, rather they are
generated by the Editor (see the Functions and Function Blocks chapter).
DB of Type
Data blocks can also be generated according to a User defined Data Type
(UDT) by the Editor. A UDT, that the user must first edit like a data block, is
used as a template for this.
The UDT can be used as a template for creating additional data blocks and / or
also in general for declaring variables and block parameters.
Page 11
ST-PRO1
Storing Process Data
Load Memory
Work Memory
DB
DB
Initial values
+ Actual values
DB
Actual values
CPU
with
STEP 7
Program
Upload in PG
Initial values
Initialize
data block
+ Actual values
SIMATIC S7
Date:
File:
14.10.2005
PRO1_11E.12
Initial Value
When you enter a data block for the first time, you can specify an intial value
that is accepted the first time the DB is saved.
If you dont specify an initial value, zero in the correct data type format is
automatically entered. To edit the initial value, the declaration view must be
switched on.
Actual Value
This is the current value in the data block. The actual value can be changed
offline in the data view or it can be overwritten by the program in the CPU. If a
data block is loaded from the CPU into the PG, the data block has the actual
values.
Initialization
You use this function to overwrite the actual values with the initial values from
creation. To do so, you switch on the Data View and use the menu option Edit
Initialize data block.
Retentivity
Retain:
Note
You will find detailed information on the Memory Concept in the S7-CPUs in the
Chapter "Documenting, Saving and Archiving".
The values stored in the data blocks are retained until the next
time the memory is reset.
Non-Retain: In order for this option to function, the CPU must support the
Retain property of DBs. A data block with the "Non-Retain"
property is not stored in the retentive memory of such a CPU
(such as CPU 317 V2.1) and thus is reset to the initial loading
values after every Power OFF ON or after every CPU STOPRUN transition.
A DB with the assigned "Non-Retain" property still occupies work memory but it
doesnt occupy retentive memory. With a cold restart (CPU 318 or S7-400), all
data blocks are reset to the initial values.
Page 12
ST-PRO1
Storing Process Data
Data View
SIMATIC S7
Date:
File:
14.10.2005
PRO1_11E.13
Declaration View
(Entering Variables)
Data blocks are edited in the "declaration view", that is, the user declares the
variables needed for storing the data here. The variables are created in a table,
organized in lines and columns.
Columns
Save
You save the data block in the S7 project using the "Diskette" icon.
Download
You download data blocks to the CPU, just as you do with logic blocks.
Data View
(Monitor DB)
You can monitor online the current variable values in the data block (values of
the variables in the CPU). To do so, you must first go into the "View" menu and
switch to the "Data View". You can then activate the function using the "Glasses"
icon.
Initialize DB
When you initialize a data block you overwrite the variables current values with
the initial values. This is also necessary when initial values that have been
changed later on have to be accepted as actual values.
The menu options for this are: View Data View Edit Initialize Data Block
Page 13
ST-PRO1
Storing Process Data
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 2004
DBW 2006
DBB 2007
SIMATIC S7
Date:
File:
General
14.10.2005
PRO1_11E.14
You address the data elements of a data block byte-by-byte, just as you do bit
memories.
You can load and transfer data bytes, data words or data doublewords. When
using data words, you specify the first byte address (such as L DBW 2) with the
operation and two bytes are loaded beginning with this first byte of this address.
With doublewords, four bytes are loaded beginning with the first byte address
that you enter.
Number, Length
The number of data blocks available depends on the CPU you use. You will find
more information in the electronic catalog CA01.
Note
If you access non-existent data elements or data blocks an Area Length error
System Fault will occur. The CPU goes into the Stop mode if you did not
program an error OB.
Page 14
ST-PRO1
Storing Process Data
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]
absolute
symbolic
OPN "Parts"
L
DBW0
or
DB18.DBW0
or
L "Parts".
ACT_Quantity
OPN DB 18
A
DBX2.0
or
DB18.DBX2.0
or
A "PARTS".FL_Aux
OPN "Parts"
T
DBW 4
or
DB18.DBW4
or
T "Parts".Number
OPN
L
or
DB18.DBD10
or
L "Parts".Weight[2]
REAL
REAL
SIMATIC S7
DB 18
DBD 10
Date:
File:
Traditional Access
Fully-qualified Access
14.10.2005
PRO1_11E.15
In the traditional (typical in the S5 world) data block access, data blocks have to
be opened explicitly before the actual access. This can take place absolutely or
symbolically with the OPN DB 18 or OPN "Parts" instruction (see example). If
another data block was open, the data block that was opened first is automatically closed. Then, the individual data elements can be accessed bit-by-bit
(DBX...), byte-by-byte (DBB...), word-by-word (DBW...) or doubleword-bydoubleword (DBD...) without a data block having to be specified each time.
Disadvantages:
When accessing data elements, you have to make sure that the correct data
block is open.
Access can be absolute only. The programmer must make sure that he
"reaches" the correct value in the data block. If DBW5 in the example were
loaded, then neither the value of the Number nor Weight[1] variables would
be loaded, but an invalid value.
Absolute accesses hamper correction possibilities and make the program
difficult to read.
Fully-qualified
Access...
...absolute
An absolute access is the opening of the data block and access of the data
element in combination with an instruction. Disadvantages are similar to those of
the traditional access.
...symbolic
A symbolic access of a variable in a data block is possible only if the data block
and its elements are both accessed symbolically. The Editor does allow the
"mixing" of absolute and symbolic addresses during editing, however, it switches
over to completely symbolic after the entry has been confirmed.
Page 15
ST-PRO1
Storing Process Data
DB 99
Data block as
transfer
interface
SIMATIC S7
Date:
File:
14.10.2005
PRO1_11E.16
Task
The objective of this exercise is that all bit memories that are linked with the Tag
Management of the Touch Panel are replaced by the corresponding declarations
from the HMI Interface data block DB99.
The functionality of the current program remains the same.
What to Do
Note
Use the block-referenced menu command Edit Find and Replace in the LAD /
FBD / STL Editor (DB Rewire is not possible).
Then enter the corresponding assignments "Old Address" and "New Address"
and confirm with "OK".
You will find further notes with regard to the necessary replacements on the
following page.The following blocks are affected:
FC 15:
FC_Modes
FC 16:
FC_Conveyor
FC 18:
FC_Count
Page 16
ST-PRO1
Storing Process Data
Situation before
the exercise
Situation after
the exercise
SIMATIC S7
Date:
File:
Further Hints
14.10.2005
PRO1_11E.17
before
M30.0
M30.1
M30.2
M30.3
M30.4
M30.5
MW20
MW200
after
DB99.DBX0.0
DB99.DBX0.1
DB99.DBX0.2
DB99.DBX0.3
DB99.DBX0.4
DB99.DBX0.5
DB99.DBW2
DB99.DBW4
Page 17
Comment
.
Jog conveyor right
Jog conveyor left
System OFF
System ON
Preselect mode
Accept mode
Actual quantity
Setpoint quantity
ST-PRO1
Storing Process Data