You are on page 1of 15

SITRAIN Training for

Automation and Industrial Solutions


ST-SERV2
Storing Process Data Page 1
Date: 18.11.2005
File: SERV2_03E.1
SIMATIC S7
Siemens AG 2005. All rights reserved.
SITRAIN Training for
Automation and Industrial Solutions
Data Blocks
Contents Page
Objectives ........................................................................................................................................ 2
Storage Areas of Data ..................................................................................................................... 3
Data Blocks (DBs) ............................................................................................................................ 4
Overview of Data Types in STEP 7 .................................................................................................. 5
Elementary Data Types in STEP 7 ................................................................................................... 6
Complex Data Types ........................................................................................................................ 7
Example of an ARRAY ..................................................................................................................... 8
Example of a STRUCTURE .............................................................................................................. 9
Defining the Address Priority (Symbolic/Absolute) ........................................................................... 10
Creating a Data Block ...................................................................................................................... 11
Initial Value, Actual Value, Initialization, Retentivity ........................................................................... 12
Entering, Saving, Downloading and Monitoring a Data Block ............................................................ 13
Addressing Data Elements ............................................................................................................... 14
Accessing Data Elements ................................................................................................................. 15
Exercise 1: ????????????????????????????? ............................................................................... 16
SITRAIN Training for
Automation and Industrial Solutions
ST-SERV2
Storing Process Data Page 2
Date: 18.11.2005
File: SERV2_03E.2
SIMATIC S7
Siemens AG 2005. All rights reserved.
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 complexdata types
... be able to monitor a data block
... be familiar with the possibilities for addressing data block variables
SITRAIN Training for
Automation and Industrial Solutions
ST-SERV2
Storing Process Data Page 3
Overview In addition to program blocks, a user program also consists of data containing
information about process states, signals, etc. This data is then processed
according to the instructions in the user program.
Data is stored in variables of the user program, which are uniquely identified by:
Storage location (address: such as P, PII, PIQ, bit memory, L stack, DB)
Data type (elementary or complex data type, parameter type)
Depending on the accessibility, a distinction is also made between:
Global variables, which are declared in the global symbol table or in global
(shared) data blocks
Local variables, which are declared in the declaration part of OBs, FBs and
FCs.
Variables can have a permanent storage location in the process image, bit
memory area or in a data block. They can also be created dynamically in the L
stack when a block is being executed.
Local Data Stack The local data stack (L stack) is an area for storing:
Temporary variables of a logic block, includingorganizationblock start
information
Actual addresses in the parameter passingof FC calls
Intermediate logic results in LAD programs
This topic is dealt with in the chapter "Functions and Function Blocks".
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.
Date: 18.11.2005
File: SERV2_03E.3
SIMATIC S7
Siemens AG 2005. All rights reserved.
SITRAIN Training for
Automation and Industrial Solutions
Storage Areas of Data
System Memory (RAM) contains:
Process images PII and PIQ
Bit memories
Timers and counters
Local data stack
Block Stack
Interrupt Stack
Diagnostic buffer
Working Memory (RAM) contains
the parts relevant for execution
such as
Logic blocks
(FC, FB and OB)
Data blocks DB, DI
Dynamic Load Memory
(RAM integrated or MMC)
contains parts of the user
programnot relevant for
execution
Retentive Load Memory
(FEPROM integrated or MMC)
contains parts of the user
programnot relevant for
execution
CPU
SITRAIN Training for
Automation and Industrial Solutions
ST-SERV2
Storing Process Data Page 4
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
doublewordoperations. 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 assignedto a particular FB. The
data in eachDB shouldbe usedonlybythe assignedFB.
Instance data blocks are dealt with in more detail in the "Functions and
Function Blocks" chapter.
Creating DBs You cancreate global DBs with either the ProgramEditor or with a "user-defined
data type" (UDT) that youhave alreadycreated.
Instance data blocks are created whena function block is called.
Registers The CPU has two data block registers, the DB and DI registers. Therefore, you
can have two data blocks openat the same time.
This topic is dealt with in an advancedprogrammingcourse.
Date: 18.11.2005
File: SERV2_03E.4
SIMATIC S7
Siemens AG 2005. All rights reserved.
SITRAIN Training for
Automation and Industrial Solutions
Data Blocks (DBs)
Function
FC10
Function
FC20
Function
Block
FB1
OB1
Global (shared)
data
DB20
Accessible to all blocks
Instance Data
DB5
Instance DB for FB1
SITRAIN Training for
Automation and Industrial Solutions
ST-SERV2
Storing Process Data Page 5
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 Elementarydata types are predefined in accordance with IEC 61131-3. The data
Data Types type determines the amount of memoryspace 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 Complexdata types canonly be used in conjunction with variables declared in
Data Types global data blocks. Complex data types cannot be completely loadedinto the
accumulators with load instructions.
You use standardblocks fromthe IEC library ("IEC" S7 Program) to process
complexdata types.
User-Defined A user-defined data type canbe used for data blocks or as a data type in a
Data Types variable declaration table.
You use the Data Block Editor to create UDTs.
The structure of a UDT cancontaingroups of elementary and/or complexdata
types.
Date: 18.11.2005
File: SERV2_03E.5
SIMATIC S7
Siemens AG 2005. All rights reserved.
SITRAIN Training for
Automation and Industrial Solutions
Overview of Data Types in STEP 7
Elementary
data types
(up to 32 bits)
Complex
data types
(longer than 32 bits)
User-defined data types
(longer than 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 type (DATE_AND_TIME)
Array (ARRAY)
Structure (STRUCT)
Character chain (STRING)
Data type UDT (User Defined
Data-Type)
SITRAIN Training for
Automation and Industrial Solutions
ST-SERV2
Storing Process Data Page 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 respectivelyof
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#, followedby the time. You specify the time in
hours, minutes, seconds or milliseconds. You canenter the timer values with an
underline (1h_4m) or without an underline (1h4m).
Functions FC 33 and FC40 fromthe library convert S5TIME to TIME format and
TIME to S5TIME format.
INT, DINT, REAL Variables of these data types represent numbers that can be used in
mathematical operations.
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 interpretedas a DINT number in milliseconds and canbe either
positive or negative (for example: T#1s=L#1 000, T#24d20h31m23s647ms =
L#2147486470).
DATE A variable of data type DATE is stored in a word in the form of an unsigned
integer. The contents of the variable represent the number of days since
01.01.1990 (for example: D#2168-12-31 =W#16#FF62).
TIME_OF_DAY A variable of data type TIME_OF_DAY takes up a doubleword. This variable
contains the number of milliseconds since the beginning of the day(0:00
oclock) in the form of an unsigned integer. (for example: TOD#23:59:59.999 =
DW#16#0526 5B77).
Date: 18.11.2005
File: SERV2_03E.6
SIMATIC S7
Siemens AG 2005. All rights reserved.
SITRAIN Training for
Automation and Industrial Solutions
Elementary Data Types in STEP 7
Keyword Length (in bits)
Examples Variables
BOOL 1 True or false I 1.0
BYTE 8 B#16#A9 MB70
WORD 16 W#16#12AF MW72
DWORD 32 DW#16#ADAC1EF5 QD40
CHAR 8 ' w ' DBB4
S5TIME 16 S5T#5s_200ms MW30
INT 16 123 #Value
DINT 32 L#65539 MD80
REAL 32 1.2 or 3.45E-11 DBD60
TIME 32 T#2D_1H_3M_45S_12MS QD44
DATE 16 D#1993-01-20 MW32
TIME_OF_DAY 32 TOD#12:23:45.12 #Time
SITRAIN Training for
Automation and Industrial Solutions
ST-SERV2
Storing Process Data Page 7
Complex Complexdata types (arrays and structures) consist of groups of elementaryor
Data Types complexdata types.
Theyenable you to create data types with which you can structure large
quantities of data and process it symbolically.
Complex data types (longer than 32 bits), cannot be processed with STEP 7
instructions all at once. Only one element at a time can be processed.
Complex data types are predefined. The data type DATE_AND_TIME has a
length of 64 bits. The lengths of the data types ARRAY, STRUCT and STRING
are defined by the user.
Variables for complex data types can be declared only in global data blocks and
as parameters or local variables of logic blocks.
User-Defined User-defineddata types represent a self-definedstructure. This structure is
Data Type stored in UDT blocks (UDT1 to UDT65535) and canbe usedas a "template" in
another variables data type.
You cansave typing time when you input a data block if youneed the same
structure several times.
Example You need the same structure 10 times in a data block. First, youdefine the
structure and save it, for example, as UDT1. In the DB, you thendefine 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".
Date: 18.11.2005
File: SERV2_03E.7
SIMATIC S7
Siemens AG 2005. All rights reserved.
SITRAIN Training for
Automation and Industrial Solutions
Complex Data Types
DATE_AND_TIME 64 DT#01-08-24-12:14:55:234-1
STRING 8 * (number of This is a string
(character string with characters +2) SIEMENS
max. 254 characters)
ARRAY user- Measured values: ARRAY[1..20]
(Group of elements defined INT
of the same data type)
STRUCT user- Motor: STRUCT
(Group of elements defined Speed : INT
of different data types) Current : REAL
END_STRUCT
UDT UDT as block UDT as array
element
(User Defined Data Type = user- STRUCT
"Template" consisting of defined Speed : INT Drive: ARRAY[1..4]
elementary or complex Current : REAL UDT1
data types END_STRUCT
Keyword Length (in bits) Example
SITRAIN Training for
Automation and Industrial Solutions
ST-SERV2
Storing Process Data Page 8
Date: 18.11.2005
File: SERV2_03E.8
SIMATIC S7
Siemens AG 2005. All rights reserved.
SITRAIN Training for
Automation and Industrial Solutions
Example of an ARRAY
Display in the Program Editor (Data Block DB 2):
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)

Array An arrayconsists of several elements of the same data type. In the slide above,
you cansee 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 addressedwith the index[1] and the
last with the index [10]. Insteadof [1..10] you could, for example, define [0..9].
The first element would index [0] and the last element [9].
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".
SITRAIN Training for
Automation and Industrial Solutions
ST-SERV2
Storing Process Data Page 9
Structure The slide shows an example of a structure named "Motor_data". The structure
consists of several elements of different data types. The individual elements of a
structure canbe elementary or complex data types.
The access to the individual elements of a structure contains the structure
name. This makes the programeasier to read.
In order to be able to access the elements symbolically, the data block must be
given a symbol name, for example, "Drive_1".
Example: accessingelements of a structure using the load command "L"
L "Drive_1".Motor_data.rated_current
L "Drive_1".Motor_data. speed
The format is: block symbolic name, dot, structure name, dot, element name.
Note that the symbolic block name ("Drive_1") is enclosed in quotations,
indicating the name is fromthe global symbol editor. The structure name and
element names are not enclosed in quotations, because theyare symbols
defined in the data block and are not listed in the global symbol editor.
Define Structure The keyword for a structure is "STRUCT". The end of a structure is indicated
in DB by"END_STRUCT". A name is definedfor the structure (in the example:
"Motor_data").
Date: 18.11.2005
File: SERV2_03E.9
SIMATIC S7
Siemens AG 2005. All rights reserved.
SITRAIN Training for
Automation and Industrial Solutions
Example of a STRUCTURE
Display in the Program Editor (Data block DB 1):
Speed, data type Integer
Rated_current, data type Real
Starting_current, data type Real
Direction, data type Bool
Structure with the name "Motor_data"
(several elements
with different data types)
Motor_data
SITRAIN Training for
Automation and Industrial Solutions
ST-SERV2
Storing Process Data Page 10
Address Priority The address priority helps you to update the programcode when you make
changes in the symbol table, changes in the parameter names of data blocks or
functionblocks, or when you make changes to component names of referenced
UDTs or multi-instances.
What to Do You select the Blocks folderin the SIMATIC Manager and choose the menu
options Edit Object Properties to define the address priority. In the tab
"Address Priority" you canmake the desired settings.
Note Symbol priority means that symbols have priorityover absolute addresses.
Symbolic programming is recommended.
When you openblocks or generate sources, everyaddress 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.
Date: 18.11.2005
File: SERV2_03E.10
SIMATIC S7
Siemens AG 2005. All rights reserved.
SITRAIN Training for
Automation and Industrial Solutions
Defining the Address Priority (Symbolic/Absolute)
SITRAIN Training for
Automation and Industrial Solutions
ST-SERV2
Storing Process Data Page 11
Creating a DB You can insert a newdata block - as shown in the slide - in the SIMATIC

Manager by first selecting the Blocks folder of the S7 programand then


following the menuoptions shown.
You canalso create a newdata 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 Shareddata blocks are used to store global data. That is, for storinggeneral
data that canbe accessedbyevery logic block (OB, FC, FB).
The user has to edit the global data blocks himself. He does so bydeclaring the
necessary variables for saving data in the data block.
Instance DB Instance data blocks are usedas the "private memoryarea" or as the "memory"
for a functionblock (FB). The parameters and the static variables of an FB are
managed in its instance DB.
Instance data blocks are generally not editedby the user, rather theyare
generated bythe Editor (see the Functions and Function Blocks chapter).
DB of Type Data blocks canalso be generatedaccording to a User defined Data Type
(UDT) by the Editor. A UDT, that the user must first edit like a data block, is
usedas a template for this.
The UDT can be usedas a template for creatingadditional data blocks and / or
also in general for declaring variables and block parameters.
Date: 18.11.2005
File: SERV2_03E.11
SIMATIC S7
Siemens AG 2005. All rights reserved.
SITRAIN Training for
Automation and Industrial Solutions
Creating a Data Block
SITRAIN Training for
Automation and Industrial Solutions
ST-SERV2
Storing Process Data Page 12
Date: 18.11.2005
File: SERV2_03E.12
SIMATIC S7
Siemens AG 2005. All rights reserved.
SITRAIN Training for
Automation and Industrial Solutions
Initial Value, Actual Value, Initialization, Retentivity
DB
Initial values
+Actual values
CPU
with
STEP 7
Program
DB
Initial values
+Actual values
Upload in PG
Initialize
data block
DB is retentive until the
next memory reset
With every CPU startup (i.e.
with every STOP-RUN
transition), the DB data are
reset to the initial loading
state
DB
Actual values
Load Memory Work Memory
Initial Value When you enter a data block for the first time, you canspecifyan intial value
that is accepted the first time the DB is saved.
If youdont specifyan initial value, zero in the correct data type format is
automatically entered. To edit the initial value, the declaration viewmust be
switchedon.
Actual Value This is the current value in the data block. The actual value canbe changed
offline in the data viewor it canbe overwrittenby the programin the CPU. If a
data block is loaded fromthe 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 Viewand use the menuoption Edit
Initialize data block.
Retentivity Retain: The values stored in the data blocks are retaineduntil 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 memoryof 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 STOP-
RUN transition.
A DB with the assigned "Non-Retain" property still occupies work memorybut it
doesnt occupy retentive memory. Witha cold restart (CPU 318 or S7-400), all
data blocks are reset to the initial values.
Note You will find detailed informationon the Memory Concept in the S7-CPUs in the
Chapter "Documenting, Saving and Archiving".
SITRAIN Training for
Automation and Industrial Solutions
ST-SERV2
Storing Process Data Page 13
Declaration View Data blocks are edited in the "declarationview", that is, the user declares the
(Entering Variables) variables needed for storing the data here. The variables are created in a table,
organized in lines and columns.
Columns The columns have the following meaning:
Address - is enteredbythe ProgramEditor. It is the first byte address
occupiedby the variable
Name - symbolic name of the variable
Type - data type (INT, REAL, ....., you select this with the right
mouse button)
Initial value - used for settinga default value for a variable the first time
the data block is createdand/or edited. If youdo not make
an entryhere, the Editor automatically enters the value 0.
Comment - is used to document the variable (optional)
Save You save the data block in the S7 project using the "Diskette" icon.
Download You download data blocks to the CPU, just as youdo with logic blocks.
Data View You can monitor online the current variable values in the data block (values of
(Monitor DB) the variables in the CPU). To do so, you must first go into the "View" menu and
switch to the "Data View". You can thenactivate the functionusing the "Glasses"
icon.
Initialize DB When you initialize a data block youoverwrite the variables current values with
the initial values. This is also necessary when initial values that have been
changed later on have to be acceptedas actual values.
The menuoptions for this are: View Data View Edit Initialize Data Block
Date: 18.11.2005
File: SERV2_03E.13
SIMATIC S7
Siemens AG 2005. All rights reserved.
SITRAIN Training for
Automation and Industrial Solutions
Entering, Saving, Downloading and Monitoring a Data Block
Declaration View
Data View
SITRAIN Training for
Automation and Industrial Solutions
ST-SERV2
Storing Process Data Page 14
Date: 18.11.2005
File: SERV2_03E.14
SIMATIC S7
Siemens AG 2005. All rights reserved.
SITRAIN Training for
Automation and Industrial Solutions
Addressing Data Elements
0 7
8 Bits
Data Byte 0 DBB 0
Data Byte 1 DBW 0
DBD 2004
DBW 2006
DBB 2007
Data Byte 2
DBD 0
Data Byte 3
DBX 4.1
General You address the data elements of a data block byte-by-byte, just as you do bit
memories.
You can loadand 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
operationand two bytes are loadedbeginning with this first byte of this address.
With doublewords, four bytes are loadedbeginning with the first byte address
that youenter.
Number, Length The number of data blocks available depends on the CPU youuse. You will find
more information in the electronic catalog CA01.
Note If youaccess non-existent data elements or data blocks an Area Length error
System Fault will occur. The CPU goes into the Stopmode if youdid not
programan error OB.
SITRAIN Training for
Automation and Industrial Solutions
ST-SERV2
Storing Process Data Page 15
Traditional Access In the traditional (typical in the S5 world) data block access, data blocks have to
be openedexplicitly before the actual access. This cantake place absolutelyor
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 automa-
tically closed. Then, the individual data elements canbe accessedbit-by-bit
(DBX...), byte-by-byte (DBB...), word-by-word (DBW...) or doubleword-by-
doubleword (DBD...) without a data block having to be specified each time.
Disadvantages:
Whenaccessing data elements, you have to make sure that the correct data
block is open.
Access canbe absolute only. The programmer must make sure that he
"reaches" the correct value in the data block. If DBW5 in the example were
loaded, thenneither the value of the Number nor Weight[1] variables would
be loaded, but an invalid value.
Absolute accesses hamper correctionpossibilities and make the program
difficult to read.
Fully-qualified A fully-qualifiedaccess is the opening of a data block which closes any
Access... previouslyopenedDBs. A fully-qualified access canbe made absolutelyand
symbolically.
...absolute An absolute access is the openingof 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 allowthe
"mixing" of absolute and symbolic addresses during editing, however, it switches
over to completelysymbolic after the entry has beenconfirmed.
Date: 18.11.2005
File: SERV2_03E.15
SIMATIC S7
Siemens AG 2005. All rights reserved.
SITRAIN Training for
Automation and Industrial Solutions
Accessing Data Elements
DB 18 "Parts"
Traditional
Access
Fully-qualified Access
or A DB18.DBX2.0 or A "PARTS".FL_Aux
or L DB18.DBW0 or
L "Parts".
ACT_Quantity
or T DB18.DBW4 or T "Parts".Number
or L DB18.DBD10 or L "Parts".Weight[2]
absolute symbolic
OPN DB 18
A DBX2.0
2.0 FL_Aux BOOL
OPN "Parts"
L DBW0
0.0 Act_Quantity INT
OPN "Parts"
T DBW 4
4.0 Number INT
Addr. Name Type
6.0 Weight[1] REAL
OPN DB 18
L DBD 10
10.0 Weight[2] REAL

You might also like