Sie sind auf Seite 1von 22

Using System Blocks

SIMATIC S7 Date: 18.09.2009 SITRAIN Training for


Automation and Industrial Solutions
Siemens AG 2008. All rights reserved. File: PRO2_08E.1

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

SITRAIN Training for ST-PRO2


Automation and Industrial Solutions Page 1 Using System Blocks
Objectives

Upon completion of this chapter the participant will ...

... be familiar with the standard libraries and their usage,


... be able to integrate blocks from the library in a user program
... be able to interpret the error numbers of the parameter "RET_VAL"

SIMATIC S7 Date: 18.09.2009 SITRAIN Training for


Automation and Industrial Solutions
Siemens AG 2008. All rights reserved. File: PRO2_08E.2

SITRAIN Training for ST-PRO2


Automation and Industrial Solutions Page 2 Using System Blocks
Interesting Facts about Libraries
‰ Area of Use:
€ Storage of reusable program components
€ It is not possible to directly transfer into the CPU and test

‰ 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

SIMATIC S7 Date: 18.09.2009 SITRAIN Training for


Automation and Industrial Solutions
Siemens AG 2008. All rights reserved. File: PRO2_08E.3

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.

Design Just as for projects, libraries have a hierarchical design:


• Libraries can contain S7 programs.
• An S7 program can have exactly one Blocks folder, one Sources folder,
one Charts folder as well as one Symbols object (symbol table).
• The Blocks folder contains the blocks that can be downloaded to the S7
CPU. The contained variable tables (VAT) and user-defined data types
(UDT) are not downloaded to the CPU.
• The Sources folder contains the sources for the programs created in the
diverse programming languages.
• The Charts folder contains the CFC Charts (only for the option software
S7-CFC)
When you insert a new S7 program, one Blocks and one Sources folder each as
well as one Symbols object is automatically created in it.

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.

SITRAIN Training for ST-PRO2


Automation and Industrial Solutions Page 3 Using System Blocks
Design and Contents of the Standard Library

SIMATIC S7 Date: 18.09.2009 SITRAIN Training for


Automation and Industrial Solutions
Siemens AG 2008. All rights reserved. File: PRO2_08E.4

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.

SITRAIN Training for ST-PRO2


Automation and Industrial Solutions Page 4 Using System Blocks
Interesting Facts about System Functions

The system functions (SFCs and SFBs) are stored


in the CPU‘s operating system

System Software Reference Manual for S7-300/400


System Functions and Standard Functions

Extensive Online help available in the STEP 7 software

SIMATIC S7 Date: 18.09.2009 SITRAIN Training for


Automation and Industrial Solutions
Siemens AG 2008. All rights reserved. File: PRO2_08E.5

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.

SITRAIN Training for ST-PRO2


Automation and Industrial Solutions Page 5 Using System Blocks
Overview of the System Functions (Excerpt)

Function Group Function Block S7-300 S7-400


Block move SFC 20 X X
Pre-assign field SFC 21 X X
Create DB SFC 22 X X
Copy and
Delete DB SFC 23 - X
Block Function
Test DB SFC 24 - X
Compress SFC 25 - X
Replace. value in Accu. 1 SFC 44 X1) X
Multi computing interrupt SFC 35 - X
Trigger cycle time SFC 43 X X
Program Control
Stop state SFC 46 X X
Delay (Wait) SFC 47 X X

Set time-of-day SFC 0 X X


Handling the Clock Read time-of-day SFC 1 X X
Synchronize SFC 48 - X

Set counter SFC 2 X1) X


Start and stop SFC 3 X1) X
Run-time Meter
Read out SFC 4 X1) X
Read system time SFC 64 X X

1) not for CPU 312IFM

SIMATIC S7 Date: 18.09.2009 SITRAIN Training for


Automation and Industrial Solutions
Siemens AG 2008. All rights reserved. File: PRO2_08E.6

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).

SITRAIN Training for ST-PRO2


Automation and Industrial Solutions Page 6 Using System Blocks
System Functions that Exist in the CPU

SIMATIC S7 Date: 18.09.2009 SITRAIN Training for


Automation and Industrial Solutions
Siemens AG 2008. All rights reserved. File: PRO2_08E.7

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

SITRAIN Training for ST-PRO2


Automation and Industrial Solutions Page 7 Using System Blocks
Call of System Functions and System Function Blocks

System Functions:
SFC20
CALL SFC 20 EN ENO
SRCBLK :=
RET_VAL:= ??.? SRCBLK RET_VAL ??.?
DSTBLK :=
DSTBLK ??.?

