Beruflich Dokumente
Kultur Dokumente
Contents Page
Objectives .......................................................................................................................................... 2
Interesting Facts about Libraries ..................................................................................................... 3
Design and Contents of the Standard Library ................................................................................... 4
Interesting Facts about System Functions ...................................................................................... 5
Overview of the System Functions (Excerpt) .................................................................................... 6
System Functions that Exist in the CPU ......................................................................................... 7
Call of System Functions and System Function Blocks .................................................................. 8
Example: "READ_CLK" (SFC 1) ....................................................................................................... 9
TIME_OF_DAY and DATE_AND_TIME Data Types ........................................................................ 10
Example: "BLKMOV" (SFC 20) .......................................................................................................... 11
Assignment of Parameters of the ANY Data Type ........................................................................... 12
Analyzing an Error Message …....................................................................................................... 13
Exercise 1: Recording the Time Stamp with SFC 1 .......................................................................... 14
Exercise 2: Data Backup with SFC 20 .............................................................................................. 15
If You Want to Know More ............................................................................................................. 16
Additional Exercise: Specified Time Relay ...................................................................................... 17
The Library: TI-S7 Converting Blocks (Excerpt) .............................................................................. 18
The Library: IEC Function Blocks (Excerpt) .................................................................................... 19
The Library: Communication Blocks .............................................................................................. 20
The Library: PID Control Blocks ..................................................................................................... 21
The Library: Miscellaneous Blocks (Excerpt) .................................................................................. 22
Library Structure:
A library may contain several program folders
A library may not contain any "Hardware"
Each program folder contains:
the folders "Blocks", "Sources", "Symbols"
the folder "Charts" (only for the option software: S7-CFC)
Using Libraries:
With the SIMATIC Manager you can:
create libraries (not with the same names as projects)
copy Blocks and Sources between libraries and projects
archive libraries
With the LAD/FBD/STL Editor you can
store network templates in libraries as Sources and then reuse them
whenever you need
Overview Libraries are used to store reusable program components for the SIMATIC S7.
The program components can be copied into a library from existing projects or
they can be created directly in the library regardless of the projects.
For the creation of S7 programs in a library, you have the same functions as for
projects – with the exception of testing.
Using Libraries Blocks that are to be used again and again can be stored in libraries. From
there, you can copy them into the appropriate user program and they can be
called by other blocks.
Introduction When you install the STEP 7 software, a standard library with the name
"Standard Library" is automatically installed on the hard drive.
Opening the Library To open a library, you either use the command: File Æ Open or the appropriate
icon in the toolbar.
Then, a further dialog pops up in which you can select the desired project,
library or sample project.
Standard Library The Standard Library contains the following S7 program folders:
• Communication Blocks: contains the functions for connecting to distributed
peripherals when using an S7-300 PROFIBUS CP,
• IEC Function Blocks: contains blocks for IEC functions such as, for handling
the data types DATE_AND_TIME and STRING,
• Miscellaneous Blocks: contains blocks for the time stamping of messages
and for time of day synchronization,
• Organization Blocks: contain all OBs with the symbolic identifiers for the start
information,
• PID Control Blocks: with function blocks for PID control,
• S5-S7 Converting Blocks: with the standard blocks needed for the
conversion of S5 programs to S7,
• System Function Blocks: contains all S7-300/400 system functions (SFCs
and SFBs),
• TI-S7 Converting Blocks: with generally usable standard functions, such as
Scaling analog values, etc.
Notes When option packages are installed, additional libraries may be created.
You can find a description of the S7 Libraries - PID and TI-S7 Converting Blocks
under: Toolbar Æ SIMATIC Æ Documentation Æ English Æ STEP 7- PID
Control or System and Standard Functions for TI-S7 Converter.
Introduction Functionality, that cannot be implemented with STEP 7 instructions (for example
DB creation, communication with other PLCs, etc.) can be implemented in
STEP7 with the help of system functions (SFCs) or system function blocks
(SFBs).
SFCs and SFBs are blocks that are stored in the CPU’s operating system
instead of in the user memory. For that reason, the actual instruction part is not
transmitted but only the SFC’s or SFB’s declaration part during the reading out
of an SFC or SFB from the CPU.
With the help of the STL/LAD/FBD Editor, the "block" that is read out can be
opened and the declaration part displayed. A reverse transmission of SFCs and
SFBs into the CPU is, however, not possible.
In the user program, the SFBs and SFCs can however be called just like FBs or
FCs using the CALL instruction. With SFBs, a user DB must also be specified as
instance DB for the SFB for that reason.
Which SFBs and SFCs are available depends individually on the PLC system
(S7-300 or S7-400) used and on the CPU installed. The blocks have, however,
regardless of whether they are called in an S7-300 or S7-400, the same
numbers, the same functionality and the same call interface.
Manual An extensive description of the system functions can be found in the manual:
• The System Software Reference Manual for S7-300/400, System Functions
and Standard Functions.
Online Help There is also an extensive description of the system functions in the STEP 7
software. Call the help menu in the program editor and select the entry:
• Help Topics Æ Calling Reference Helps (LAD, FBD, STL, Blocks ... )
Æ Jumps to Language Descriptions and Help on Blocks and System
Attributes Æ Help on SFBs/SFCs.
Copy and Block • SFC 20 copies the contents of a memory area (source) into another memory
Functions area (destination)
• SFC 21 fills a memory area (destination field) with the contents of a pre-
defined memory area (source field)
• SFC 22 creates a non-initialized DB in the work memory
• SFC 23 deletes a DB in the work memory and if necessary in the load mem.
• SFC 24 determines whether a DB exists in the work memory (with length)
• SFC 25 compresses the memory, since gaps occur when block corrections
are made and these gaps are closed when compression takes place
• SFC 44 (Call in OB 122) deposits a replacement value for a faulty input
module in the Accumulator. Usage in OB121 is also possible.
Program Control • SFC 35 triggers the synchronized start of OB 60 in all CPUs when
multicomputing
• SFC 43 restarts the cycle time monitoring of the CPU
• SFC 46 puts the CPU into the Stop state
• SFC 47 implements waiting times in the user program of up to 32767 µs
Handling the Clock • SFC 0 sets the real-time clock date and time on the CPU
• SFC 1 reads the current date and time of the CPU
• SFC 48 synchronizes all the slave clocks on a bus segment. The CPU with
the call must be parameterized as the master clock.
Run-Time Meter The CPU has a specific number of run-time meters with which it can record the
operating time of equipment, for example.
• SFC 2 sets the run-time meter to a pre-assigned value
• SFC 3 starts and stops the run-time meter
• SFC 4 reads the current operating hours and the status
• SFC 64 reads the CPU‘s system time. The system time is a cyclic time
counter that counts up every 10 ms (S7-300) or 1 ms (S7-400).
General In the "Performance Data" you can, among other things, query online which
system functions are available on a CPU.
SIMATIC Manager Æ PLC Æ Diagnostic/Settings Æ Module Information ... Æ
Performance Data
System Functions:
SFC20
CALL SFC 20 EN ENO
SRCBLK :=
RET_VAL:= ??.? SRCBLK RET_VAL ??.?
DSTBLK :=
DSTBLK ??.?
System Function A system function block SFB is a function block that is integrated in the
Blocks operating system of an S7-CPU. For that reason, SFBs are not downloaded into
the CPU as part of the user program.
Just like FBs, SFBs are blocks "with a memory". They have to be instantiated in
the user program.
System Functions A system function is a function that is integrated in the operating system of the
S7-CPU. SFCs can be called from the user program just like FCs.
Just like FCs, SFCs are blocks "without a memory".
Call When a system function is called it is automatically copied into the associated
user program.
Furthermore, all system functions are stored in the Standard Library, S7
Program System Function Blocks. From this library, the SFCs and SFBs can
also be copied into the user program.
There is a completed symbol list (with English identifiers) in the library from
which the symbols of the blocks used are automatically entered in the symbol
list of the user program.
SFC1
EN ENO
RET_VAL ??.?
CDT ??.?
SFC1 "READ_CLK" The SFC 1 "READ_CLK" (read system clock) reads out the time in the CPU and
provides as a result a time stamp consisting of a date and the time of day.
Year Month
Byte n1) Byte n+1
(90 ... 89) (01 ... 12)
Byte n+2
Day Hour
(01 ... 31) (00 ... 23) Byte n+3
Minutes 1=Sunday
Byte n+4
Seconds 2=Monday
(00 ... 59) (00 ... 59) Byte n+5
3=Tuesday
4=Wednesday
Milliseconds Weekday 5=Thursday
Byte n+6 Byte n+7 6=Friday
(000 ... 999) (1..7) 7=Saturday
DATE_AND_TIME The DATE_AND_TIME data type represents a point in time, consisting of the
date and the time. Instead of DATE_AND_TIME you can also use the
abbreviation DT.
DATE_AND_TIME or DT are key words and can therefore also be written in
lower case.
In the declaration, you can pre-assign an initial value to a variable (not as block
parameter in an FC, as in/out parameter in an FB or as temporary variable).
The pre-assignment must be of the type:
• DT#year-month-day-hours:minutes:seconds.milliseconds
You don‘t have to specify the milliseconds.
Variables of the DATE_AND_TIME data type can either be processed with the
help of absolute accesses to the individual components or with the associated
functions of the IEC library.
SFC20
EN ENO
DST_BLK ??.?
SFC20 "BLKMOV" The system function "BLKMOV" (block move) copies the contents of a memory
area (= source field) into another memory area (= destination field).
Permitable source areas (fields) are:
• parts of data blocks
· • bit memories
· • process image input table
· • process image output table
Notes Source and destination areas may not overlap. If the specified destination area
is larger than the source area, then only as much data is copied into the
destination area as is contained in the source area. If the specified destination
area is smaller than the source area, then only as much data as fits into the
destination area is copied.
The source area can also be located in a data block that is only stored in the
load memory (DB that was compiled with the keyword UNLINKED ) !
Assignment A parameter of the "ANY" data type can be assigned using the pointer display
as well as by direct declaration of address (variables).
Pointer Display With assignment using the pointer display (for example: P#DB5.DBX10.0 INT 8)
the STL/LAD/FBD Editor sets up an ANY pointer that corresponds in type and in
number with the declarations.
Assignment in the pointer display always makes sense when a data area is to
be addressed for which no variable was defined or for example, no suitable
variable (ARRAY or STRUCT, for example) can be defined (P, PII, PIQ, M, for
example).
In addition, the absolute pointer display must be used when the correct
information about the replication factor and the data type is required within the
called block (for example, ARRAY[1..8] OF REAL).
Address A parameter of the "ANY" type can also be directly assigned with the address
Display to which the ANY pointer is to point. This declaration can take place absolute or
using the symbolic variable name.
With the declaration of an absolute address, the STL/LAD/FBD Editor
automatically determines the associated data type (BOOL, BYTE, WORD,
DWORD,), a replication factor of "1", the DB number as well as the area-
crossing pointer to the first bit of the address and enters these values in the
pointer structure.
Likewise, the STL/LAD/FBD Editor determines the correct information using the
address when the declaration takes place using the symbol name and the
variable that is entered is of the elementary data type.
Note If a variable is of the complex data type (for example, ARRAY[1..8] OF REAL),
then the STL/LAD/FBD Editor merely enters information in bytes about the area
occupied by the variable (that is,: replication factor: 32, data type: BYTE).
Example:
W#16#8081 is an SFC specific error code.
W#16#823A is a general error code; the error was caused by
Parameter No. 2.
Error Information A processed SFC shows you in the user program, whether the CPU could
successfully execute the SFC function or not. You receive corresponding error
information in two ways:
• in the BR bit of the status word and
• in the output parameter RET_VAL (return value).
Note You should always proceed as follows before evaluating the SFC specific output
parameter:
• first of all evaluate the BR bit of the status word.
• subsequently check the output parameter RET_VAL.
If a faulty processing of the SFC is signalized through the BR bit or a general
error code is found in RET_VAL, you may not analyze the SFC specific output
parameter.
General Errors The general error code indicates errors that can occur with all system functions.
A general error code consists of the following two numbers:
• a parameter number between 1 and 127, whereby 1 indicates the first
parameter, 2 the second parameter etc., of the SFC called.
• an event number between 0 and 127. The event number indicates a
synchronous error.
An extensive description of the general error codes can be found in the manual:
"System Functions and Standard Functions" or in the Online Help.
Specific Errors Several system functions (SFCs) have a return value that provides a specific
error code. This error code indicates that an error that belongs to a specific
system function occurred during the processing of the function.
A description of the specific error code can be found in the Online Help for the
associated system function (keyword "Error Information").
Year/Month
Day
Hours/Minutes
Seconds
ms/weekday
Function (FB 18) The parts transported while in AUTO mode are counted for each bay. The total
Count Parts/Statistic quantity and the quantities of the individual bays as well as their percentage
utilization are stored in the statistic variable "Statistic_Values" (declared
according to UDT18, see slide).
Task In the next exercise a data backup of the variable #Statistic_Values is carried
out.
But first, the time stamp for the data backup is to be entered in the variable
"DB_DataBackup".DateTime.
What to Do 1. Create the new data block "DB_DataBackup" (DB 10) with the variable
shown in the slide.
2. In FB 18, call the system function SFC 1 for reading out the system time and
pass the variable "DB_DataBackup".DateTime onto its OUT parameter CDT
(see slide).
3. Select the screen "Conv" and switch off the AUTO mode (Q 4.3) and then
switch it back on again.
4. With the test function "Monitor/Modify Variables" monitor the data block
operands or components of the variable "DB_DataBackup".DateTime
shown in the slide.
Note Monitoring data block variables of the data type Date_and_Time (DT) is not
possible with the test function "Monitor Data Block". The test function "Monitor
Variable" provides help because you can monitor the individual components of
the DT variable (see slide).
FB 18
Function (FB 18) The parts transported while in AUTO mode are counted for each bay. The total
Count Parts/Statistic quantity and the quantities of the individual bays as well as their percentage
utilization are stored in the statistic variable "Statistic_Values" (declared
according to UDT18, see slide).
Task For purposes of data backup, all values of the static variable "Statistic_Values"
are to be stored in the data block "DB_DataBackup" (DB 10) every time
"L_AUTO" (rising edge of Q 4.3 = #ON_Edge) is turned on, before the values
are overwritten with 0. That way, the old statistic values are still available even
after the system has been turned on.
What to Do 1. In FB 18, call the SFC 20 block and check the program function as follows:
2. Open "DB_DataBackup" (DB 10) in the data view and activate the "Monitor"
test function.
3. On the touchpanel select the "Statistic" screen and make note of the current
quantities and utilization of the individual bays.
4. Select the "Conv" screen, switch the AUTO mode off and then switch it on
again and in the process observe whether the statistic values are
transferred into the data block.
5. Select the "Statistic" screen once more and check whether the current values
shown have been reset to 0.
Note The following pages contain either further information or are for reference to
complete a topic.
General With the IEC Function Blocks, the Standard Library provides very useful
complex functions, such as how a specified time relay can be used for a system
expansion.
Task In a new FC119, create a specified time relay with the help of the IEC Function
Blocks from the Standard Library. The relay is to be used to switch an oil heater
on at 8:00 o‘clock in the morning and switch it off at 16:00 o‘clock. The heater is
energized through the output Q 5.3.
In the Standard Library S7 program "System Function Blocks", use the SFC 1 to
read the current time from the real-time clock in the CPU. With the FC8 function
from the S7 program "IEC Function Blocks", the current time can be extracted
from the time stamp of SFC1. Then the times 8:00 o‘clock and 16:00 o‘clock can
then be compared using 2 comparison functions.
To simulate these times, the desired time in the CPU is adjusted in each case
using the menu options PLC Æ Set Date and Time.
FC 80 The FC80 function starts the "timer function as storing ON Delay (TONR)". The
FC80 accumulates time until the current value of elapsed time (#ET) equals or
exceeds the preset value (#PV).
FC 81 With the indirect move of a data area function (IBLKMOV), you can move a
block of data consisting of either bytes, words, integers (16 bits), double words
or double integers (32 bits) from a source block to a destination block.
The #S_DATA and #D_DATA POINTERS point to structures of the POINTER
data type which identify the starting locations of the source and destination data.
The area length to be copied is determined through special parameters.
FC 82/83 Sets the signal state of each bit in a specified range to "1" (FC83), or to "0" (FC
82), if the MCR bit is "1". If the MCR bit is "0", the signal state of each bit in the
range remains unchanged.
FC 84 - FC 92 These functions are table functions to implement FIFO functions, for example.
The values are to be entered in the word format; the length can be set.
FC 105 Converts the digitalized value of an analog channel into a physical quantity
(such as weight).
FC 3 The FC 3 function combines the data formats DATE and TIME_OF_DAY (TOD)
and converts these formats into the data format DATE_AND_TIME (DT).
FC 6 The FC 6 function extracts the data format DATE from the format
DATE_AND_TIME.
FC 7 The FC 7 function extracts the day of the week from the format
DATE_AND_TIME. The weekday exists in the data format INTEGER and begins
with 1 = Sunday to 7 = Saturday.
FC 8 The FC 8 function extracts the data format TIME_OF_DAY from the format
DATE_AND_TIME. The input value can only be assigned with a symbolically
defined variable.
Overview The library functions FC1, FC2, FC3 and FC4 are used exclusively in the
following configuration:
• S7-300 CPU with external PROFIBUS CP 342-5
In all other cases, that is, for S7-300 with integrated PROFIBUS-DP interface
and for the entire S7-400 system, the corresponding functions are implemented
with the standard load and transfer commands (L ... , T...) or through SFC14
(DPRD_DAT), SFC15 (DPWR_DAT), SFC11 (DPSYC_FR) and SFC13
(DPNRM_DG).
FC1 The DP_SEND block transfers the data of a specified DP output area to the
PROFIBUSCP for output to the distributed peripherals.
FC2 The DP_RECV block receives the process data of the distributed peripherals as
well as status information in a specified DP input area.
FC3 The DP_DIAG FC block is used to request diagnostic information. The following
types of job are possible:
• Request DP station list;
• Request DP diagnostic list;
• Request DP single diagnosis (status);
• Read input / output data of a DP slave acyclically;
• Read DP mode.
FC4 The DP_CTRL FC block transfers control jobs to the PROFIBUS CP. The
following types of job are possible:
• Global control acyclic / cyclic;
• Delete older diagnostic data;
• Set current DP mode;
• Set DP mode for PLC/CP stop;
• Read input/output data cyclically;
• Set the operating mode of the DP slave.
FB43 The SFB "PULSEGEN" (pulse generator) is used to structure a PID controller
with pulse output for proportional actuators.
Using SFB "PULSEGEN", PID two or three step controllers with pulse duration
modulation can be configured. The function is normally used in conjunction with
the continuous controller "CONT_C".
FC 60 The FC reads the time-of-day status and the time of the CPU and calculates the
local time from it.
This function is not available for all CPUs. If it is not, the FC 60 gives out an
error message.
Time-of-Day Status You can determine the current time-of-day status of your CPU with the SFC 51
"RDSYSST". The time-of-day status contains the following information:
• correction factor for the clock
• Standard/Daylight-saving Time identification
• Announced hour of transition (the next time the hour changes, the clock is
adjusted from Standard to Daylight-saving or vice versa).