Programming-Guideline-Safety DOC V10 en
Programming-Guideline-Safety DOC V10 en
Programming-Guideline-Safety DOC V10 en
Note The Application Examples are not binding and do not claim to be complete regarding the
circuits shown, equipping and any eventuality. The Application Examples do not represent
customer-specific solutions. They are only intended to provide support for typical
applications. You are responsible for ensuring that the described products are used
correctly. These Application Examples do not relieve you of the responsibility to use safe
practices in application, installation, operation and maintenance. When using these
Application Examples, you recognize that we cannot be made liable for any
damage/claims beyond the liability clause described. We reserve the right to make
changes to these Application Examples at any time without prior notice.
If there are any deviations between the recommendations provided in these Application
Examples and other Siemens publications e.g. Catalogs the contents of the other
documents have priority.
We do not accept any liability for the information contained in this document.
Any claims against us based on whatever legal reason resulting from the use of
the examples, information, programs, engineering and performance data etc.,
described in this Application Example shall be excluded. Such an exclusion shall
not apply in the case of mandatory liability, e.g. under the German Product Liability
Act (Produkthaftungsgesetz), in case of intent, gross negligence, or injury of life,
body or health, guarantee for the quality of a product, fraudulent concealment of a
deficiency or breach of a condition which goes to the root of the contract
(wesentliche Vertragspflichten). The damages for a breach of a substantial
contractual obligation are, however, limited to the foreseeable damage, typical for
Siemens AG 2017 All rights reserved
the type of contract, except in the event of intent or gross negligence or injury to
life, body or health. The above provisions do not imply a change of the burden of
proof to your detriment.
Any form of duplication or distribution of these Application Examples or excerpts
hereof is prohibited without the expressed consent of the Siemens AG.
Security Siemens provides products and solutions with industrial security functions that support the
informa- secure operation of plants, systems, machines and networks.
tion In order to protect plants, systems, machines and networks against cyber threats, it is
necessary to implement and continuously maintain a holistic, state-of-the-art industrial
security concept. Siemens products and solutions only form one element of such a
concept.
Customer is responsible to prevent unauthorized access to its plants, systems, machines
and networks. Systems, machines and components should only be connected to the
enterprise network or the internet if and to the extent necessary and with appropriate
security measures (e.g. use of firewalls and network segmentation) in place.
Additionally, Siemens guidance on appropriate security measures should be taken into
account. For more information about industrial security, please visit
http://www.siemens.com/industrialsecurity.
Siemens products and solutions undergo continuous development to make them more
secure. Siemens strongly recommends to apply product updates as soon as available and
to always use the latest product versions. Use of product versions that are no longer
supported, and failure to apply latest updates may increase customers exposure to cyber
threats.
To stay informed about product updates, subscribe to the Siemens Industrial Security
RSS Feed under http://www.siemens.com/industrialsecurity.
Table of Contents
Warranty and Liability ................................................................................................. 2
1 Introduction ........................................................................................................ 4
2 Configuring Fail-Safe Controllers .................................................................... 6
2.1 Selecting the suitable F-CPU ............................................................... 6
2.2 PROFIsafe address types .................................................................... 8
2.3 Protecting the F-CPU against unauthorized access ............................ 9
2.4 F-change history................................................................................. 11
2.5 Consistently uploading F-CPUs ......................................................... 12
2.6 Know-how protection .......................................................................... 13
3 Methods for Safety Programming .................................................................. 14
3.1 Program structures ............................................................................. 14
3.1.1 Defining a program structure .............................................................. 14
3.1.2 Call levels of F-FBs/F-FCs ................................................................. 16
3.1.3 Call sequence of the blocks in the Main Safety ................................. 16
3.1.4 F-suitable PLC data type .................................................................... 18
3.2 Block information and comments ....................................................... 20
3.3 Functional identifiers of variables ....................................................... 21
3.4 True & False ....................................................................................... 22
3.5 Standardizing blocks .......................................................................... 23
3.5.1 Standardizing sensor evaluation ........................................................ 23
Siemens AG 2017 All rights reserved
1 Introduction
The new controller generation SIMATIC S7-1200 and S7-1500 has an up-to-date
system architecture and, together with TIA Portal, offers new and efficient
programming and configuration options.
If the programming is sloppy, the many options provided by STEP 7 can also
produce negative results:
CPU stops
Long compilation processes
Additional, comprehensive acceptance testing
This document provides you with many recommendations and notes for the optimal
configuration and programming of S7-1200/1500 controllers. This helps you create
standardized and optimal programming of your automation solutions.
The examples described in this document can be universally used on the S7-1200
and S7-1500 controllers.
Advantages
Following the recommendations given in this document provides you with many
Siemens AG 2017 All rights reserved
advantages:
Reusability of program parts
Easier acceptance (code review, error detection and correction)
More flexibility in terms of program changes
Reduction of programming errors
Increased plant availability by avoiding CPU stops
Easier readability for third parties
Reduced runtime of the safety program
Note Not all the recommendations provided in this document can be applied at the
same time. In these cases, it is up to you as the user to decide on the
prioritization of the recommendations (e.g., standardization or runtime
optimization of the safety program).
This document is a supplement to the documents above and deals with special
aspects of programming safety programs with STEP 7.
Siemens AG 2017 All rights reserved
Figure 2-1: Reaction time wizard of the SIMATIC STEP 7 Reaction Time Table
Siemens AG 2017 All rights reserved
Influence of the safety program's cycle time on the standard user program
A long cycle time of the safety program slows down the response time of your
safety functions, but allows more time for processing the standard user program.
A short cycle time of the safety program increases the response time of your safety
functions, but allows less time for processing the standard user program.
The following figure shows the influence of the safety program's cycle time on the
time that is available for processing the standard user program.
Figure 2-2: Influence of the safety program's cycle time on the standard user program
Siemens AG 2017 All rights reserved
Note Please note that higher-priority organization blocks (e.g., cyclic interrupt OBs or
motion control OBs) can interrupt the safety program in the same way as shown
in Figure 2-2.
To make sure that the safety program cannot be interrupted, you can customize
the priorities in the properties of the appropriate OBs.
NOTICE The cycle time must be longer than the execution duration of the safety program.
Recommendation
Already at the outset of the project, look at possible communication
relationships and network topologies. Consult with the parties involved to
derive measures for assigning PROFIsafe addresses.
Assign separate address ranges to PROFIsafe address types 1 and 2:
1)
Assign a low number range to F-I/O of PROFIsafe address type 1 .
Assign a high number range to F-I/O of PROFIsafe address type 2.
Always define unique F-source addresses for all F-CPUs. This makes both
working across projects and later extensions easier.
Additional information
For more information about PPROFIsafe address types, visit Siemens Industry
Online Support:
What is the difference between the PROFIsafe address types 1 and 2 in relation to
the uniqueness of the PROFIsafe address?
https://support.industry.siemens.com/cs/ww/en/view/109479905
How do you assign PROFIsafe addresses so that they are unique network-wide
Siemens AG 2017 All rights reserved
and CPU-wide?
https://support.industry.siemens.com/cs/ww/en/view/109740240
Once you have logged in with the password for the safety program, you can
remove the access rights to the safety program as follows:
Log out of Safety Administration
In the menu bar, "Online > Delete access rights"
Close TIA Portal
Siemens AG 2017 All rights reserved
Note Collaboration of programmers with and without rights for the user program
Changes to standard DBs that are read/write accessed by the safety program
require a recompilation of the safety program. These standard DBs are not
subject to the access permission for the safety program. Therefore, data
exchange between the F-program and the standard program requires a defined
interface that the programmer of the standard user program does not have to
change during his work.
For more information about this data exchange, please refer to Chapter 3.9.
Access protection applies only to the appropriate F-CPU. This password is also
used for identification of the F-CPU and must therefore be unique throughout the
network.
Recommendation
Activate change history when you start configuring or at the latest when you have
defined the final project-specific CPU name as the change history is linked to the
CPU name.
Advantages
Ensures that the last change was loaded by comparing the online and offline
status of the CRC.
Which user changed or downloaded the safety program can be tracked in
multi-user projects.
Matching of online and offline status without an online connection between
CPU and PG/PC.
NOTICE F-change history must not be used to detect changes in the safety program or
when accepting changes in the F-I/O configuration.
Recommendation
Siemens AG 2017 All rights reserved
An upload from the automation system is only possible if the project has been
released for it.
When you start configuring, check the "Consistent upload" check box in Safety
Administration in TIA Portal.
Advantages
As there is no complex "offline" project management, you can avoid errors and
further reduce the service effort.
Recommendation
During the project phase, determine to what extent it makes sense to protect the
blocks of a safety program against third-party access.
Advantages
Protects your know-how across contents of program parts.
Accepted blocks cannot be modified.
Additional information
Siemens AG 2017 All rights reserved
Recommendation
Modularly divide the program code, e.g.,
into subparts for detecting, evaluating, reacting or
plant sections.
In the preliminary stages, create a specification for each module (based on the
risk assessment requirements).
Avoid complex signal paths.
Advantages
Minimizes complexity.
Reduces programming errors.
Allows the program code to be analyzed/tested without running the program
(e.g., code review or PLCSIM).
Siemens AG 2017 All rights reserved
Example
The following figure shows a safety application that is divided into three machine
areas (safety zones).
As some of the sensor signals are interconnected across areas (e.g., emergency
stop functions that act globally), they are grouped into a "Sensors" FB (they could
also be split up into physical or logical areas). The respective sensors are
evaluated using standardized function blocks (e.g., "GuardDoor").
The Mobile Panels' blocks are also called here.
Separate logic and actuator FBs are created for each machine area. The actuators
are controlled using standardized function blocks (e.g., "ContactorControl").
Note The structure shown here is an example. Depending on the size and complexity
of the safety program, you can also choose a different structure. In smaller
applications, it would, for example, also be possible to implement the logic and
actuator control in a shared function block.
For standard user programs, the number of call levels is limited depending on the
CPU. For safety programs, you can use a maximum of eight call levels. A warning
appears when this limit is exceeded and an error message is displayed for pure FC
and multi-instance call chains.
System instructions ("ESTOP1", "SF_DOOR", etc.) are not included in the number
of call levels.
Note On the system side, functions are mapped as FBs with a multi-instance call in
the protection program; this is the reason why an error message is also
displayed for FC call chains with more than eight call levels.
The program structure in Figure 3-1 shows one way of keeping the call levels
relatively flat so that the safety program remains within the limit specified here.
Recommendation
Within the Main Safety, call blocks in the following sequence:
Siemens AG 2017 All rights reserved
Advantages
The CPU always uses the latest values
Facilitates orientation in the Main Safety
For safety programs, too, it is possible to optimally structure data using PLC data
types.
F-suitable PLC data types have the following features:
F-suitable PLC data types are declared and used in the same way as PLC data
types.
All data types that are allowed in the safety program can be used in F-suitable
PLC data types.
Nesting F-suitable PLC data types within other F-suitable PLC data types is not
supported.
F-suitable PLC data types can be used both in the safety program and in the
standard user program.
Recommendation
Create F-suitable PLC data types to structure data also in the safety program.
Use F-suitable PLC data types to transfer large numbers of variables to blocks.
Use F-suitable PLC data types for access to I/O ranges.
In this context, follow the below rules:
Siemens AG 2017 All rights reserved
The structure of the tags of the F-suitable PLC data type must match the
channel structure of the F-I/O.
Example of an F-suitable PLC data type for an F-I/O with 8 channels:
8 BOOL variables (channel value) or
16 BOOL variables (channel value + value status)
Access to F-I/O is only allowed for activated channels. When configuring a
1oo2 evaluation, the higher-level channel is always deactivated.
Advantages
A change in a PLC data type is automatically updated in all points of use in the
user program.
Example
Figure 3-3: Access to I/O ranges with F-suitable PLC data types
F-suitable PLC data type F-I/O
PLC tag
Siemens AG 2017 All rights reserved
Recommendation
In the block comment of your block, enter formal information about the block with
the aid of the following template.
If you implement diagnostic functions relevant to the PL / SILCL of another
subsystem (Detect or Evaluate) in an F-FB, include normative parameters such as
PL / SILCL and category (according to ISO 13849-1), DC measures, CCF
measures, etc. in the block comment.
After successful acceptance of the block, also include the signature in the block
comment. This makes it easier to track functional changes of the block.
//============================================================================
Siemens AG 2017 All rights reserved
// Company
//----------------------------------------------------------------------------
// Library: (that the source is dedicated to)
// Tested with: (test system with FW version)
// Engineering: TIA Portal (SW version)
// Restrictions: (OB types, etc.)
// Requirements: (hardware, technological package, memory needed, etc.)
// Functionality: (that is implemented in the block)
//----------------------------------------------------------------------------
// Reference to Safety Requirement Specification:
// Safety related information: (SIL/PL (Cat.), DC, methods against CFF for connected
subsystems)
//----------------------------------------------------------------------------
// Change log table:
// Version Date Signature Expert in charge Changes applied
// 01.00.00 (dd.mm.yyyy) (Block CRC) (Name of expert) First released version
//============================================================================
Recommendation
Before the start of the project, define a uniform name of the variables with the
appropriate suffixes. The identifier reflects the meaning and purpose of the
variables in the source code context.
Choose the variable identifier such that it reflects the logic "1" state ("true").
For example, "maintDoorEnable" or "conveyorSafetyRelease".
Siemens AG 2017 All rights reserved
Note The standardized names of the drive functions (e.g., STO and SLS) according to
IEC 61800-5-2 do not comply with the above recommendation.
Assignments on operations
To generate "TRUE" / "FALSE" signals for operations, proceed as follows:
8. Create two static tags, "statTrue" and "statFalse", of the BOOL data type.
9. Assign the default "true" to the "statTrue" tag.
10. Assign the default "false" to the "statFalse" tag.
In the complete function block, you can use the tags as reading "TRUE" and
"FALSE" signals.
Recommendation
Create modular blocks you can reuse:
Blocks for typical fail-safe sensors
Blocks for typical fail-safe actuators
Blocks for frequently used functions (e.g., reintegration, operating mode)
Advantages
Reused blocks have to be accepted only once
Siemens AG 2017 All rights reserved
Note The following block programming shows examples. The actual function depends
on the application's risk assessment or the project requirements.
Recommendation
Create a separate function block for each sensor type (e.g., emergency stop
command device, safety door, light curtain, etc.) that combines the evaluation of
the sensor and the necessary auxiliary functions. Use this sensor block for other
sensors of the same type.
Create F-data types for complex sensors.
Recommendation
Create a separate function block for each actuator type (e.g., contactors, valves,
drives, etc.) that combines actuator control and the necessary auxiliary functions.
Use this actuator block for other actuators of the same type.
Create F-data types for complex actuators.
Recommendation
Use mainly AND and OR logic elements
Reduce the use of SR blocks to a minimum
Avoid jumps in binary logic
Example
Three safety functions are implemented on a machine: The "estop" emergency
stop function is active in each mode. The "guardDoor" safety door monitoring and
the "enablingSwitch" enabling function are only active in one mode.
Advantages
Modular block concept
Reuse of program parts in other projects without modifications
Reduces programming errors
Makes the overall program easier readable as the general function of a block
can already be estimated from the interfaces.
Recommendation
Use global standard data blocks to exchange data between the standard user
program and the safety program.
To ensure a good overview of which program part reads and which one writes, it is
recommended to create two data blocks for the two directions.
You should not store any other information (e.g., diagnostic data from the standard
user program) in the data blocks as each modification of the data block involves a
modification of the safety program.
Siemens AG 2017 All rights reserved
Figure 3-10: Data exchange between standard user program and safety program
Advantages
Lean F-runtime group
Better overview of the exchanged data
Changes of the diagnostic and signaling concept in the standard user
program do not affect the safety program's signature
Minimized risk of downtimes caused by data corruption due to write access
to the safety program
Simplified typing of F-blocks
Changes to the standard user program can be loaded without stopping the
CPU
Standard user program and safety program can be created independently
of each other, provided that interfaces have already been defined
3.9.1 Reading diagnostic and message information from the safety program
A frequent application for data exchange between the standard user program and
the safety program is the visualization of diagnostic and message information such
as:
Acknowledgment requests of errors
Reset requests of safety functions
Siemens AG 2017 All rights reserved
Error messages
States of safety functions
Transfer the "raw data" from the safety program. The logic operation then takes
place in the standard user program. This has the advantage that the safety
program is kept lean and is independent of changes in the standard user program.
Smaller changes at a later stage (e.g., changes to the control of an indicator light)
are made in the standard user program. This does not change accepted F-blocks.
If you transfer a large amount of diagnostic data from the safety program, create an
F-data type for this purpose. A tag with a self-defined data type keeps the block
interface compact and clear. For data always to be transferred in a similar way, it is
recommended to standardize these F-data types across all F-function blocks.
Figure 3-11: Reading diagnostic and message information from the safety program
Standard inputs that are required directly in the safety program must be read
directly in the safety program. A "detour" via the standard user program should be
avoided.
The background to this is that non-safety-related signals are also included in the
application's systematic integrity. Typical examples are acknowledgment / reset
buttons or mode selectors. Which button / switch is allowed to reset which safety
function is a direct result of the risk assessment. A change of the command
devices must therefore influence the signature and must be made only
accompanied by a reassessment and an acceptance test for changes.
Siemens AG 2017 All rights reserved
NOTICE The assessment of the specific signals that influence an application's systematic
integrity and, depending on this, are evaluated in the standard user program or in
the safety program depends on the risk assessment of an application.
Recommendation
Use another data block for communication with the HMI and copy the safety-
related data in the standard user program to the data buffer.
Siemens AG 2017 All rights reserved
Create a data type for the data from the HMI to the safety program. Use this data
type in the HMI tags, in the data buffer for the safety program and in the standard
user program where the data is copied.
To add more tags to be written from the HMI to the safety program, merely modify
this data type.
Figure 3-13: Copying data from the HMI to the safety program in the standard user program
For resetting safety functions or acknowledging errors using an HMI, TIA Portal
provides the "ACK_OP" system block.
An acknowledgment consists of two steps:
1. Change in/out IN to value "6" for exactly one cycle.
2. Change in/out IN to value at input "ACK_ID" for exactly one cycle within one
minute.
Recommendation
Lock process control in the standard user program with the release signal from
the safety program. As a result, safe shutdown also resets process control.
Transfer the release signal from the safety program using a global data block
(see also Chapter 3.9).
ProcessControl Safety
start release
Siemens AG 2017 All rights reserved
stop
DataFromSafety
General
Whether a channel is passivated can be evaluated as follows:
The channel's value status is "false"
The "QBAD" tag of the module's F-I/O data block is "true"
LEDs of channel and module light up red
Entry in diagnostic buffer
Some of the instructions that can be used in the safety program influence a fail-
safe controller's performance to a greater extent than others.
This chapter shows different options for reducing the compilation and program
runtime.
Note Depending on the application, it is not always possible to use all the suggestions.
However, they show why certain programming methods cause shorter
compilation and program runtimes than a non-optimized program.
In a standard user program, a jump from one network to another (jump to label) or
from the block (return) is a simple program branch that is recalculated for each
cycle but not additionally protected. This means there is no check whether or not,
for example due to a memory error caused by EMC, a jump takes place despite the
"false" condition.
This is not allowed in a fail-safe program as it must be ensured at all times that the
program is in the correct branch.
This requires that both alternatives (jump to label is "true" or "false") be calculated
in their entirety in the protection program.
The more jumps you use in a safety program, the greater the influence on the
controller's performance.
Recommendation
Where possible, avoid jumps in the safety program.
Use state machines instead of jumps in FBs with binary logic.
Timers are an integral part of a safety program as many of the system functions
such as "ESTOP1" internally use these timers. Despite this fact, generating a fail-
safe time value requires considerable effort and regeneration for each single timer
block.
Recommendation
Reduce the number of timer blocks to a minimum.
4.1.3 Multi-instances
Recommendation
Use multi-instances for fail-safe function blocks. This means that the block-internal
tags are integrated into the block interface of the calling block.
Advantages
Standardization of safety programs:
No global data is used for block tags. This allows reuse of the calling block
Siemens AG 2017 All rights reserved
Example
Two drives are safely controlled with the same "LDrvSafe_CtrlT30SinaS" function
block. The data is stored in multi-instances with unique names.
The "LDrvSafe" library for controlling the safety functions of SINAMICS drives is
available in Industry Online Support:
https://support.industry.siemens.com/cs/ww/en/view/109485794
For information about how to correctly program access from the standard user
program to the safety program, see Chapter 3.9.
Siemens AG 2017 All rights reserved
Checklist
The following checklist allows you to identify and correct user-generated STOP
causes.
Additional information
For more information and causes of data corruption, visit Siemens Industry Online
Support:
https://support.industry.siemens.com/cs/ww/en/view/19183712
5 Glossary
Coded processing
To meet the normative requirements in terms of redundancy and diversity, all
SIMATIC F-CPUs use the "coded processing" principle. In coded processing, the
safety program is processed twice by a single processor.
To this end, the compiler generates a diverse (encoded) safety program that is
referred to as the protection program.
The first program run processes the unmodified safety program of the user. After
that, the protection program is processed. Then the F-CPU compares the results. If
processed correctly, the safe outputs are written. If there are differences between
the two program parts (e.g., due to data corruption), the F-CPU goes to stop and
generates an entry in the diagnostic buffer.
Sicherheitsprogramm bearbeiten
F-Ablaufgruppe
Zeit Absicherungsprogramm bearbeiten
Siemens AG 2017 All rights reserved
Ergebnisse vergleichen
Data corruption
Data corruption means that data of the safety program has been tampered with by
external influences (e.g., EMC influences) or illegal write access.
F-CPU
An F-CPU is a controller suitable for safety-related tasks.
PROFIsafe
PROFIsafe is a protocol for fail-safe communication via PROFINET.
Cross-circuit
Cross-circuit detection is a diagnostic function of an evaluation unit that detects
short-circuits or cross-circuits between two input channels (sensor circuits).
A cross-circuit can be caused, for example, by a squashed light plastic-sheathed
cable. Without cross-circuit detection, this would result in, for example, a two-
channel emergency stop circuit not tripping even though only one normally closed
contact is faulty (secondary error).
RIOforFA
RIOforFA (Remote IO for Factory Automation) is a standard from the PROFIBUS &
PROFINET International organization. Among other features, it describes the
following functions:
Synchronous provision of channel-specific diagnostics of remote IOs for high
performance
Channel-specific passivation and reintegration of PROFIsafe remote IOs
Feedback circuit
A feedback circuit is used for monitoring controlled actuators (e.g., relays or load
contactors) with positive-action contacts or mirror contacts. The outputs can only
be activated when the feedback circuit is closed. When using a redundant
shutdown path, the feedback circuit of both actuators must be evaluated. For this
purpose, they may also be connected in series.
phrase.
Safety program
Part of the safety program that processes safety-related tasks.
6 Appendix
6.1 Service and Support
Industry Online Support
Do you have any questions or do you need support?
With Industry Online Support, our complete service and support know-how and
services are available to you 24/7.
Industry Online Support is the place to go to for information about our products,
solutions and services.
Product Information, Manuals, Downloads, FAQs and Application Examples all
the information can be accessed with just a few clicks:
https://support.industry.siemens.com
Technical Support
Siemens Industrys Technical Support offers you fast and competent support for
any technical queries you may have, including numerous tailor-made offerings
ranging from basic support to custom support contracts.
You can use the web form below to send queries to Technical Support:
www.siemens.com/industry/supportrequest.
Service offer
Siemens AG 2017 All rights reserved