Call in STL Call in LAD

System Function DB5


Blocks: SFB3
EN ENO
CALL SFB 3,DB5
IN:=
PT:= ... IN Q ...
Q := ... PT ET ...
ET:=

SIMATIC S7 Date: 18.09.2009 SITRAIN Training for


Automation and Industrial Solutions
Siemens AG 2008. All rights reserved. File: PRO2_08E.8

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.

SITRAIN Training for ST-PRO2


Automation and Industrial Solutions Page 8 Using System Blocks
Example: "READ_CLK" (SFC 1)

SFC1
EN ENO

RET_VAL ??.?

CDT ??.?

Parameter Declaration Data Type Memory Area Description


ENO OUTPUT BOOL I, Q, M, D, L = '1' if error-free exeuction of the function
(BR Bit) = '0' if faulty execution of the function

RET_VAL OUTPUT INT I, Q, M, D, L = 0 if error-free execution of the function


= Error code if execution with errors

CDT OUTPUT DT D, L Date and Time

SIMATIC S7 Date: 18.09.2009 SITRAIN Training for


Automation and Industrial Solutions
Siemens AG 2008. All rights reserved. File: PRO2_08E.9

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.

SITRAIN Training for ST-PRO2


Automation and Industrial Solutions Page 9 Using System Blocks
TIME_OF_DAY and DATE_AND_TIME Data Types

Structure of TIME_OF_ DAY (TOD):

Number of milliseconds since 0:00 o‘clock

Structure of DATE_AND_TIME (DT):

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

All Values in BCD format

SIMATIC S7 Date: 18.09.2009 SITRAIN Training for


Automation and Industrial Solutions
Siemens AG 2008. All rights reserved. File: PRO2_08E.10

TIME_OF_DAY A variable of the TIME_OF_DAY data type occupies a doubleword. It contains


the number of milliseconds since the beginning of the day (0:00 o‘clock) as
unsigned integer. (such as: TOD#23:59:59.999).

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.

SITRAIN Training for ST-PRO2


Automation and Industrial Solutions Page 10 Using System Blocks
Example: "BLKMOV" (SFC 20)

SFC20
EN ENO

??.? SRC_BLK RET_VAL ??.?

DST_BLK ??.?

Parameter Declaration Data Type Memory Area Description

SRC_BLK INPUT ANY I, Q, M, D, L Memory area to be copied


(=source field).

ENO OUTPUT BOOL I, Q, M, D, L = '1' if error-free execution of the function


(BR Bit) = '0' if faulty execution of the function

RET_VAL OUTPUT INT I, Q, M, D, L = 0 if error-free execution of the function


= Error code if execution with errors

DST_BLK OUTPUT ANY I, Q, M, D, L Memory area in which copying is to


take place (destination field)

SIMATIC S7 Date: 18.09.2009 SITRAIN Training for


Automation and Industrial Solutions
Siemens AG 2008. All rights reserved. File: PRO2_08E.11

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 ) !

SITRAIN Training for ST-PRO2


Automation and Industrial Solutions Page 11 Using System Blocks
Assignment of Parameters of the ANY Data Type
Pointer Display:
z P#[Data block.]Bit address Type Number
P#DB10.DBX12.0 REAL 20 Pointer to an area in DB10, beginning with
Byte 12, consisting of 20 addresses of
data type REAL (ARRAY[1..20] OF REAL)
P#I 10.0 BOOL 8 Pointer to a field of 8 bits in IB10
Declaration of Address:
z absolute:
DB5.DBD10 Data type: DWORD, Replication factor: 1
DB number: 5, Pointer: P#DBX10.0
IW32 Type: WORD, WF: 1, DB Nr: 0, Pointer: P#I 32.0
T35 Type: TIMER, Nr.: 35
z symbolic:
#Motor_1.speed With elementary data types, the compiler
"Pump".Start establishes the correct data type, replication
factor 1 and pointer
Note
With symbolic assignment (ARRAY, STRUCT, STRING, UDT), the data type
identifier 02 (BYTE) and the area length in bytes is merely established by the
compiler and entered in the ANY pointer
SIMATIC S7 Date: 18.09.2009 SITRAIN Training for
Automation and Industrial Solutions
Siemens AG 2008. All rights reserved. File: PRO2_08E.12

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).

SITRAIN Training for ST-PRO2


Automation and Industrial Solutions Page 12 Using System Blocks
Analyzing an Error Message

