Programming Recommendation For PLC S7 300 en
Programming Recommendation For PLC S7 300 en
recommendation for
PLC S7-300
SINUMERIK
Siemens
SINUMERIK 840D sl, from SW 4.5 Industry
Online
https://support.industry.siemens.com/cs/ww/en/view/109478721 Support
Warranty and liability
Note The application examples are not binding and do not claim to be complete
regarding the circuits shown, equipment and any other 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,
Siemens AG 2017 All rights reserved
Security Siemens provides products and solutions with industrial security functions that
informati support the secure operation of plants, solutions, machines, equipment, and/or
on networks. They are important components in a holistic industrial security
concept. With this in mind, Siemens' products and solutions undergo continuous
development. Siemens recommends strongly that you regularly check for
product updates.
For the secure operation of Siemens products and solutions, it is necessary to
take suitable preventive action (e.g. cell protection concept) and integrate each
component into a holistic, state-of-the-art industrial security concept. Third-party
products that may be in use should also be considered. For more information
about industrial security, visit http://www.siemens.com/industrialsecurity.
To stay informed about product updates as they occur, sign up for a product-
specific newsletter. For more information, visit
http://support.automation.siemens.com.
Table of contents
Warranty and liability ................................................................................................... 2
1 Task ..................................................................................................................... 5
1.1 Overview............................................................................................... 5
1.2 Requirements/scenarios....................................................................... 5
1.2.1 Symbolic programming......................................................................... 5
1.2.2 Optimized block access (S7-1500) ...................................................... 6
1.2.3 STEP 7 (TIA Portal) Compiler and IEC check...................................... 6
2 Preconditions ..................................................................................................... 7
2.1 Software ............................................................................................... 7
2.2 Hardware .............................................................................................. 7
2.3 Knowledge ............................................................................................ 9
3 Preparations in STEP 7 V5.x project .............................................................. 10
Preparatory programming .................................................................. 10
3.1 Symbols .............................................................................................. 10
3.1.1 Absolute and symbolic programming ................................................. 10
3.1.2 Advantages of symbolic addressing ................................................... 10
3.1.3 Integrated definition and use of symbols ............................................ 11
3.1.4 Address priority .................................................................................. 11
3.2 Blocks ................................................................................................. 14
3.2.1 Naming of blocks ................................................................................ 14
Siemens AG 2017 All rights reserved
1 Task
1.1 Overview
Introduction
The goal of this application is to provide the STEP 7 V5.x project with a
SINUMERIK with an integrated S7-300 PLC for the migration to STEP 7 (TIA
Portal) and to a successor generation of SINUMERIK.
1.2 Requirements/scenarios
This programming recommendation is intended to support the optimization of the
STEP 7 V5.x programs for the STEP 7 (TIA Portal) with 840D sl and for a later
migration of your projects to NCUs with integrated S7-1500 PLC. If you heed and
implement our recommendations in STEP 7 V5.x, the switchover migration to
STEP 7 (TIA Portal) will be easy.
In addition to the new interface and operator control, STEP 7 (TIA Portal) also
entails additional changes that must be taken into consideration. These changes
are addressed in detail in the following.
Siemens AG 2017 All rights reserved
Note In this document, you will find examples of how you can prepare your STEP 7
V5.x SINUMERIK project in regard to optimized block access and while adhering
to IEC rules.
You can later migrate a project that is prepared in this way to STEP 7 (TIA
Portal) with an NCU with PLC S7-300. In STEP 7 (TIA Portal), the existing
software for a newly created NCU with PLC S7-1500 can be migrated.
STEP 7 (TIA Portal) is optimized for symbolic programming. This results in many
benefits that you can also use in STEP 7 V5.x and which make the later switchover
to NCUs with integrated S7-1500 PLC easier. You can program NCUs with
integrated S7-1500 PLC using symbolic addressing without considering the internal
data storage. The controller is concerned with where the data can be saved in a
memory-optimized way.
In the TIA Portal, the Compiler works to compile the project according to IEC rules.
Data incompatibilities and errors that can lead to runtime errors are detected as
early as the syntax check by checking the project using Compiler and by applying
the IEC rules.
2 Preconditions
2.1 Software
To be able to carry out a migration of the STEP 7 V5.x SINUMERIK project, the
licensed software listed in the following must be installed, at a minimum:
If STEP 7 V5.x and STEP 7 (TIA Portal) are installed on different computers, you
must first convert the project to be migrated to a format that is compatible with the
migration. You need the "Migration Tool TIA Portal" for the conversion. You can
find the migration tool on the product DVD in the
Siemens AG 2017 All rights reserved
2.2 Hardware
The following relevant Siemens product families are supported as of the cited
hardware versions or publication dates:
SINUMERIK 840D sl NCU Type 1B V4.5 SP2
SIMATIC modules, reference date Oct. 1, 2007
To check whether the modules of your project are supported, use the free
Readiness Check Tool prior to the migration
(https://support.industry.siemens.com/cs/de/en/view/60162195).
In Table 2-2: Checking the project with the Readiness Check Tool it is described
how to export the hardware list from your STEP 7 V5.x project and export it in the
Readiness Check Tool.
Table 2-2: Checking the project with the Readiness Check Tool
2.3 Knowledge
You should also possess the following knowledge when implementing a
SINUMERIK project in regard to the migration to STEP 7 (TIA Portal):
Siemens AG 2017 All rights reserved
SIMATIC S7 programming
SIMATIC S7 programming in TIA Portal
SINUMERIK 840D sl start-up
Documentation "Getting Started SINUMERIK 840D sl SINUMERIK TIA Portal
Toolbox V1x"
Migrating STEP 7 programs (see Chapter 7 References)
3.1 Symbols
3.1.1 Absolute and symbolic programming
Absolute addressing
With absolute programming, the address (e.g. of the input E1.0) is specified
Siemens AG 2017 All rights reserved
directly. In this case, no symbol table is required. But the program is difficult to
read. Extensive projects thus lose a clear overview.
The use of meaningful symbols allows you to clearly and legibly display the
program code in your project.
This results in further advantages:
No long, all-encompassing comments are necessary
High-performance, error-free data access (STEP 7 (TIA Portal))
Optimized blocks are only addressed symbolically (S7-1500)
The use of absolute addresses can be dispensed with
Assignment monitoring by STEP 7
To improve the legibility, assign meaningful names to your addresses, which you
either:
define as variables in databases, or
assign the memory addresses of the inputs and outputs, flags, timers and
counters in the symbol table
After entering in the LAD/FBD/STL/SCL editor, the associated symbol is
automatically displayed.
With the "address priority" in the properties of the block folder, you can set whether
the symbol or the absolute value is to be authoritative after the change in the
symbol table when the block is opened.
Note You can continue to absolutely address all of the declarations in function blocks
with known addresses according to the SIMATIC rules. This data is displayed by
the system and is also saved in SIMATIC format in the memory of the CPU,
although this lead to reduced performance in newer S7-300 CPU modules,
because your processors cannot optimally access this SIMATIC data storage.
Siemens AG 2017 All rights reserved
3.2 Blocks
3.2.1 Naming of blocks
In TIA Portal, each block has a number and a name. It is therefore not necessary to
declare a symbolic name in STEP 7 (TIA Portal). If the migrated program contains
symbol declarations for blocks or UDTs, these will be used as names after the
migration. Therefore, it makes sense to give all of the blocks in STEP 7 V5.x
meaningful symbolic names.
The following rules must be observed when using block parameters within a block:
Input parameters must only be read.
Output parameters must only be written.
In/out parameters may be read and written.
In a STEP 7 (TIA Portal) project, all of the blocks containing data that is used must
be available. In STEP 7 V5.x, it was sufficient to only declare the blocks in the
symbol table if they were available online in the PLC Runtime.
You can move the necessary blocks, such as the axis and channel blocks, from the
SINUMERIK TIA Portal Toolbox library into the project after the migration in STEP
7 (TIA Portal). You import the names of the blocks with the default names, as
specified by SIEMENS. You can find more on the default names in Chapter
"Tabular block list" in the commissioning manual CNC: NC, PLC, drive for TIA (IDsl
TIA).
If you would like to assign your own names, you can change the names either in
STEP 7 (TIA Portal) or create them directly in STEP 7 V5.x. Create a DB for the
SINUMERIK blocks of the type UDT with the matching UDT (e.g. UDT31). To do
this, define the name you want as the symbol.
3.3 Programming
3.3.1 Fully qualified addressing
Absolute addressing of the L stack is to be avoided. The reason for this is the
Siemens AG 2017 All rights reserved
A frequently used example is the use of the local data stack when swapping bits in
a byte, as shown in the following code in Table 3-3: Swapping bits with local data
stack. An alternative with SCL is shown in Table 3-4: Swapping bits without local
data stack.
VAR_OUTPUT
Output_byte_1 : Byte;
END_VAR
VAR_TEMP
Buffer_Input_byte : Byte;
Buffer_Output_byte : Byte;
END_VAR
BEGIN
Siemens AG 2017 All rights reserved
NETWORK
TITLE = Swapping the bits 0 to 7 in a byte
L #Input_byte_1;
T #Buffer_Input;
U %L0.7;
= %L1.0;
U %L0.6;
= %L1.1;
U %L0.5;
= %L1.2;
U %L0.4;
= %L1.3;
U %L0.3;
= %L1.4;
U %L0.2;
= %L1.5;
U %L0.1;
= %L1.6;
U %L0.0;
= %L1.7;
L #Buffer_Output;
T #Output_byte_1;
NETWORK
TITLE = block end
BE;
END_FUNCTION
VAR_OUTPUT
Output_byte_1 : Byte;
END_VAR
BEGIN
#Output_byte_1 := SHL(IN := #Input_byte_1, N := 7)
OR SHR(IN := #Input_byte_1 , N := 7 )
OR (ROR(IN := #Input_byte1, N := 3) AND 2#01000100)
OR (ROL(IN := #Input_byte1, N := 3) AND 2#00100010)
OR (SHL(IN := #Input_byte1, N := 1) AND 2#00010000)
OR (SHR(IN := #Input_byte1, N := 1) AND 2#00001000);
END_FUNCTION
Siemens AG 2017 All rights reserved
If you link several addresses in an instruction, you must observe the compatibility
of your data types. This also applies to assignments or when supplying block
parameters. In STEP 7 V5.x, it is possible to convert incompatible data types and
to load them into the controller without a check. STEP 7 (TIA Portal) uses a stricter
IEC check (Table 3-5: Type check differences). Conversions take place there
according to the following rules:
Implicit conversion
Implicit conversion is supported by the programming languages LAD, FBD,
SCL, and GRAPH. Implicit conversion is not possible in the programming
language STL:
The bit length of the source data type must not exceed the bit length of the
destination data type.
Explicit conversion
You use an explicit conversion instruction before the actual instruction is
carried out:
A possible overflow is displayed in the enable output ENO.
Note
Converting of bit sequences in SCL
In expressions, all bit sequences (BYTE, WORD, DWORD and LWORD) are
treated like the corresponding integers without signs (USINT, UINT, UDINT and
Siemens AG 2017 All rights reserved
Configurations in which blocks on the NC are deleted in OB100 at the start of the
program should be avoided at all costs (Fig. 3-1: Should be avoided: delete data
block in OB100). This leads to all of the missing blocks in the NC being reloaded.
In STEP 7 (TIA Portal), the blocks would then be differentiated and designated as
offline/online and the project would thus no longer be consistent.
Also to be avoided are configurations in which user areas in created FBs are
deleted in OB100 after FB2 is called (Fig. 3-2: Should be avoided: delete user area
after calling FB2).
Fig. 3-2: Should be avoided: delete user area after calling FB2
If possible, try to avoid an evaluation of ENO when programming your S7-300. With
S7-1500 it is possible to disable the generation of ENO (Table 3-6: Effect of ENO
states). This saves testing during runtime.
In many cases, a "Struct" with several "Bools" is created, mostly with a size of one
byte or word (8 or 16 bits). The background of a "Struct" is mostly the capability of
assigning each bit its own name. Often, however, byte addressing is also applied to
a "Struct of Bool" (8 bits) for this "Struct" (or the other way around: bit addressing
for a byte). STEP 7 (TIA Portal) will display warnings in this case: "The address is
not occupied by a variable.". With the aid of the "BLKMOV" instruction, you can
copy specific data areas without a warning being displayed.
END_DATA_BLOCK
Siemens AG 2017 All rights reserved
END_DATA_BLOCK
Siemens AG 2017 All rights reserved
Note You can find more information on the BLKMOV function in the respective online
help of STEP 7 V5.x and STEP 7 (TIA Portal).
3.4 Configuration
3.4.1 General information
An orderly and structured configuration of the STEP 7 V5.x project is essential for a
migration to STEP 7 (TIA Portal). Keep your project as current as possible. Blocks
from STEP 5 are to be avoided.
In STEP 7 V5.x, you must check your project for consistency, this is done by
means of the consistency check. The consistency check is a prerequisite to be able
to migrate this project to STEP 7 (TIA Portal). An inconsistent project cannot be
migrated.
Table 3-9: Executing the consistency check in STEP 7 V5.x
3.4.3 Hardware
Ensure that you use hardware with firmware V4.5 SP2 for the configuration. Also,
you must ensure that you do not use any I/O modules which have been
discontinued as of October 1, 2007, because such hardware is not supported by
STEP 7 (TIA Portal).
3.5 Structure
Try to keep your project as structured as possible. A well-structured project has the
following advantages:
Functions can be comprehended more easily and more quickly.
Others can find their way around in the project more quickly.
Faster and simpler troubleshooting.
Compilation of changes is processed more quickly.
Observe your nesting depth in your program. The deeper your nesting depth in a
block or a network, the less manageable the function and the more difficult it is to
Siemens AG 2017 All rights reserved
Use local variables as much as possible. This allows the blocks to be used
universally and modularly.
Use the exchange of data via the block interfaces (In, Out, InOut) to ensure the
re-usability of the blocks.
Use instance data blocks as local memory for the respective function block.
Other blocks should not write to instance data blocks (Fig. 3-3: Avoiding
access to instance data blocks).
Note If only the interfaces of the blocks are used for data exchange, it is ensured that
all of the blocks can be used independently of one another.
Siemens AG 2017 All rights reserved
Optimized global DBs of a PLC 1500 are significantly more powerful than the flag
area, which is not optimized due to compatibility reasons.
Working with flags (including system and cycle flags) is problematic, because each
controller has a differently sized flag area.
Therefore, do not use flags for programming. Instead, always use global data
blocks and IEC counters and timers (Fig. 3-5: IEC Timer in STEP 7 (TIA Portal)) in
connection with multi-instances instead of cycle flags. Thus, the program remains
universally usable and you ensure that your blocks can be used on all controllers
problem-free and without any further adaptations.
The inspector window (Fig. 4-1: Inspector window) is one of the most important
elements in STEP 7 (TIA Portal); additional information on a selected object or on
executed actions is displayed.
1 2 3
4
Siemens AG 2017 All rights reserved
1 "Properties" tab
2 "Info" tab
3 "Diagnostics" tab
4 Area navigation in the "Properties" tab
5 Content of the "Properties" tab
"Properties" tab
This tab displays the properties of the selected object. You can change editable
properties here.
"Info" tab
This tab displays additional information on the object selected, as well as alarms on
the actions executed (such as compiling).
"Diagnostics" tab
This tab provides information on system diagnostics events, configured alarm
events, and connection diagnostics.
4.1.2 Library
You store objects that you want to reuse in the libraries. For each project, there is a
project library that is integrated into the project. In addition to the project library,
you can create any number of global libraries, which can be used across projects.
The libraries are mutually compatible, which means that you can copy and move
library elements between the libraries. With the aid of libraries you create, for
example, templates for blocks, which you first insert into the project library and
further develop them there. Lastly, you copy the blocks from the project library to a
global library. You provide the global libraries to other employees in your project.
They use the blocks further and adapt them to their personal requirements, if
applicable.
Both the project library and global libraries distinguish between two different types
of objects:
Siemens AG 2017 All rights reserved
Copy templates
Almost any object can be saved as copy template and re-inserted into the
project later. You can, for example, save entire devices with their contents or
cover sheets as copy templates for the system documentation.
Types
Elements which are necessary for the execution of user programs, e.g. blocks,
PLC data types, HMI user data types or image blocks, are suitable as types.
Types can be versioned and support professional further development.
Projects in which the types are used can be updated once new versions of the
types are available.
More on libraries can be found in the system manual "STEP 7 Professional V1x".
With the aid of the version management of types, you have the capability of
centrally developing types and rolling out the latest version to the individual
projects as updates. In this way, error corrections and function expansions can be
easily integrated into existing projects. If you have created a new version of a
global library, you update existing projects in an automatic process.
As a result, errors are minimized and the effort for maintaining large automation
solutions with many individual projects is reduced. More on version management
and its handling can be found in the system manual "STEP 7 Professional V1x".
In STEP 7 (TIA Portal), it is possible to create different groups in the project and to
thus sort your blocks. You can create further folders in the "Program blocks" folder
via the shortcut menu. With the aid of these so-called "Groups" you can design
your project in a more manageable way.
Simply move your blocks into the created groups using drag & drop. One option for
sorting would be to first divide the blocks into basic program blocks and user
program blocks. In the two existing groups, you can then further differentiate
between the different block types. (Fig. 4-2: Example of sorting the program
blocks).
4.2 Configuration
4.2.1 Addressing of the machine control panel
To keep the project in STEP 7 (TIA Portal) consistent, it is advisable to include the
machine control panel in the hardware configuration.
Requirement
The current version of the general station description (GSD/GSDML) files to be
installed is stored on your PG/PC.
Fig. 4-6: Table for the input image for the MCP 483C PN
Fig. 4-8: Converted input and output image in the DB for MCP 483C PN
connections
In STEP 7 V5.x, you open NetPro to In the TIA Portal, you can edit
edit connections. connections in the net view under
"Connections".
Creating SINUMERIK Extended functionality
archives
In STEP 7 V5.x, you can create In addition to the SINUMERIK PLC
SINUMERIK PLC hardware upgrade archives known from STEP 7 V5.x, you
archives and PLC commissioning can now create PLC reload archives in
archives to obtain precompiled data which a selection of program blocks is
for use with SINUMERIK Operate. saved.
Accessing Changed handling
PLC
machine data In STEP 7 V5.x, you can use absolute In the TIA Portal, you can symbolically
symbolically addressing to access elements of the directly access block elements of the
DB20 (interface for PLC machine DB20 and so access the PLC machine
data). You can use the symbol table data when you add and declare the
to symbolically address the DB20. DB20 in the project.
The DB20 is created at runtime on the
controller.
Requirements:
STEP 7 V5.5 SP2 HF4 (or later) and STEP 7 (TIA Portal) are installed on the
PG/PC.
Or the project has been converted to the format .amxx with the migration tool
(see the information system of the TIA Portal, keyword "Migration tool").
All option packages used to create the project in STEP 7 V5.x are installed and
licensed (e.g. the option package for SCL);
specific information concerning the migration of other option packages is
contained in the associated documentation.
Siemens AG 2017 All rights reserved
Migration procedure
The procedure is divided into different sections (Fig. 6-1: Migration steps, which
can all be processed in succession.
Start
Check hardware
and components
with Readyness
Check Tool
Ok
Check block
consistency
Siemens AG 2017 All rights reserved
Rectify
inconsistency,
Result Not ok
create user data
block
Ok
Migrate project
correct
in V5.x
Follow up
Result Not ok information in
migrate log
Ok
correction way
Follow up
Result Not ok information in
compile log
Ok
End
STEP 7 V5.x
1. Check the hardware components with the Readiness Check Tool (reference
date Oct. 1, 2007).
2. Bring the project to be migrated to SINUMERIK 840D sl Toolbox 4.5 SP2 (or
higher) for STEP 7 V5.5 SP2 HF4 (or higher).
3. You can migrate projects with protected blocks in the TIA Portal.
Note Save your user data blocks from the basic program in your project beforehand.
To do this, create a DB of the type with the associated UDT (e.g. UDT 31 for
Axis 1). You can use your own names or the names from the TIA Portal system
library as a symbolic name.
These can also be added after the migration from the SINUMERIK TIA Portal
Toolbox library with the default names. You can then keep the default name or
rename the blocks.
(See Chapter 3.2.3 Blocks in the project)
ATTENTION If you use your own names for the user data blocks from the basic
program, you must observe the following in STEP 7 (TIA Portal) when
updating or copying blocks:
After you have copied SINUMERIK basic program blocks into the project,
you must always delete your blocks (with user-defined names) and assign
your user-defined names to the newly copied blocks.
Examples:
An 8-byte Date_And_Time is copied in two halves of 4 bytes each instead of
using Blockmove.
Scratch flags are used with various types; better to clean up beforehand.
Note During the migration, it may happen that some networks cannot be displayed in
LAD or FBD. STEP 7 (TIA Portal) then converts the networks to STL.
The causes for this are often stricter type checks or missing implicit type
conversions.
This problem can be avoided through corresponding preliminary work in Classic,
but not during the migration.
The issues to be resolved may be difficult to find in STEP 7 V5.x. After the
migration, you can see in the inspection window which networks were not
imported in the original language. This allows you to search in the STEP 7 V5.x
project in a targeted manner, resolve the issue, and perform another migration.
Clear errors and warnings in the PLC program (see history of messages in
the inspection window after the compilation).
Once you have cleared all the errors and warnings, the migration is finished.
7 References
Table 7-1
Topic Title
\1\ Siemens Industry http://support.industry.siemens.com
Online Support
\2\ Download page of https://support.industry.siemens.com/cs/ww/de/view/109478721
the entry
\3\ Programming https://support.industry.siemens.com/cs/ww/en/view/81318674
style guide for S7-
1200/S7-1500
\4\ Programming http://support.automation.siemens.com/WW/view/en/81318674
guideline for S7-
1200/S7-1500
\5\ STEP 7 https://support.industry.siemens.com/cs/ww/en/view/1097471
Professional 36
V14SP1
\6\ SIMATIC S7-1200 https://support.industry.siemens.com/cs/ww/de/view/86630375
/ S7-1500
comparison list for
programming
languages
\7\ SINUMERIK https://support.industry.siemens.com/cs/ww/en/view/74607149
Siemens AG 2017 All rights reserved
840D sl operator
components
machine control
panels
\8\ Collection of https://support.industry.siemens.com/cs/document/56314851
relevant entries
for migration
\9\ Prerequisites for https://support.industry.siemens.com/cs/document/62100731
migration
8 Contact
Siemens AG
Digital Factory
Motion Control
SINUMERIK Support
DF MC MTS PPM
Frauenauracher Strasse 80
91056 Erlangen
Germany
9 History
Table 9-1
Version Date Revision
V1.0 06/2017 First edition
Siemens AG 2017 All rights reserved