‰ The scan of the BR-bit (binary result) returns RLO=0 for


processing with fault and RLO=1 for fault-free processing.
€ Scan of BR for STL with A BR
€ Scan in LAD/FBD using the output parameter ENO

‰ Most of the system functions return an error code with the


following configuration in the output parameter RET_VAL (INT):
€ RET_VAL=W#16#8 X Y Z

Error class, error‘s individual number (SFC specific)


or event number (general)
X>0: general error, X= No. of faulty parameter
X=0: SFC specific error occurred
"8" signals: error occurred

€ 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.

SIMATIC S7 Date: 18.09.2009 SITRAIN Training for


Automation and Industrial Solutions
Siemens AG 2008. All rights reserved. File: PRO2_08E.13

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").

SITRAIN Training for ST-PRO2


Automation and Industrial Solutions Page 13 Using System Blocks
Exercise 1: Recording the Time Stamp with SFC 1
DB 18
FB 18

Year/Month
Day
Hours/Minutes
Seconds
ms/weekday

SIMATIC S7 Date: 18.09.2009 SITRAIN Training for


Automation and Industrial Solutions
Siemens AG 2008. All rights reserved. File: PRO2_08E.14

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).

SITRAIN Training for ST-PRO2


Automation and Industrial Solutions Page 14 Using System Blocks
Exercise 2: Data Backup with SFC 20
DB 18

FB 18

SIMATIC S7 Date: 18.09.2009 SITRAIN Training for


Automation and Industrial Solutions
Siemens AG 2008. All rights reserved. File: PRO2_08E.15

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.

SITRAIN Training for ST-PRO2


Automation and Industrial Solutions Page 15 Using System Blocks
If You Want to Know More

SIMATIC S7 Date: 18.09.2009 SITRAIN Training for


Automation and Industrial Solutions
Siemens AG 2008. All rights reserved. File: PRO2_08E.16

Note The following pages contain either further information or are for reference to
complete a topic.

SITRAIN Training for ST-PRO2


Automation and Industrial Solutions Page 16 Using System Blocks
Additional Exercise: Specified Time Relay

SIMATIC S7 Date: 18.09.2009 SITRAIN Training for


Automation and Industrial Solutions
Siemens AG 2008. All rights reserved. File: PRO2_08E.17

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.

What to Do 1. Create an FC 119 according to the task


2. Also call the FC 119 block in OB 1
3. Download the blocks and test the function by changing the time in the CPU.

Note So that in Network 2, a direct comparison of the time can be programmed in


LAD or FBD, either switch off the type check or copy the variable #time into a
variable of the DINT data type.
To switch off the type check use the menu options Options Æ Customize and
deactivate the option "Type Check of Addresses" in the LAD/FBD tab.

SITRAIN Training for ST-PRO2


Automation and Industrial Solutions Page 17 Using System Blocks
The Library: TI-S7 Converting Blocks (Excerpt)
Block Symbol Description

FC 80 TONR Start time as stored ON Delay


FC 81 IBLKMOV Indirectly transfer data area
FC 82 RSET Reset memory bit or peripheral range
FC 83 SET Set memory bit or peripheral range
FC 84 ATT Enter value in table
FC 85 FIFO Output first value in table
FC 86 TBL_FIND Find value in table
FC 87 LIFO Output last value in table
FC 88 TBL Execute table operation
FC 89 TBL_WRD Copy value from table
FC 90 WSR Save date in shift register
FC 91 WRD_TBL Logically gate value with table element and save
FC 92 SHRB Shift bit into shift register
FC 93 SEG Generate bit sequence for 7 segment display
FC 94 ATH Convert ASCII character string into hexadecimal number
FC 95 HTA Convert hexadecimal number into ASCII character string
FC 96 ENCO Set preset bit in the word
FC 97 DECO Read bit number of least significant set bit
FC 98 BCDCPL Generate ten‘s complement
FC 99 BITSUM Count number of set bits
FC 105 SCALE Scale analog value (convert to physical quantity)

SIMATIC S7 Date: 18.09.2009 SITRAIN Training for


Automation and Industrial Solutions
Siemens AG 2008. All rights reserved. File: PRO2_08E.18

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 93 - FC 99 This group provides various conversion functions.

FC 105 Converts the digitalized value of an analog channel into a physical quantity
(such as weight).

SITRAIN Training for ST-PRO2


Automation and Industrial Solutions Page 18 Using System Blocks
The Library: IEC Function Blocks (Excerpt)
Block Symbol Description

FC 3 D_TOD_DT Combine variable Date and TIME_OF_DAY as DT


FC 6 DT_DATE Extract date from variable of type DT
FC 7 DT_DAY Extract day of week from variable of type DT
FC 8 DT_TOD Extract time-of-day from variable of type DT
FC 9 EQ_DT Compare 2 variables of type DT for equal to
FC 12 GE_DT Compare 2 variables of type DT for greater than or equal to
FC 14 GT_DT Compare 2 variables of type DT for greater than
FC 18 LE_DT Compare 2 variables of type DT for smaller than or equal to
FC 23 LT_DT Compare 2 variables of type DT for smaller than
FC 28 NE_DT Compare 2 variables of type DT for unequal

SIMATIC S7 Date: 18.09.2009 SITRAIN Training for


Automation and Industrial Solutions
Siemens AG 2008. All rights reserved. File: PRO2_08E.19

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.

FC 9 - FC 28 The functions compare the contents of two variables in the DATE_AND_TIME


format for same, greater than, smaller than, etc., and output the result as a
return value. The return value is signal state "1", when the comparison of both
times is fulfilled.

SITRAIN Training for ST-PRO2


Automation and Industrial Solutions Page 19 Using System Blocks
The Library: Communication Blocks

Block Symbol Description

FC 1 DP_SEND Send data to PROFIBUS CP


FC 2 DP_RECV Receive data from PROFIBUS CP
FC 3 DP_DIAG Load diagnostic data of a station
FC 4 DP_CTRL Send control tasks to the CP

Exclusively in the configuration:


S7-300 CPU with CP 342-5
CP 342-5

SIMATIC S7 Date: 18.09.2009 SITRAIN Training for


Automation and Industrial Solutions
Siemens AG 2008. All rights reserved. File: PRO2_08E.20

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.

SITRAIN Training for ST-PRO2


Automation and Industrial Solutions Page 20 Using System Blocks
The Library: PID Control Blocks

Block Symbol Description

FB 41 CONT_C continuous PID control block


FB 42 CONT_S PI controller with binary manipulated value
output
FB 43 PULSEGEN Pulse generator for PID controller with pulse
output

SIMATIC S7 Date: 18.09.2009 SITRAIN Training for


Automation and Industrial Solutions
Siemens AG 2008. All rights reserved. File: PRO2_08E.21

FB 41 The SFB "CONT_C" (continuous controller) is used on SIMATIC S7


programmable logic controllers to control technical processes with continuous
input and output variables. During parameter assignment, you can activate or
deactivate sub-functions of the PID controller to adapt the controller to the
process.
You can use the controller as a PID fixed setpoint controller or in multi-loop
controls as a cascade, blending or ratio controller. The functions of the controller
are based on the PID control algorithm of the sampling controller with an analog
output signal, if necessary extended by including a pulse generator stage to
generate pulse duration modulated output signals for two or three step
controllers with proportional actuators.

FB42 The SFB "CONT_S" (step controller) is used on SIMATIC S7 programmable


logic controllers to control technical processes with binary manipulated value
output signals for integrating actuators. During parameter assignment, you can
activate or deactivate sub-functions of the PI step controller to adapt the
controller to the process.
You can use the controller as a PI fixed setpoint controller or in secondary
control loops in cascade, blending or ratio controllers, however not as the
primary controller. The functions of the controller are based on the PI control
algorithm of the sampling controller supplemented by the functions for
generating the binary output signal from the analog actuating signal.

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".

SITRAIN Training for ST-PRO2


Automation and Industrial Solutions Page 21 Using System Blocks
The Library: Miscellaneous Blocks (Auszug)

Block Symbol Description

FB 60 SET_SW Standard/Daylight-savings time adjustment


FB 62 TIMESTMP Messages with time-stamp from IM 153-2
FC 60 LOC_TIME Determine local time

SIMATIC S7 Date: 18.09.2009 SITRAIN Training for


Automation and Industrial Solutions
Siemens AG 2008. All rights reserved. File: PRO2_08E.22

FB 60 The FB supports Standard/Daylight-saving Time adjustment for CPUs that do


not have the time status. The block adjusts the CPU clock to the currently
applicable time according to the adjustment rules in the Rule DB.

FB 62 The FB TIMESTMP transmits time-stamped messages of an IM153-2 to its


instance DB. There, data are available for further processing in the user
program.

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).

SITRAIN Training for ST-PRO2


Automation and Industrial Solutions Page 22 Using System Blocks

Das könnte Ihnen auch gefallen